Enable strict type checks for onewire (#50422)

This commit is contained in:
epenet 2021-05-11 17:28:17 +02:00 committed by GitHub
parent efa5c59559
commit d6c99a3db9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 202 additions and 84 deletions

View file

@ -1,9 +1,14 @@
"""Config flow for 1-Wire component."""
from __future__ import annotations
from typing import Any
import voluptuous as vol
from homeassistant.config_entries import ConfigFlow
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TYPE
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResult
from .const import (
CONF_MOUNT_DIR,
@ -32,7 +37,9 @@ DATA_SCHEMA_MOUNTDIR = vol.Schema(
)
async def validate_input_owserver(hass: HomeAssistant, data):
async def validate_input_owserver(
hass: HomeAssistant, data: dict[str, Any]
) -> dict[str, str]:
"""Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA_OWSERVER with values provided by the user.
@ -49,7 +56,9 @@ async def validate_input_owserver(hass: HomeAssistant, data):
return {"title": host}
def is_duplicate_owserver_entry(hass: HomeAssistant, user_input):
def is_duplicate_owserver_entry(
hass: HomeAssistant, user_input: dict[str, Any]
) -> bool:
"""Check existing entries for matching host and port."""
for config_entry in hass.config_entries.async_entries(DOMAIN):
if (
@ -61,7 +70,9 @@ def is_duplicate_owserver_entry(hass: HomeAssistant, user_input):
return False
async def validate_input_mount_dir(hass: HomeAssistant, data):
async def validate_input_mount_dir(
hass: HomeAssistant, data: dict[str, Any]
) -> dict[str, str]:
"""Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA_MOUNTDIR with values provided by the user.
@ -82,16 +93,18 @@ class OneWireFlowHandler(ConfigFlow, domain=DOMAIN):
VERSION = 1
def __init__(self):
def __init__(self) -> None:
"""Initialize 1-Wire config flow."""
self.onewire_config = {}
self.onewire_config: dict[str, Any] = {}
async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle 1-Wire config flow start.
Let user manually input configuration.
"""
errors = {}
errors: dict[str, str] = {}
if user_input is not None:
self.onewire_config.update(user_input)
if CONF_TYPE_OWSERVER == user_input[CONF_TYPE]:
@ -105,7 +118,9 @@ class OneWireFlowHandler(ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_owserver(self, user_input=None):
async def async_step_owserver(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle OWServer configuration."""
errors = {}
if user_input:
@ -130,7 +145,9 @@ class OneWireFlowHandler(ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_mount_dir(self, user_input=None):
async def async_step_mount_dir(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle SysBus configuration."""
errors = {}
if user_input:
@ -157,7 +174,7 @@ class OneWireFlowHandler(ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_import(self, platform_config):
async def async_step_import(self, platform_config: dict[str, Any]) -> FlowResult:
"""Handle import configuration from YAML."""
# OWServer
if platform_config[CONF_TYPE] == CONF_TYPE_OWSERVER: