Add Met eireann to strict typing (#107486)
parent
d609344f40
commit
7202126751
|
@ -265,6 +265,7 @@ homeassistant.components.matter.*
|
|||
homeassistant.components.media_extractor.*
|
||||
homeassistant.components.media_player.*
|
||||
homeassistant.components.media_source.*
|
||||
homeassistant.components.met_eireann.*
|
||||
homeassistant.components.metoffice.*
|
||||
homeassistant.components.mikrotik.*
|
||||
homeassistant.components.min_max.*
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
"""The met_eireann component."""
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import Self
|
||||
from types import MappingProxyType
|
||||
from typing import Any, Self
|
||||
|
||||
import meteireann
|
||||
|
||||
|
@ -32,7 +33,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||
altitude=config_entry.data[CONF_ELEVATION],
|
||||
)
|
||||
|
||||
weather_data = MetEireannWeatherData(hass, config_entry.data, raw_weather_data)
|
||||
weather_data = MetEireannWeatherData(config_entry.data, raw_weather_data)
|
||||
|
||||
async def _async_update_data() -> MetEireannWeatherData:
|
||||
"""Fetch data from Met Éireann."""
|
||||
|
@ -70,14 +71,15 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||
class MetEireannWeatherData:
|
||||
"""Keep data for Met Éireann weather entities."""
|
||||
|
||||
def __init__(self, hass, config, weather_data):
|
||||
def __init__(
|
||||
self, config: MappingProxyType[str, Any], weather_data: meteireann.WeatherData
|
||||
) -> None:
|
||||
"""Initialise the weather entity data."""
|
||||
self.hass = hass
|
||||
self._config = config
|
||||
self._weather_data = weather_data
|
||||
self.current_weather_data = {}
|
||||
self.daily_forecast = None
|
||||
self.hourly_forecast = None
|
||||
self.current_weather_data: dict[str, Any] = {}
|
||||
self.daily_forecast: list[dict[str, Any]] = []
|
||||
self.hourly_forecast: list[dict[str, Any]] = []
|
||||
|
||||
async def fetch_data(self) -> Self:
|
||||
"""Fetch data from API - (current weather and forecast)."""
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
"""Config flow to configure Met Éireann component."""
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_ELEVATION, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from .const import DOMAIN, HOME_LOCATION_NAME
|
||||
|
@ -14,10 +16,10 @@ class MetEireannFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Handle a flow initialized by the user."""
|
||||
errors = {}
|
||||
|
||||
if user_input is not None:
|
||||
# Check if an identical entity is already configured
|
||||
await self.async_set_unique_id(
|
||||
|
@ -41,6 +43,5 @@ class MetEireannFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
): int,
|
||||
}
|
||||
),
|
||||
errors=errors,
|
||||
)
|
||||
return self.async_create_entry(title=user_input[CONF_NAME], data=user_input)
|
||||
|
|
|
@ -88,7 +88,12 @@ class MetEireannWeather(
|
|||
WeatherEntityFeature.FORECAST_DAILY | WeatherEntityFeature.FORECAST_HOURLY
|
||||
)
|
||||
|
||||
def __init__(self, coordinator, config, hourly):
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: DataUpdateCoordinator[MetEireannWeatherData],
|
||||
config: MappingProxyType[str, Any],
|
||||
hourly: bool,
|
||||
) -> None:
|
||||
"""Initialise the platform with a data instance and site."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_unique_id = _calculate_unique_id(config, hourly)
|
||||
|
@ -103,41 +108,41 @@ class MetEireannWeather(
|
|||
self._attr_device_info = DeviceInfo(
|
||||
name="Forecast",
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
identifiers={(DOMAIN,)},
|
||||
identifiers={(DOMAIN,)}, # type: ignore[arg-type]
|
||||
manufacturer="Met Éireann",
|
||||
model="Forecast",
|
||||
configuration_url="https://www.met.ie",
|
||||
)
|
||||
|
||||
@property
|
||||
def condition(self):
|
||||
def condition(self) -> str | None:
|
||||
"""Return the current condition."""
|
||||
return format_condition(
|
||||
self.coordinator.data.current_weather_data.get("condition")
|
||||
)
|
||||
|
||||
@property
|
||||
def native_temperature(self):
|
||||
def native_temperature(self) -> float | None:
|
||||
"""Return the temperature."""
|
||||
return self.coordinator.data.current_weather_data.get("temperature")
|
||||
|
||||
@property
|
||||
def native_pressure(self):
|
||||
def native_pressure(self) -> float | None:
|
||||
"""Return the pressure."""
|
||||
return self.coordinator.data.current_weather_data.get("pressure")
|
||||
|
||||
@property
|
||||
def humidity(self):
|
||||
def humidity(self) -> float | None:
|
||||
"""Return the humidity."""
|
||||
return self.coordinator.data.current_weather_data.get("humidity")
|
||||
|
||||
@property
|
||||
def native_wind_speed(self):
|
||||
def native_wind_speed(self) -> float | None:
|
||||
"""Return the wind speed."""
|
||||
return self.coordinator.data.current_weather_data.get("wind_speed")
|
||||
|
||||
@property
|
||||
def wind_bearing(self):
|
||||
def wind_bearing(self) -> float | None:
|
||||
"""Return the wind direction."""
|
||||
return self.coordinator.data.current_weather_data.get("wind_bearing")
|
||||
|
||||
|
|
10
mypy.ini
10
mypy.ini
|
@ -2411,6 +2411,16 @@ disallow_untyped_defs = true
|
|||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.met_eireann.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.metoffice.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
|
Loading…
Reference in New Issue