hass-core/homeassistant/components/lutron_caseta.py
Mitesh Patel 61730012d8 Adds Support for Lutron Caseta devices. (#6631)
* Adds support for the Lutron Caseta family of devices

* Added external requirement

* Removes unuse import

* Adds requirement to requirements_all.txt

* Removes unuse import

* fixes requirement_all.txt. by regenerating

* Cleans up syantax

* Cleans up syantax

* Cleans up syantax

* Cleans up syantax

* Shortens long line

* adds lutron_caseta component to .coveragerc

* Merges into light, removes component

* Fixes long lines

* Fixes requirement.txt

* Removes 'ERROR' log statements. Adds missing dependency

* savig work to pick up on other machine

* Enables Lutron Caseta component with Light and Switch platforms

* Add missing file to .coveragerc

* Changes based on PR review

* fixes requirements file

* Fixes install of paramiko dependency.

* Moves callback registration to

* comment changes

* Platform have no return value

* Change style for guard

* fix logic

* fix lint
2017-03-23 01:18:14 +01:00

100 lines
2.9 KiB
Python

"""
Component for interacting with a Lutron Caseta system.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/lutron_caseta/
"""
import asyncio
import logging
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.const import (CONF_HOST,
CONF_USERNAME,
CONF_PASSWORD)
from homeassistant.helpers import discovery
from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['https://github.com/gurumitts/'
'pylutron-caseta/archive/v0.2.4.zip#'
'pylutron-caseta==v0.2.4']
_LOGGER = logging.getLogger(__name__)
LUTRON_CASETA_SMARTBRIDGE = 'lutron_smartbridge'
DOMAIN = 'lutron_caseta'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string
})
}, extra=vol.ALLOW_EXTRA)
def setup(hass, base_config):
"""Setup the Lutron component."""
from pylutron_caseta.smartbridge import Smartbridge
config = base_config.get(DOMAIN)
hass.data[LUTRON_CASETA_SMARTBRIDGE] = Smartbridge(
hostname=config[CONF_HOST],
username=config[CONF_USERNAME],
password=config[CONF_PASSWORD]
)
if not hass.data[LUTRON_CASETA_SMARTBRIDGE].is_connected():
_LOGGER.error("Unable to connect to Lutron smartbridge at %s",
config[CONF_HOST])
return False
_LOGGER.info("Connected to Lutron smartbridge at %s",
config[CONF_HOST])
for component in ('light', 'switch'):
discovery.load_platform(hass, component, DOMAIN, {}, config)
return True
class LutronCasetaDevice(Entity):
"""Common base class for all Lutron Caseta devices."""
def __init__(self, device, bridge):
"""Set up the base class.
[:param]device the device metadata
[:param]bridge the smartbridge object
"""
self._device_id = device["device_id"]
self._device_type = device["type"]
self._device_name = device["name"]
self._state = None
self._smartbridge = bridge
@asyncio.coroutine
def async_added_to_hass(self):
"""Register callbacks."""
self._smartbridge.add_subscriber(self._device_id,
self._update_callback)
def _update_callback(self):
self.schedule_update_ha_state()
@property
def name(self):
"""Return the name of the device."""
return self._device_name
@property
def device_state_attributes(self):
"""Return the state attributes."""
attr = {'Lutron Integration ID': self._device_id}
return attr
@property
def should_poll(self):
"""No polling needed."""
return False