1 """Config flow for Snooz component."""
3 from __future__
import annotations
6 from dataclasses
import dataclass
9 from pysnooz.advertisement
import SnoozAdvertisementData
10 import voluptuous
as vol
13 BluetoothScanningMode,
15 async_discovered_service_info,
16 async_process_advertisements,
21 from .const
import DOMAIN
24 WAIT_FOR_PAIRING_TIMEOUT = 30
29 """Represents a discovered Snooz device."""
31 info: BluetoothServiceInfo
32 device: SnoozAdvertisementData
36 """Handle a config flow for Snooz."""
41 """Initialize the config flow."""
42 self.
_discovery_discovery: DiscoveredSnooz |
None =
None
43 self._discovered_devices: dict[str, DiscoveredSnooz] = {}
47 self, discovery_info: BluetoothServiceInfo
48 ) -> ConfigFlowResult:
49 """Handle the bluetooth discovery step."""
52 device = SnoozAdvertisementData()
53 if not device.supported(discovery_info):
59 self, user_input: dict[str, Any] |
None =
None
60 ) -> ConfigFlowResult:
61 """Confirm discovery."""
64 if user_input
is not None:
65 if not self.
_discovery_discovery.device.is_pairing:
71 assert self.
_discovery_discovery.device.display_name
72 placeholders = {
"name": self.
_discovery_discovery.device.display_name}
73 self.context[
"title_placeholders"] = placeholders
75 step_id=
"bluetooth_confirm", description_placeholders=placeholders
79 self, user_input: dict[str, Any] |
None =
None
80 ) -> ConfigFlowResult:
81 """Handle the user step to pick discovered device."""
82 if user_input
is not None:
83 name = user_input[CONF_NAME]
85 discovered = self._discovered_devices[name]
87 assert discovered
is not None
91 if not discovered.device.is_pairing:
94 address = discovered.info.address
102 address = info.address
103 if address
in configured_addresses:
105 device = SnoozAdvertisementData()
106 if device.supported(info):
107 assert device.display_name
112 if not self._discovered_devices:
117 data_schema=vol.Schema(
119 vol.Required(CONF_NAME): vol.In(
121 d.device.display_name
122 for d
in self._discovered_devices.values()
130 self, user_input: dict[str, Any] |
None =
None
131 ) -> ConfigFlowResult:
132 """Wait for device to enter pairing mode."""
140 step_id=
"wait_for_pairing_mode",
141 progress_action=
"wait_for_pairing_mode",
155 self, user_input: dict[str, Any] |
None =
None
156 ) -> ConfigFlowResult:
157 """Create a configuration entry for a device that entered pairing mode."""
161 self.
_discovery_discovery.info.address, raise_on_progress=
False
168 self, user_input: dict[str, Any] |
None =
None
169 ) -> ConfigFlowResult:
170 """Inform the user that the device never entered pairing mode."""
171 if user_input
is not None:
178 assert discovery.device.display_name
180 title=discovery.device.display_name,
182 CONF_ADDRESS: discovery.info.address,
183 CONF_TOKEN: discovery.device.pairing_token,
188 """Process advertisements until pairing mode is detected."""
192 def is_device_in_pairing_mode(
193 service_info: BluetoothServiceInfo,
195 return device.supported(service_info)
and device.is_pairing
199 is_device_in_pairing_mode,
200 {
"address": self.
_discovery_discovery.info.address},
201 BluetoothScanningMode.ACTIVE,
202 WAIT_FOR_PAIRING_TIMEOUT,
ConfigFlowResult _create_snooz_entry(self, DiscoveredSnooz discovery)
ConfigFlowResult async_step_pairing_timeout(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_bluetooth_confirm(self, dict[str, Any]|None user_input=None)
None _async_wait_for_pairing_mode(self)
ConfigFlowResult async_step_bluetooth(self, BluetoothServiceInfo discovery_info)
ConfigFlowResult async_step_wait_for_pairing_mode(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_pairing_complete(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")
None _set_confirm_only(self)
set[str|None] _async_current_ids(self, bool include_ignore=True)
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)
_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_progress(self, *str|None step_id=None, str progress_action, Mapping[str, str]|None description_placeholders=None, asyncio.Task[Any]|None progress_task=None)
_FlowResultT async_show_progress_done(self, *str next_step_id)
_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)
Iterable[BluetoothServiceInfoBleak] async_discovered_service_info(HomeAssistant hass, bool connectable=True)
BluetoothServiceInfoBleak async_process_advertisements(HomeAssistant hass, ProcessAdvertisementCallback callback, BluetoothCallbackMatcher match_dict, BluetoothScanningMode mode, int timeout)