mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Fix met TypeVar usage (#68152)
* Fix met TypeVar usage * Change format_condition
This commit is contained in:
parent
1a27025793
commit
db4b69663f
@ -82,12 +82,12 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
||||
return unload_ok
|
||||
|
||||
|
||||
class MetDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
class MetDataUpdateCoordinator(DataUpdateCoordinator["MetWeatherData"]):
|
||||
"""Class to manage fetching Met data."""
|
||||
|
||||
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||
"""Initialize global Met data updater."""
|
||||
self._unsub_track_home: Callable | None = None
|
||||
self._unsub_track_home: Callable[[], None] | None = None
|
||||
self.weather = MetWeatherData(
|
||||
hass, config_entry.data, hass.config.units.is_metric
|
||||
)
|
||||
@ -137,8 +137,8 @@ class MetWeatherData:
|
||||
self._is_metric = is_metric
|
||||
self._weather_data: metno.MetWeatherData
|
||||
self.current_weather_data: dict = {}
|
||||
self.daily_forecast = None
|
||||
self.hourly_forecast = None
|
||||
self.daily_forecast: list[dict] = []
|
||||
self.hourly_forecast: list[dict] = []
|
||||
self._coordinates: dict[str, str] | None = None
|
||||
|
||||
def set_coordinates(self) -> bool:
|
||||
|
@ -40,15 +40,12 @@ from homeassistant.helpers.device_registry import DeviceEntryType
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
T,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util.distance import convert as convert_distance
|
||||
from homeassistant.util.pressure import convert as convert_pressure
|
||||
from homeassistant.util.speed import convert as convert_speed
|
||||
|
||||
from . import MetDataUpdateCoordinator, MetWeatherData
|
||||
from .const import (
|
||||
ATTR_FORECAST_PRECIPITATION,
|
||||
ATTR_MAP,
|
||||
@ -109,7 +106,7 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Add a weather entity from a config_entry."""
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
coordinator: MetDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
async_add_entities(
|
||||
[
|
||||
MetWeather(
|
||||
@ -130,12 +127,14 @@ def format_condition(condition: str) -> str:
|
||||
return condition
|
||||
|
||||
|
||||
class MetWeather(CoordinatorEntity, WeatherEntity):
|
||||
class MetWeather(CoordinatorEntity[MetWeatherData], WeatherEntity):
|
||||
"""Implementation of a Met.no weather condition."""
|
||||
|
||||
coordinator: MetDataUpdateCoordinator
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: DataUpdateCoordinator[T],
|
||||
coordinator: MetDataUpdateCoordinator,
|
||||
config: MappingProxyType[str, Any],
|
||||
is_metric: bool,
|
||||
hourly: bool,
|
||||
@ -187,6 +186,8 @@ class MetWeather(CoordinatorEntity, WeatherEntity):
|
||||
def condition(self) -> str | None:
|
||||
"""Return the current condition."""
|
||||
condition = self.coordinator.data.current_weather_data.get("condition")
|
||||
if condition is None:
|
||||
return None
|
||||
return format_condition(condition)
|
||||
|
||||
@property
|
||||
|
Loading…
x
Reference in New Issue
Block a user