1 """Support for INSTEON Modems (PLM and Hub)."""
3 from contextlib
import suppress
6 from pyinsteon
import async_close, async_connect, devices
7 from pyinsteon.constants
import ReadWriteMode
30 async_register_services,
32 register_new_device_callback,
35 _LOGGER = logging.getLogger(__name__)
40 """Initiate the connection and services."""
44 for address
in list(devices):
45 if devices[address].is_battery:
47 with suppress(AttributeError):
48 await devices[address].async_status()
50 load_aldb = 2
if devices.modem.aldb.read_write_mode == ReadWriteMode.UNKNOWN
else 1
51 await devices.async_load(id_devices=1, load_modem_aldb=load_aldb)
52 for addr
in list(devices):
53 device = devices[addr]
55 for name
in device.operating_flags:
56 if not device.operating_flags[name].is_loaded:
60 for name
in device.properties:
61 if not device.properties[name].is_loaded:
66 if not device.aldb.is_loaded
or not flags:
67 await device.async_read_config()
69 await devices.async_save(workdir=hass.config.config_dir)
73 """Close the Insteon connection."""
78 """Set up an Insteon entry."""
80 if dev_path := entry.options.get(CONF_DEV_PATH):
81 hass.data[DOMAIN] = {}
82 hass.data[DOMAIN][CONF_DEV_PATH] = dev_path
84 api.async_load_api(hass)
85 await api.async_register_insteon_frontend(hass)
89 await async_connect(**entry.data)
90 except ConnectionError
as exception:
91 _LOGGER.error(
"Could not connect to Insteon modem")
92 raise ConfigEntryNotReady
from exception
94 entry.async_on_unload(
95 hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, close_insteon_connection)
98 await devices.async_load(
99 workdir=hass.config.config_dir, id_devices=0, load_modem_aldb=0
106 and entry.source == SOURCE_IMPORT
107 and hass.data.get(DOMAIN)
108 and hass.data[DOMAIN].
get(OPTIONS)
110 hass.config_entries.async_update_entry(
112 options=hass.data[DOMAIN][OPTIONS],
115 for device_override
in entry.options.get(CONF_OVERRIDE, []):
117 address = device_override.get(
"address")
118 if not devices.get(address):
119 cat = device_override[CONF_CAT]
120 subcat = device_override[CONF_SUBCAT]
121 devices.set_id(address, cat, subcat, 0)
123 for device
in entry.options.get(CONF_X10, []):
124 housecode = device.get(CONF_HOUSECODE)
125 unitcode = device.get(CONF_UNITCODE)
127 steps = device.get(CONF_DIM_STEPS, 22)
128 if device.get(CONF_PLATFORM) ==
"light":
129 x10_type =
"dimmable"
130 elif device.get(CONF_PLATFORM) ==
"binary_sensor":
133 "Adding X10 device to Insteon: %s %d %s", housecode, unitcode, x10_type
135 device = devices.add_x10_device(housecode, unitcode, x10_type, steps)
137 await hass.config_entries.async_forward_entry_setups(entry, INSTEON_PLATFORMS)
139 for address
in devices:
140 device = devices[address]
146 _LOGGER.debug(
"Insteon device count: %s", len(devices))
152 entry.async_create_background_task(
160 """Create an Insteon device."""
161 device_registry = dr.async_get(hass)
162 device_registry.async_get_or_create(
163 config_entry_id=config_entry_id,
164 identifiers={(DOMAIN,
str(device.address))},
165 manufacturer=
"SmartLabs, Inc",
166 name=f
"{device.description} {device.address}",
167 model=f
"{device.model} ({device.cat!r}, 0x{device.subcat:02x})",
168 sw_version=f
"{device.firmware:02x} Engine Version: {device.engine_version}",
web.Response get(self, web.Request request, str config_key)
None async_register_services(HomeAssistant hass)
dict[Platform, Iterable[int]] get_device_platforms(device)
def register_new_device_callback(hass)
None add_insteon_events(HomeAssistant hass, Device device)
def close_insteon_connection(*args)
def create_insteon_device(hass, device, config_entry_id)
def async_get_device_config(hass, config_entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)