Fix BME280 and sensor cards not displaying

- Refactor sensor card creation to use config_table instead of non-existent config_scripts_table
- Fix BME280 card check: use config.BME280 instead of response["BME280/get_data_v2.py"]
- Fix NOISE card check: use config.NOISE instead of response.i2C_sound
- Fix Envea card check: use config.envea instead of response["envea/read_value_v2.py"]
- Create dedicated createSensorCards() function for cleaner code
- Remove obsolete get_config_scripts_sqlite AJAX call

Now sensor cards properly display based on config_table settings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
PaulVua
2026-01-05 17:49:02 +01:00
parent 954680ef6e
commit 906eaa851d

View File

@@ -273,6 +273,8 @@ function getBME280_values(){
window.onload = function() { window.onload = function() {
//NEW way to get config (SQLite) //NEW way to get config (SQLite)
let mainConfig = {}; // Store main config for use in sensor card creation
$.ajax({ $.ajax({
url: 'launcher.php?type=get_config_sqlite', url: 'launcher.php?type=get_config_sqlite',
dataType:'json', dataType:'json',
@@ -282,33 +284,32 @@ $.ajax({
console.log("Getting SQLite config table:"); console.log("Getting SQLite config table:");
console.log(response); console.log(response);
mainConfig = response; // Store for later use
//device name_side bar //device name_side bar
const elements = document.querySelectorAll('.sideBar_sensorName'); const elements = document.querySelectorAll('.sideBar_sensorName');
elements.forEach((element) => { elements.forEach((element) => {
element.innerText = response.deviceName; element.innerText = response.deviceName;
}); });
// After getting main config, create sensor cards
createSensorCards(mainConfig);
}, },
error: function(xhr, status, error) { error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error); console.error('AJAX request failed:', status, error);
} }
});//end AJAX });//end AJAX
//getting config_scripts table //Function to create sensor cards based on config
$.ajax({ function createSensorCards(config) {
url: 'launcher.php?type=get_config_scripts_sqlite', console.log("Creating sensor cards with config:");
dataType:'json', console.log(config);
//dataType: 'json', // Specify that you expect a JSON response
method: 'GET', // Use GET or POST depending on your needs
success: function(response) {
console.log("Getting SQLite config scripts table:");
console.log(response);
const container = document.getElementById('card-container'); // Conteneur des cartes const container = document.getElementById('card-container'); // Conteneur des cartes
//creates NPM card (by default) //creates NPM card (by default)
const cardHTML = ` const cardHTML = `
<div class="col-sm-3"> <div class="col-sm-3">
<div class="card"> <div class="card">
@@ -327,12 +328,12 @@ error: function(xhr, status, error) {
</div> </div>
</div> </div>
</div>`; </div>`;
container.innerHTML += cardHTML; // Add the I2C card if condition is met container.innerHTML += cardHTML; // Add the I2C card if condition is met
//creates i2c BME280 card //creates i2c BME280 card
if (response["BME280/get_data_v2.py"]) { if (config.BME280) {
const i2C_BME_HTML = ` const i2C_BME_HTML = `
<div class="col-sm-3"> <div class="col-sm-3">
<div class="card"> <div class="card">
@@ -356,7 +357,7 @@ error: function(xhr, status, error) {
} }
//creates i2c sound card //creates i2c sound card
if (response.i2C_sound) { if (config.NOISE) {
const i2C_HTML = ` const i2C_HTML = `
<div class="col-sm-3"> <div class="col-sm-3">
<div class="card"> <div class="card">
@@ -383,7 +384,7 @@ error: function(xhr, status, error) {
//Si on a des SONDES ENVEA connectée il faut faire un deuxième call dans la table envea_sondes_table //Si on a des SONDES ENVEA connectée il faut faire un deuxième call dans la table envea_sondes_table
//creates ENVEA cards //creates ENVEA cards
if (response["envea/read_value_v2.py"]) { if (config.envea) {
console.log("Need to display ENVEA sondes"); console.log("Need to display ENVEA sondes");
//getting config_scripts table //getting config_scripts table
$.ajax({ $.ajax({
@@ -429,14 +430,9 @@ error: function(xhr, status, error) {
});//end AJAX envea Sondes });//end AJAX envea Sondes
}//end if }//end if envea
}, } // end createSensorCards function
error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error);
}
});//end AJAX (config_scripts)
//get local RTC //get local RTC
$.ajax({ $.ajax({