def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the MySensors platform for sensors.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return gateways = hass.data.get(mysensors.MYSENSORS_GATEWAYS) if not gateways: return for gateway in gateways: # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_DOOR: [set_req.V_TRIPPED], pres.S_MOTION: [set_req.V_TRIPPED], pres.S_SMOKE: [set_req.V_TRIPPED], } if float(gateway.protocol_version) >= 1.5: map_sv_types.update({ pres.S_SPRINKLER: [set_req.V_TRIPPED], pres.S_WATER_LEAK: [set_req.V_TRIPPED], pres.S_SOUND: [set_req.V_TRIPPED], pres.S_VIBRATION: [set_req.V_TRIPPED], pres.S_MOISTURE: [set_req.V_TRIPPED], }) devices = {} gateway.platform_callbacks.append(mysensors.pf_callback_factory( map_sv_types, devices, MySensorsBinarySensor, add_devices))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for switches.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return for gateway in mysensors.GATEWAYS.values(): # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_DOOR: [set_req.V_ARMED], pres.S_MOTION: [set_req.V_ARMED], pres.S_SMOKE: [set_req.V_ARMED], pres.S_LOCK: [set_req.V_LOCK_STATUS], } if float(gateway.version) >= 1.5: map_sv_types.update({ pres.S_BINARY: [set_req.V_STATUS, set_req.V_LIGHT], pres.S_SPRINKLER: [set_req.V_STATUS], pres.S_WATER_LEAK: [set_req.V_ARMED], pres.S_SOUND: [set_req.V_ARMED], pres.S_VIBRATION: [set_req.V_ARMED], pres.S_MOISTURE: [set_req.V_ARMED], }) devices = {} gateway.platform_callbacks.append(mysensors.pf_callback_factory( map_sv_types, devices, add_devices, MySensorsSwitch))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for switches.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return for gateway in mysensors.GATEWAYS.values(): # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_DOOR: [set_req.V_ARMED], pres.S_MOTION: [set_req.V_ARMED], pres.S_SMOKE: [set_req.V_ARMED], pres.S_LOCK: [set_req.V_LOCK_STATUS], } if float(gateway.version) >= 1.5: map_sv_types.update({ pres.S_BINARY: [set_req.V_STATUS, set_req.V_LIGHT], pres.S_SPRINKLER: [set_req.V_STATUS], pres.S_WATER_LEAK: [set_req.V_ARMED], pres.S_SOUND: [set_req.V_ARMED], pres.S_VIBRATION: [set_req.V_ARMED], pres.S_MOISTURE: [set_req.V_ARMED], }) devices = {} gateway.platform_callbacks.append( mysensors.pf_callback_factory(map_sv_types, devices, add_devices, MySensorsSwitch))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for sensors.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return for gateway in mysensors.GATEWAYS.values(): # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_LIGHT: [set_req.V_LIGHT], pres.S_DIMMER: [set_req.V_DIMMER], } if float(gateway.version) >= 1.5: # Add V_RGBW when rgb_white is implemented in the frontend map_sv_types.update({ pres.S_RGB_LIGHT: [set_req.V_RGB], }) map_sv_types[pres.S_LIGHT].append(set_req.V_STATUS) map_sv_types[pres.S_DIMMER].append(set_req.V_PERCENTAGE) devices = {} gateway.platform_callbacks.append(mysensors.pf_callback_factory( map_sv_types, devices, add_devices, MySensorsLight))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for sensors.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return gateways = hass.data.get(mysensors.MYSENSORS_GATEWAYS) if not gateways: return for gateway in gateways: # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_DIMMER: [set_req.V_DIMMER], } device_class_map = { pres.S_DIMMER: MySensorsLightDimmer, } if float(gateway.protocol_version) >= 1.5: map_sv_types.update({ pres.S_RGB_LIGHT: [set_req.V_RGB], pres.S_RGBW_LIGHT: [set_req.V_RGBW], }) map_sv_types[pres.S_DIMMER].append(set_req.V_PERCENTAGE) device_class_map.update({ pres.S_RGB_LIGHT: MySensorsLightRGB, pres.S_RGBW_LIGHT: MySensorsLightRGBW, }) devices = {} gateway.platform_callbacks.append(mysensors.pf_callback_factory( map_sv_types, devices, add_devices, device_class_map))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for sensors.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return for gateway in mysensors.GATEWAYS.values(): # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a defaultdict(list). pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_DOOR: [set_req.V_TRIPPED], pres.S_MOTION: [set_req.V_TRIPPED], pres.S_SMOKE: [set_req.V_TRIPPED], pres.S_TEMP: [set_req.V_TEMP], pres.S_HUM: [set_req.V_HUM], pres.S_BARO: [set_req.V_PRESSURE, set_req.V_FORECAST], pres.S_WIND: [set_req.V_WIND, set_req.V_GUST], pres.S_RAIN: [set_req.V_RAIN, set_req.V_RAINRATE], pres.S_UV: [set_req.V_UV], pres.S_WEIGHT: [set_req.V_WEIGHT, set_req.V_IMPEDANCE], pres.S_POWER: [set_req.V_WATT, set_req.V_KWH], pres.S_DISTANCE: [set_req.V_DISTANCE], pres.S_LIGHT_LEVEL: [set_req.V_LIGHT_LEVEL], pres.S_IR: [set_req.V_IR_SEND, set_req.V_IR_RECEIVE], pres.S_WATER: [set_req.V_FLOW, set_req.V_VOLUME], pres.S_CUSTOM: [set_req.V_VAR1, set_req.V_VAR2, set_req.V_VAR3, set_req.V_VAR4, set_req.V_VAR5], pres.S_SCENE_CONTROLLER: [set_req.V_SCENE_ON, set_req.V_SCENE_OFF], } if float(gateway.version) < 1.5: map_sv_types.update({ pres.S_AIR_QUALITY: [set_req.V_DUST_LEVEL], pres.S_DUST: [set_req.V_DUST_LEVEL], }) if float(gateway.version) >= 1.5: map_sv_types.update({ pres.S_COLOR_SENSOR: [set_req.V_RGB], pres.S_MULTIMETER: [set_req.V_VOLTAGE, set_req.V_CURRENT, set_req.V_IMPEDANCE], pres.S_SPRINKLER: [set_req.V_TRIPPED], pres.S_WATER_LEAK: [set_req.V_TRIPPED], pres.S_SOUND: [set_req.V_TRIPPED, set_req.V_LEVEL], pres.S_VIBRATION: [set_req.V_TRIPPED, set_req.V_LEVEL], pres.S_MOISTURE: [set_req.V_TRIPPED, set_req.V_LEVEL], pres.S_AIR_QUALITY: [set_req.V_LEVEL], pres.S_DUST: [set_req.V_LEVEL], }) map_sv_types[pres.S_LIGHT_LEVEL].append(set_req.V_LEVEL) devices = {} gateway.platform_callbacks.append(mysensors.pf_callback_factory( map_sv_types, devices, add_devices, MySensorsSensor))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for sensors.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return gateways = hass.data.get(mysensors.MYSENSORS_GATEWAYS) if not gateways: return for gateway in gateways: # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_DOOR: [set_req.V_TRIPPED], pres.S_MOTION: [set_req.V_TRIPPED], pres.S_SMOKE: [set_req.V_TRIPPED], } if float(gateway.protocol_version) >= 1.5: map_sv_types.update({ pres.S_SPRINKLER: [set_req.V_TRIPPED], pres.S_WATER_LEAK: [set_req.V_TRIPPED], pres.S_SOUND: [set_req.V_TRIPPED], pres.S_VIBRATION: [set_req.V_TRIPPED], pres.S_MOISTURE: [set_req.V_TRIPPED], }) devices = {} gateway.platform_callbacks.append( mysensors.pf_callback_factory(map_sv_types, devices, MySensorsBinarySensor, add_devices))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for sensors.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return for gateway in mysensors.GATEWAYS.values(): # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a defaultdict(list). pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_DOOR: [set_req.V_TRIPPED], pres.S_MOTION: [set_req.V_TRIPPED], pres.S_SMOKE: [set_req.V_TRIPPED], pres.S_TEMP: [set_req.V_TEMP], pres.S_HUM: [set_req.V_HUM], pres.S_BARO: [set_req.V_PRESSURE, set_req.V_FORECAST], pres.S_WIND: [set_req.V_WIND, set_req.V_GUST], pres.S_RAIN: [set_req.V_RAIN, set_req.V_RAINRATE], pres.S_UV: [set_req.V_UV], pres.S_WEIGHT: [set_req.V_WEIGHT, set_req.V_IMPEDANCE], pres.S_POWER: [set_req.V_WATT, set_req.V_KWH], pres.S_DISTANCE: [set_req.V_DISTANCE], pres.S_LIGHT_LEVEL: [set_req.V_LIGHT_LEVEL], pres.S_IR: [set_req.V_IR_SEND, set_req.V_IR_RECEIVE], pres.S_WATER: [set_req.V_FLOW, set_req.V_VOLUME], pres.S_CUSTOM: [ set_req.V_VAR1, set_req.V_VAR2, set_req.V_VAR3, set_req.V_VAR4, set_req.V_VAR5 ], pres.S_SCENE_CONTROLLER: [set_req.V_SCENE_ON, set_req.V_SCENE_OFF], } if float(gateway.version) < 1.5: map_sv_types.update({ pres.S_AIR_QUALITY: [set_req.V_DUST_LEVEL], pres.S_DUST: [set_req.V_DUST_LEVEL], }) if float(gateway.version) >= 1.5: map_sv_types.update({ pres.S_COLOR_SENSOR: [set_req.V_RGB], pres.S_MULTIMETER: [set_req.V_VOLTAGE, set_req.V_CURRENT, set_req.V_IMPEDANCE], pres.S_SPRINKLER: [set_req.V_TRIPPED], pres.S_WATER_LEAK: [set_req.V_TRIPPED], pres.S_SOUND: [set_req.V_TRIPPED, set_req.V_LEVEL], pres.S_VIBRATION: [set_req.V_TRIPPED, set_req.V_LEVEL], pres.S_MOISTURE: [set_req.V_TRIPPED, set_req.V_LEVEL], pres.S_AIR_QUALITY: [set_req.V_LEVEL], pres.S_DUST: [set_req.V_LEVEL], }) map_sv_types[pres.S_LIGHT_LEVEL].append(set_req.V_LEVEL) devices = {} gateway.platform_callbacks.append( mysensors.pf_callback_factory(map_sv_types, devices, add_devices, MySensorsSensor))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for sensors.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return for gateway in mysensors.GATEWAYS.values(): # Define the S_TYPES and V_TYPES that the platform should handle as # states. s_types = [ gateway.const.Presentation.S_DOOR, gateway.const.Presentation.S_MOTION, gateway.const.Presentation.S_SMOKE, gateway.const.Presentation.S_TEMP, gateway.const.Presentation.S_HUM, gateway.const.Presentation.S_BARO, gateway.const.Presentation.S_WIND, gateway.const.Presentation.S_RAIN, gateway.const.Presentation.S_UV, gateway.const.Presentation.S_WEIGHT, gateway.const.Presentation.S_POWER, gateway.const.Presentation.S_DISTANCE, gateway.const.Presentation.S_LIGHT_LEVEL, gateway.const.Presentation.S_IR, gateway.const.Presentation.S_WATER, gateway.const.Presentation.S_AIR_QUALITY, gateway.const.Presentation.S_CUSTOM, gateway.const.Presentation.S_DUST, gateway.const.Presentation.S_SCENE_CONTROLLER, ] not_v_types = [ gateway.const.SetReq.V_ARMED, gateway.const.SetReq.V_LIGHT, gateway.const.SetReq.V_LOCK_STATUS, ] if float(gateway.version) >= 1.5: s_types.extend([ gateway.const.Presentation.S_COLOR_SENSOR, gateway.const.Presentation.S_MULTIMETER, gateway.const.Presentation.S_SPRINKLER, gateway.const.Presentation.S_WATER_LEAK, gateway.const.Presentation.S_SOUND, gateway.const.Presentation.S_VIBRATION, gateway.const.Presentation.S_MOISTURE, ]) not_v_types.extend([gateway.const.SetReq.V_STATUS, ]) v_types = [member for member in gateway.const.SetReq if member.value not in not_v_types] devices = defaultdict(list) gateway.platform_callbacks.append(mysensors.pf_callback_factory( s_types, v_types, devices, add_devices, MySensorsSensor))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors climate.""" if discovery_info is None: return for gateway in mysensors.GATEWAYS.values(): if float(gateway.protocol_version) < 1.5: continue pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_HVAC: [set_req.V_HVAC_FLOW_STATE], } devices = {} gateway.platform_callbacks.append(mysensors.pf_callback_factory( map_sv_types, devices, add_devices, MySensorsHVAC))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for covers.""" if discovery_info is None: return for gateway in mysensors.GATEWAYS.values(): pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_COVER: [set_req.V_DIMMER, set_req.V_LIGHT], } if float(gateway.protocol_version) >= 1.5: map_sv_types.update({ pres.S_COVER: [set_req.V_PERCENTAGE, set_req.V_STATUS], }) devices = {} gateway.platform_callbacks.append(mysensors.pf_callback_factory( map_sv_types, devices, add_devices, MySensorsCover))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for covers.""" if discovery_info is None: return for gateway in mysensors.GATEWAYS.values(): pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_COVER: [set_req.V_DIMMER, set_req.V_LIGHT], } if float(gateway.protocol_version) >= 1.5: map_sv_types.update({ pres.S_COVER: [set_req.V_PERCENTAGE, set_req.V_STATUS], }) devices = {} gateway.platform_callbacks.append( mysensors.pf_callback_factory(map_sv_types, devices, add_devices, MySensorsCover))
def get_service(hass, config, discovery_info=None): """Get the MySensors notification service.""" if discovery_info is None: return platform_devices = [] gateways = hass.data.get(mysensors.MYSENSORS_GATEWAYS) if not gateways: return for gateway in gateways: pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_INFO: [set_req.V_TEXT], } devices = {} gateway.platform_callbacks.append(mysensors.pf_callback_factory( map_sv_types, devices, MySensorsNotificationDevice)) platform_devices.append(devices) return MySensorsNotificationService(platform_devices)
def get_service(hass, config, discovery_info=None): """Get the MySensors notification service.""" if discovery_info is None: return platform_devices = [] gateways = hass.data.get(mysensors.MYSENSORS_GATEWAYS) if not gateways: return for gateway in gateways: pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_INFO: [set_req.V_TEXT], } devices = {} gateway.platform_callbacks.append( mysensors.pf_callback_factory(map_sv_types, devices, MySensorsNotificationDevice)) platform_devices.append(devices) return MySensorsNotificationService(platform_devices)
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for switches.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return for gateway in mysensors.GATEWAYS.values(): # Define the S_TYPES and V_TYPES that the platform should handle as # states. s_types = [ gateway.const.Presentation.S_DOOR, gateway.const.Presentation.S_MOTION, gateway.const.Presentation.S_SMOKE, gateway.const.Presentation.S_LIGHT, gateway.const.Presentation.S_LOCK, ] v_types = [ gateway.const.SetReq.V_ARMED, gateway.const.SetReq.V_LIGHT, gateway.const.SetReq.V_LOCK_STATUS, ] if float(gateway.version) >= 1.5: s_types.extend([ gateway.const.Presentation.S_BINARY, gateway.const.Presentation.S_SPRINKLER, gateway.const.Presentation.S_WATER_LEAK, gateway.const.Presentation.S_SOUND, gateway.const.Presentation.S_VIBRATION, gateway.const.Presentation.S_MOISTURE, ]) v_types.extend([gateway.const.SetReq.V_STATUS, ]) devices = defaultdict(list) gateway.platform_callbacks.append(mysensors.pf_callback_factory( s_types, v_types, devices, add_devices, MySensorsSwitch))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for switches.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return gateways = hass.data.get(mysensors.MYSENSORS_GATEWAYS) if not gateways: return for gateway in gateways: # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_DOOR: [set_req.V_ARMED], pres.S_MOTION: [set_req.V_ARMED], pres.S_SMOKE: [set_req.V_ARMED], pres.S_LIGHT: [set_req.V_LIGHT], pres.S_LOCK: [set_req.V_LOCK_STATUS], pres.S_IR: [set_req.V_IR_SEND], } device_class_map = { pres.S_DOOR: MySensorsSwitch, pres.S_MOTION: MySensorsSwitch, pres.S_SMOKE: MySensorsSwitch, pres.S_LIGHT: MySensorsSwitch, pres.S_LOCK: MySensorsSwitch, pres.S_IR: MySensorsIRSwitch, } if float(gateway.protocol_version) >= 1.5: map_sv_types.update({ pres.S_BINARY: [set_req.V_STATUS, set_req.V_LIGHT], pres.S_SPRINKLER: [set_req.V_STATUS], pres.S_WATER_LEAK: [set_req.V_ARMED], pres.S_SOUND: [set_req.V_ARMED], pres.S_VIBRATION: [set_req.V_ARMED], pres.S_MOISTURE: [set_req.V_ARMED], }) map_sv_types[pres.S_LIGHT].append(set_req.V_STATUS) device_class_map.update({ pres.S_BINARY: MySensorsSwitch, pres.S_SPRINKLER: MySensorsSwitch, pres.S_WATER_LEAK: MySensorsSwitch, pres.S_SOUND: MySensorsSwitch, pres.S_VIBRATION: MySensorsSwitch, pres.S_MOISTURE: MySensorsSwitch, }) if float(gateway.protocol_version) >= 2.0: map_sv_types.update({ pres.S_WATER_QUALITY: [set_req.V_STATUS], }) device_class_map.update({ pres.S_WATER_QUALITY: MySensorsSwitch, }) devices = {} gateway.platform_callbacks.append( mysensors.pf_callback_factory(map_sv_types, devices, add_devices, device_class_map)) def 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) 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: device.turn_on(**kwargs) descriptions = load_yaml_config_file( os.path.join(os.path.dirname(__file__), 'services.yaml')) hass.services.register(DOMAIN, SERVICE_SEND_IR_CODE, send_ir_code_service, descriptions.get(SERVICE_SEND_IR_CODE), schema=SEND_IR_CODE_SERVICE_SCHEMA)
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the mysensors platform for switches.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return for gateway in mysensors.GATEWAYS.values(): # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_DOOR: [set_req.V_ARMED], pres.S_MOTION: [set_req.V_ARMED], pres.S_SMOKE: [set_req.V_ARMED], pres.S_LIGHT: [set_req.V_LIGHT], pres.S_LOCK: [set_req.V_LOCK_STATUS], pres.S_IR: [set_req.V_IR_SEND], } device_class_map = { pres.S_DOOR: MySensorsSwitch, pres.S_MOTION: MySensorsSwitch, pres.S_SMOKE: MySensorsSwitch, pres.S_LIGHT: MySensorsSwitch, pres.S_LOCK: MySensorsSwitch, pres.S_IR: MySensorsIRSwitch, } if float(gateway.protocol_version) >= 1.5: map_sv_types.update({ pres.S_BINARY: [set_req.V_STATUS, set_req.V_LIGHT], pres.S_SPRINKLER: [set_req.V_STATUS], pres.S_WATER_LEAK: [set_req.V_ARMED], pres.S_SOUND: [set_req.V_ARMED], pres.S_VIBRATION: [set_req.V_ARMED], pres.S_MOISTURE: [set_req.V_ARMED], }) map_sv_types[pres.S_LIGHT].append(set_req.V_STATUS) device_class_map.update({ pres.S_BINARY: MySensorsSwitch, pres.S_SPRINKLER: MySensorsSwitch, pres.S_WATER_LEAK: MySensorsSwitch, pres.S_SOUND: MySensorsSwitch, pres.S_VIBRATION: MySensorsSwitch, pres.S_MOISTURE: MySensorsSwitch, }) if float(gateway.protocol_version) >= 2.0: map_sv_types.update({ pres.S_WATER_QUALITY: [set_req.V_STATUS], }) device_class_map.update({ pres.S_WATER_QUALITY: MySensorsSwitch, }) devices = {} gateway.platform_callbacks.append(mysensors.pf_callback_factory( map_sv_types, devices, add_devices, device_class_map)) def 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) 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: device.turn_on(**kwargs) descriptions = load_yaml_config_file( os.path.join(os.path.dirname(__file__), 'services.yaml')) hass.services.register(DOMAIN, SERVICE_SEND_IR_CODE, send_ir_code_service, descriptions.get(SERVICE_SEND_IR_CODE), schema=SEND_IR_CODE_SERVICE_SCHEMA)
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the MySensors platform for sensors.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return gateways = hass.data.get(mysensors.MYSENSORS_GATEWAYS) if not gateways: return for gateway in gateways: # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_TEMP: [set_req.V_TEMP], pres.S_HUM: [set_req.V_HUM], pres.S_BARO: [set_req.V_PRESSURE, set_req.V_FORECAST], pres.S_WIND: [set_req.V_WIND, set_req.V_GUST, set_req.V_DIRECTION], pres.S_RAIN: [set_req.V_RAIN, set_req.V_RAINRATE], pres.S_UV: [set_req.V_UV], pres.S_WEIGHT: [set_req.V_WEIGHT, set_req.V_IMPEDANCE], pres.S_POWER: [set_req.V_WATT, set_req.V_KWH], pres.S_DISTANCE: [set_req.V_DISTANCE], pres.S_LIGHT_LEVEL: [set_req.V_LIGHT_LEVEL], pres.S_IR: [set_req.V_IR_RECEIVE], pres.S_WATER: [set_req.V_FLOW, set_req.V_VOLUME], pres.S_CUSTOM: [set_req.V_VAR1, set_req.V_VAR2, set_req.V_VAR3, set_req.V_VAR4, set_req.V_VAR5], pres.S_SCENE_CONTROLLER: [set_req.V_SCENE_ON, set_req.V_SCENE_OFF], } if float(gateway.protocol_version) < 1.5: map_sv_types.update({ pres.S_AIR_QUALITY: [set_req.V_DUST_LEVEL], pres.S_DUST: [set_req.V_DUST_LEVEL], }) if float(gateway.protocol_version) >= 1.5: map_sv_types.update({ pres.S_COLOR_SENSOR: [set_req.V_RGB], pres.S_MULTIMETER: [set_req.V_VOLTAGE, set_req.V_CURRENT, set_req.V_IMPEDANCE], pres.S_SOUND: [set_req.V_LEVEL], pres.S_VIBRATION: [set_req.V_LEVEL], pres.S_MOISTURE: [set_req.V_LEVEL], pres.S_AIR_QUALITY: [set_req.V_LEVEL], pres.S_DUST: [set_req.V_LEVEL], }) map_sv_types[pres.S_LIGHT_LEVEL].append(set_req.V_LEVEL) if float(gateway.protocol_version) >= 2.0: map_sv_types.update({ pres.S_INFO: [set_req.V_TEXT], pres.S_GAS: [set_req.V_FLOW, set_req.V_VOLUME], pres.S_GPS: [set_req.V_POSITION], pres.S_WATER_QUALITY: [set_req.V_TEMP, set_req.V_PH, set_req.V_ORP, set_req.V_EC] }) map_sv_types[pres.S_CUSTOM].append(set_req.V_CUSTOM) map_sv_types[pres.S_POWER].extend( [set_req.V_VAR, set_req.V_VA, set_req.V_POWER_FACTOR]) devices = {} gateway.platform_callbacks.append(mysensors.pf_callback_factory( map_sv_types, devices, MySensorsSensor, add_devices))
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the MySensors platform for sensors.""" # Only act if loaded via mysensors by discovery event. # Otherwise gateway is not setup. if discovery_info is None: return gateways = hass.data.get(mysensors.MYSENSORS_GATEWAYS) if not gateways: return for gateway in gateways: # Define the S_TYPES and V_TYPES that the platform should handle as # states. Map them in a dict of lists. pres = gateway.const.Presentation set_req = gateway.const.SetReq map_sv_types = { pres.S_TEMP: [set_req.V_TEMP], pres.S_HUM: [set_req.V_HUM], pres.S_BARO: [set_req.V_PRESSURE, set_req.V_FORECAST], pres.S_WIND: [set_req.V_WIND, set_req.V_GUST], pres.S_RAIN: [set_req.V_RAIN, set_req.V_RAINRATE], pres.S_UV: [set_req.V_UV], pres.S_WEIGHT: [set_req.V_WEIGHT, set_req.V_IMPEDANCE], pres.S_POWER: [set_req.V_WATT, set_req.V_KWH], pres.S_DISTANCE: [set_req.V_DISTANCE], pres.S_LIGHT_LEVEL: [set_req.V_LIGHT_LEVEL], pres.S_IR: [set_req.V_IR_RECEIVE], pres.S_WATER: [set_req.V_FLOW, set_req.V_VOLUME], pres.S_CUSTOM: [ set_req.V_VAR1, set_req.V_VAR2, set_req.V_VAR3, set_req.V_VAR4, set_req.V_VAR5 ], pres.S_SCENE_CONTROLLER: [set_req.V_SCENE_ON, set_req.V_SCENE_OFF], } if float(gateway.protocol_version) < 1.5: map_sv_types.update({ pres.S_AIR_QUALITY: [set_req.V_DUST_LEVEL], pres.S_DUST: [set_req.V_DUST_LEVEL], }) if float(gateway.protocol_version) >= 1.5: map_sv_types.update({ pres.S_COLOR_SENSOR: [set_req.V_RGB], pres.S_MULTIMETER: [set_req.V_VOLTAGE, set_req.V_CURRENT, set_req.V_IMPEDANCE], pres.S_SOUND: [set_req.V_LEVEL], pres.S_VIBRATION: [set_req.V_LEVEL], pres.S_MOISTURE: [set_req.V_LEVEL], pres.S_AIR_QUALITY: [set_req.V_LEVEL], pres.S_DUST: [set_req.V_LEVEL], }) map_sv_types[pres.S_LIGHT_LEVEL].append(set_req.V_LEVEL) if float(gateway.protocol_version) >= 2.0: map_sv_types.update({ pres.S_INFO: [set_req.V_TEXT], pres.S_GAS: [set_req.V_FLOW, set_req.V_VOLUME], pres.S_GPS: [set_req.V_POSITION], pres.S_WATER_QUALITY: [set_req.V_TEMP, set_req.V_PH, set_req.V_ORP, set_req.V_EC] }) map_sv_types[pres.S_CUSTOM].append(set_req.V_CUSTOM) map_sv_types[pres.S_POWER].extend( [set_req.V_VAR, set_req.V_VA, set_req.V_POWER_FACTOR]) devices = {} gateway.platform_callbacks.append( mysensors.pf_callback_factory(map_sv_types, devices, MySensorsSensor, add_devices))