mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
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.
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""Support for UV data from openuv.io."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
|
from homeassistant.helpers.entity import EntityDescription
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
from .const import DOMAIN
|
|
from .coordinator import OpenUvCoordinator
|
|
|
|
|
|
class OpenUvEntity(CoordinatorEntity):
|
|
"""Define a generic OpenUV entity."""
|
|
|
|
_attr_has_entity_name = True
|
|
|
|
def __init__(
|
|
self, coordinator: OpenUvCoordinator, description: EntityDescription
|
|
) -> None:
|
|
"""Initialize."""
|
|
super().__init__(coordinator)
|
|
|
|
self._attr_extra_state_attributes = {}
|
|
self._attr_unique_id = (
|
|
f"{coordinator.latitude}_{coordinator.longitude}_{description.key}"
|
|
)
|
|
self.entity_description = description
|
|
self._attr_device_info = DeviceInfo(
|
|
identifiers={(DOMAIN, f"{coordinator.latitude}_{coordinator.longitude}")},
|
|
name="OpenUV",
|
|
entry_type=DeviceEntryType.SERVICE,
|
|
)
|
|
|
|
self._update_attrs()
|
|
|
|
def _update_attrs(self) -> None:
|
|
"""Override point for updating attributes during init."""
|