mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
IHC service functions support for multiple IHC controllers (#44626)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
d81017f62e
commit
b80571519b
@ -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(
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user