1 """Config flow for the Home Assistant Yellow integration."""
3 from __future__
import annotations
5 from abc
import ABC, abstractmethod
8 from typing
import Any, final
11 from universal_silabs_flasher.const
import ApplicationType
12 import voluptuous
as vol
16 async_get_yellow_settings,
18 async_set_yellow_settings,
21 BaseFirmwareConfigFlow,
22 BaseFirmwareOptionsFlow,
25 OptionsFlowHandler
as MultiprotocolOptionsFlowHandler,
26 SerialPortSettings
as MultiprotocolSerialPortSettings,
37 from .const
import DOMAIN, FIRMWARE, RADIO_DEVICE, ZHA_DOMAIN, ZHA_HW_DISCOVERY_DATA
38 from .hardware
import BOARD_NAME
40 _LOGGER = logging.getLogger(__name__)
42 STEP_HW_SETTINGS_SCHEMA = vol.Schema(
44 vol.Required(
"disk_led"): selector.BooleanSelector(),
45 vol.Required(
"heartbeat_led"): selector.BooleanSelector(),
46 vol.Required(
"power_led"): selector.BooleanSelector(),
52 """Handle a config flow for Home Assistant Yellow."""
57 def __init__(self, *args: Any, **kwargs: Any) ->
None:
58 """Instantiate config flow."""
66 config_entry: ConfigEntry,
68 """Return the options flow."""
69 firmware_type = ApplicationType(config_entry.data[FIRMWARE])
71 if firmware_type
is ApplicationType.CPC:
77 self, data: dict[str, Any] |
None =
None
78 ) -> ConfigFlowResult:
79 """Handle the initial step."""
85 discovery_flow.async_create_flow(
88 context={
"source": SOURCE_HARDWARE},
89 data=ZHA_HW_DISCOVERY_DATA,
95 """Create the config entry."""
106 """Base Home Assistant Yellow options flow shared between firmware and multi-PAN."""
108 _hw_settings: dict[str, bool] |
None =
None
112 """Show the main menu."""
115 async
def async_step_init(
116 self, user_input: dict[str, Any] |
None =
None
117 ) -> ConfigFlowResult:
118 """Manage the options flow."""
122 async
def async_step_on_supervisor(
123 self, user_input: dict[str, Any] |
None =
None
124 ) -> ConfigFlowResult:
125 """Handle logic when on Supervisor host."""
128 async
def async_step_hardware_settings(
129 self, user_input: dict[str, Any] |
None =
None
130 ) -> ConfigFlowResult:
131 """Handle hardware settings."""
133 if user_input
is not None:
137 async
with asyncio.timeout(10):
139 except (aiohttp.ClientError, TimeoutError, HassioAPIError)
as err:
140 _LOGGER.warning(
"Failed to write hardware settings", exc_info=err)
141 return self.
async_abortasync_abort(reason=
"write_hw_settings_error")
142 return await self.async_step_reboot_menu()
145 async
with asyncio.timeout(10):
149 except (aiohttp.ClientError, TimeoutError, HassioAPIError)
as err:
150 _LOGGER.warning(
"Failed to read hardware settings", exc_info=err)
151 return self.
async_abortasync_abort(reason=
"read_hw_settings_error")
157 return self.
async_show_formasync_show_form(step_id=
"hardware_settings", data_schema=schema)
159 async
def async_step_reboot_menu(
160 self, user_input: dict[str, Any] |
None =
None
161 ) -> ConfigFlowResult:
162 """Confirm reboot host."""
164 step_id=
"reboot_menu",
171 async
def async_step_reboot_now(
172 self, user_input: dict[str, Any] |
None =
None
173 ) -> ConfigFlowResult:
178 async
def async_step_reboot_later(
179 self, user_input: dict[str, Any] |
None =
None
180 ) -> ConfigFlowResult:
186 BaseHomeAssistantYellowOptionsFlow, MultiprotocolOptionsFlowHandler
188 """Handle a multi-PAN options flow for Home Assistant Yellow."""
191 """Show the main menu."""
200 async
def async_step_multipan_settings(
201 self, user_input: dict[str, Any] |
None =
None
202 ) -> ConfigFlowResult:
203 """Handle multipan settings."""
204 return await MultiprotocolOptionsFlowHandler.async_step_on_supervisor(
208 async
def _async_serial_port_settings(
210 ) -> MultiprotocolSerialPortSettings:
211 """Return the radio serial port settings."""
212 return MultiprotocolSerialPortSettings(
218 async
def _async_zha_physical_discovery(self) -> dict[str, Any]:
219 """Return ZHA discovery data when multiprotocol FW is not used.
221 Passed to ZHA do determine if the ZHA config entry is connected to the radio
224 return {
"hw": ZHA_HW_DISCOVERY_DATA}
226 def _zha_name(self) -> str:
227 """Return the ZHA name."""
228 return "Yellow Multiprotocol"
230 def _hardware_name(self) -> str:
231 """Return the name of the hardware."""
234 async
def async_step_flashing_complete(
235 self, user_input: dict[str, Any] |
None =
None
236 ) -> ConfigFlowResult:
237 """Finish flashing and update the config entry."""
238 self.hass.config_entries.async_update_entry(
242 FIRMWARE: ApplicationType.EZSP.value,
246 return await super().async_step_flashing_complete(user_input)
250 BaseHomeAssistantYellowOptionsFlow, BaseFirmwareOptionsFlow
252 """Handle a firmware options flow for Home Assistant Yellow."""
254 def __init__(self, *args: Any, **kwargs: Any) ->
None:
255 """Instantiate options flow."""
265 """Show the main menu."""
275 self, user_input: dict[str, Any] |
None =
None
276 ) -> ConfigFlowResult:
277 """Handle firmware configuration settings."""
281 """Create the config entry."""
284 self.hass.config_entries.async_update_entry(
ConfigFlowResult _async_flow_finished(self)
dict[str, str] _get_translation_placeholders(self)
bool _probe_firmware_type(self)
ConfigFlowResult async_step_pick_firmware(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_main_menu(self, None _=None)
None __init__(self, *Any args, **Any kwargs)
ConfigFlowResult async_step_system(self, dict[str, Any]|None data=None)
OptionsFlow async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult _async_flow_finished(self)
ConfigFlowResult async_step_main_menu(self, None _=None)
ConfigFlowResult _async_flow_finished(self)
None __init__(self, *Any args, **Any kwargs)
ConfigFlowResult async_step_firmware_settings(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_main_menu(self, None _=None)
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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
vol.Schema add_suggested_values_to_schema(self, vol.Schema data_schema, Mapping[str, Any]|None suggested_values)
_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_show_menu(self, *str|None step_id=None, Container[str] menu_options, Mapping[str, str]|None description_placeholders=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)
dict async_set_yellow_settings(HomeAssistant hass, dict[str, bool] settings)
dict async_reboot_host(HomeAssistant hass)
dict[str, bool] async_get_yellow_settings(HomeAssistant hass)