Adjust config-flow type hints in gogogate2 (#72445)

This commit is contained in:
epenet 2022-05-30 08:54:29 +02:00 committed by GitHub
parent 8d72891d83
commit 6bc09741c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,12 +1,14 @@
"""Config flow for Gogogate2.""" """Config flow for Gogogate2."""
from __future__ import annotations
import dataclasses import dataclasses
import re import re
from typing import Any
from ismartgate.common import AbstractInfoResponse, ApiError from ismartgate.common import AbstractInfoResponse, ApiError
from ismartgate.const import GogoGate2ApiErrorCode, ISmartGateApiErrorCode from ismartgate.const import GogoGate2ApiErrorCode, ISmartGateApiErrorCode
import voluptuous as vol import voluptuous as vol
from homeassistant import data_entry_flow
from homeassistant.components import dhcp, zeroconf from homeassistant.components import dhcp, zeroconf
from homeassistant.config_entries import ConfigFlow from homeassistant.config_entries import ConfigFlow
from homeassistant.const import ( from homeassistant.const import (
@ -15,6 +17,7 @@ from homeassistant.const import (
CONF_PASSWORD, CONF_PASSWORD,
CONF_USERNAME, CONF_USERNAME,
) )
from homeassistant.data_entry_flow import AbortFlow, FlowResult
from .common import get_api from .common import get_api
from .const import DEVICE_TYPE_GOGOGATE2, DEVICE_TYPE_ISMARTGATE, DOMAIN from .const import DEVICE_TYPE_GOGOGATE2, DEVICE_TYPE_ISMARTGATE, DOMAIN
@ -30,28 +33,26 @@ class Gogogate2FlowHandler(ConfigFlow, domain=DOMAIN):
VERSION = 1 VERSION = 1
def __init__(self): def __init__(self) -> None:
"""Initialize the config flow.""" """Initialize the config flow."""
self._ip_address = None self._ip_address: str | None = None
self._device_type = None self._device_type: str | None = None
async def async_step_homekit( async def async_step_homekit(
self, discovery_info: zeroconf.ZeroconfServiceInfo self, discovery_info: zeroconf.ZeroconfServiceInfo
) -> data_entry_flow.FlowResult: ) -> FlowResult:
"""Handle homekit discovery.""" """Handle homekit discovery."""
await self.async_set_unique_id( await self.async_set_unique_id(
discovery_info.properties[zeroconf.ATTR_PROPERTIES_ID] discovery_info.properties[zeroconf.ATTR_PROPERTIES_ID]
) )
return await self._async_discovery_handler(discovery_info.host) return await self._async_discovery_handler(discovery_info.host)
async def async_step_dhcp( async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowResult:
self, discovery_info: dhcp.DhcpServiceInfo
) -> data_entry_flow.FlowResult:
"""Handle dhcp discovery.""" """Handle dhcp discovery."""
await self.async_set_unique_id(discovery_info.macaddress) await self.async_set_unique_id(discovery_info.macaddress)
return await self._async_discovery_handler(discovery_info.ip) return await self._async_discovery_handler(discovery_info.ip)
async def _async_discovery_handler(self, ip_address): async def _async_discovery_handler(self, ip_address: str) -> FlowResult:
"""Start the user flow from any discovery.""" """Start the user flow from any discovery."""
self.context[CONF_IP_ADDRESS] = ip_address self.context[CONF_IP_ADDRESS] = ip_address
self._abort_if_unique_id_configured({CONF_IP_ADDRESS: ip_address}) self._abort_if_unique_id_configured({CONF_IP_ADDRESS: ip_address})
@ -61,12 +62,14 @@ class Gogogate2FlowHandler(ConfigFlow, domain=DOMAIN):
self._ip_address = ip_address self._ip_address = ip_address
for progress in self._async_in_progress(): for progress in self._async_in_progress():
if progress.get("context", {}).get(CONF_IP_ADDRESS) == self._ip_address: if progress.get("context", {}).get(CONF_IP_ADDRESS) == self._ip_address:
raise data_entry_flow.AbortFlow("already_in_progress") raise AbortFlow("already_in_progress")
self._device_type = DEVICE_TYPE_ISMARTGATE self._device_type = DEVICE_TYPE_ISMARTGATE
return await self.async_step_user() return await self.async_step_user()
async def async_step_user(self, user_input: dict = None): async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle user initiated flow.""" """Handle user initiated flow."""
user_input = user_input or {} user_input = user_input or {}
errors = {} errors = {}