1
mirror of https://github.com/home-assistant/core synced 2024-09-28 03:04:04 +02:00

Improve laundrify generic typing (#84635)

This commit is contained in:
Marc Mueller 2022-12-27 21:24:09 +01:00 committed by GitHub
parent 1cad55f721
commit 44e37a8026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -25,7 +25,9 @@ async def async_setup_entry(
) -> None:
"""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(
LaundrifyPowerPlug(coordinator, device) for device in coordinator.data.values()
@ -39,6 +41,7 @@ class LaundrifyPowerPlug(
_attr_device_class = BinarySensorDeviceClass.RUNNING
_attr_icon = "mdi:washing-machine"
_attr_unique_id: str
def __init__(
self, coordinator: LaundrifyUpdateCoordinator, device: LaundrifyDevice
@ -63,7 +66,7 @@ class LaundrifyPowerPlug(
def available(self) -> bool:
"""Check if the device is available."""
return (
self.unique_id in self.coordinator.data
self._attr_unique_id in self.coordinator.data
and self.coordinator.last_update_success
)
@ -80,5 +83,5 @@ class LaundrifyPowerPlug(
@callback
def _handle_coordinator_update(self) -> None:
"""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()

View File

@ -16,7 +16,7 @@ from .model import LaundrifyDevice
_LOGGER = logging.getLogger(__name__)
class LaundrifyUpdateCoordinator(DataUpdateCoordinator):
class LaundrifyUpdateCoordinator(DataUpdateCoordinator[dict[str, LaundrifyDevice]]):
"""Class to manage fetching laundrify API data."""
def __init__(