Add separate on/off ids on manual configured IHC lights (#20253)
* Add support for separate on/off ids on manual configured IHC lights. This makes it easier to support IHC code units thats relies on being turned on and off through specific inputs. Also adds a pulse service (ihc.pulse) that supports sending a short on/off pulse to an IHC input. * Fix * Lint fix * Add on/off id support in switch * Make pulse async * Code review fixes
This commit is contained in:
1 parent
ee4be13bda
commit
0aba49adce
6 files changed
+109
-23
No files matched your search
@@ -1,5 +1,7 @@
|
||||
"""Support for IHC switches."""
|
||||
from homeassistant.components.ihc import IHC_CONTROLLER, IHC_DATA, IHC_INFO
|
||||
from homeassistant.components.ihc.const import CONF_OFF_ID, CONF_ON_ID
|
||||
from homeassistant.components.ihc.util import async_pulse, async_set_bool
|
||||
from homeassistant.components.ihc.ihcdevice import IHCDevice
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
|
||||
@@ -13,14 +15,18 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
devices = []
|
||||
for name, device in discovery_info.items():
|
||||
ihc_id = device['ihc_id']
|
||||
product_cfg = device['product_cfg']
|
||||
product = device['product']
|
||||
# Find controller that corresponds with device id
|
||||
ctrl_id = device['ctrl_id']
|
||||
ihc_key = IHC_DATA.format(ctrl_id)
|
||||
info = hass.data[ihc_key][IHC_INFO]
|
||||
ihc_controller = hass.data[ihc_key][IHC_CONTROLLER]
|
||||
ihc_off_id = product_cfg.get(CONF_OFF_ID)
|
||||
ihc_on_id = product_cfg.get(CONF_ON_ID)
|
||||
|
||||
switch = IHCSwitch(ihc_controller, name, ihc_id, info, product)
|
||||
switch = IHCSwitch(ihc_controller, name, ihc_id, ihc_off_id, ihc_on_id,
|
||||
info, product)
|
||||
devices.append(switch)
|
||||
add_entities(devices)
|
||||
|
||||
@@ -28,10 +34,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
class IHCSwitch(IHCDevice, SwitchDevice):
|
||||
"""Representation of an IHC switch."""
|
||||
|
||||
def __init__(self, ihc_controller, name: str, ihc_id: int,
|
||||
info: bool, product=None) -> None:
|
||||
def __init__(self, ihc_controller, name: str, ihc_id: int, ihc_off_id: int,
|
||||
ihc_on_id: int, info: bool, product=None) -> None:
|
||||
"""Initialize the IHC switch."""
|
||||
super().__init__(ihc_controller, name, ihc_id, product)
|
||||
self._ihc_off_id = ihc_off_id
|
||||
self._ihc_on_id = ihc_on_id
|
||||
self._state = False
|
||||
|
||||
@property
|
||||
@@ -39,13 +47,21 @@ class IHCSwitch(IHCDevice, SwitchDevice):
|
||||
"""Return true if switch is on."""
|
||||
return self._state
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the switch on."""
|
||||
self.ihc_controller.set_runtime_value_bool(self.ihc_id, True)
|
||||
if self._ihc_on_id:
|
||||
await async_pulse(self.hass, self.ihc_controller, self._ihc_on_id)
|
||||
else:
|
||||
await async_set_bool(self.hass, self.ihc_controller,
|
||||
self.ihc_id, True)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn the device off."""
|
||||
self.ihc_controller.set_runtime_value_bool(self.ihc_id, False)
|
||||
if self._ihc_off_id:
|
||||
await async_pulse(self.hass, self.ihc_controller, self._ihc_off_id)
|
||||
else:
|
||||
await async_set_bool(self.hass, self.ihc_controller,
|
||||
self.ihc_id, False)
|
||||
|
||||
def on_ihc_change(self, ihc_id, value):
|
||||
"""Handle IHC resource change."""
|
||||
|
||||
Reference in new issue
Block a user