From ba07111d88a14f6fc77cbc6db98441e92d25fa49 Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Fri, 3 May 2024 21:00:35 -0400 Subject: [PATCH 1/2] Refactor Check_tarif MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La fonction était rendue trop complexe pour linter et en menait trop large inutilement. J'ai séparé la partie du unknown source tracker complètement car selon moi ça devrait être géré à part puisque c'est optionnel comme fonctionalité. --- custom_components/hilo/__init__.py | 11 ++++++++--- custom_components/hilo/manifest.json | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/custom_components/hilo/__init__.py b/custom_components/hilo/__init__.py index 6da5a97..d2c625c 100755 --- a/custom_components/hilo/__init__.py +++ b/custom_components/hilo/__init__.py @@ -511,6 +511,9 @@ async def async_update(self) -> None: if self.generate_energy_meters or self.track_unknown_sources: self.check_tarif() + if self.track_unknown_sources: + self.handle_unknown_power() + def find_meter(self, hass): entity_registry_dict = {} @@ -600,6 +603,11 @@ def check_tarif(self): LOG.debug( f"check_tarif: Current plan: {plan_name} Target Tarif: {tarif} Energy used: {energy_used.state} Peak: {self.high_times}" ) + for state in self._hass.states.async_all(): + entity = state.entity_id + self.set_tarif(entity, state.state, tarif) + + def handle_unknown_power(self): known_power = 0 smart_meter = self.find_meter(self._hass) # comes from find_meter function LOG.debug(f"Smart meter used currently is: {smart_meter}") @@ -609,9 +617,6 @@ def check_tarif(self): if entity.endswith("hilo_rate_current"): continue - if self.generate_energy_meters: - self.set_tarif(entity, state.state, tarif) - if entity.endswith("_power") and entity not in [ unknown_source_tracker, smart_meter, diff --git a/custom_components/hilo/manifest.json b/custom_components/hilo/manifest.json index 02a5d44..1afbdfc 100755 --- a/custom_components/hilo/manifest.json +++ b/custom_components/hilo/manifest.json @@ -12,5 +12,5 @@ "iot_class": "cloud_push", "issue_tracker": "https://github.com/dvd-dev/hilo/issues", "requirements": ["python-hilo>=2024.4.1"], - "version": "2024.5.1" + "version": "2024.5.2" } From 71a05e97574c2e68b5a8476f104ff62fab9c7323 Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Sat, 4 May 2024 07:25:41 -0400 Subject: [PATCH 2/2] Ajout de commentaires Pour clarifier un peu --- custom_components/hilo/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/custom_components/hilo/__init__.py b/custom_components/hilo/__init__.py index d2c625c..983ccd7 100755 --- a/custom_components/hilo/__init__.py +++ b/custom_components/hilo/__init__.py @@ -603,11 +603,14 @@ def check_tarif(self): LOG.debug( f"check_tarif: Current plan: {plan_name} Target Tarif: {tarif} Energy used: {energy_used.state} Peak: {self.high_times}" ) + + # ic-dev21 : make sure the select for all meters still work by moving this here for state in self._hass.states.async_all(): entity = state.entity_id self.set_tarif(entity, state.state, tarif) def handle_unknown_power(self): + # ic-dev21 : new function that takes care of the unknown source meter known_power = 0 smart_meter = self.find_meter(self._hass) # comes from find_meter function LOG.debug(f"Smart meter used currently is: {smart_meter}")