From e00808bea86fe9e4267e01ff56f0d395aaad21d4 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 25 Nov 2022 16:09:01 +0100 Subject: [PATCH] Use SchemaOptionsFlowHandler in apple_tv (#82688) --- .../components/apple_tv/config_flow.py | 46 ++++++------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/homeassistant/components/apple_tv/config_flow.py b/homeassistant/components/apple_tv/config_flow.py index b78add3260e..d000c0346af 100644 --- a/homeassistant/components/apple_tv/config_flow.py +++ b/homeassistant/components/apple_tv/config_flow.py @@ -22,6 +22,10 @@ from homeassistant.core import callback from homeassistant.data_entry_flow import AbortFlow, FlowResult from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.aiohttp_client import async_get_clientsession +from homeassistant.helpers.schema_config_entry_flow import ( + SchemaFlowFormStep, + SchemaOptionsFlowHandler, +) from homeassistant.util.network import is_ipv6_address from .const import CONF_CREDENTIALS, CONF_IDENTIFIERS, CONF_START_OFF, DOMAIN @@ -36,6 +40,15 @@ DEFAULT_START_OFF = False DISCOVERY_AGGREGATION_TIME = 15 # seconds +OPTIONS_SCHEMA = vol.Schema( + { + vol.Optional(CONF_START_OFF, default=DEFAULT_START_OFF): bool, + } +) +OPTIONS_FLOW = { + "init": SchemaFlowFormStep(OPTIONS_SCHEMA), +} + async def device_scan(hass, identifier, loop): """Scan for a specific device using identifier as filter.""" @@ -76,9 +89,9 @@ class AppleTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): @callback def async_get_options_flow( config_entry: config_entries.ConfigEntry, - ) -> AppleTVOptionsFlow: + ) -> SchemaOptionsFlowHandler: """Get options flow for this handler.""" - return AppleTVOptionsFlow(config_entry) + return SchemaOptionsFlowHandler(config_entry, OPTIONS_FLOW) def __init__(self): """Initialize a new AppleTVConfigFlow.""" @@ -525,35 +538,6 @@ class AppleTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): return self.async_create_entry(title=self.atv.name, data=data) -class AppleTVOptionsFlow(config_entries.OptionsFlow): - """Handle Apple TV options.""" - - def __init__(self, config_entry: config_entries.ConfigEntry) -> None: - """Initialize Apple TV options flow.""" - self.config_entry = config_entry - self.options = dict(config_entry.options) - - async def async_step_init(self, user_input=None): - """Manage the Apple TV options.""" - if user_input is not None: - self.options[CONF_START_OFF] = user_input[CONF_START_OFF] - return self.async_create_entry(title="", data=self.options) - - return self.async_show_form( - step_id="init", - data_schema=vol.Schema( - { - vol.Optional( - CONF_START_OFF, - default=self.config_entry.options.get( - CONF_START_OFF, DEFAULT_START_OFF - ), - ): bool, - } - ), - ) - - class DeviceNotFound(HomeAssistantError): """Error to indicate device could not be found."""