1 """The Steamist integration discovery."""
3 from __future__
import annotations
9 from discovery30303
import AIODiscovery30303, Device30303
11 from homeassistant
import config_entries
18 from .const
import DISCOVER_SCAN_TIMEOUT, DISCOVERY, DOMAIN
20 _LOGGER = logging.getLogger(__name__)
23 MODEL_450_HOSTNAME_PREFIX =
"MY450-"
24 MODEL_550_HOSTNAME_PREFIX =
"MY550-"
29 """Check if a 30303 discovery is a steamist device."""
30 return device.hostname.startswith(
31 MODEL_450_HOSTNAME_PREFIX
32 )
or device.hostname.startswith(MODEL_550_HOSTNAME_PREFIX)
41 """Update a config entry from a discovery."""
42 data_updates: dict[str, Any] = {}
43 updates: dict[str, Any] = {}
44 if not entry.unique_id:
45 updates[
"unique_id"] = dr.format_mac(device.mac)
46 if not entry.data.get(CONF_NAME)
or is_ip_address(entry.data[CONF_NAME]):
47 updates[
"title"] = data_updates[CONF_NAME] = device.name
48 if not entry.data.get(CONF_MODEL)
and "-" in device.hostname:
49 data_updates[CONF_MODEL] = device.hostname.split(
"-", maxsplit=1)[0]
51 updates[
"data"] = {**entry.data, **data_updates}
53 return hass.config_entries.async_update_entry(entry, **updates)
58 hass: HomeAssistant, timeout: int, address: str |
None =
None
59 ) -> list[Device30303]:
60 """Discover devices."""
65 str(broadcast_address)
66 for broadcast_address
in await network.async_get_ipv4_broadcast_addresses(
71 scanner = AIODiscovery30303()
72 for idx, discovered
in enumerate(
75 scanner.async_scan(timeout=timeout, address=target_address)
76 for target_address
in targets
78 return_exceptions=
True,
81 if isinstance(discovered, Exception):
82 _LOGGER.debug(
"Scanning %s failed with error: %s", targets[idx], discovered)
85 _LOGGER.debug(
"Found devices: %s", scanner.found_devices)
89 for device
in scanner.found_devices
93 return [device
for device
in scanner.found_devices
if device.ipaddress == address]
98 discoveries: list[Device30303], host: str
99 ) -> Device30303 |
None:
100 """Search a list of discoveries for one with a matching ip."""
101 for discovery
in discoveries:
102 if discovery.ipaddress == host:
108 """Direct discovery to a single ip instead of broadcast."""
116 """Check if a device was already discovered via a broadcast discovery."""
117 discoveries: list[Device30303] = hass.data[DOMAIN][DISCOVERY]
124 discovered_devices: list[Device30303],
126 """Trigger config flows for discovered devices."""
127 for device
in discovered_devices:
128 discovery_flow.async_create_flow(
131 context={
"source": config_entries.SOURCE_INTEGRATION_DISCOVERY},
133 "ipaddress": device.ipaddress,
136 "hostname": device.hostname,
Device30303|None async_find_discovery_by_ip(list[Device30303] discoveries, str host)
Device30303|None async_get_discovery(HomeAssistant hass, str host)
list[Device30303] async_discover_devices(HomeAssistant hass, int timeout, str|None address=None)
None async_trigger_discovery(HomeAssistant hass, list[Device30303] discovered_devices)
bool async_update_entry_from_discovery(HomeAssistant hass, config_entries.ConfigEntry entry, Device30303 device)
Device30303|None async_discover_device(HomeAssistant hass, str host)
bool async_is_steamist_device(Device30303 device)
bool is_ip_address(str address)