Skip to content

Commit

Permalink
Fix sensors update error
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed May 23, 2024
1 parent 41709ce commit 067a149
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
15 changes: 10 additions & 5 deletions custom_components/gismeteo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
https://github.com/Limych/ha-gismeteo/
"""

from functools import cached_property
import logging

from aiohttp import ClientConnectorError
Expand All @@ -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 (
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions custom_components/gismeteo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions custom_components/gismeteo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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:
Expand Down
21 changes: 10 additions & 11 deletions custom_components/gismeteo/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
https://github.com/Limych/ha-gismeteo/
"""

from functools import cached_property
import logging

from homeassistant.components.weather import (
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 067a149

Please sign in to comment.