2015-04-04 08:33:03 +00:00
|
|
|
""" Support for ISY994 sensors. """
|
|
|
|
# system imports
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# homeassistant imports
|
2015-04-15 06:05:34 +00:00
|
|
|
from homeassistant.components.isy994 import (ISY, ISYDeviceABC, SENSOR_STRING,
|
|
|
|
HIDDEN_STRING)
|
2015-04-13 05:47:32 +00:00
|
|
|
from homeassistant.const import (STATE_OPEN, STATE_CLOSED, STATE_HOME,
|
|
|
|
STATE_NOT_HOME, STATE_ON, STATE_OFF)
|
2015-04-04 08:33:03 +00:00
|
|
|
|
2015-04-15 06:05:34 +00:00
|
|
|
DEFAULT_HIDDEN_WEATHER = ['Temperature_High', 'Temperature_Low', 'Feels_Like',
|
|
|
|
'Temperature_Average', 'Pressure', 'Dew_Point',
|
|
|
|
'Gust_Speed', 'Evapotranspiration',
|
|
|
|
'Irrigation_Requirement', 'Water_Deficit_Yesterday',
|
|
|
|
'Elevation', 'Average_Temperature_Tomorrow',
|
|
|
|
'High_Temperature_Tomorrow',
|
|
|
|
'Low_Temperature_Tomorrow', 'Humidity_Tomorrow',
|
|
|
|
'Wind_Speed_Tomorrow', 'Gust_Speed_Tomorrow',
|
|
|
|
'Rain_Tomorrow', 'Snow_Tomorrow',
|
|
|
|
'Forecast_Average_Temperature',
|
|
|
|
'Forecast_High_Temperature',
|
|
|
|
'Forecast_Low_Temperature', 'Forecast_Humidity',
|
|
|
|
'Forecast_Rain', 'Forecast_Snow']
|
|
|
|
|
2015-04-04 08:33:03 +00:00
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
|
|
""" Sets up the isy994 platform. """
|
2015-04-15 06:05:34 +00:00
|
|
|
# pylint: disable=protected-access
|
2015-04-04 08:33:03 +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 weather
|
|
|
|
if ISY.climate is not None:
|
|
|
|
for prop in ISY.climate._id2name:
|
|
|
|
if prop is not None:
|
2015-04-17 13:27:14 +00:00
|
|
|
prefix = HIDDEN_STRING \
|
|
|
|
if prop in DEFAULT_HIDDEN_WEATHER else ''
|
2015-04-15 06:05:34 +00:00
|
|
|
node = WeatherPseudoNode('ISY.weather.' + prop, prefix + prop,
|
2015-04-12 20:45:23 +00:00
|
|
|
getattr(ISY.climate, prop),
|
|
|
|
getattr(ISY.climate, prop + '_units'))
|
|
|
|
devs.append(ISYSensorDevice(node))
|
2015-04-04 08:33:03 +00:00
|
|
|
|
2015-04-13 16:56:37 +00:00
|
|
|
# import sensor nodes
|
2015-04-17 13:27:14 +00:00
|
|
|
for (path, node) in ISY.nodes:
|
2015-04-13 16:56:37 +00:00
|
|
|
if SENSOR_STRING in node.name:
|
2015-04-17 13:27:14 +00:00
|
|
|
if HIDDEN_STRING in path:
|
|
|
|
node.name += HIDDEN_STRING
|
2015-04-13 16:56:37 +00:00
|
|
|
devs.append(ISYSensorDevice(node, [STATE_ON, STATE_OFF]))
|
|
|
|
|
2015-04-13 05:47:32 +00:00
|
|
|
# import sensor programs
|
|
|
|
for (folder_name, states) in (
|
|
|
|
('HA.locations', [STATE_HOME, STATE_NOT_HOME]),
|
|
|
|
('HA.sensors', [STATE_OPEN, STATE_CLOSED]),
|
|
|
|
('HA.states', [STATE_ON, STATE_OFF])):
|
|
|
|
try:
|
|
|
|
folder = ISY.programs['My Programs'][folder_name]
|
|
|
|
except KeyError:
|
|
|
|
# folder does not exist
|
|
|
|
pass
|
|
|
|
else:
|
2015-04-15 06:05:34 +00:00
|
|
|
for _, _, node_id in folder.children:
|
2015-04-13 05:47:32 +00:00
|
|
|
node = folder[node_id].leaf
|
|
|
|
devs.append(ISYSensorDevice(node, states))
|
|
|
|
|
2015-04-04 08:33:03 +00:00
|
|
|
add_devices(devs)
|
|
|
|
|
|
|
|
|
2015-04-12 20:45:23 +00:00
|
|
|
class WeatherPseudoNode(object):
|
|
|
|
""" This class allows weather variable to act as regular nodes. """
|
2015-04-15 06:05:34 +00:00
|
|
|
# pylint: disable=too-few-public-methods
|
2015-04-04 08:33:03 +00:00
|
|
|
|
2015-04-12 20:45:23 +00:00
|
|
|
def __init__(self, device_id, name, status, units=None):
|
2015-04-04 08:33:03 +00:00
|
|
|
self._id = device_id
|
2015-04-12 20:45:23 +00:00
|
|
|
self.name = name
|
|
|
|
self.status = status
|
|
|
|
self.units = units
|
2015-04-04 08:33:03 +00:00
|
|
|
|
|
|
|
|
2015-04-12 20:45:23 +00:00
|
|
|
class ISYSensorDevice(ISYDeviceABC):
|
|
|
|
""" represents a isy sensor within home assistant. """
|
2015-04-04 08:33:03 +00:00
|
|
|
|
2015-04-12 20:45:23 +00:00
|
|
|
_domain = 'sensor'
|
2015-04-13 05:47:32 +00:00
|
|
|
|
2015-04-15 06:05:34 +00:00
|
|
|
def __init__(self, node, states=None):
|
2015-04-13 05:47:32 +00:00
|
|
|
super().__init__(node)
|
2015-04-15 06:05:34 +00:00
|
|
|
self._states = states or []
|