mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 06:17:07 +00:00
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:
parent
627831dfaf
commit
7aa9301038
@ -49,6 +49,10 @@ class OpenUvBinarySensor(OpenUvEntity, BinarySensorEntity):
|
|||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self) -> None:
|
def _handle_coordinator_update(self) -> None:
|
||||||
"""Update the entity from the latest data."""
|
"""Update the entity from the latest data."""
|
||||||
|
self._update_attrs()
|
||||||
|
super()._handle_coordinator_update()
|
||||||
|
|
||||||
|
def _update_attrs(self) -> None:
|
||||||
data = self.coordinator.data
|
data = self.coordinator.data
|
||||||
|
|
||||||
for key in ("from_time", "to_time", "from_uv", "to_uv"):
|
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),
|
ATTR_PROTECTION_WINDOW_STARTING_TIME: as_local(from_dt),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
super()._handle_coordinator_update()
|
|
||||||
|
@ -31,3 +31,8 @@ class OpenUvEntity(CoordinatorEntity):
|
|||||||
name="OpenUV",
|
name="OpenUV",
|
||||||
entry_type=DeviceEntryType.SERVICE,
|
entry_type=DeviceEntryType.SERVICE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._update_attrs()
|
||||||
|
|
||||||
|
def _update_attrs(self) -> None:
|
||||||
|
"""Override point for updating attributes during init."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user