2015-05-13 17:18:30 +00:00
|
|
|
"""
|
|
|
|
homeassistant.components.switch.isy994
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Support for ISY994 switches.
|
|
|
|
"""
|
2015-04-12 21:18:14 +00:00
|
|
|
import logging
|
|
|
|
|
2015-04-17 13:27:14 +00:00
|
|
|
from homeassistant.components.isy994 import (ISY, ISYDeviceABC, SENSOR_STRING,
|
|
|
|
HIDDEN_STRING)
|
2015-04-13 02:30:14 +00:00
|
|
|
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.
|
2015-04-12 21:18:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2015-05-13 17:18:30 +00:00
|
|
|
""" Sets up the ISY994 platform. """
|
2015-04-22 04:22:48 +00:00
|
|
|
# pylint: disable=too-many-locals
|
2015-04-12 21:18:14 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
devs = []
|
|
|
|
# verify connection
|
|
|
|
if ISY is None or not ISY.connected:
|
|
|
|
logger.error('A connection has not been made to the ISY controller.')
|
|
|
|
return False
|
|
|
|
|
|
|
|
# import not dimmable nodes and groups
|
2015-04-17 13:27:14 +00:00
|
|
|
for (path, node) in ISY.nodes:
|
2015-04-13 16:56:37 +00:00
|
|
|
if not node.dimmable and SENSOR_STRING not in node.name:
|
2015-04-17 13:27:14 +00:00
|
|
|
if HIDDEN_STRING in path:
|
|
|
|
node.name += HIDDEN_STRING
|
2015-04-12 21:18:14 +00:00
|
|
|
devs.append(ISYSwitchDevice(node))
|
2015-04-13 02:30:14 +00:00
|
|
|
|
|
|
|
# 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))
|
2015-04-12 21:18:14 +00:00
|
|
|
|
|
|
|
add_devices(devs)
|
|
|
|
|
|
|
|
|
|
|
|
class ISYSwitchDevice(ISYDeviceABC):
|
2015-05-13 17:18:30 +00:00
|
|
|
""" Represents as ISY light. """
|
2015-04-12 21:18:14 +00:00
|
|
|
|
|
|
|
_domain = 'switch'
|
|
|
|
_dtype = 'binary'
|
|
|
|
_states = [STATE_ON, STATE_OFF]
|
2015-04-13 02:30:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ISYProgramDevice(ISYSwitchDevice):
|
2015-05-13 17:18:30 +00:00
|
|
|
""" Represents a door that can be manipulated. """
|
2015-04-13 02:30:14 +00:00
|
|
|
|
|
|
|
_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):
|
2015-05-13 17:18:30 +00:00
|
|
|
""" Turns the device on/closes the device. """
|
2015-04-13 02:30:14 +00:00
|
|
|
self.action_node.runThen()
|
|
|
|
|
|
|
|
def turn_off(self, **kwargs):
|
2015-05-13 17:18:30 +00:00
|
|
|
""" Turns the device off/opens the device. """
|
2015-04-13 02:30:14 +00:00
|
|
|
self.action_node.runElse()
|