Règlages des SMS
This commit is contained in:
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@@ -7,4 +7,7 @@
|
|||||||
<component name="PyPackaging">
|
<component name="PyPackaging">
|
||||||
<option name="earlyReleasesAsUpgrades" value="true" />
|
<option name="earlyReleasesAsUpgrades" value="true" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="PythonCompatibilityInspectionAdvertiser">
|
||||||
|
<option name="version" value="3" />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -103,7 +103,7 @@ def insert_gyro_log(lieu: str, etat: str, topic: str, payload_raw: str,
|
|||||||
try:
|
try:
|
||||||
cur = cnx.cursor()
|
cur = cnx.cursor()
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"INSERT INTO `Gyro` (Lieu, Sonde, Etat, Date, Topic, Payload, QoS, Retained) "
|
"INSERT INTO Sondes.Gyro (Lieu, Sonde, Etat, Date, Topic, Payload, QoS, Retained) "
|
||||||
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
|
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
|
||||||
(
|
(
|
||||||
lieu,
|
lieu,
|
||||||
@@ -124,7 +124,7 @@ def insert_gyro_log(lieu: str, etat: str, topic: str, payload_raw: str,
|
|||||||
cnx.close()
|
cnx.close()
|
||||||
|
|
||||||
def should_insert_gyro(lieu: str, etat: str, sonde: str = "Gyro") -> bool:
|
def should_insert_gyro(lieu: str, etat: str, sonde: str = "Gyro") -> bool:
|
||||||
sql = "SELECT Etat FROM `Gyro` WHERE Lieu=%s AND Sonde=%s ORDER BY Date DESC LIMIT 1"
|
sql = "SELECT Etat FROM Sondes.Gyro WHERE Lieu=%s AND Sonde=%s ORDER BY Date DESC LIMIT 1"
|
||||||
cnx = get_db()
|
cnx = get_db()
|
||||||
try:
|
try:
|
||||||
cur = cnx.cursor()
|
cur = cnx.cursor()
|
||||||
@@ -170,7 +170,7 @@ def lire_cfg_chambres(site: str):
|
|||||||
"""
|
"""
|
||||||
sql = """
|
sql = """
|
||||||
SELECT Sonde, Temp_Max, Etat, En_entretien
|
SELECT Sonde, Temp_Max, Etat, En_entretien
|
||||||
FROM Chambres_froides
|
FROM Sondes.Chambres_froides
|
||||||
WHERE Lieu=%s
|
WHERE Lieu=%s
|
||||||
"""
|
"""
|
||||||
cnx = get_db()
|
cnx = get_db()
|
||||||
@@ -208,7 +208,7 @@ def compute_site_alarm(last_values: list[dict], cfg: dict[str, dict], hysteresis
|
|||||||
def lire_seuils_depuis_db(site: str):
|
def lire_seuils_depuis_db(site: str):
|
||||||
sql = """
|
sql = """
|
||||||
SELECT Sonde, Temp_Max
|
SELECT Sonde, Temp_Max
|
||||||
FROM Chambres_froides
|
FROM Sondes.Chambres_froides
|
||||||
WHERE Lieu=%s AND Etat='ON'
|
WHERE Lieu=%s AND Etat='ON'
|
||||||
"""
|
"""
|
||||||
cnx = get_db()
|
cnx = get_db()
|
||||||
@@ -791,7 +791,8 @@ class GyroPulseController:
|
|||||||
log.info("Gyro → ON déclenché par %s: %.2f > %.2f (mode %s)",
|
log.info("Gyro → ON déclenché par %s: %.2f > %.2f (mode %s)",
|
||||||
s, t, se, "CONTINU" if os.getenv("GYRO_MODE_CONTINUOUS","1")=="1" else "PULSE")
|
s, t, se, "CONTINU" if os.getenv("GYRO_MODE_CONTINUOUS","1")=="1" else "PULSE")
|
||||||
# SMS alerte immédiat
|
# SMS alerte immédiat
|
||||||
self._send_alert_sms(trigger)
|
if os.getenv("ALERT_INTERNAL_SMS_ENABLED", "0") == "1":
|
||||||
|
self._send_alert_sms(trigger)
|
||||||
|
|
||||||
elif self.state == _GyroState.PULSE_ON:
|
elif self.state == _GyroState.PULSE_ON:
|
||||||
if not active:
|
if not active:
|
||||||
@@ -802,7 +803,8 @@ class GyroPulseController:
|
|||||||
self._normal_count = 0
|
self._normal_count = 0
|
||||||
log.info("Gyro → OFF (retour à la normale confirmé)")
|
log.info("Gyro → OFF (retour à la normale confirmé)")
|
||||||
# SMS OK immédiat
|
# SMS OK immédiat
|
||||||
self._send_ok_sms_from_last_trigger()
|
if os.getenv("ALERT_OK_SMS_GYRO", "0") == "1":
|
||||||
|
self._send_ok_sms_from_last_trigger()
|
||||||
else:
|
else:
|
||||||
self._normal_count = 0
|
self._normal_count = 0
|
||||||
if os.getenv("GYRO_MODE_CONTINUOUS", "1") != "1":
|
if os.getenv("GYRO_MODE_CONTINUOUS", "1") != "1":
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ def lire_cfg_chambres(site: str):
|
|||||||
"""
|
"""
|
||||||
sql = """
|
sql = """
|
||||||
SELECT Sonde, Temp_Max, Etat, En_entretien
|
SELECT Sonde, Temp_Max, Etat, En_entretien
|
||||||
FROM Chambres_froides
|
FROM Sondes.Chambres_froides
|
||||||
WHERE Lieu=%s
|
WHERE Lieu=%s
|
||||||
"""
|
"""
|
||||||
cnx = get_db()
|
cnx = get_db()
|
||||||
@@ -208,7 +208,7 @@ def compute_site_alarm(last_values: list[dict], cfg: dict[str, dict], hysteresis
|
|||||||
def lire_seuils_depuis_db(site: str):
|
def lire_seuils_depuis_db(site: str):
|
||||||
sql = """
|
sql = """
|
||||||
SELECT Sonde, Temp_Max
|
SELECT Sonde, Temp_Max
|
||||||
FROM Chambres_froides
|
FROM Sondes.Chambres_froides
|
||||||
WHERE Lieu=%s AND Etat='ON'
|
WHERE Lieu=%s AND Etat='ON'
|
||||||
"""
|
"""
|
||||||
cnx = get_db()
|
cnx = get_db()
|
||||||
@@ -789,9 +789,10 @@ class GyroPulseController:
|
|||||||
if trigger:
|
if trigger:
|
||||||
s, t, se = trigger
|
s, t, se = trigger
|
||||||
log.info("Gyro → ON déclenché par %s: %.2f > %.2f (mode %s)",
|
log.info("Gyro → ON déclenché par %s: %.2f > %.2f (mode %s)",
|
||||||
s, t, se, "CONTINU" if os.getenv("GYRO_MODE_CONTINUOUS","1")=="1" else "PULSE")
|
s, t, se, "CONTINU" if os.getenv("GYRO_MODE_CONTINUOUS", "1") == "1" else "PULSE")
|
||||||
# SMS alerte immédiat
|
# SMS alerte immédiat (optionnel)
|
||||||
self._send_alert_sms(trigger)
|
if os.getenv("ALERT_INTERNAL_SMS_ENABLED", "0") == "1":
|
||||||
|
self._send_alert_sms(trigger)
|
||||||
|
|
||||||
elif self.state == _GyroState.PULSE_ON:
|
elif self.state == _GyroState.PULSE_ON:
|
||||||
if not active:
|
if not active:
|
||||||
@@ -802,7 +803,8 @@ class GyroPulseController:
|
|||||||
self._normal_count = 0
|
self._normal_count = 0
|
||||||
log.info("Gyro → OFF (retour à la normale confirmé)")
|
log.info("Gyro → OFF (retour à la normale confirmé)")
|
||||||
# SMS OK immédiat
|
# SMS OK immédiat
|
||||||
self._send_ok_sms_from_last_trigger()
|
if os.getenv("ALERT_OK_SMS_GYRO", "0") == "1":
|
||||||
|
self._send_ok_sms_from_last_trigger()
|
||||||
else:
|
else:
|
||||||
self._normal_count = 0
|
self._normal_count = 0
|
||||||
if os.getenv("GYRO_MODE_CONTINUOUS", "1") != "1":
|
if os.getenv("GYRO_MODE_CONTINUOUS", "1") != "1":
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ import pandas as pd
|
|||||||
pd.set_option('future.no_silent_downcasting', True)
|
pd.set_option('future.no_silent_downcasting', True)
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
from dotenv import load_dotenv
|
from dotenv import find_dotenv, load_dotenv
|
||||||
|
env_file = find_dotenv(usecwd=True)
|
||||||
|
if env_file:
|
||||||
|
load_dotenv(env_file)
|
||||||
from fpdf import FPDF
|
from fpdf import FPDF
|
||||||
|
|
||||||
# =========================================================
|
# =========================================================
|
||||||
@@ -45,7 +48,7 @@ def fetch_gyro(site: str):
|
|||||||
"""Retourne (etat, ts) depuis la vue v_gyro_last pour le site donné."""
|
"""Retourne (etat, ts) depuis la vue v_gyro_last pour le site donné."""
|
||||||
q = """
|
q = """
|
||||||
SELECT Etat, `Date`
|
SELECT Etat, `Date`
|
||||||
FROM v_gyro_last
|
FROM Sondes.v_gyro_last
|
||||||
WHERE Lieu = %s AND Sonde = 'Gyro'
|
WHERE Lieu = %s AND Sonde = 'Gyro'
|
||||||
ORDER BY `Date` DESC
|
ORDER BY `Date` DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
|
|||||||
Reference in New Issue
Block a user