mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Use OptionsFlowWithReload in control4 (#149058)
This commit is contained in:
parent
2577d9f108
commit
dbdc666a92
@ -54,16 +54,20 @@ class Control4RuntimeData:
|
|||||||
type Control4ConfigEntry = ConfigEntry[Control4RuntimeData]
|
type Control4ConfigEntry = ConfigEntry[Control4RuntimeData]
|
||||||
|
|
||||||
|
|
||||||
async def call_c4_api_retry(func, *func_args): # noqa: RET503
|
async def call_c4_api_retry(func, *func_args):
|
||||||
"""Call C4 API function and retry on failure."""
|
"""Call C4 API function and retry on failure."""
|
||||||
# Ruff doesn't understand this loop - the exception is always raised after the retries
|
exc = None
|
||||||
for i in range(API_RETRY_TIMES):
|
for i in range(API_RETRY_TIMES):
|
||||||
try:
|
try:
|
||||||
return await func(*func_args)
|
return await func(*func_args)
|
||||||
except client_exceptions.ClientError as exception:
|
except client_exceptions.ClientError as exception:
|
||||||
_LOGGER.error("Error connecting to Control4 account API: %s", exception)
|
_LOGGER.error(
|
||||||
if i == API_RETRY_TIMES - 1:
|
"Try: %d, Error connecting to Control4 account API: %s",
|
||||||
raise ConfigEntryNotReady(exception) from exception
|
i + 1,
|
||||||
|
exception,
|
||||||
|
)
|
||||||
|
exc = exception
|
||||||
|
raise ConfigEntryNotReady(exc) from exc
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: Control4ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: Control4ConfigEntry) -> bool:
|
||||||
@ -141,21 +145,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: Control4ConfigEntry) ->
|
|||||||
ui_configuration=ui_configuration,
|
ui_configuration=ui_configuration,
|
||||||
)
|
)
|
||||||
|
|
||||||
entry.async_on_unload(entry.add_update_listener(update_listener))
|
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def update_listener(
|
|
||||||
hass: HomeAssistant, config_entry: Control4ConfigEntry
|
|
||||||
) -> None:
|
|
||||||
"""Update when config_entry options update."""
|
|
||||||
_LOGGER.debug("Config entry was updated, rerunning setup")
|
|
||||||
await hass.config_entries.async_reload(config_entry.entry_id)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: Control4ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: Control4ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
@ -11,7 +11,11 @@ from pyControl4.director import C4Director
|
|||||||
from pyControl4.error_handling import NotFound, Unauthorized
|
from pyControl4.error_handling import NotFound, Unauthorized
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow
|
from homeassistant.config_entries import (
|
||||||
|
ConfigFlow,
|
||||||
|
ConfigFlowResult,
|
||||||
|
OptionsFlowWithReload,
|
||||||
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
@ -153,7 +157,7 @@ class Control4ConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
return OptionsFlowHandler()
|
return OptionsFlowHandler()
|
||||||
|
|
||||||
|
|
||||||
class OptionsFlowHandler(OptionsFlow):
|
class OptionsFlowHandler(OptionsFlowWithReload):
|
||||||
"""Handle a option flow for Control4."""
|
"""Handle a option flow for Control4."""
|
||||||
|
|
||||||
async def async_step_init(
|
async def async_step_init(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user