mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Improve DataUpdateCoordinator typing in integrations (9) (#85332)
This commit is contained in:
parent
a2ef0caa07
commit
2e989b16ad
@ -33,7 +33,7 @@ CONF_SHOW_INACTIVE = "show_inactive"
|
|||||||
class TileData:
|
class TileData:
|
||||||
"""Define an object to be stored in `hass.data`."""
|
"""Define an object to be stored in `hass.data`."""
|
||||||
|
|
||||||
coordinators: dict[str, DataUpdateCoordinator]
|
coordinators: dict[str, DataUpdateCoordinator[None]]
|
||||||
tiles: dict[str, Tile]
|
tiles: dict[str, Tile]
|
||||||
|
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
except TileError as err:
|
except TileError as err:
|
||||||
raise UpdateFailed(f"Error while retrieving data: {err}") from err
|
raise UpdateFailed(f"Error while retrieving data: {err}") from err
|
||||||
|
|
||||||
coordinators = {}
|
coordinators: dict[str, DataUpdateCoordinator[None]] = {}
|
||||||
coordinator_init_tasks = []
|
coordinator_init_tasks = []
|
||||||
|
|
||||||
for tile_uuid, tile in tiles.items():
|
for tile_uuid, tile in tiles.items():
|
||||||
|
@ -78,13 +78,13 @@ async def async_setup_scanner(
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class TileDeviceTracker(CoordinatorEntity, TrackerEntity):
|
class TileDeviceTracker(CoordinatorEntity[DataUpdateCoordinator[None]], TrackerEntity):
|
||||||
"""Representation of a network infrastructure device."""
|
"""Representation of a network infrastructure device."""
|
||||||
|
|
||||||
_attr_icon = DEFAULT_ICON
|
_attr_icon = DEFAULT_ICON
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, entry: ConfigEntry, coordinator: DataUpdateCoordinator, tile: Tile
|
self, entry: ConfigEntry, coordinator: DataUpdateCoordinator[None], tile: Tile
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
"""Support for Twente Milieu Calendar."""
|
"""Support for Twente Milieu Calendar."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import date, datetime
|
||||||
|
|
||||||
|
from twentemilieu import WasteType
|
||||||
|
|
||||||
from homeassistant.components.calendar import CalendarEntity, CalendarEvent
|
from homeassistant.components.calendar import CalendarEntity, CalendarEvent
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -33,7 +35,7 @@ class TwenteMilieuCalendar(TwenteMilieuEntity, CalendarEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: DataUpdateCoordinator,
|
coordinator: DataUpdateCoordinator[dict[WasteType, list[date]]],
|
||||||
entry: ConfigEntry,
|
entry: ConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the Twente Milieu entity."""
|
"""Initialize the Twente Milieu entity."""
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
"""Diagnostics support for TwenteMilieu."""
|
"""Diagnostics support for TwenteMilieu."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import date
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from twentemilieu import WasteType
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_ID
|
from homeassistant.const import CONF_ID
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -15,8 +18,10 @@ async def async_get_config_entry_diagnostics(
|
|||||||
hass: HomeAssistant, entry: ConfigEntry
|
hass: HomeAssistant, entry: ConfigEntry
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Return diagnostics for a config entry."""
|
"""Return diagnostics for a config entry."""
|
||||||
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.data[CONF_ID]]
|
coordinator: DataUpdateCoordinator[dict[WasteType, list[date]]] = hass.data[DOMAIN][
|
||||||
|
entry.data[CONF_ID]
|
||||||
|
]
|
||||||
return {
|
return {
|
||||||
waste_type: [waste_date.isoformat() for waste_date in waste_dates]
|
str(waste_type): [waste_date.isoformat() for waste_date in waste_dates]
|
||||||
for waste_type, waste_dates in coordinator.data.items()
|
for waste_type, waste_dates in coordinator.data.items()
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ class TwenteMilieuSensor(TwenteMilieuEntity, SensorEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: DataUpdateCoordinator,
|
coordinator: DataUpdateCoordinator[dict[WasteType, list[date]]],
|
||||||
description: TwenteMilieuSensorDescription,
|
description: TwenteMilieuSensorDescription,
|
||||||
entry: ConfigEntry,
|
entry: ConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""WiZ integration models."""
|
"""WiZ integration models."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from pywizlight import wizlight
|
from pywizlight import wizlight
|
||||||
@ -10,6 +12,6 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
|||||||
class WizData:
|
class WizData:
|
||||||
"""Data for the wiz integration."""
|
"""Data for the wiz integration."""
|
||||||
|
|
||||||
coordinator: DataUpdateCoordinator
|
coordinator: DataUpdateCoordinator[float | None]
|
||||||
bulb: wizlight
|
bulb: wizlight
|
||||||
scenes: list
|
scenes: list
|
||||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
from miio import (
|
from miio import (
|
||||||
@ -289,7 +290,7 @@ async def async_create_miio_device_and_coordinator(
|
|||||||
device: MiioDevice | None = None
|
device: MiioDevice | None = None
|
||||||
migrate = False
|
migrate = False
|
||||||
update_method = _async_update_data_default
|
update_method = _async_update_data_default
|
||||||
coordinator_class: type[DataUpdateCoordinator] = DataUpdateCoordinator
|
coordinator_class: type[DataUpdateCoordinator[Any]] = DataUpdateCoordinator
|
||||||
|
|
||||||
if (
|
if (
|
||||||
model not in MODELS_HUMIDIFIER
|
model not in MODELS_HUMIDIFIER
|
||||||
|
@ -16,9 +16,9 @@ async def test_diagnostics(
|
|||||||
assert await get_diagnostics_for_config_entry(
|
assert await get_diagnostics_for_config_entry(
|
||||||
hass, hass_client, init_integration
|
hass, hass_client, init_integration
|
||||||
) == {
|
) == {
|
||||||
"0": ["2021-11-01", "2021-12-01"],
|
"WasteType.NON_RECYCLABLE": ["2021-11-01", "2021-12-01"],
|
||||||
"1": ["2021-11-02"],
|
"WasteType.ORGANIC": ["2021-11-02"],
|
||||||
"2": [],
|
"WasteType.PAPER": [],
|
||||||
"6": ["2022-01-06"],
|
"WasteType.TREE": ["2022-01-06"],
|
||||||
"10": ["2021-11-03"],
|
"WasteType.PACKAGES": ["2021-11-03"],
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user