From b80571519b39427f23a399ed7a1e6d45ba309902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20=C3=98stergaard=20Nielsen?= Date: Sat, 30 Jan 2021 12:46:50 +0100 Subject: [PATCH] IHC service functions support for multiple IHC controllers (#44626) Co-authored-by: Martin Hjelmare --- homeassistant/components/ihc/__init__.py | 31 ++++++++++++++++--- homeassistant/components/ihc/const.py | 1 + .../components/ihc/ihc_auto_setup.yaml | 24 ++++++++++++++ homeassistant/components/ihc/services.yaml | 27 ++++++++++++++++ 4 files changed, 79 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/ihc/__init__.py b/homeassistant/components/ihc/__init__.py index f200c9651f0..8769f73e365 100644 --- a/homeassistant/components/ihc/__init__.py +++ b/homeassistant/components/ihc/__init__.py @@ -23,6 +23,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.typing import HomeAssistantType from .const import ( + ATTR_CONTROLLER_ID, ATTR_IHC_ID, ATTR_VALUE, CONF_AUTOSETUP, @@ -186,13 +187,18 @@ AUTO_SETUP_SCHEMA = vol.Schema( ) SET_RUNTIME_VALUE_BOOL_SCHEMA = vol.Schema( - {vol.Required(ATTR_IHC_ID): cv.positive_int, vol.Required(ATTR_VALUE): cv.boolean} + { + vol.Required(ATTR_IHC_ID): cv.positive_int, + vol.Required(ATTR_VALUE): cv.boolean, + vol.Optional(ATTR_CONTROLLER_ID, default=0): cv.positive_int, + } ) SET_RUNTIME_VALUE_INT_SCHEMA = vol.Schema( { vol.Required(ATTR_IHC_ID): cv.positive_int, vol.Required(ATTR_VALUE): vol.Coerce(int), + vol.Optional(ATTR_CONTROLLER_ID, default=0): cv.positive_int, } ) @@ -200,10 +206,16 @@ SET_RUNTIME_VALUE_FLOAT_SCHEMA = vol.Schema( { vol.Required(ATTR_IHC_ID): cv.positive_int, vol.Required(ATTR_VALUE): vol.Coerce(float), + vol.Optional(ATTR_CONTROLLER_ID, default=0): cv.positive_int, } ) -PULSE_SCHEMA = vol.Schema({vol.Required(ATTR_IHC_ID): cv.positive_int}) +PULSE_SCHEMA = vol.Schema( + { + vol.Required(ATTR_IHC_ID): cv.positive_int, + vol.Optional(ATTR_CONTROLLER_ID, default=0): cv.positive_int, + } +) def setup(hass, config): @@ -237,7 +249,9 @@ def ihc_setup(hass, config, conf, controller_id): # Store controller configuration ihc_key = f"ihc{controller_id}" hass.data[ihc_key] = {IHC_CONTROLLER: ihc_controller, IHC_INFO: conf[CONF_INFO]} - setup_service_functions(hass, ihc_controller) + # We only want to register the service functions once for the first controller + if controller_id == 0: + setup_service_functions(hass) return True @@ -329,30 +343,39 @@ def get_discovery_info(component_setup, groups, controller_id): return discovery_data -def setup_service_functions(hass: HomeAssistantType, ihc_controller): +def setup_service_functions(hass: HomeAssistantType): """Set up the IHC service functions.""" + def _get_controller(call): + controller_id = call.data[ATTR_CONTROLLER_ID] + ihc_key = f"ihc{controller_id}" + return hass.data[ihc_key][IHC_CONTROLLER] + def set_runtime_value_bool(call): """Set a IHC runtime bool value service function.""" ihc_id = call.data[ATTR_IHC_ID] value = call.data[ATTR_VALUE] + ihc_controller = _get_controller(call) ihc_controller.set_runtime_value_bool(ihc_id, value) def set_runtime_value_int(call): """Set a IHC runtime integer value service function.""" ihc_id = call.data[ATTR_IHC_ID] value = call.data[ATTR_VALUE] + ihc_controller = _get_controller(call) ihc_controller.set_runtime_value_int(ihc_id, value) def set_runtime_value_float(call): """Set a IHC runtime float value service function.""" ihc_id = call.data[ATTR_IHC_ID] value = call.data[ATTR_VALUE] + ihc_controller = _get_controller(call) ihc_controller.set_runtime_value_float(ihc_id, value) async def async_pulse_runtime_input(call): """Pulse a IHC controller input function.""" ihc_id = call.data[ATTR_IHC_ID] + ihc_controller = _get_controller(call) await async_pulse(hass, ihc_controller, ihc_id) hass.services.register( diff --git a/homeassistant/components/ihc/const.py b/homeassistant/components/ihc/const.py index 15db19ba58b..30103e2bdba 100644 --- a/homeassistant/components/ihc/const.py +++ b/homeassistant/components/ihc/const.py @@ -18,6 +18,7 @@ CONF_XPATH = "xpath" ATTR_IHC_ID = "ihc_id" ATTR_VALUE = "value" +ATTR_CONTROLLER_ID = "controller_id" SERVICE_SET_RUNTIME_VALUE_BOOL = "set_runtime_value_bool" SERVICE_SET_RUNTIME_VALUE_FLOAT = "set_runtime_value_float" diff --git a/homeassistant/components/ihc/ihc_auto_setup.yaml b/homeassistant/components/ihc/ihc_auto_setup.yaml index d5f8d26e2b7..7a94afdae44 100644 --- a/homeassistant/components/ihc/ihc_auto_setup.yaml +++ b/homeassistant/components/ihc/ihc_auto_setup.yaml @@ -34,6 +34,30 @@ binary_sensor: type: "light" light: + # Swedish Wireless dimmer (Mobil VU/Dimmer 1-knapp/touch) + - xpath: './/product_airlink[@product_identifier="_0x4301"]' + node: "airlink_dimming" + dimmable: true + # Swedish Wireless dimmer (Lamputtag/Dimmer 1-knapp/touch) + - xpath: './/product_airlink[@product_identifier="_0x4302"]' + node: "airlink_dimming" + dimmable: true + # Swedish Wireless dimmer (Blind/Dimmer 1-knapp/touch) + - xpath: './/product_airlink[@product_identifier="_0x4305"]' + node: "airlink_dimming" + dimmable: true + # Swedish Wireless dimmer (3-tråds Puck/Dimmer 1-knapp/touch) + - xpath: './/product_airlink[@product_identifier="_0x4307"]' + node: "airlink_dimming" + dimmable: true + # Swedish Wireless dimmer (3-tråds Puck/Dimmer 2-knapp) + - xpath: './/product_airlink[@product_identifier="_0x4308"]' + node: "airlink_dimming" + dimmable: true + # 2 channel RS485 dimmer + - xpath: './/rs485_led_dimmer_channel[@product_identifier="_0x4410"]' + node: "airlink_dimming" + dimmable: true # Wireless Combi dimmer 4 buttons - xpath: './/product_airlink[@product_identifier="_0x4406"]' node: "airlink_dimming" diff --git a/homeassistant/components/ihc/services.yaml b/homeassistant/components/ihc/services.yaml index ad41539162c..a65d5f5b78c 100644 --- a/homeassistant/components/ihc/services.yaml +++ b/homeassistant/components/ihc/services.yaml @@ -3,29 +3,56 @@ set_runtime_value_bool: description: Set a boolean runtime value on the IHC controller. fields: + controller_id: + description: | + If you have multiple controller, this is the index of you controller + starting with 0 (0 is default) + example: 0 ihc_id: description: The integer IHC resource ID. + example: 123456 value: description: The boolean value to set. + example: true set_runtime_value_int: description: Set an integer runtime value on the IHC controller. fields: + controller_id: + description: | + If you have multiple controller, this is the index of you controller + starting with 0 (0 is default) + example: 0 ihc_id: description: The integer IHC resource ID. + example: 123456 value: description: The integer value to set. + example: 50 set_runtime_value_float: description: Set a float runtime value on the IHC controller. fields: + controller_id: + description: | + If you have multiple controller, this is the index of you controller + starting with 0 (0 is default) + example: 0 ihc_id: description: The integer IHC resource ID. + example: 123456 value: description: The float value to set. + example: 1.47 pulse: description: Pulses an input on the IHC controller. fields: + controller_id: + description: | + If you have multiple controller, this is the index of you controller + starting with 0 (0 is default) + example: 0 ihc_id: description: The integer IHC resource ID. + example: 123456