Add type annotations for Netatmo (#52811)

This commit is contained in:
Tobias Sauerwein 2021-07-21 23:36:57 +02:00 committed by GitHub
parent 84c482441d
commit 583deada83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 288 additions and 177 deletions

View file

@ -1,4 +1,6 @@
"""Config flow for Netatmo."""
from __future__ import annotations
import logging
import uuid
@ -7,6 +9,7 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_SHOW_ON_MAP
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv
from .const import (
@ -32,7 +35,9 @@ class NetatmoFlowHandler(
@staticmethod
@callback
def async_get_options_flow(config_entry):
def async_get_options_flow(
config_entry: config_entries.ConfigEntry,
) -> config_entries.OptionsFlow:
"""Get the options flow for this handler."""
return NetatmoOptionsFlowHandler(config_entry)
@ -62,7 +67,7 @@ class NetatmoFlowHandler(
return {"scope": " ".join(scopes)}
async def async_step_user(self, user_input=None):
async def async_step_user(self, user_input: dict | None = None) -> FlowResult:
"""Handle a flow start."""
await self.async_set_unique_id(DOMAIN)
@ -81,17 +86,19 @@ class NetatmoOptionsFlowHandler(config_entries.OptionsFlow):
self.options = dict(config_entry.options)
self.options.setdefault(CONF_WEATHER_AREAS, {})
async def async_step_init(self, user_input=None):
async def async_step_init(self, user_input: dict | None = None) -> FlowResult:
"""Manage the Netatmo options."""
return await self.async_step_public_weather_areas()
async def async_step_public_weather_areas(self, user_input=None):
async def async_step_public_weather_areas(
self, user_input: dict | None = None
) -> FlowResult:
"""Manage configuration of Netatmo public weather areas."""
errors = {}
errors: dict = {}
if user_input is not None:
new_client = user_input.pop(CONF_NEW_AREA, None)
areas = user_input.pop(CONF_WEATHER_AREAS, None)
areas = user_input.pop(CONF_WEATHER_AREAS, [])
user_input[CONF_WEATHER_AREAS] = {
area: self.options[CONF_WEATHER_AREAS][area] for area in areas
}
@ -110,7 +117,7 @@ class NetatmoOptionsFlowHandler(config_entries.OptionsFlow):
vol.Optional(
CONF_WEATHER_AREAS,
default=weather_areas,
): cv.multi_select(weather_areas),
): cv.multi_select({wa: None for wa in weather_areas}),
vol.Optional(CONF_NEW_AREA): str,
}
)
@ -120,7 +127,7 @@ class NetatmoOptionsFlowHandler(config_entries.OptionsFlow):
errors=errors,
)
async def async_step_public_weather(self, user_input=None):
async def async_step_public_weather(self, user_input: dict) -> FlowResult:
"""Manage configuration of Netatmo public weather sensors."""
if user_input is not None and CONF_NEW_AREA not in user_input:
self.options[CONF_WEATHER_AREAS][
@ -181,14 +188,14 @@ class NetatmoOptionsFlowHandler(config_entries.OptionsFlow):
return self.async_show_form(step_id="public_weather", data_schema=data_schema)
def _create_options_entry(self):
def _create_options_entry(self) -> FlowResult:
"""Update config entry options."""
return self.async_create_entry(
title="Netatmo Public Weather", data=self.options
)
def fix_coordinates(user_input):
def fix_coordinates(user_input: dict) -> dict:
"""Fix coordinates if they don't comply with the Netatmo API."""
# Ensure coordinates have acceptable length for the Netatmo API
for coordinate in (CONF_LAT_NE, CONF_LAT_SW, CONF_LON_NE, CONF_LON_SW):