From 83aea10f06101c7dc6cf7f232cd4b413d2ebbc14 Mon Sep 17 00:00:00 2001 From: Ryan Kraus <rmkraus@gmail.com> Date: Mon, 13 Apr 2015 12:56:37 -0400 Subject: [PATCH] Added hidden_string and sensor_string properties to the isy994 configuration to allow nodes to be hidden and to be handled as sensors. Implimented the sensor_string. Any node name that contains the sensor_string in its name will be treated as a sensor instead of a switch or light. The hidden_string will be implimented later. --- homeassistant/components/isy994.py | 42 ++++++++++++++--------- homeassistant/components/light/isy994.py | 4 +-- homeassistant/components/sensor/isy994.py | 7 +++- homeassistant/components/switch/isy994.py | 4 +-- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/isy994.py b/homeassistant/components/isy994.py index 6c4a431c100..7fa0524d32f 100644 --- a/homeassistant/components/isy994.py +++ b/homeassistant/components/isy994.py @@ -25,6 +25,8 @@ DISCOVER_LIGHTS = "isy994.lights" DISCOVER_SWITCHES = "isy994.switches" DISCOVER_SENSORS = "isy994.sensors" ISY = None +SENSOR_STRING = 'Sensor' +HIDDEN_STRING = '{HIDE ME}' # setup logger logger = logging.getLogger(__name__) @@ -32,28 +34,34 @@ logger.setLevel(logging.DEBUG) def setup(hass, config): - # pull values from configuration file + # check for required values in configuration file if not validate_config(config, {DOMAIN: [CONF_HOST, CONF_USERNAME, CONF_PASSWORD]}, logger): return False + + # pull and parse standard configuration + user = config[DOMAIN][CONF_USERNAME] + password = config[DOMAIN][CONF_PASSWORD] + host = urlparse(config[DOMAIN][CONF_HOST]) + addr = host.geturl() + if host.scheme == 'http': + addr = addr.replace('http://', '') + https = False + elif host.scheme == 'https': + addr = addr.replace('https://', '') + https = True else: - user = config[DOMAIN][CONF_USERNAME] - password = config[DOMAIN][CONF_PASSWORD] - host = urlparse(config[DOMAIN][CONF_HOST]) - addr = host.geturl() - if host.scheme == 'http': - addr = addr.replace('http://', '') - https = False - elif host.scheme == 'https': - addr = addr.replace('https://', '') - https = True - else: - logger.error('isy994 host value in configuration ' + - 'file is invalid.') - return False - port = host.port - addr = addr.replace(':{}'.format(port), '') + logger.error('isy994 host value in configuration file is invalid.') + return False + port = host.port + addr = addr.replace(':{}'.format(port), '') + + # pull and parse optional configuration + global SENSOR_STRING + global HIDDEN_STRING + SENSOR_STRING = config[DOMAIN].get('sensor_string', SENSOR_STRING) + HIDDEN_STRING = config[DOMAIN].get('hidden_string', HIDDEN_STRING) # connect to ISY controller global ISY diff --git a/homeassistant/components/light/isy994.py b/homeassistant/components/light/isy994.py index 16d7f6b052c..60a4faafe13 100644 --- a/homeassistant/components/light/isy994.py +++ b/homeassistant/components/light/isy994.py @@ -3,7 +3,7 @@ import logging # homeassistant imports -from homeassistant.components.isy994 import ISYDeviceABC, ISY +from homeassistant.components.isy994 import ISYDeviceABC, ISY, SENSOR_STRING from homeassistant.components.light import ATTR_BRIGHTNESS from homeassistant.const import STATE_ON, STATE_OFF @@ -19,7 +19,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): # import dimmable nodes for node in ISY.nodes: - if node.dimmable: + if node.dimmable and SENSOR_STRING not in node.name: devs.append(ISYLightDevice(node)) add_devices(devs) diff --git a/homeassistant/components/sensor/isy994.py b/homeassistant/components/sensor/isy994.py index a05257f2c3b..aa98c594910 100644 --- a/homeassistant/components/sensor/isy994.py +++ b/homeassistant/components/sensor/isy994.py @@ -3,7 +3,7 @@ import logging # homeassistant imports -from homeassistant.components.isy994 import ISY, ISYDeviceABC +from homeassistant.components.isy994 import ISY, ISYDeviceABC, SENSOR_STRING from homeassistant.const import (STATE_OPEN, STATE_CLOSED, STATE_HOME, STATE_NOT_HOME, STATE_ON, STATE_OFF) @@ -26,6 +26,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None): getattr(ISY.climate, prop + '_units')) devs.append(ISYSensorDevice(node)) + # import sensor nodes + for node in ISY.nodes: + if SENSOR_STRING in node.name: + devs.append(ISYSensorDevice(node, [STATE_ON, STATE_OFF])) + # import sensor programs for (folder_name, states) in ( ('HA.locations', [STATE_HOME, STATE_NOT_HOME]), diff --git a/homeassistant/components/switch/isy994.py b/homeassistant/components/switch/isy994.py index c33e0666fd3..1ea87e3fc2e 100644 --- a/homeassistant/components/switch/isy994.py +++ b/homeassistant/components/switch/isy994.py @@ -3,7 +3,7 @@ import logging # homeassistant imports -from homeassistant.components.isy994 import ISY, ISYDeviceABC +from homeassistant.components.isy994 import ISY, ISYDeviceABC, SENSOR_STRING 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 @@ -21,7 +21,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): # import not dimmable nodes and groups for node in ISY.nodes: - if not node.dimmable: + if not node.dimmable and SENSOR_STRING not in node.name: devs.append(ISYSwitchDevice(node)) # import ISY doors programs -- GitLab