This commit is contained in:
Your Name
2025-05-23 17:22:37 +02:00
parent b93f205fd4
commit c6a8b02c38
2 changed files with 40 additions and 10 deletions

View File

@@ -91,7 +91,7 @@
</div> </div>
<div class="form-check mb-3"> <div class="form-check mb-3">
<input class="form-check-input" type="checkbox" value="" id="check_envea" onchange="update_config_sqlite('envea', this.checked)"> <input class="form-check-input" type="checkbox" value="" id="check_envea" onchange="update_config_sqlite('envea', this.checked);add_sondeEnveaContainer() ">
<label class="form-check-label" for="check_envea"> <label class="form-check-label" for="check_envea">
Send Envea sensor data Send Envea sensor data
</label> </label>
@@ -342,6 +342,11 @@ window.onload = function() {
checkbox_wind.checked = response["windMeter"]; checkbox_wind.checked = response["windMeter"];
checkbox_uSpot.checked = response["send_uSpot"]; checkbox_uSpot.checked = response["send_uSpot"];
// If envea is enabled, show the envea sondes container
if (response["envea"]) {
add_sondeEnveaContainer();
}
}, },
error: function(xhr, status, error) { error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error); console.error('AJAX request failed:', status, error);
@@ -726,11 +731,14 @@ function add_sondeEnveaContainer() {
onchange="updateSondeStatus(${sonde.id}, this.checked)"> onchange="updateSondeStatus(${sonde.id}, this.checked)">
</div> </div>
<input type="text" class="form-control" placeholder="Name" value="${sonde.name}" <input type="text" class="form-control" placeholder="Name" value="${sonde.name}"
id="${sondeId}_name" onchange="updateSondeName(${sonde.id}, this.value)"> id="${sondeId}_name" readonly style="background-color: #f8f9fa;">
<input type="text" class="form-control" placeholder="Port" value="${sonde.port}" <select class="form-control" id="${sondeId}_port" onchange="updateSondePort(${sonde.id}, this.value)">
id="${sondeId}_port" onchange="updateSondePort(${sonde.id}, this.value)"> <option value="ttyAMA3" ${sonde.port === 'ttyAMA3' ? 'selected' : ''}>ttyAMA3</option>
<option value="ttyAMA4" ${sonde.port === 'ttyAMA4' ? 'selected' : ''}>ttyAMA4</option>
<option value="ttyAMA5" ${sonde.port === 'ttyAMA5' ? 'selected' : ''}>ttyAMA5</option>
</select>
<input type="number" class="form-control" placeholder="Coefficient" value="${sonde.coefficient}" <input type="number" class="form-control" placeholder="Coefficient" value="${sonde.coefficient}"
id="${sondeId}_coefficient" onchange="updateSondeCoefficient(${sonde.id}, this.value)"> id="${sondeId}_coefficient" readonly style="background-color: #f8f9fa;">
</div> </div>
`; `;

View File

@@ -56,7 +56,21 @@ for key, value, value_type in config_entries:
(key, value, value_type) (key, value, value_type)
) )
# Insert envea sondes # Clean up duplicate envea sondes first (keep only first occurrence of each name)
print("Cleaning up duplicate envea sondes...")
cursor.execute("""
DELETE FROM envea_sondes_table
WHERE id NOT IN (
SELECT MIN(id)
FROM envea_sondes_table
GROUP BY name
)
""")
deleted_count = cursor.rowcount
if deleted_count > 0:
print(f"Deleted {deleted_count} duplicate envea sonde entries")
# Insert envea sondes (only if they don't already exist)
envea_sondes = [ envea_sondes = [
(False, "ttyAMA4", "h2s", 4), (False, "ttyAMA4", "h2s", 4),
(False, "ttyAMA3", "no2", 1), (False, "ttyAMA3", "no2", 1),
@@ -64,10 +78,18 @@ envea_sondes = [
] ]
for connected, port, name, coefficient in envea_sondes: for connected, port, name, coefficient in envea_sondes:
cursor.execute( # Check if sensor with this name already exists
"INSERT OR IGNORE INTO envea_sondes_table (connected, port, name, coefficient) VALUES (?, ?, ?, ?)", cursor.execute("SELECT COUNT(*) FROM envea_sondes_table WHERE name = ?", (name,))
(1 if connected else 0, port, name, coefficient) exists = cursor.fetchone()[0] > 0
)
if not exists:
cursor.execute(
"INSERT INTO envea_sondes_table (connected, port, name, coefficient) VALUES (?, ?, ?, ?)",
(1 if connected else 0, port, name, coefficient)
)
print(f"Added envea sonde: {name}")
else:
print(f"Envea sonde '{name}' already exists, skipping")
# Commit and close the connection # Commit and close the connection