1 """Support for IHC devices."""
3 import voluptuous
as vol
16 SERVICE_SET_RUNTIME_VALUE_BOOL,
17 SERVICE_SET_RUNTIME_VALUE_FLOAT,
18 SERVICE_SET_RUNTIME_VALUE_INT,
20 from .util
import async_pulse, async_set_bool, async_set_float, async_set_int
22 SET_RUNTIME_VALUE_BOOL_SCHEMA = vol.Schema(
24 vol.Required(ATTR_IHC_ID): cv.positive_int,
25 vol.Required(ATTR_VALUE): cv.boolean,
26 vol.Optional(ATTR_CONTROLLER_ID, default=0): cv.positive_int,
30 SET_RUNTIME_VALUE_INT_SCHEMA = vol.Schema(
32 vol.Required(ATTR_IHC_ID): cv.positive_int,
33 vol.Required(ATTR_VALUE): vol.Coerce(int),
34 vol.Optional(ATTR_CONTROLLER_ID, default=0): cv.positive_int,
38 SET_RUNTIME_VALUE_FLOAT_SCHEMA = vol.Schema(
40 vol.Required(ATTR_IHC_ID): cv.positive_int,
41 vol.Required(ATTR_VALUE): vol.Coerce(float),
42 vol.Optional(ATTR_CONTROLLER_ID, default=0): cv.positive_int,
46 PULSE_SCHEMA = vol.Schema(
48 vol.Required(ATTR_IHC_ID): cv.positive_int,
49 vol.Optional(ATTR_CONTROLLER_ID, default=0): cv.positive_int,
55 """Set up the IHC service functions."""
57 def _get_controller(call):
58 controller_index = call.data[ATTR_CONTROLLER_ID]
59 for controller_id
in hass.data[DOMAIN]:
60 controller_conf = hass.data[DOMAIN][controller_id]
61 if controller_conf[IHC_CONTROLLER_INDEX] == controller_index:
62 return controller_conf[IHC_CONTROLLER]
64 raise ValueError(
"The controller index is out of range")
66 async
def async_set_runtime_value_bool(call):
67 """Set a IHC runtime bool value service function."""
68 ihc_id = call.data[ATTR_IHC_ID]
69 value = call.data[ATTR_VALUE]
70 ihc_controller = _get_controller(call)
73 async
def async_set_runtime_value_int(call):
74 """Set a IHC runtime integer value service function."""
75 ihc_id = call.data[ATTR_IHC_ID]
76 value = call.data[ATTR_VALUE]
77 ihc_controller = _get_controller(call)
80 async
def async_set_runtime_value_float(call):
81 """Set a IHC runtime float value service function."""
82 ihc_id = call.data[ATTR_IHC_ID]
83 value = call.data[ATTR_VALUE]
84 ihc_controller = _get_controller(call)
87 async
def async_pulse_runtime_input(call):
88 """Pulse a IHC controller input function."""
89 ihc_id = call.data[ATTR_IHC_ID]
90 ihc_controller = _get_controller(call)
93 hass.services.register(
95 SERVICE_SET_RUNTIME_VALUE_BOOL,
96 async_set_runtime_value_bool,
97 schema=SET_RUNTIME_VALUE_BOOL_SCHEMA,
99 hass.services.register(
101 SERVICE_SET_RUNTIME_VALUE_INT,
102 async_set_runtime_value_int,
103 schema=SET_RUNTIME_VALUE_INT_SCHEMA,
105 hass.services.register(
107 SERVICE_SET_RUNTIME_VALUE_FLOAT,
108 async_set_runtime_value_float,
109 schema=SET_RUNTIME_VALUE_FLOAT_SCHEMA,
111 hass.services.register(
112 DOMAIN, SERVICE_PULSE, async_pulse_runtime_input, schema=PULSE_SCHEMA
None setup_service_functions(HomeAssistant hass)
asyncio.Future[bool] async_set_float(HomeAssistant hass, IHCController ihc_controller, int ihc_id, float value)
None async_pulse(HomeAssistant hass, IHCController ihc_controller, int ihc_id)
asyncio.Future[bool] async_set_int(HomeAssistant hass, IHCController ihc_controller, int ihc_id, int value)
asyncio.Future[bool] async_set_bool(HomeAssistant hass, IHCController ihc_controller, int ihc_id, bool value)