Enable strict typing for isy994 (#65439)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
2f0d0998a2
commit
6c38a6b569
18 changed files with 351 additions and 279 deletions
|
@ -1,5 +1,8 @@
|
|||
"""Config flow for Universal Devices ISY994 integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
|
||||
from aiohttp import CookieJar
|
||||
|
@ -38,7 +41,7 @@ from .const import (
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _data_schema(schema_input):
|
||||
def _data_schema(schema_input: dict[str, str]) -> vol.Schema:
|
||||
"""Generate schema with defaults."""
|
||||
return vol.Schema(
|
||||
{
|
||||
|
@ -51,7 +54,9 @@ def _data_schema(schema_input):
|
|||
)
|
||||
|
||||
|
||||
async def validate_input(hass: core.HomeAssistant, data):
|
||||
async def validate_input(
|
||||
hass: core.HomeAssistant, data: dict[str, Any]
|
||||
) -> dict[str, str]:
|
||||
"""Validate the user input allows us to connect.
|
||||
|
||||
Data has the keys from DATA_SCHEMA with values provided by the user.
|
||||
|
@ -65,7 +70,7 @@ async def validate_input(hass: core.HomeAssistant, data):
|
|||
https = False
|
||||
port = host.port or HTTP_PORT
|
||||
session = aiohttp_client.async_create_clientsession(
|
||||
hass, verify_ssl=None, cookie_jar=CookieJar(unsafe=True)
|
||||
hass, verify_ssl=False, cookie_jar=CookieJar(unsafe=True)
|
||||
)
|
||||
elif host.scheme == SCHEME_HTTPS:
|
||||
https = True
|
||||
|
@ -113,18 +118,22 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the isy994 config flow."""
|
||||
self.discovered_conf = {}
|
||||
self.discovered_conf: dict[str, str] = {}
|
||||
|
||||
@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 OptionsFlowHandler(config_entry)
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> data_entry_flow.FlowResult:
|
||||
"""Handle the initial step."""
|
||||
errors = {}
|
||||
info = None
|
||||
info: dict[str, str] = {}
|
||||
if user_input is not None:
|
||||
try:
|
||||
info = await validate_input(self.hass, user_input)
|
||||
|
@ -149,11 +158,15 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_import(self, user_input):
|
||||
async def async_step_import(
|
||||
self, user_input: dict[str, Any]
|
||||
) -> data_entry_flow.FlowResult:
|
||||
"""Handle import."""
|
||||
return await self.async_step_user(user_input)
|
||||
|
||||
async def _async_set_unique_id_or_update(self, isy_mac, ip_address, port) -> None:
|
||||
async def _async_set_unique_id_or_update(
|
||||
self, isy_mac: str, ip_address: str, port: int | None
|
||||
) -> None:
|
||||
"""Abort and update the ip address on change."""
|
||||
existing_entry = await self.async_set_unique_id(isy_mac)
|
||||
if not existing_entry:
|
||||
|
@ -211,6 +224,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
"""Handle a discovered isy994."""
|
||||
friendly_name = discovery_info.upnp[ssdp.ATTR_UPNP_FRIENDLY_NAME]
|
||||
url = discovery_info.ssdp_location
|
||||
assert isinstance(url, str)
|
||||
parsed_url = urlparse(url)
|
||||
mac = discovery_info.upnp[ssdp.ATTR_UPNP_UDN]
|
||||
if mac.startswith(UDN_UUID_PREFIX):
|
||||
|
@ -224,6 +238,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
elif parsed_url.scheme == SCHEME_HTTPS:
|
||||
port = HTTPS_PORT
|
||||
|
||||
assert isinstance(parsed_url.hostname, str)
|
||||
await self._async_set_unique_id_or_update(mac, parsed_url.hostname, port)
|
||||
|
||||
self.discovered_conf = {
|
||||
|
@ -242,7 +257,9 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
|||
"""Initialize options flow."""
|
||||
self.config_entry = config_entry
|
||||
|
||||
async def async_step_init(self, user_input=None):
|
||||
async def async_step_init(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> data_entry_flow.FlowResult:
|
||||
"""Handle options flow."""
|
||||
if user_input is not None:
|
||||
return self.async_create_entry(title="", data=user_input)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue