Adjust async_step_homekit signature for strict typing (#59745)

* Use ZeroconfServiceInfo in async_step_homekit

* Update DiscoveryFlowHandler

* Update components
This commit is contained in:
epenet 2021-11-16 00:27:04 +01:00 committed by GitHub
parent c0a8cea6fb
commit 4d96ca3ddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 16 deletions

View File

@ -93,17 +93,17 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
) -> FlowResult:
"""Handle Nanoleaf Zeroconf discovery."""
_LOGGER.debug("Zeroconf discovered: %s", discovery_info)
return await self._async_homekit_zeroconf_discovery_handler(
cast(dict, discovery_info)
)
return await self._async_homekit_zeroconf_discovery_handler(discovery_info)
async def async_step_homekit(self, discovery_info: DiscoveryInfoType) -> FlowResult:
async def async_step_homekit(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle Nanoleaf Homekit discovery."""
_LOGGER.debug("Homekit discovered: %s", discovery_info)
return await self._async_homekit_zeroconf_discovery_handler(discovery_info)
async def _async_homekit_zeroconf_discovery_handler(
self, discovery_info: DiscoveryInfoType
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle Nanoleaf Homekit and Zeroconf discovery."""
return await self._async_discovery_handler(

View File

@ -1,7 +1,7 @@
"""Config flow to configure the RainMachine component."""
from __future__ import annotations
from typing import Any, cast
from typing import Any
from regenmaschine import Client
from regenmaschine.controller import Controller
@ -15,7 +15,6 @@ from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_PORT, CONF_
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import aiohttp_client, config_validation as cv
from homeassistant.helpers.typing import DiscoveryInfoType
from .const import CONF_ZONE_RUN_TIME, DEFAULT_PORT, DEFAULT_ZONE_RUN, DOMAIN
@ -55,7 +54,9 @@ class RainMachineFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Define the config flow to handle options."""
return RainMachineOptionsFlowHandler(config_entry)
async def async_step_homekit(self, discovery_info: DiscoveryInfoType) -> FlowResult:
async def async_step_homekit(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle a flow initialized by homekit discovery."""
return await self.async_step_homekit_zeroconf(discovery_info)
@ -63,10 +64,10 @@ class RainMachineFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle discovery via zeroconf."""
return await self.async_step_homekit_zeroconf(cast(dict, discovery_info))
return await self.async_step_homekit_zeroconf(discovery_info)
async def async_step_homekit_zeroconf(
self, discovery_info: DiscoveryInfoType
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle discovery via zeroconf."""
ip_address = discovery_info["host"]

View File

@ -11,9 +11,9 @@ from pytradfri.api.aiocoap_api import APIFactory
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components import zeroconf
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.typing import DiscoveryInfoType
from .const import (
CONF_GATEWAY_ID,
@ -42,7 +42,7 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
def __init__(self) -> None:
"""Initialize flow."""
self._host = None
self._host: str | None = None
self._import_groups = False
async def async_step_user(
@ -92,7 +92,9 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
step_id="auth", data_schema=vol.Schema(fields), errors=errors
)
async def async_step_homekit(self, discovery_info: DiscoveryInfoType) -> FlowResult:
async def async_step_homekit(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle homekit discovery."""
await self.async_set_unique_id(discovery_info["properties"]["id"])
self._abort_if_unique_id_configured({CONF_HOST: discovery_info["host"]})

View File

@ -1354,10 +1354,10 @@ class ConfigFlow(data_entry_flow.FlowHandler):
return await self.async_step_discovery(discovery_info)
async def async_step_homekit(
self, discovery_info: DiscoveryInfoType
self, discovery_info: ZeroconfServiceInfo
) -> data_entry_flow.FlowResult:
"""Handle a flow initialized by Homekit discovery."""
return await self.async_step_discovery(discovery_info)
return await self.async_step_discovery(cast(dict, discovery_info))
async def async_step_mqtt(
self, discovery_info: DiscoveryInfoType

View File

@ -82,6 +82,17 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
return await self.async_step_confirm()
async def async_step_homekit(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
"""Handle a flow initialized by Homekit discovery."""
if self._async_in_progress() or self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
await self.async_set_unique_id(self._domain)
return await self.async_step_confirm()
async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> FlowResult:
@ -95,7 +106,6 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
async_step_ssdp = async_step_discovery
async_step_mqtt = async_step_discovery
async_step_homekit = async_step_discovery
async_step_dhcp = async_step_discovery
async def async_step_import(self, _: dict[str, Any] | None) -> FlowResult: