diff --git a/apps/meters_to_ha/meters_to_ha.py b/apps/meters_to_ha/meters_to_ha.py index d9284bf..8e48c30 100755 --- a/apps/meters_to_ha/meters_to_ha.py +++ b/apps/meters_to_ha/meters_to_ha.py @@ -1662,8 +1662,8 @@ def get_veolia_idf_file(self): r"//span[" r"contains(text(), 'Alertes de consommation')" + r" or contains(text(), 'Contrats')" - + r" or contains(text(), 'consulter l\'historique')" - + r' or contains(translate(text(), "CLH", "clh"), "consulter l\'historique")' + + r" or contains(text(), 'consulter l')" + + r' or contains(translate(text(), "CLH", "clh"), "consulter l")' + r"]", ) ) @@ -2613,7 +2613,6 @@ def parse_veolia_historical_data(self, csv_file, website): # Remove the first row (header) from the list that is not useful rows = rows[1:] - last_total = 0 # Set date format for service (IDF || service.eau.veolia.fr) if website == SERVICE_EAU_VEOLIA_FR: @@ -2624,10 +2623,8 @@ def parse_veolia_historical_data(self, csv_file, website): for row in rows: method = row[3] # "Mesuré" or "Estimé" if method in ("E", "Estimé"): - # Ignore estimated index (we use the last total) - meter_total = last_total + int(row[2]) - else: - meter_total = int(row[1]) + int(row[2]) + # Ignore estimated values + continue date_obj = dt.datetime.strptime(row[0], date_format) @@ -2640,11 +2637,10 @@ def parse_veolia_historical_data(self, csv_file, website): stat = { "start": date_formatted, # formatted date "state": int(row[2]), - "sum": meter_total, + "sum": int(row[1]) } # Add the stat to the array stats_array.append(stat) - last_total = meter_total self.mylog(st="OK") return stats_array @@ -3086,19 +3082,51 @@ def sanity_check(self): ) def update_veolia_historical_data(self, stats_array): - # Prepare the statistics that need to be sent + # Prepare the statistics that need to be sent for _period_total + + total_stats = [ + {"start": stat["start"], "state": stat["sum"]} + for stat in stats_array + ] data = { "has_mean": False, - "has_sum": True, + "has_sum": False, "statistic_id": ( "sensor.veolia_%s_total" % self.configuration[PARAM_VEOLIA_CONTRACT] ), "unit_of_measurement": "L", "source": "recorder", - "stats": stats_array, + "stats": total_stats, } - self.mylog("Publish all the historical data in the statistics") + + self.mylog(f"Publish all the historical data in the statistics of _total sensor : {total_stats}") + self.open_url(HA_API_STATISTICS, data) + self.mylog(st="OK") + + # Prepare the statistics that need to be sent + period_stats = [ + { + "start": stat["start"], + "state": stat["state"], + "mean": stat["state"], + "min": stat["state"], + "max": stat["state"] + } + for stat in stats_array + ] + data = { + "has_mean": True, + "has_sum": False, + "statistic_id": ( + "sensor.veolia_%s_period_total" + % self.configuration[PARAM_VEOLIA_CONTRACT] + ), + "unit_of_measurement": "L", + "source": "recorder", + "stats": period_stats, + } + self.mylog(f"Publish all the historical data in the statistics of _period_total sensor : {period_stats}") self.open_url(HA_API_STATISTICS, data) self.mylog(st="OK")