From f10f0c44b16ac8b323a47c7d8c21180134c3f690 Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Tue, 27 Jan 2026 18:59:16 -0500 Subject: [PATCH 1/3] Adding specific weather scan interval Putting in a dedicated scan interval for weather polling instead of the default. --- custom_components/hilo/const.py | 1 + custom_components/hilo/sensor.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/hilo/const.py b/custom_components/hilo/const.py index e61d071..48431f1 100755 --- a/custom_components/hilo/const.py +++ b/custom_components/hilo/const.py @@ -46,6 +46,7 @@ MAX_SUB_INTERVAL = 120 MIN_SCAN_INTERVAL = 60 REWARD_SCAN_INTERVAL = 7200 +WEATHER_SCAN_INTERVAL = 900 CONF_TARIFF = { "rate d": { diff --git a/custom_components/hilo/sensor.py b/custom_components/hilo/sensor.py index a4a9e49..e94a6e7 100755 --- a/custom_components/hilo/sensor.py +++ b/custom_components/hilo/sensor.py @@ -67,6 +67,7 @@ REWARD_SCAN_INTERVAL, TARIFF_LIST, WEATHER_CONDITIONS, + WEATHER_SCAN_INTERVAL, ) from .entity import HiloEntity from .managers import EnergyManager, UtilityManager @@ -1247,7 +1248,7 @@ def __init__(self, hilo, device, scan_interval): f"{slugify(device.identifier)}-{slugify(self._attr_name)}" ) LOG.debug("Setting up OutdoorWeatherSensor entity: %s", self._attr_name) - self.scan_interval = timedelta(seconds=EVENT_SCAN_INTERVAL_REDUCTION) + self.scan_interval = timedelta(seconds=WEATHER_SCAN_INTERVAL) self._state = STATE_UNKNOWN self._weather = {} self.async_update = Throttle(self.scan_interval)(self._async_update) From ec8a802042f884019e1e4ce1bd9753829f8f2acd Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Tue, 27 Jan 2026 19:36:58 -0500 Subject: [PATCH 2/3] Removing throttle and checking for last update Adding manual throttling. --- custom_components/hilo/const.py | 2 +- custom_components/hilo/sensor.py | 40 ++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/custom_components/hilo/const.py b/custom_components/hilo/const.py index 48431f1..50ab127 100755 --- a/custom_components/hilo/const.py +++ b/custom_components/hilo/const.py @@ -46,7 +46,7 @@ MAX_SUB_INTERVAL = 120 MIN_SCAN_INTERVAL = 60 REWARD_SCAN_INTERVAL = 7200 -WEATHER_SCAN_INTERVAL = 900 +WEATHER_SCAN_INTERVAL = 1800 CONF_TARIFF = { "rate d": { diff --git a/custom_components/hilo/sensor.py b/custom_components/hilo/sensor.py index e94a6e7..b9bc26e 100755 --- a/custom_components/hilo/sensor.py +++ b/custom_components/hilo/sensor.py @@ -1248,10 +1248,11 @@ def __init__(self, hilo, device, scan_interval): f"{slugify(device.identifier)}-{slugify(self._attr_name)}" ) LOG.debug("Setting up OutdoorWeatherSensor entity: %s", self._attr_name) - self.scan_interval = timedelta(seconds=WEATHER_SCAN_INTERVAL) + # self.scan_interval = timedelta(seconds=WEATHER_SCAN_INTERVAL) self._state = STATE_UNKNOWN self._weather = {} - self.async_update = Throttle(self.scan_interval)(self._async_update) + self._last_weather_update = None + # self.async_update = Throttle(self.scan_interval)(self._async_update) @property def state(self): @@ -1289,9 +1290,34 @@ async def async_added_to_hass(self): """Handle entity about to be added to hass event.""" await super().async_added_to_hass() - async def _async_update(self): - self._weather = {} - self._weather = await self._hilo._api.get_weather( - self._hilo.devices.location_id + async def async_update(self): + """Update the weather data with proper throttling. + + Weather data from Hilo API changes every hour, using 1800s (30min) to + make sure we get the latest data without overloading the API. + """ + + now = dt_util.utcnow() + if self._last_weather_update is not None: + elapsed = (now - self._last_weather_update).total_seconds() + if elapsed < WEATHER_SCAN_INTERVAL: + LOG.debug( + "Skipping weather update, only %s seconds since last update", + elapsed, + ) + return + + LOG.debug( + "Calling Hilo API to get weather data with location id %s", + self._hilo.devices.location_id, ) - self._state = self._weather.get("temperature") + self._last_weather_update = now + + try: + self._weather = await self._hilo._api.get_weather( + self._hilo.devices.location_id + ) + LOG.debug("Weather data received: %s", self._weather) + self._state = self._weather.get("temperature") + except Exception as err: + LOG.error("Error fetching weather data: %s", err) From 4f1bada35bdc445d91563fe92fc10b9eca612cd5 Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Tue, 27 Jan 2026 20:06:29 -0500 Subject: [PATCH 3/3] Update sensor.py Remove unneeded comments --- custom_components/hilo/sensor.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/custom_components/hilo/sensor.py b/custom_components/hilo/sensor.py index b9bc26e..3ce23aa 100755 --- a/custom_components/hilo/sensor.py +++ b/custom_components/hilo/sensor.py @@ -1248,11 +1248,9 @@ def __init__(self, hilo, device, scan_interval): f"{slugify(device.identifier)}-{slugify(self._attr_name)}" ) LOG.debug("Setting up OutdoorWeatherSensor entity: %s", self._attr_name) - # self.scan_interval = timedelta(seconds=WEATHER_SCAN_INTERVAL) self._state = STATE_UNKNOWN self._weather = {} self._last_weather_update = None - # self.async_update = Throttle(self.scan_interval)(self._async_update) @property def state(self):