diff --git a/custom_components/gismeteo/__init__.py b/custom_components/gismeteo/__init__.py index 2890f02..aadd253 100644 --- a/custom_components/gismeteo/__init__.py +++ b/custom_components/gismeteo/__init__.py @@ -7,6 +7,7 @@ https://github.com/Limych/ha-gismeteo/ """ +from functools import cached_property import logging from aiohttp import ClientConnectorError @@ -27,7 +28,11 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.storage import STORAGE_DIR from homeassistant.helpers.typing import ConfigType -from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed +from homeassistant.helpers.update_coordinator import ( + DataUpdateCoordinator, + UpdateFailed, + _DataT, +) from .api import ApiError, GismeteoApiClient from .const import ( @@ -185,12 +190,12 @@ def __init__( self.gismeteo = gismeteo self._unique_id = unique_id - @property - def unique_id(self): - """Return a unique_id.""" + @cached_property + def unique_id(self) -> str | None: + """Return a unique ID.""" return self._unique_id - async def _async_update_data(self): + async def _async_update_data(self) -> _DataT: """Update data via library.""" try: async with timeout(10): diff --git a/custom_components/gismeteo/api.py b/custom_components/gismeteo/api.py index 1dd0384..213d1cb 100644 --- a/custom_components/gismeteo/api.py +++ b/custom_components/gismeteo/api.py @@ -619,12 +619,15 @@ def _get_utime(source: str, tzone: int) -> datetime: return dt_util.parse_datetime(local_date, raise_on_error=True) @Throttle(PARSED_UPDATE_INTERVAL) - async def async_update_parsed(self): + async def async_update_parsed(self) -> None: """Update parsed data.""" self._parsed = await self.async_get_parsed() async def async_update(self) -> bool: - """Get the latest data from Gismeteo.""" + """Get the latest data from Gismeteo. + + :raise ApiError + """ response = await self.async_get_forecast() try: xml = etree.fromstring(response) diff --git a/custom_components/gismeteo/sensor.py b/custom_components/gismeteo/sensor.py index 6836932..1300b16 100644 --- a/custom_components/gismeteo/sensor.py +++ b/custom_components/gismeteo/sensor.py @@ -9,7 +9,6 @@ from datetime import date, datetime from decimal import Decimal -from functools import cached_property import logging from homeassistant.components.sensor import ( @@ -134,7 +133,7 @@ def __init__( self._day = day - @cached_property + @property def native_value(self) -> StateType | date | datetime | Decimal: """Return the value reported by the sensor.""" try: diff --git a/custom_components/gismeteo/weather.py b/custom_components/gismeteo/weather.py index d0a274b..38d2428 100644 --- a/custom_components/gismeteo/weather.py +++ b/custom_components/gismeteo/weather.py @@ -7,7 +7,6 @@ https://github.com/Limych/ha-gismeteo/ """ -from functools import cached_property import logging from homeassistant.components.weather import ( @@ -85,52 +84,52 @@ def __init__( "location_name": location_name, } - @cached_property + @property def condition(self) -> str | None: """Return the current condition.""" return self._gismeteo.condition() - @cached_property + @property def native_apparent_temperature(self) -> float | None: """Return the apparent temperature in native units.""" return self._gismeteo.apparent_temperature() - @cached_property + @property def native_temperature(self) -> float | None: """Return the temperature in native units.""" return self._gismeteo.temperature() - @cached_property + @property def native_pressure(self) -> float | None: """Return the pressure in native units.""" return self._gismeteo.pressure() - @cached_property + @property def humidity(self) -> float | None: """Return the humidity in %.""" return self._gismeteo.humidity() - @cached_property + @property def wind_bearing(self) -> float | str | None: """Return the wind bearing.""" return self._gismeteo.wind_bearing() - @cached_property + @property def native_wind_gust_speed(self) -> float | None: """Return the wind gust speed in native units.""" return self._gismeteo.wind_gust_speed() - @cached_property + @property def native_wind_speed(self) -> float | None: """Return the wind speed in native units.""" return self._gismeteo.wind_speed() - @cached_property + @property def cloud_coverage(self) -> float | None: """Return the Cloud coverage in %.""" return self._gismeteo.cloud_coverage() - @cached_property + @property def uv_index(self) -> float | None: """Return the UV index.""" return self._gismeteo.uv_index()