mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Improve laundrify
generic typing (#84635)
This commit is contained in:
parent
1cad55f721
commit
44e37a8026
@ -25,7 +25,9 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up sensors from a config entry created in the integrations UI."""
|
"""Set up sensors from a config entry created in the integrations UI."""
|
||||||
|
|
||||||
coordinator = hass.data[DOMAIN][config.entry_id]["coordinator"]
|
coordinator: LaundrifyUpdateCoordinator = hass.data[DOMAIN][config.entry_id][
|
||||||
|
"coordinator"
|
||||||
|
]
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
LaundrifyPowerPlug(coordinator, device) for device in coordinator.data.values()
|
LaundrifyPowerPlug(coordinator, device) for device in coordinator.data.values()
|
||||||
@ -39,6 +41,7 @@ class LaundrifyPowerPlug(
|
|||||||
|
|
||||||
_attr_device_class = BinarySensorDeviceClass.RUNNING
|
_attr_device_class = BinarySensorDeviceClass.RUNNING
|
||||||
_attr_icon = "mdi:washing-machine"
|
_attr_icon = "mdi:washing-machine"
|
||||||
|
_attr_unique_id: str
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, coordinator: LaundrifyUpdateCoordinator, device: LaundrifyDevice
|
self, coordinator: LaundrifyUpdateCoordinator, device: LaundrifyDevice
|
||||||
@ -63,7 +66,7 @@ class LaundrifyPowerPlug(
|
|||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Check if the device is available."""
|
"""Check if the device is available."""
|
||||||
return (
|
return (
|
||||||
self.unique_id in self.coordinator.data
|
self._attr_unique_id in self.coordinator.data
|
||||||
and self.coordinator.last_update_success
|
and self.coordinator.last_update_success
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -80,5 +83,5 @@ class LaundrifyPowerPlug(
|
|||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self) -> None:
|
def _handle_coordinator_update(self) -> None:
|
||||||
"""Handle updated data from the coordinator."""
|
"""Handle updated data from the coordinator."""
|
||||||
self._device = self.coordinator.data[self.unique_id]
|
self._device = self.coordinator.data[self._attr_unique_id]
|
||||||
super()._handle_coordinator_update()
|
super()._handle_coordinator_update()
|
||||||
|
@ -16,7 +16,7 @@ from .model import LaundrifyDevice
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LaundrifyUpdateCoordinator(DataUpdateCoordinator):
|
class LaundrifyUpdateCoordinator(DataUpdateCoordinator[dict[str, LaundrifyDevice]]):
|
||||||
"""Class to manage fetching laundrify API data."""
|
"""Class to manage fetching laundrify API data."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user