Skip to content

Commit

Permalink
Adding version "error-check"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ic-dev21 committed Jul 2, 2024
1 parent e233fe8 commit d54af95
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions custom_components/hilo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
UnitOfPower,
UnitOfSoundPressure,
UnitOfTemperature,
__short_version__ as current_version,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceInfo
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d54af95

Please sign in to comment.