Migrate integrations n-r to generic flowhandler (#111864)

This commit is contained in:
Erik Montnemery 2024-02-29 20:09:01 +01:00 committed by GitHub
parent 52e7912caf
commit e0c1feb22c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
113 changed files with 890 additions and 746 deletions

View file

@ -13,8 +13,12 @@ import serial
import serial.tools.list_ports
import voluptuous as vol
from homeassistant import config_entries, data_entry_flow, exceptions
from homeassistant.config_entries import ConfigEntry
from homeassistant.config_entries import (
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
OptionsFlow,
)
from homeassistant.const import (
CONF_COMMAND_OFF,
CONF_COMMAND_ON,
@ -26,6 +30,7 @@ from homeassistant.const import (
CONF_TYPE,
)
from homeassistant.core import State, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import (
config_validation as cv,
device_registry as dr,
@ -74,7 +79,7 @@ def none_or_int(value: str | None, base: int) -> int | None:
return int(value, base)
class OptionsFlow(config_entries.OptionsFlow):
class RfxtrxOptionsFlow(OptionsFlow):
"""Handle Rfxtrx options."""
_device_registry: dr.DeviceRegistry
@ -91,13 +96,13 @@ class OptionsFlow(config_entries.OptionsFlow):
async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> data_entry_flow.FlowResult:
) -> ConfigFlowResult:
"""Manage the options."""
return await self.async_step_prompt_options()
async def async_step_prompt_options(
self, user_input: dict[str, Any] | None = None
) -> data_entry_flow.FlowResult:
) -> ConfigFlowResult:
"""Prompt for options."""
errors = {}
@ -171,7 +176,7 @@ class OptionsFlow(config_entries.OptionsFlow):
async def async_step_set_device_options(
self, user_input: dict[str, Any] | None = None
) -> data_entry_flow.FlowResult:
) -> ConfigFlowResult:
"""Manage device options."""
errors = {}
assert self._selected_device_object
@ -489,14 +494,14 @@ class OptionsFlow(config_entries.OptionsFlow):
)
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
class RfxtrxConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for RFXCOM RFXtrx."""
VERSION = 1
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> data_entry_flow.FlowResult:
) -> ConfigFlowResult:
"""Step when user initializes a integration."""
await self.async_set_unique_id(DOMAIN)
self._abort_if_unique_id_configured()
@ -515,7 +520,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
async def async_step_setup_network(
self, user_input: dict[str, Any] | None = None
) -> data_entry_flow.FlowResult:
) -> ConfigFlowResult:
"""Step when setting up network configuration."""
errors: dict[str, str] = {}
@ -542,7 +547,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
async def async_step_setup_serial(
self, user_input: dict[str, Any] | None = None
) -> data_entry_flow.FlowResult:
) -> ConfigFlowResult:
"""Step when setting up serial configuration."""
errors: dict[str, str] = {}
@ -581,7 +586,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
async def async_step_setup_serial_manual_path(
self, user_input: dict[str, Any] | None = None
) -> data_entry_flow.FlowResult:
) -> ConfigFlowResult:
"""Select path manually."""
errors: dict[str, str] = {}
@ -628,7 +633,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
@callback
def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow:
"""Get the options flow for this handler."""
return OptionsFlow(config_entry)
return RfxtrxOptionsFlow(config_entry)
def _test_transport(host: str | None, port: int | None, device: str | None) -> bool:
@ -658,5 +663,5 @@ def get_serial_by_id(dev_path: str) -> str:
return dev_path
class CannotConnect(exceptions.HomeAssistantError):
class CannotConnect(HomeAssistantError):
"""Error to indicate we cannot connect."""