1 """Config flow for Vera."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
11 from requests.exceptions
import RequestException
12 import voluptuous
as vol
27 from .const
import CONF_CONTROLLER, CONF_LEGACY_UNIQUE_ID, DOMAIN
29 LIST_REGEX = re.compile(
"[^0-9]+")
30 _LOGGER = logging.getLogger(__name__)
34 """Fix the id list by converting it to a supported int list."""
39 """Convert a string to an int list."""
40 return [
int(s)
for s
in LIST_REGEX.split(data)
if len(s) > 0]
44 """Convert an int list to a string."""
45 return " ".join([
str(i)
for i
in data])
48 def new_options(lights: list[int], exclude: list[int]) -> dict[str, list[int]]:
49 """Create a standard options object."""
50 return {CONF_LIGHTS: lights, CONF_EXCLUDE: exclude}
54 """Return options schema."""
55 options = options
or {}
68 def options_data(user_input: dict[str, str]) -> dict[str, list[int]]:
69 """Return options dict."""
77 """Options for the component."""
81 user_input: dict[str, str] |
None =
None,
82 ) -> ConfigFlowResult:
83 """Manage the options."""
84 if user_input
is not None:
97 """Vera config flow."""
102 """Get the options flow."""
106 self, user_input: dict[str, Any] |
None =
None
107 ) -> ConfigFlowResult:
108 """Handle user initiated flow."""
109 if user_input
is not None:
114 CONF_SOURCE: SOURCE_USER,
115 CONF_LEGACY_UNIQUE_ID:
False,
121 data_schema=vol.Schema(
127 """Handle a flow initialized by import."""
131 entity_registry = er.async_get(self.hass)
132 use_legacy_unique_id = (
136 for entry
in entity_registry.entities.values()
137 if entry.platform == DOMAIN
and entry.unique_id.isdigit()
146 CONF_SOURCE: SOURCE_IMPORT,
147 CONF_LEGACY_UNIQUE_ID: use_legacy_unique_id,
152 """Validate and create config entry."""
153 base_url = config[CONF_CONTROLLER] = config[CONF_CONTROLLER].rstrip(
"/")
154 controller = pv.VeraController(base_url)
158 await self.hass.async_add_executor_job(controller.refresh_data)
159 except RequestException:
160 _LOGGER.error(
"Failed to connect to vera controller %s", base_url)
162 reason=
"cannot_connect", description_placeholders={
"base_url": base_url}
ConfigFlowResult async_step_init(self, dict[str, str]|None user_input=None)
ConfigFlowResult async_step_import(self, dict[str, Any] import_data)
ConfigFlowResult async_step_finish(self, dict[str, Any] config)
OptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry|None async_set_unique_id(self, str|None unique_id=None, *bool raise_on_progress=True)
ConfigFlowResult async_create_entry(self, *str title, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None, Mapping[str, Any]|None options=None)
ConfigFlowResult async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
ConfigFlowResult async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
_FlowResultT async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
str list_to_str(list[Any] data)
list[int] fix_device_id_list(list[Any] data)
dict[str, list[int]] options_data(dict[str, str] user_input)
dict[str, list[int]] new_options(list[int] lights, list[int] exclude)
list[int] str_to_int_list(str data)
VolDictType options_schema(Mapping[str, Any]|None options=None)