From 48a4aed734f43e1a57112f225ad7c5f9d0e244f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20VALENTIN?= Date: Mon, 5 Feb 2024 20:38:29 +0100 Subject: [PATCH 1/3] ci: fix --- .github/workflows/semantic_prerelease.yaml | 1 + .github/workflows/semantic_release.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/semantic_prerelease.yaml b/.github/workflows/semantic_prerelease.yaml index 8a0da0a6..0d3a24d1 100644 --- a/.github/workflows/semantic_prerelease.yaml +++ b/.github/workflows/semantic_prerelease.yaml @@ -13,6 +13,7 @@ jobs: PRE_RELEASE: true Trig-Generate-Pre-Release: + needs: ["Semantic-Pre-Release"] runs-on: ubuntu-latest steps: - name: Repository Dispatch diff --git a/.github/workflows/semantic_release.yaml b/.github/workflows/semantic_release.yaml index c7b59700..480aceba 100644 --- a/.github/workflows/semantic_release.yaml +++ b/.github/workflows/semantic_release.yaml @@ -11,6 +11,7 @@ jobs: PRE_RELEASE: false Trig-Generate-Release: + needs: ["Semantic-Release"] runs-on: ubuntu-latest steps: - name: Repository Dispatch From ca54fa6ae2c51c4ad8acf6b11d3b11e0d1843449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20VALENTIN?= Date: Tue, 6 Feb 2024 00:14:32 +0100 Subject: [PATCH 2/3] ci: clean --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f683de9e..646ee84d 100755 --- a/Makefile +++ b/Makefile @@ -108,7 +108,7 @@ debug: init enable_debug up bootstrap down ## Start all external ressource necessary to debug (MQTT, InfluxDB,...) up: - docker compose -f dev/docker-compose.dev.yaml start + cd dev; docker compose up --force-recreate --detach; cd - ## Stop all external ressource necessary to debug (MQTT, InfluxDB,...) down: From bdee3e1796f3cadeea4dd998cce9433e6955b63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20VALENTIN?= Date: Tue, 6 Feb 2024 00:16:24 +0100 Subject: [PATCH 3/3] fix: tempo days color --- src/models/export_home_assistant.py | 11 ++++++++++ src/models/jobs.py | 4 ++-- src/models/query_tempo.py | 32 ++++++++++++++++++++++++++++- src/models/stat.py | 2 +- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/models/export_home_assistant.py b/src/models/export_home_assistant.py index 79124f2c..10952a07 100644 --- a/src/models/export_home_assistant.py +++ b/src/models/export_home_assistant.py @@ -644,6 +644,17 @@ def tempo_days(self): self.tempo_days_sensor(f"{color}", days) def tempo_days_sensor(self, color, days): + """ + Add a sensor to Home Assistant with the given name and state. + + Args: + color (str): The color of the tempo (e.g. blue, white, red). + days (int): The number of days in the tempo. + + Returns: + None + + """ uniq_id = f"myelectricaldata_tempo_days_{color}" self.sensor( topic=f"myelectricaldata_edf/tempo_days_{color}", diff --git a/src/models/jobs.py b/src/models/jobs.py index 38149aba..dc8d8aa5 100644 --- a/src/models/jobs.py +++ b/src/models/jobs.py @@ -371,8 +371,8 @@ def get_tempo(self): try: title(f"Récupération des données Tempo :") Tempo().fetch() - title(f"Récupération des jours Tempo :") - Tempo().fetch_day() + title(f"Calcul des jours Tempo :") + Tempo().calc_day() title(f"Récupération des tarifs Tempo :") Tempo().fetch_price() export_finish() diff --git a/src/models/query_tempo.py b/src/models/query_tempo.py index 380e6891..e273b3ed 100644 --- a/src/models/query_tempo.py +++ b/src/models/query_tempo.py @@ -1,7 +1,7 @@ import json import logging import traceback -from datetime import datetime +from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta @@ -18,6 +18,11 @@ def __init__(self): self.url = URL self.valid_date = datetime.combine(datetime.now() + relativedelta(days=1), datetime.min.time()) self.nb_check_day = 31 + self.total_tempo_days = { + "red": 22, + "white": 43, + "blue": 300, + } def run(self): start = (datetime.now() - relativedelta(years=3)).strftime("%Y-%m-%d") @@ -79,6 +84,31 @@ def fetch(self): return "OK" return result + def calc_day(self): + """ + Calculates the number of days left for each color based on the current date. + + Args: + None + + Returns: + A dictionary containing the number of days left for each color. + + """ + now = datetime.now() + begin = datetime.combine(now.replace(month=9, day=1), datetime.min.time()) + if now < begin: + begin = begin.replace(year=int(now.strftime("%Y")) - 1) + end = datetime.combine(begin - timedelta(hours=5), datetime.max.time()).replace( + year=int(begin.strftime("%Y")) + 1 + ) + current_tempo_day = self.db.get_tempo_range(begin=begin, end=end) + result = self.total_tempo_days + for day in current_tempo_day: + result[day.color.lower()] -= 1 + self.db.set_tempo_config("days", result) + return result + def fetch_day(self): target = f"{self.url}/edf/tempo/days" query_response = Query(endpoint=target).get() diff --git a/src/models/stat.py b/src/models/stat.py index b0156bc3..24831b7d 100644 --- a/src/models/stat.py +++ b/src/models/stat.py @@ -120,7 +120,7 @@ def tempo_color(self, index=0): end = datetime.combine(begin, datetime.max.time()) value = "" for data in self.db.get_tempo_range(begin, end): - logging.info(f"tempo data: {data}") + logging.debug(f"tempo data: {data}") value = value + data.color return { "value": value,