Add ISY programs and support for all device types (#3082)

*  ISY Lock, Binary Sensor, Cover devices, Sensors and Fan support
* Support for ISY Programs
This commit is contained in:
Teagan Glenn authored and Johann Kellerman committed 2016-09-11 20:18:53 +02:00
1 parent 8c7a1b4b05
commit 05a3b610ff
9 files changed
+1057 -321

No files matched your search

+50 -40
View File
@@ -2,58 +2,68 @@
Support for ISY994 lights.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/isy994/
https://home-assistant.io/components/light.isy994/
"""
import logging
from typing import Callable
from homeassistant.components.isy994 import (
HIDDEN_STRING, ISY, SENSOR_STRING, ISYDeviceABC)
from homeassistant.components.light import (ATTR_BRIGHTNESS,
ATTR_SUPPORTED_FEATURES,
SUPPORT_BRIGHTNESS)
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.components.light import Light
import homeassistant.components.isy994 as isy
from homeassistant.const import STATE_ON, STATE_OFF, STATE_UNKNOWN
from homeassistant.helpers.typing import ConfigType
SUPPORT_ISY994 = SUPPORT_BRIGHTNESS
_LOGGER = logging.getLogger(__name__)
VALUE_TO_STATE = {
False: STATE_OFF,
True: STATE_ON,
}
UOM = ['2', '78']
STATES = [STATE_OFF, STATE_ON, 'true', 'false']
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the ISY994 platform."""
logger = logging.getLogger(__name__)
devs = []
if ISY is None or not ISY.connected:
logger.error('A connection has not been made to the ISY controller.')
# pylint: disable=unused-argument
def setup_platform(hass, config: ConfigType,
add_devices: Callable[[list], None], discovery_info=None):
"""Set up the ISY994 light platform."""
if isy.ISY is None or not isy.ISY.connected:
_LOGGER.error('A connection has not been made to the ISY controller.')
return False
# Import dimmable nodes
for (path, node) in ISY.nodes:
if node.dimmable and SENSOR_STRING not in node.name:
if HIDDEN_STRING in path:
node.name += HIDDEN_STRING
devs.append(ISYLightDevice(node))
devices = []
add_devices(devs)
for node in isy.filter_nodes(isy.NODES, units=UOM,
states=STATES):
if node.dimmable:
devices.append(ISYLightDevice(node))
add_devices(devices)
class ISYLightDevice(ISYDeviceABC):
"""Representation of a ISY light."""
class ISYLightDevice(isy.ISYDevice, Light):
"""Representation of an ISY994 light devie."""
_domain = 'light'
_dtype = 'analog'
_attrs = {
ATTR_BRIGHTNESS: 'value',
ATTR_SUPPORTED_FEATURES: 'supported_features',
}
_onattrs = [ATTR_BRIGHTNESS]
_states = [STATE_ON, STATE_OFF]
def __init__(self, node: object) -> None:
"""Initialize the ISY994 light device."""
isy.ISYDevice.__init__(self, node)
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_ISY994
def is_on(self) -> bool:
"""Get whether the ISY994 light is on."""
return self.state == STATE_ON
def _attr_filter(self, attr):
"""Filter brightness out of entity while off."""
if ATTR_BRIGHTNESS in attr and not self.is_on:
del attr[ATTR_BRIGHTNESS]
return attr
@property
def state(self) -> str:
"""Get the state of the ISY994 light."""
return VALUE_TO_STATE.get(bool(self.value), STATE_UNKNOWN)
def turn_off(self, **kwargs) -> None:
"""Send the turn off command to the ISY994 light device."""
if not self._node.fastOff():
_LOGGER.debug('Unable to turn on light.')
def turn_on(self, brightness=100, **kwargs) -> None:
"""Send the turn on command to the ISY994 light device."""
if not self._node.on(val=brightness):
_LOGGER.debug('Unable to turn on light.')