mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Added support for the creation of custom switches using the ISY994 device.
This commit is contained in:
parent
4e3ccfffbb
commit
510064d9c8
@ -130,6 +130,9 @@ class ISYDeviceABC(ToggleEntity):
|
|||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
""" Returns the name of the node if any. """
|
""" Returns the name of the node if any. """
|
||||||
|
try:
|
||||||
|
return self._name
|
||||||
|
except AttributeError:
|
||||||
return self.node.name
|
return self.node.name
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
@ -143,7 +146,7 @@ class ISYDeviceABC(ToggleEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
return self.value > 0
|
return bool(self.value)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_open(self):
|
def is_open(self):
|
||||||
|
@ -4,7 +4,10 @@ import logging
|
|||||||
|
|
||||||
# homeassistant imports
|
# homeassistant imports
|
||||||
from homeassistant.components.isy994 import ISY, ISYDeviceABC
|
from homeassistant.components.isy994 import ISY, ISYDeviceABC
|
||||||
from homeassistant.const import STATE_ON, STATE_OFF
|
from homeassistant.const import STATE_ON, STATE_OFF # STATE_OPEN, STATE_CLOSED
|
||||||
|
# The frontend doesn't seem to fully support the open and closed states yet.
|
||||||
|
# Once it does, the HA.doors programs should report open and closed instead of
|
||||||
|
# off and on. It appears that on should be open and off should be closed.
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
@ -20,7 +23,28 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
for node in ISY.nodes:
|
for node in ISY.nodes:
|
||||||
if not node.dimmable:
|
if not node.dimmable:
|
||||||
devs.append(ISYSwitchDevice(node))
|
devs.append(ISYSwitchDevice(node))
|
||||||
# import ISY programs
|
|
||||||
|
# import ISY doors programs
|
||||||
|
for folder_name, states in (('HA.doors', [STATE_ON, STATE_OFF]),
|
||||||
|
('HA.switches', [STATE_ON, STATE_OFF])):
|
||||||
|
try:
|
||||||
|
folder = ISY.programs['My Programs'][folder_name]
|
||||||
|
except KeyError:
|
||||||
|
# HA.doors folder does not exist
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
for dtype, name, node_id in folder.children:
|
||||||
|
if dtype is 'folder':
|
||||||
|
custom_switch = folder[node_id]
|
||||||
|
try:
|
||||||
|
actions = custom_switch['actions'].leaf
|
||||||
|
assert actions.dtype == 'program', 'Not a program'
|
||||||
|
node = custom_switch['status'].leaf
|
||||||
|
except (KeyError, AssertionError):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
devs.append(ISYProgramDevice(name, node, actions,
|
||||||
|
states))
|
||||||
|
|
||||||
add_devices(devs)
|
add_devices(devs)
|
||||||
|
|
||||||
@ -31,3 +55,24 @@ class ISYSwitchDevice(ISYDeviceABC):
|
|||||||
_domain = 'switch'
|
_domain = 'switch'
|
||||||
_dtype = 'binary'
|
_dtype = 'binary'
|
||||||
_states = [STATE_ON, STATE_OFF]
|
_states = [STATE_ON, STATE_OFF]
|
||||||
|
|
||||||
|
|
||||||
|
class ISYProgramDevice(ISYSwitchDevice):
|
||||||
|
""" represents a door that can be manipulated within home assistant. """
|
||||||
|
|
||||||
|
_domain = 'switch'
|
||||||
|
_dtype = 'binary'
|
||||||
|
|
||||||
|
def __init__(self, name, node, actions, states):
|
||||||
|
super().__init__(node)
|
||||||
|
self._states = states
|
||||||
|
self._name = name
|
||||||
|
self.action_node = actions
|
||||||
|
|
||||||
|
def turn_on(self, **kwargs):
|
||||||
|
""" turns the device on/closes the device """
|
||||||
|
self.action_node.runThen()
|
||||||
|
|
||||||
|
def turn_off(self, **kwargs):
|
||||||
|
""" turns the device off/opens the device """
|
||||||
|
self.action_node.runElse()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user