Fix initial state of UV protection window (#146408)

The `binary_sensor` is created when the config entry is loaded after the
`async_config_entry_first_refresh` has completed (during the forward of
setup to platforms). Therefore, the update coordinator will already have
data and will not trigger the invocation of
`_handle_coordinator_update`.

Fixing this just means performing the same update at initialization.
This commit is contained in:
Whitney Young 2025-06-10 08:35:40 -07:00 committed by GitHub
parent 627831dfaf
commit 7aa9301038
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -49,6 +49,10 @@ class OpenUvBinarySensor(OpenUvEntity, BinarySensorEntity):
@callback
def _handle_coordinator_update(self) -> None:
"""Update the entity from the latest data."""
self._update_attrs()
super()._handle_coordinator_update()
def _update_attrs(self) -> None:
data = self.coordinator.data
for key in ("from_time", "to_time", "from_uv", "to_uv"):
@ -78,5 +82,3 @@ class OpenUvBinarySensor(OpenUvEntity, BinarySensorEntity):
ATTR_PROTECTION_WINDOW_STARTING_TIME: as_local(from_dt),
}
)
super()._handle_coordinator_update()

View File

@ -31,3 +31,8 @@ class OpenUvEntity(CoordinatorEntity):
name="OpenUV",
entry_type=DeviceEntryType.SERVICE,
)
self._update_attrs()
def _update_attrs(self) -> None:
"""Override point for updating attributes during init."""