From e233fe867c8c660affd8c89a665b2ac0ffdaf3b4 Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Thu, 27 Jun 2024 19:03:53 -0400 Subject: [PATCH 1/2] Fix pour issue #442 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Causé par un upstream PR dans le codebase de HA. Voir home-assistant/core##110685 --- custom_components/hilo/const.py | 1 + custom_components/hilo/manifest.json | 2 +- custom_components/hilo/sensor.py | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/custom_components/hilo/const.py b/custom_components/hilo/const.py index 7f3518a..6a86e7e 100755 --- a/custom_components/hilo/const.py +++ b/custom_components/hilo/const.py @@ -42,6 +42,7 @@ # Note ic-dev21: we'll stay at 300 until proper fix EVENT_SCAN_INTERVAL_REDUCTION = 300 NOTIFICATION_SCAN_INTERVAL = 1800 +MAX_SUB_INTERVAL = 120 MIN_SCAN_INTERVAL = 60 REWARD_SCAN_INTERVAL = 7200 diff --git a/custom_components/hilo/manifest.json b/custom_components/hilo/manifest.json index 5c1d72c..3005cba 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.6.1"], - "version": "2024.6.2" + "version": "2024.7.1" } diff --git a/custom_components/hilo/sensor.py b/custom_components/hilo/sensor.py index c9fc4d9..2a71e98 100755 --- a/custom_components/hilo/sensor.py +++ b/custom_components/hilo/sensor.py @@ -55,6 +55,7 @@ HILO_ENERGY_TOTAL, HILO_SENSOR_CLASSES, LOG, + MAX_SUB_INTERVAL, NOTIFICATION_SCAN_INTERVAL, REWARD_SCAN_INTERVAL, TARIFF_LIST, @@ -294,6 +295,7 @@ def __init__(self, hilo, device): super().__init__( integration_method=METHOD_LEFT, + max_sub_interval=timedelta(seconds=MAX_SUB_INTERVAL), name=self._attr_name, round_digits=2, source_entity=self._source, From d54af954405fc3cd4c4489198e5d6c21779dd400 Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:45:41 -0400 Subject: [PATCH 2/2] Adding version "error-check" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Si on met à jour le custom component à 2024.7.1 sans avoir au moins HA 2024.7.X, le component brisait. Cette boucle if permet de conserver l'ancienne logique si la version est plus vieille. C'est pas joli mais ça marche. --- custom_components/hilo/sensor.py | 36 ++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/custom_components/hilo/sensor.py b/custom_components/hilo/sensor.py index 2a71e98..ed1ac9e 100755 --- a/custom_components/hilo/sensor.py +++ b/custom_components/hilo/sensor.py @@ -24,6 +24,7 @@ UnitOfPower, UnitOfSoundPressure, UnitOfTemperature, + __short_version__ as current_version, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceInfo @@ -32,6 +33,7 @@ from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.util import Throttle, slugify import homeassistant.util.dt as dt_util +from packaging.version import Version from pyhilo.const import UNMONITORED_DEVICES from pyhilo.device import HiloDevice from pyhilo.event import Event @@ -293,17 +295,29 @@ def __init__(self, hilo, device): identifiers={(DOMAIN, self._device.identifier)}, ) - super().__init__( - integration_method=METHOD_LEFT, - max_sub_interval=timedelta(seconds=MAX_SUB_INTERVAL), - name=self._attr_name, - round_digits=2, - source_entity=self._source, - unique_id=self._attr_unique_id, - unit_prefix="k", - unit_time="h", - device_info=self._device_info, - ) + if Version(current_version) >= Version("2024.7"): + super().__init__( + integration_method=METHOD_LEFT, + max_sub_interval=timedelta(seconds=MAX_SUB_INTERVAL), + name=self._attr_name, + round_digits=2, + source_entity=self._source, + unique_id=self._attr_unique_id, + unit_prefix="k", + unit_time="h", + device_info=self._device_info, + ) + else: + super().__init__( + integration_method=METHOD_LEFT, + name=self._attr_name, + round_digits=2, + source_entity=self._source, + unique_id=self._attr_unique_id, + unit_prefix="k", + unit_time="h", + device_info=self._device_info, + ) self._unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR self._suggested_display_precision = 2