From c4b45fb110f25c94910d1523fbd79cf234f35929 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 29 Dec 2022 09:35:06 +0100 Subject: [PATCH] Improve `ondilo_ico` generic typing (#84738) --- homeassistant/components/ondilo_ico/api.py | 3 ++- homeassistant/components/ondilo_ico/sensor.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/ondilo_ico/api.py b/homeassistant/components/ondilo_ico/api.py index f698dcc693e..e0c6f9001c4 100644 --- a/homeassistant/components/ondilo_ico/api.py +++ b/homeassistant/components/ondilo_ico/api.py @@ -1,6 +1,7 @@ """API for Ondilo ICO bound to Home Assistant OAuth.""" from asyncio import run_coroutine_threadsafe import logging +from typing import Any from ondilo import Ondilo @@ -35,7 +36,7 @@ class OndiloClient(Ondilo): return self.session.token - def get_all_pools_data(self) -> dict: + def get_all_pools_data(self) -> list[dict[str, Any]]: """Fetch pools and add pool details and last measures to pool data.""" pools = self.get_pools() diff --git a/homeassistant/components/ondilo_ico/sensor.py b/homeassistant/components/ondilo_ico/sensor.py index b6a3b25f3f2..129cdf50979 100644 --- a/homeassistant/components/ondilo_ico/sensor.py +++ b/homeassistant/components/ondilo_ico/sensor.py @@ -3,6 +3,7 @@ from __future__ import annotations from datetime import timedelta import logging +from typing import Any from ondilo import OndiloError @@ -28,6 +29,7 @@ from homeassistant.helpers.update_coordinator import ( UpdateFailed, ) +from .api import OndiloClient from .const import DOMAIN SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( @@ -91,9 +93,9 @@ async def async_setup_entry( ) -> None: """Set up the Ondilo ICO sensors.""" - api = hass.data[DOMAIN][entry.entry_id] + api: OndiloClient = hass.data[DOMAIN][entry.entry_id] - async def async_update_data(): + async def async_update_data() -> list[dict[str, Any]]: """Fetch data from API endpoint. This is the place to pre-process the data to lookup tables @@ -132,12 +134,14 @@ async def async_setup_entry( async_add_entities(entities) -class OndiloICO(CoordinatorEntity, SensorEntity): +class OndiloICO( + CoordinatorEntity[DataUpdateCoordinator[list[dict[str, Any]]]], SensorEntity +): """Representation of a Sensor.""" def __init__( self, - coordinator: DataUpdateCoordinator, + coordinator: DataUpdateCoordinator[list[dict[str, Any]]], poolidx: int, description: SensorEntityDescription, ) -> None: