diff --git a/.coveragerc b/.coveragerc index 1eb46d9b37cb92128452c9e8247b978026fb60c5..a2cf15f021aea49dcf8f04da8b9fca2f45a1e4bc 100644 --- a/.coveragerc +++ b/.coveragerc @@ -10,6 +10,9 @@ omit = homeassistant/components/arduino.py homeassistant/components/*/arduino.py + homeassistant/components/insteon.py + homeassistant/components/*/insteon.py + homeassistant/components/isy994.py homeassistant/components/*/isy994.py diff --git a/.gitignore b/.gitignore index 3ee71808ab110dc379486ad944397651613eb2fa..90562a0f9092d724ab9c74e56e0506f8ee1ee8da 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,7 @@ nosetests.xml # venv stuff pyvenv.cfg pip-selfcheck.json + +# vimmy stuff +*.swp +*.swo diff --git a/homeassistant/components/insteon.py b/homeassistant/components/insteon.py new file mode 100644 index 0000000000000000000000000000000000000000..76ca2d303a7c632218460b6ad7cc15e1e7daa360 --- /dev/null +++ b/homeassistant/components/insteon.py @@ -0,0 +1,93 @@ +""" +homeassistant.components.light +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Support for Insteon Hub. +""" + +import logging +import homeassistant.bootstrap as bootstrap +from homeassistant.helpers import validate_config +from homeassistant.loader import get_component +from homeassistant.helpers.entity import ToggleEntity +from homeassistant.const import ( + CONF_USERNAME, CONF_PASSWORD, ATTR_DISCOVERED, + ATTR_SERVICE, EVENT_PLATFORM_DISCOVERED) + +# The domain of your component. Should be equal to the name of your component +DOMAIN = "insteon" + +# List of component names (string) your component depends upon +REQUIREMENTS = [ + 'insteon_hub==0.4.5' +] + +API_KEY = "3eb14d15-a486-4d9e-99af-179d0e9417c11444718937.80636061" +INSTEON = None + +DISCOVER_LIGHTS = "insteon.lights" + +_LOGGER = logging.getLogger(__name__) + + +def setup(hass, config): + """ + Setup Insteon Hub component. + This will automatically import associated lights. + """ + if not validate_config( + config, + {DOMAIN: [CONF_USERNAME, CONF_PASSWORD]}, + _LOGGER): + return False + + import insteon + username = config[DOMAIN][CONF_USERNAME] + password = config[DOMAIN][CONF_PASSWORD] + global INSTEON + INSTEON = insteon.Insteon(username, password, API_KEY) + + comp_name = 'light' + discovery = DISCOVER_LIGHTS + component = get_component(comp_name) + bootstrap.setup_component(hass, component.DOMAIN, config) + hass.bus.fire( + EVENT_PLATFORM_DISCOVERED, + {ATTR_SERVICE: discovery, ATTR_DISCOVERED: {}}) + return True + + +class InsteonToggleDevice(ToggleEntity): + """ Abstract Class for an Insteon node. """ + + def __init__(self, node): + self.node = node + self._value = 0 + + @property + def name(self): + """ Returns the name of the node. """ + return self.node.DeviceName + + @property + def unique_id(self): + """ Returns the id of this insteon node. """ + return self.node.DeviceID + + def update(self): + """ Update state of the sensor. """ + resp = self.node.send_command('get_status', wait=True) + try: + self._value = resp['response']['level'] + except KeyError: + pass + + @property + def is_on(self): + """ Returns boolean response if the node is on. """ + return self._value != 0 + + def turn_on(self, **kwargs): + self.node.send_command('on') + + def turn_off(self, **kwargs): + self.node.send_command('off') diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index b1017900b17010829cd0706ad9618b27b857e03b..47bfd68345f159fb512b91f7c8424b89b239c052 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -10,7 +10,8 @@ import logging import os import csv -from homeassistant.components import group, discovery, wink, isy994, zwave +from homeassistant.components import ( + group, discovery, wink, isy994, zwave, insteon) from homeassistant.config import load_yaml_config_file from homeassistant.const import ( STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE, @@ -59,6 +60,7 @@ LIGHT_PROFILES_FILE = "light_profiles.csv" # Maps discovered services to their platforms DISCOVERY_PLATFORMS = { wink.DISCOVER_LIGHTS: 'wink', + insteon.DISCOVER_LIGHTS: 'insteon', isy994.DISCOVER_LIGHTS: 'isy994', discovery.SERVICE_HUE: 'hue', zwave.DISCOVER_LIGHTS: 'zwave', diff --git a/homeassistant/components/light/insteon.py b/homeassistant/components/light/insteon.py new file mode 100644 index 0000000000000000000000000000000000000000..07c4d19b202215009c120f8370a70f4436d75c9f --- /dev/null +++ b/homeassistant/components/light/insteon.py @@ -0,0 +1,16 @@ +""" +homeassistant.components.light.insteon +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Support for Insteon Hub lights. +""" + +from homeassistant.components.insteon import (INSTEON, InsteonToggleDevice) + + +def setup_platform(hass, config, add_devices, discovery_info=None): + """ Sets up the Insteon Hub light platform. """ + devs = [] + for device in INSTEON.devices: + if device.DeviceCategory == "Switched Lighting Control": + devs.append(InsteonToggleDevice(device)) + add_devices(devs) diff --git a/requirements_all.txt b/requirements_all.txt index 45c57425eace10efc4dd796e2a08b1c417279eae..087e22afd2fd8e97459610844eef70a1d07ff2da 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -39,6 +39,9 @@ pyfttt==0.3 # homeassistant.components.influxdb influxdb==2.10.0 +# homeassistant.components.insteon +insteon_hub==0.4.5 + # homeassistant.components.isy994 PyISY==1.0.5