From c3991b591a6c438cbd8a48fc2da7df6331181908 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 7 Jan 2023 14:55:19 +0100 Subject: [PATCH] Improve DataUpdateCoordinator typing in integrations (8) (#85331) --- homeassistant/components/airthings_ble/sensor.py | 2 +- homeassistant/components/ld2410_ble/binary_sensor.py | 4 +++- homeassistant/components/ld2410_ble/coordinator.py | 4 ++-- homeassistant/components/nanoleaf/__init__.py | 2 +- homeassistant/components/nanoleaf/button.py | 4 +++- homeassistant/components/nanoleaf/entity.py | 6 ++++-- homeassistant/components/nanoleaf/light.py | 4 +++- homeassistant/components/simplisafe/__init__.py | 4 ++-- homeassistant/components/solaredge/coordinator.py | 2 +- homeassistant/components/solaredge/sensor.py | 9 +++++++-- 10 files changed, 27 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/airthings_ble/sensor.py b/homeassistant/components/airthings_ble/sensor.py index 57a8c3827d2..641b0b02f9f 100644 --- a/homeassistant/components/airthings_ble/sensor.py +++ b/homeassistant/components/airthings_ble/sensor.py @@ -154,7 +154,7 @@ class AirthingsSensor( def __init__( self, - coordinator: DataUpdateCoordinator, + coordinator: DataUpdateCoordinator[AirthingsDevice], airthings_device: AirthingsDevice, entity_description: SensorEntityDescription, ) -> None: diff --git a/homeassistant/components/ld2410_ble/binary_sensor.py b/homeassistant/components/ld2410_ble/binary_sensor.py index 7d8cd8a90b5..6e84904774b 100644 --- a/homeassistant/components/ld2410_ble/binary_sensor.py +++ b/homeassistant/components/ld2410_ble/binary_sensor.py @@ -46,7 +46,9 @@ async def async_setup_entry( ) -class LD2410BLEBinarySensor(CoordinatorEntity, BinarySensorEntity): +class LD2410BLEBinarySensor( + CoordinatorEntity[LD2410BLECoordinator], BinarySensorEntity +): """Moving/static sensor for LD2410BLE.""" def __init__( diff --git a/homeassistant/components/ld2410_ble/coordinator.py b/homeassistant/components/ld2410_ble/coordinator.py index a397191f133..6ab25553094 100644 --- a/homeassistant/components/ld2410_ble/coordinator.py +++ b/homeassistant/components/ld2410_ble/coordinator.py @@ -12,7 +12,7 @@ from .const import DOMAIN _LOGGER = logging.getLogger(__name__) -class LD2410BLECoordinator(DataUpdateCoordinator): +class LD2410BLECoordinator(DataUpdateCoordinator[None]): """Data coordinator for receiving LD2410B updates.""" def __init__(self, hass: HomeAssistant, ld2410_ble: LD2410BLE) -> None: @@ -31,7 +31,7 @@ class LD2410BLECoordinator(DataUpdateCoordinator): def _async_handle_update(self, state: LD2410BLEState) -> None: """Just trigger the callbacks.""" self.connected = True - self.async_set_updated_data(True) + self.async_set_updated_data(None) @callback def _async_handle_disconnect(self) -> None: diff --git a/homeassistant/components/nanoleaf/__init__.py b/homeassistant/components/nanoleaf/__init__.py index 1d18e0078ec..4c3b0880170 100644 --- a/homeassistant/components/nanoleaf/__init__.py +++ b/homeassistant/components/nanoleaf/__init__.py @@ -41,7 +41,7 @@ class NanoleafEntryData: """Class for sharing data within the Nanoleaf integration.""" device: Nanoleaf - coordinator: DataUpdateCoordinator + coordinator: DataUpdateCoordinator[None] event_listener: asyncio.Task diff --git a/homeassistant/components/nanoleaf/button.py b/homeassistant/components/nanoleaf/button.py index 5297e98c88e..b6e48928473 100644 --- a/homeassistant/components/nanoleaf/button.py +++ b/homeassistant/components/nanoleaf/button.py @@ -27,7 +27,9 @@ async def async_setup_entry( class NanoleafIdentifyButton(NanoleafEntity, ButtonEntity): """Representation of a Nanoleaf identify button.""" - def __init__(self, nanoleaf: Nanoleaf, coordinator: DataUpdateCoordinator) -> None: + def __init__( + self, nanoleaf: Nanoleaf, coordinator: DataUpdateCoordinator[None] + ) -> None: """Initialize the Nanoleaf button.""" super().__init__(nanoleaf, coordinator) self._attr_unique_id = f"{nanoleaf.serial_no}_identify" diff --git a/homeassistant/components/nanoleaf/entity.py b/homeassistant/components/nanoleaf/entity.py index 8df9e243d71..0fb043c4cc4 100644 --- a/homeassistant/components/nanoleaf/entity.py +++ b/homeassistant/components/nanoleaf/entity.py @@ -11,10 +11,12 @@ from homeassistant.helpers.update_coordinator import ( from .const import DOMAIN -class NanoleafEntity(CoordinatorEntity): +class NanoleafEntity(CoordinatorEntity[DataUpdateCoordinator[None]]): """Representation of a Nanoleaf entity.""" - def __init__(self, nanoleaf: Nanoleaf, coordinator: DataUpdateCoordinator) -> None: + def __init__( + self, nanoleaf: Nanoleaf, coordinator: DataUpdateCoordinator[None] + ) -> None: """Initialize an Nanoleaf entity.""" super().__init__(coordinator) self._nanoleaf = nanoleaf diff --git a/homeassistant/components/nanoleaf/light.py b/homeassistant/components/nanoleaf/light.py index 1a43cb4989a..20992594cb8 100644 --- a/homeassistant/components/nanoleaf/light.py +++ b/homeassistant/components/nanoleaf/light.py @@ -47,7 +47,9 @@ class NanoleafLight(NanoleafEntity, LightEntity): _attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS} _attr_supported_features = LightEntityFeature.EFFECT | LightEntityFeature.TRANSITION - def __init__(self, nanoleaf: Nanoleaf, coordinator: DataUpdateCoordinator) -> None: + def __init__( + self, nanoleaf: Nanoleaf, coordinator: DataUpdateCoordinator[None] + ) -> None: """Initialize the Nanoleaf light.""" super().__init__(nanoleaf, coordinator) self._attr_unique_id = nanoleaf.serial_no diff --git a/homeassistant/components/simplisafe/__init__.py b/homeassistant/components/simplisafe/__init__.py index 7b431368328..6a3523f07c9 100644 --- a/homeassistant/components/simplisafe/__init__.py +++ b/homeassistant/components/simplisafe/__init__.py @@ -489,7 +489,7 @@ class SimpliSafe: self.systems: dict[int, SystemType] = {} # This will get filled in by async_init: - self.coordinator: DataUpdateCoordinator | None = None + self.coordinator: DataUpdateCoordinator[None] | None = None @callback def _async_process_new_notifications(self, system: SystemType) -> None: @@ -692,7 +692,7 @@ class SimpliSafe: raise UpdateFailed(f"SimpliSafe error while updating: {result}") -class SimpliSafeEntity(CoordinatorEntity): +class SimpliSafeEntity(CoordinatorEntity[DataUpdateCoordinator[None]]): """Define a base SimpliSafe entity.""" _attr_has_entity_name = True diff --git a/homeassistant/components/solaredge/coordinator.py b/homeassistant/components/solaredge/coordinator.py index 839f2cf37eb..4938a54ed65 100644 --- a/homeassistant/components/solaredge/coordinator.py +++ b/homeassistant/components/solaredge/coordinator.py @@ -24,7 +24,7 @@ from .const import ( class SolarEdgeDataService(ABC): """Get and update the latest data.""" - coordinator: DataUpdateCoordinator + coordinator: DataUpdateCoordinator[None] def __init__(self, hass: HomeAssistant, api: Solaredge, site_id: str) -> None: """Initialize the data object.""" diff --git a/homeassistant/components/solaredge/sensor.py b/homeassistant/components/solaredge/sensor.py index a27c180e0b9..3a4b5ad90c2 100644 --- a/homeassistant/components/solaredge/sensor.py +++ b/homeassistant/components/solaredge/sensor.py @@ -9,7 +9,10 @@ from homeassistant.components.sensor import SensorDeviceClass, SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.update_coordinator import CoordinatorEntity +from homeassistant.helpers.update_coordinator import ( + CoordinatorEntity, + DataUpdateCoordinator, +) from .const import CONF_SITE_ID, DATA_API_CLIENT, DOMAIN, SENSOR_TYPES from .coordinator import ( @@ -108,7 +111,9 @@ class SolarEdgeSensorFactory: return sensor_class(self.platform_name, sensor_type, service) -class SolarEdgeSensorEntity(CoordinatorEntity, SensorEntity): +class SolarEdgeSensorEntity( + CoordinatorEntity[DataUpdateCoordinator[None]], SensorEntity +): """Abstract class for a solaredge sensor.""" entity_description: SolarEdgeSensorEntityDescription