mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Use SchemaOptionsFlowHandler in apple_tv (#82688)
This commit is contained in:
parent
e9ce08763c
commit
e00808bea8
@ -22,6 +22,10 @@ from homeassistant.core import callback
|
|||||||
from homeassistant.data_entry_flow import AbortFlow, FlowResult
|
from homeassistant.data_entry_flow import AbortFlow, FlowResult
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
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 homeassistant.util.network import is_ipv6_address
|
||||||
|
|
||||||
from .const import CONF_CREDENTIALS, CONF_IDENTIFIERS, CONF_START_OFF, DOMAIN
|
from .const import CONF_CREDENTIALS, CONF_IDENTIFIERS, CONF_START_OFF, DOMAIN
|
||||||
@ -36,6 +40,15 @@ DEFAULT_START_OFF = False
|
|||||||
|
|
||||||
DISCOVERY_AGGREGATION_TIME = 15 # seconds
|
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):
|
async def device_scan(hass, identifier, loop):
|
||||||
"""Scan for a specific device using identifier as filter."""
|
"""Scan for a specific device using identifier as filter."""
|
||||||
@ -76,9 +89,9 @@ class AppleTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
@callback
|
@callback
|
||||||
def async_get_options_flow(
|
def async_get_options_flow(
|
||||||
config_entry: config_entries.ConfigEntry,
|
config_entry: config_entries.ConfigEntry,
|
||||||
) -> AppleTVOptionsFlow:
|
) -> SchemaOptionsFlowHandler:
|
||||||
"""Get options flow for this handler."""
|
"""Get options flow for this handler."""
|
||||||
return AppleTVOptionsFlow(config_entry)
|
return SchemaOptionsFlowHandler(config_entry, OPTIONS_FLOW)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initialize a new AppleTVConfigFlow."""
|
"""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)
|
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):
|
class DeviceNotFound(HomeAssistantError):
|
||||||
"""Error to indicate device could not be found."""
|
"""Error to indicate device could not be found."""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user