async def async_discover(discovery_info): """Discover and add a MySensors light.""" mysensors.setup_mysensors_platform( opp, DOMAIN, discovery_info, device_class_map, async_add_entities=async_add_entities, )
async def async_discover(discovery_info): """Discover and add a MySensors climate.""" mysensors.setup_mysensors_platform( opp, DOMAIN, discovery_info, MySensorsHVAC, async_add_entities=async_add_entities, )
async def async_setup_platform(opp, config, async_add_entities, discovery_info=None): """Set up the mysensors platform for binary sensors.""" mysensors.setup_mysensors_platform( opp, DOMAIN, discovery_info, MySensorsBinarySensor, async_add_entities=async_add_entities, )
async def async_setup_platform(opp, config, async_add_entities, discovery_info=None): """Set up the mysensors climate.""" mysensors.setup_mysensors_platform( opp, DOMAIN, discovery_info, MySensorsHVAC, async_add_entities=async_add_entities, )
def async_discover(discovery_info): """Discover and add a MySensors binary_sensor.""" mysensors.setup_mysensors_platform( opp, DOMAIN, discovery_info, MySensorsBinarySensor, async_add_entities=async_add_entities, )
async def async_setup_platform(opp, config, async_add_entities, discovery_info=None): """Set up the mysensors platform for switches.""" device_class_map = { "S_DOOR": MySensorsSwitch, "S_MOTION": MySensorsSwitch, "S_SMOKE": MySensorsSwitch, "S_LIGHT": MySensorsSwitch, "S_LOCK": MySensorsSwitch, "S_IR": MySensorsIRSwitch, "S_BINARY": MySensorsSwitch, "S_SPRINKLER": MySensorsSwitch, "S_WATER_LEAK": MySensorsSwitch, "S_SOUND": MySensorsSwitch, "S_VIBRATION": MySensorsSwitch, "S_MOISTURE": MySensorsSwitch, "S_WATER_QUALITY": MySensorsSwitch, } mysensors.setup_mysensors_platform( opp, DOMAIN, discovery_info, device_class_map, async_add_entities=async_add_entities, ) async def async_send_ir_code_service(service): """Set IR code as device state attribute.""" entity_ids = service.data.get(ATTR_ENTITY_ID) ir_code = service.data.get(ATTR_IR_CODE) devices = mysensors.get_mysensors_devices(opp, DOMAIN) if entity_ids: _devices = [ device for device in devices.values() if isinstance(device, MySensorsIRSwitch) and device.entity_id in entity_ids ] else: _devices = [ device for device in devices.values() if isinstance(device, MySensorsIRSwitch) ] kwargs = {ATTR_IR_CODE: ir_code} for device in _devices: await device.async_turn_on(**kwargs) opp.services.async_register( MYSENSORS_DOMAIN, SERVICE_SEND_IR_CODE, async_send_ir_code_service, schema=SEND_IR_CODE_SERVICE_SCHEMA, )
async def async_setup_scanner(opp, config, async_see, discovery_info=None): """Set up the MySensors device scanner.""" new_devices = mysensors.setup_mysensors_platform( opp, DOMAIN, discovery_info, MySensorsDeviceScanner, device_args=(opp, async_see), ) if not new_devices: return False for device in new_devices: gateway_id = id(device.gateway) dev_id = (gateway_id, device.node_id, device.child_id, device.value_type) async_dispatcher_connect( opp, mysensors.const.CHILD_CALLBACK.format(*dev_id), device.async_update_callback, ) async_dispatcher_connect( opp, mysensors.const.NODE_CALLBACK.format(gateway_id, device.node_id), device.async_update_callback, ) return True
async def async_setup_platform(opp, config, async_add_entities, discovery_info=None): """Set up the mysensors platform for lights.""" device_class_map = { "S_DIMMER": MySensorsLightDimmer, "S_RGB_LIGHT": MySensorsLightRGB, "S_RGBW_LIGHT": MySensorsLightRGBW, } mysensors.setup_mysensors_platform( opp, DOMAIN, discovery_info, device_class_map, async_add_entities=async_add_entities, )
async def async_get_service(opp, config, discovery_info=None): """Get the MySensors notification service.""" new_devices = mysensors.setup_mysensors_platform( opp, DOMAIN, discovery_info, MySensorsNotificationDevice ) if not new_devices: return None return MySensorsNotificationService(opp)
async def async_setup_scanner(opp: OpenPeerPower, config, async_see, discovery_info=None): """Set up the MySensors device scanner.""" if not discovery_info: return False new_devices = mysensors.setup_mysensors_platform( opp, DOMAIN, discovery_info, MySensorsDeviceScanner, device_args=(opp, async_see), ) if not new_devices: return False for device in new_devices: gateway_id: GatewayId = discovery_info[ATTR_GATEWAY_ID] dev_id: DevId = (gateway_id, device.node_id, device.child_id, device.value_type) await on_unload( opp, gateway_id, async_dispatcher_connect( opp, mysensors.const.CHILD_CALLBACK.format(*dev_id), device.async_update_callback, ), ) await on_unload( opp, gateway_id, async_dispatcher_connect( opp, mysensors.const.NODE_CALLBACK.format(gateway_id, device.node_id), device.async_update_callback, ), ) return True