Add Met eireann to strict typing (#107486)

This commit is contained in:
Joost Lekkerkerker 2024-01-08 09:13:15 +01:00 committed by GitHub
parent d609344f40
commit 7202126751
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 19 deletions

View file

@ -265,6 +265,7 @@ homeassistant.components.matter.*
homeassistant.components.media_extractor.* homeassistant.components.media_extractor.*
homeassistant.components.media_player.* homeassistant.components.media_player.*
homeassistant.components.media_source.* homeassistant.components.media_source.*
homeassistant.components.met_eireann.*
homeassistant.components.metoffice.* homeassistant.components.metoffice.*
homeassistant.components.mikrotik.* homeassistant.components.mikrotik.*
homeassistant.components.min_max.* homeassistant.components.min_max.*

View file

@ -1,7 +1,8 @@
"""The met_eireann component.""" """The met_eireann component."""
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import Self from types import MappingProxyType
from typing import Any, Self
import meteireann import meteireann
@ -32,7 +33,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
altitude=config_entry.data[CONF_ELEVATION], 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: async def _async_update_data() -> MetEireannWeatherData:
"""Fetch data from Met Éireann.""" """Fetch data from Met Éireann."""
@ -70,14 +71,15 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
class MetEireannWeatherData: class MetEireannWeatherData:
"""Keep data for Met Éireann weather entities.""" """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.""" """Initialise the weather entity data."""
self.hass = hass
self._config = config self._config = config
self._weather_data = weather_data self._weather_data = weather_data
self.current_weather_data = {} self.current_weather_data: dict[str, Any] = {}
self.daily_forecast = None self.daily_forecast: list[dict[str, Any]] = []
self.hourly_forecast = None self.hourly_forecast: list[dict[str, Any]] = []
async def fetch_data(self) -> Self: async def fetch_data(self) -> Self:
"""Fetch data from API - (current weather and forecast).""" """Fetch data from API - (current weather and forecast)."""

View file

@ -1,9 +1,11 @@
"""Config flow to configure Met Éireann component.""" """Config flow to configure Met Éireann component."""
from typing import Any
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.const import CONF_ELEVATION, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME 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 import homeassistant.helpers.config_validation as cv
from .const import DOMAIN, HOME_LOCATION_NAME from .const import DOMAIN, HOME_LOCATION_NAME
@ -14,10 +16,10 @@ class MetEireannFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1 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.""" """Handle a flow initialized by the user."""
errors = {}
if user_input is not None: if user_input is not None:
# Check if an identical entity is already configured # Check if an identical entity is already configured
await self.async_set_unique_id( await self.async_set_unique_id(
@ -41,6 +43,5 @@ class MetEireannFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
): int, ): int,
} }
), ),
errors=errors,
) )
return self.async_create_entry(title=user_input[CONF_NAME], data=user_input) return self.async_create_entry(title=user_input[CONF_NAME], data=user_input)

View file

@ -88,7 +88,12 @@ class MetEireannWeather(
WeatherEntityFeature.FORECAST_DAILY | WeatherEntityFeature.FORECAST_HOURLY 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.""" """Initialise the platform with a data instance and site."""
super().__init__(coordinator) super().__init__(coordinator)
self._attr_unique_id = _calculate_unique_id(config, hourly) self._attr_unique_id = _calculate_unique_id(config, hourly)
@ -103,41 +108,41 @@ class MetEireannWeather(
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
name="Forecast", name="Forecast",
entry_type=DeviceEntryType.SERVICE, entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN,)}, identifiers={(DOMAIN,)}, # type: ignore[arg-type]
manufacturer="Met Éireann", manufacturer="Met Éireann",
model="Forecast", model="Forecast",
configuration_url="https://www.met.ie", configuration_url="https://www.met.ie",
) )
@property @property
def condition(self): def condition(self) -> str | None:
"""Return the current condition.""" """Return the current condition."""
return format_condition( return format_condition(
self.coordinator.data.current_weather_data.get("condition") self.coordinator.data.current_weather_data.get("condition")
) )
@property @property
def native_temperature(self): def native_temperature(self) -> float | None:
"""Return the temperature.""" """Return the temperature."""
return self.coordinator.data.current_weather_data.get("temperature") return self.coordinator.data.current_weather_data.get("temperature")
@property @property
def native_pressure(self): def native_pressure(self) -> float | None:
"""Return the pressure.""" """Return the pressure."""
return self.coordinator.data.current_weather_data.get("pressure") return self.coordinator.data.current_weather_data.get("pressure")
@property @property
def humidity(self): def humidity(self) -> float | None:
"""Return the humidity.""" """Return the humidity."""
return self.coordinator.data.current_weather_data.get("humidity") return self.coordinator.data.current_weather_data.get("humidity")
@property @property
def native_wind_speed(self): def native_wind_speed(self) -> float | None:
"""Return the wind speed.""" """Return the wind speed."""
return self.coordinator.data.current_weather_data.get("wind_speed") return self.coordinator.data.current_weather_data.get("wind_speed")
@property @property
def wind_bearing(self): def wind_bearing(self) -> float | None:
"""Return the wind direction.""" """Return the wind direction."""
return self.coordinator.data.current_weather_data.get("wind_bearing") return self.coordinator.data.current_weather_data.get("wind_bearing")

View file

@ -2411,6 +2411,16 @@ disallow_untyped_defs = true
warn_return_any = true warn_return_any = true
warn_unreachable = 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.*] [mypy-homeassistant.components.metoffice.*]
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true