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() {
//NEW way to get config (SQLite)
let mainConfig = {}; // Store main config for use in sensor card creation
$.ajax({
url: 'launcher.php?type=get_config_sqlite',
dataType:'json',
@@ -282,6 +284,7 @@ $.ajax({
console.log("Getting SQLite config table:");
console.log(response);
mainConfig = response; // Store for later use
//device name_side bar
const elements = document.querySelectorAll('.sideBar_sensorName');
@@ -289,21 +292,19 @@ $.ajax({
element.innerText = response.deviceName;
});
// After getting main config, create sensor cards
createSensorCards(mainConfig);
},
error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error);
}
});//end AJAX
//getting config_scripts table
$.ajax({
url: 'launcher.php?type=get_config_scripts_sqlite',
dataType:'json',
//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);
//Function to create sensor cards based on config
function createSensorCards(config) {
console.log("Creating sensor cards with config:");
console.log(config);
const container = document.getElementById('card-container'); // Conteneur des cartes
@@ -332,7 +333,7 @@ error: function(xhr, status, error) {
//creates i2c BME280 card
if (response["BME280/get_data_v2.py"]) {
if (config.BME280) {
const i2C_BME_HTML = `
<div class="col-sm-3">
<div class="card">
@@ -356,7 +357,7 @@ error: function(xhr, status, error) {
}
//creates i2c sound card
if (response.i2C_sound) {
if (config.NOISE) {
const i2C_HTML = `
<div class="col-sm-3">
<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
//creates ENVEA cards
if (response["envea/read_value_v2.py"]) {
if (config.envea) {
console.log("Need to display ENVEA sondes");
//getting config_scripts table
$.ajax({
@@ -429,14 +430,9 @@ error: function(xhr, status, error) {
});//end AJAX envea Sondes
}//end if
}//end if envea
},
error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error);
}
});//end AJAX (config_scripts)
} // end createSensorCards function
//get local RTC
$.ajax({