1 """Helper functions for the Broadlink integration."""
3 from base64
import b64decode
5 from homeassistant
import config_entries
9 from .const
import DOMAIN
13 """Decode a data packet given for a Broadlink remote."""
14 value = cv.string(value)
15 extra = len(value) % 4
17 value = value + (
"=" * (4 - extra))
18 return b64decode(value)
22 """Validate and convert a MAC address to bytes."""
25 mac =
"".join(mac[i : i + 2]
for i
in range(0, 17, 3))
27 mac =
"".join(mac[i : i + 4]
for i
in range(0, 14, 5))
29 raise ValueError(
"Invalid MAC address")
30 return bytes.fromhex(mac)
34 """Format a MAC address."""
35 return ":".join([format(octet,
"02x")
for octet
in mac])
39 """Create a config flow for a device."""
41 entry.data.get(CONF_HOST)
for entry
in hass.config_entries.async_entries(DOMAIN)
44 if host
not in configured_hosts:
45 task = hass.config_entries.flow.async_init(
47 context={
"source": config_entries.SOURCE_IMPORT},
48 data={CONF_HOST: host},
50 hass.async_create_task(task)
def import_device(hass, host)