Skip to content

Commit e469c68

Browse files
authored
Add Airnow to strict typing (home-assistant#105566)
1 parent 278c7ac commit e469c68

File tree

4 files changed

+49
-16
lines changed

4 files changed

+49
-16
lines changed

.strict-typing

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ homeassistant.components.adguard.*
4848
homeassistant.components.aftership.*
4949
homeassistant.components.air_quality.*
5050
homeassistant.components.airly.*
51+
homeassistant.components.airnow.*
5152
homeassistant.components.airvisual.*
5253
homeassistant.components.airvisual_pro.*
5354
homeassistant.components.airzone.*

homeassistant/components/airnow/config_flow.py

+23-12
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66
from pyairnow.errors import AirNowError, EmptyResponseError, InvalidKeyError
77
import voluptuous as vol
88

9-
from homeassistant import config_entries, core, data_entry_flow, exceptions
9+
from homeassistant import core
10+
from homeassistant.config_entries import (
11+
ConfigEntry,
12+
ConfigFlow,
13+
OptionsFlow,
14+
OptionsFlowWithConfigEntry,
15+
)
1016
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_RADIUS
17+
from homeassistant.core import HomeAssistant
18+
from homeassistant.data_entry_flow import FlowResult
19+
from homeassistant.exceptions import HomeAssistantError
1120
from homeassistant.helpers.aiohttp_client import async_get_clientsession
1221
import homeassistant.helpers.config_validation as cv
1322

@@ -16,7 +25,7 @@
1625
_LOGGER = logging.getLogger(__name__)
1726

1827

19-
async def validate_input(hass: core.HomeAssistant, data):
28+
async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> bool:
2029
"""Validate the user input allows us to connect.
2130
2231
Data has the keys from DATA_SCHEMA with values provided by the user.
@@ -46,12 +55,14 @@ async def validate_input(hass: core.HomeAssistant, data):
4655
return True
4756

4857

49-
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
58+
class AirNowConfigFlow(ConfigFlow, domain=DOMAIN):
5059
"""Handle a config flow for AirNow."""
5160

5261
VERSION = 2
5362

54-
async def async_step_user(self, user_input=None):
63+
async def async_step_user(
64+
self, user_input: dict[str, Any] | None = None
65+
) -> FlowResult:
5566
"""Handle the initial step."""
5667
errors = {}
5768
if user_input is not None:
@@ -108,18 +119,18 @@ async def async_step_user(self, user_input=None):
108119
@staticmethod
109120
@core.callback
110121
def async_get_options_flow(
111-
config_entry: config_entries.ConfigEntry,
112-
) -> config_entries.OptionsFlow:
122+
config_entry: ConfigEntry,
123+
) -> OptionsFlow:
113124
"""Return the options flow."""
114-
return OptionsFlowHandler(config_entry)
125+
return AirNowOptionsFlowHandler(config_entry)
115126

116127

117-
class OptionsFlowHandler(config_entries.OptionsFlowWithConfigEntry):
128+
class AirNowOptionsFlowHandler(OptionsFlowWithConfigEntry):
118129
"""Handle an options flow for AirNow."""
119130

120131
async def async_step_init(
121132
self, user_input: dict[str, Any] | None = None
122-
) -> data_entry_flow.FlowResult:
133+
) -> FlowResult:
123134
"""Manage the options."""
124135
if user_input is not None:
125136
return self.async_create_entry(data=user_input)
@@ -141,13 +152,13 @@ async def async_step_init(
141152
)
142153

143154

144-
class CannotConnect(exceptions.HomeAssistantError):
155+
class CannotConnect(HomeAssistantError):
145156
"""Error to indicate we cannot connect."""
146157

147158

148-
class InvalidAuth(exceptions.HomeAssistantError):
159+
class InvalidAuth(HomeAssistantError):
149160
"""Error to indicate there is invalid auth."""
150161

151162

152-
class InvalidLocation(exceptions.HomeAssistantError):
163+
class InvalidLocation(HomeAssistantError):
153164
"""Error to indicate the location is invalid."""

homeassistant/components/airnow/coordinator.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
"""DataUpdateCoordinator for the AirNow integration."""
2+
from datetime import timedelta
23
import logging
4+
from typing import Any
35

6+
from aiohttp import ClientSession
47
from aiohttp.client_exceptions import ClientConnectorError
58
from pyairnow import WebServiceAPI
69
from pyairnow.conv import aqi_to_concentration
710
from pyairnow.errors import AirNowError
811

12+
from homeassistant.core import HomeAssistant
913
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
1014

1115
from .const import (
@@ -31,12 +35,19 @@
3135
_LOGGER = logging.getLogger(__name__)
3236

3337

34-
class AirNowDataUpdateCoordinator(DataUpdateCoordinator):
38+
class AirNowDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
3539
"""The AirNow update coordinator."""
3640

3741
def __init__(
38-
self, hass, session, api_key, latitude, longitude, distance, update_interval
39-
):
42+
self,
43+
hass: HomeAssistant,
44+
session: ClientSession,
45+
api_key: str,
46+
latitude: float,
47+
longitude: float,
48+
distance: int,
49+
update_interval: timedelta,
50+
) -> None:
4051
"""Initialize."""
4152
self.latitude = latitude
4253
self.longitude = longitude
@@ -46,7 +57,7 @@ def __init__(
4657

4758
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=update_interval)
4859

49-
async def _async_update_data(self):
60+
async def _async_update_data(self) -> dict[str, Any]:
5061
"""Update data via library."""
5162
data = {}
5263
try:

mypy.ini

+10
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ disallow_untyped_defs = true
240240
warn_return_any = true
241241
warn_unreachable = true
242242

243+
[mypy-homeassistant.components.airnow.*]
244+
check_untyped_defs = true
245+
disallow_incomplete_defs = true
246+
disallow_subclassing_any = true
247+
disallow_untyped_calls = true
248+
disallow_untyped_decorators = true
249+
disallow_untyped_defs = true
250+
warn_return_any = true
251+
warn_unreachable = true
252+
243253
[mypy-homeassistant.components.airvisual.*]
244254
check_untyped_defs = true
245255
disallow_incomplete_defs = true

0 commit comments

Comments
 (0)