update
This commit is contained in:
@@ -56,7 +56,21 @@ for key, value, value_type in config_entries:
|
||||
(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 = [
|
||||
(False, "ttyAMA4", "h2s", 4),
|
||||
(False, "ttyAMA3", "no2", 1),
|
||||
@@ -64,10 +78,18 @@ envea_sondes = [
|
||||
]
|
||||
|
||||
for connected, port, name, coefficient in envea_sondes:
|
||||
cursor.execute(
|
||||
"INSERT OR IGNORE INTO envea_sondes_table (connected, port, name, coefficient) VALUES (?, ?, ?, ?)",
|
||||
(1 if connected else 0, port, name, coefficient)
|
||||
)
|
||||
# Check if sensor with this name already exists
|
||||
cursor.execute("SELECT COUNT(*) FROM envea_sondes_table WHERE name = ?", (name,))
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user