From 8893b31f21cd42fcc225e37b8c8b7202742c31c5 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski <75446+jpawlowski@users.noreply.github.com> Date: Wed, 3 Dec 2025 13:14:26 +0000 Subject: [PATCH] fix(binary_sensor): restore push updates from coordinator Binary sensor _handle_coordinator_update() was empty, blocking all push updates from coordinator. This prevented binary sensors from reflecting state changes immediately after API fetch or error conditions. Changes: - Implement _handle_coordinator_update() to call async_write_ha_state() - All binary sensors now receive push updates when coordinator has new data Binary sensors affected: - tomorrow_data_available: Now reflects data availability immediately after API fetch - connection: Now shows disconnected state immediately on auth/API errors - chart_data_export: Now updates chart data when price data changes - peak_price_period, best_price_period: Get push updates when periods change - data_lifecycle_status: Gets push updates on status changes Impact: Binary sensors update in real-time instead of waiting for next timer cycle or user interaction. Fixes stale state issue where tomorrow_data_available remained off despite data being available, and connection sensor not reflecting authentication failures immediately. --- .../tibber_prices/binary_sensor/core.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/custom_components/tibber_prices/binary_sensor/core.py b/custom_components/tibber_prices/binary_sensor/core.py index d1c51e3..04fdd56 100644 --- a/custom_components/tibber_prices/binary_sensor/core.py +++ b/custom_components/tibber_prices/binary_sensor/core.py @@ -217,11 +217,13 @@ class TibberPricesBinarySensor(TibberPricesEntity, BinarySensorEntity): @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" - # Chart data export: No automatic refresh needed. - # Data only refreshes on: - # 1. Initial sensor activation (async_added_to_hass) - # 2. Config changes via Options Flow (triggers re-add) - # Hourly coordinator updates don't change the chart data content. + # All binary sensors get push updates when coordinator has new data: + # - tomorrow_data_available: Reflects new data availability immediately after API fetch + # - connection: Reflects connection state changes immediately + # - chart_data_export: Updates chart data when price data changes + # - peak_price_period, best_price_period: Update when periods change (also get Timer #2 updates) + # - data_lifecycle_status: Gets both push and Timer #2 updates + self.async_write_ha_state() @property def is_on(self) -> bool | None: