async def websocket_add_device( hass: HomeAssistant, connection: websocket_api.connection.ActiveConnection, msg: dict, ) -> None: """Add one or more Insteon devices.""" @callback def linking_complete(address: str, action: DeviceAction): """Forward device events to websocket.""" if action == DeviceAction.COMPLETED: forward_data = {"type": "linking_stopped", "address": ""} else: return connection.send_message( websocket_api.event_message(msg["id"], forward_data)) @callback def async_cleanup() -> None: """Remove signal listeners.""" devices.unsubscribe(linking_complete) connection.subscriptions[msg["id"]] = async_cleanup devices.subscribe(linking_complete) async for address in devices.async_add_device( address=msg.get(DEVICE_ADDRESS), multiple=msg[MULTIPLE]): forward_data = {"type": "device_added", "address": str(address)} connection.send_message( websocket_api.event_message(msg["id"], forward_data)) connection.send_result(msg[ID])
def register_new_device_callback(hass): """Register callback for new Insteon device.""" @callback def async_new_insteon_device(address=None): """Detect device from transport to be delegated to platform.""" hass.async_create_task(async_create_new_entities(address)) async def async_create_new_entities(address): _LOGGER.debug( "Adding new INSTEON device to Home Assistant with address %s", address ) await devices.async_save(workdir=hass.config.config_dir) device = devices[address] await device.async_status() platforms = get_device_platforms(device) for platform in platforms: if platform == ON_OFF_EVENTS: add_on_off_event_device(hass, device) else: signal = f"{SIGNAL_ADD_ENTITIES}_{platform}" dispatcher_send(hass, signal, {"address": device.address}) devices.subscribe(async_new_insteon_device, force_strong_ref=True)
def register_new_device_callback(hass, config): """Register callback for new Insteon device.""" new_device_lock = asyncio.Lock() @callback def async_new_insteon_device(address=None): """Detect device from transport to be delegated to platform.""" hass.async_create_task(async_create_new_entities(address)) async def async_create_new_entities(address): _LOGGER.debug( "Adding new INSTEON device to Home Assistant with address %s", address) async with new_device_lock: await devices.async_save(workdir=hass.config.config_dir) device = devices[address] await device.async_status() platforms = get_device_platforms(device) tasks = [] for platform in platforms: if platform == ON_OFF_EVENTS: add_on_off_event_device(hass, device) else: tasks.append( discovery.async_load_platform( hass, platform, DOMAIN, discovered={"address": device.address.id}, hass_config=config, )) await asyncio.gather(*tasks) devices.subscribe(async_new_insteon_device, force_strong_ref=True)
async def do_run(): """Connect to the PLM and load the ALDB.""" # devices = await async_connect(device=DEVICE) devices = await async_connect(host=HOST, username=USERNAME, password=PASSWORD) await devices.async_load(workdir=PATH, id_devices=0) devices.subscribe(device_added) await async_enter_linking_mode(link_mode=AllLinkMode.EITHER, group=0) _LOGGER.info("Press device SET button") await done.get() await async_close()
async def run(): """Run the monitoring.""" set_log_levels( logger="info", logger_pyinsteon="info", logger_messages="info", logger_topics=True, ) # await async_connect(host=HOST, username=USERNAME, password=PASSWORD) await async_connect(device=DEVICE) devices.subscribe(device_added) await devices.async_load(workdir=PATH, id_devices=0) await devices.async_save(workdir=PATH) address = "453194" device = devices[address] if device: await device.async_read_op_flags() await device.async_read_ext_properties() _LOGGER.info( "LED_BLINK_ON_TX_ON: %s", device.operating_flags[MOMENTARY_ON_OFF_TRIGGER].value, ) device.operating_flags[MOMENTARY_ON_OFF_TRIGGER].new_value = True await device.async_write_op_flags() await device.async_write_ext_properties() await device.async_read_op_flags() await device.async_read_ext_properties() _LOGGER.info( "LED_BLINK_ON_TX_ON: %s", device.operating_flags[MOMENTARY_ON_OFF_TRIGGER].value, ) else: _LOGGER.info("No device found for address: %s", address) await devices.async_save(workdir=PATH) await async_close()
async def run(): """Run the monitoring.""" set_log_levels(logger='info', logger_pyinsteon='info', logger_messages='debug', logger_topics=True) await async_connect(host=HOST, username=USERNAME, password=PASSWORD) devices.subscribe(device_added) await devices.async_load(workdir=PATH) await devices.async_save(workdir=PATH) await devices.modem.async_get_configuration() await devices.modem.async_set_configuration( disable_auto_linking=devices.modem.disable_auto_linking, monitor_mode=True, auto_led=devices.modem.auto_led, deadman=devices.modem.deadman) _LOGGER.info('Devices loaded: %d', len(devices)) try: while True: await asyncio.sleep(5) except KeyboardInterrupt: await async_close() raise KeyboardInterrupt()