diff --git a/custom_components/apiEnedis/sensorEnedis.py b/custom_components/apiEnedis/sensorEnedis.py index 81739c8..6117092 100644 --- a/custom_components/apiEnedis/sensorEnedis.py +++ b/custom_components/apiEnedis/sensorEnedis.py @@ -413,6 +413,20 @@ def getStatus(self, typeSensor=_consommation): # noqa C901 status["errorLastCall"] = data.getCardErrorLastCall() status["errorLastCallInterne"] = data.getErrorLastCall() + if ( + (lastYear is not None) + and (lastYear != 0) + and (currYear is not None) + ): + valeur = ( + 100 + * (currYear - lastYear) + / lastYear + ) + status["year_evolution"] = f"{valeur:.3f}" + else: + status["year_evolution"] = 0 + if ( (lastMonthLastYear is not None) and (lastMonthLastYear != 0) diff --git a/testEnedis.py b/testEnedis.py index d58b019..d78b8b9 100644 --- a/testEnedis.py +++ b/testEnedis.py @@ -36,7 +36,7 @@ def testMulti(): mon_conteneur = configparser.ConfigParser() mon_conteneur.read("../myCredential/security.txt") - for qui in ["ENEDIS100"]: + for qui in ["ENEDIS102"]: LOGGER.info(f"*** traitement de {qui} ") token = mon_conteneur[qui]["TOKEN"] PDL_ID = mon_conteneur[qui]["CODE"] @@ -44,7 +44,7 @@ def testMulti(): if "SERVICE" in mon_conteneur[qui].keys(): serviceEnedis = mon_conteneur[qui]["SERVICE"] - print(mon_conteneur[qui]["QUI"]) + print(mon_conteneur[qui]["QUI"], serviceEnedis) heureCreusesCh = ast.literal_eval("[['00:00','05:00'], ['22:00', '24:00']]") heuresCreusesON = True diff --git a/tests/test_myEnedis.py b/tests/test_myEnedis.py index 6402cad..e1bb0e6 100644 --- a/tests/test_myEnedis.py +++ b/tests/test_myEnedis.py @@ -348,6 +348,7 @@ def test_update_data(caplog, tmpdir): "errorLastCall": "", "errorLastCallInterne": "", "monthly_evolution": "-3.990", + "year_evolution": "-78.023", "current_week_evolution": "-11.906", "current_month_evolution": "-7.119", "yesterday_evolution": "-20.122",