2015-03-08 14:14:44 +00:00
|
|
|
"""
|
2015-08-11 12:54:23 +00:00
|
|
|
homeassistant.components.light.vera
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2015-10-20 20:07:24 +00:00
|
|
|
Support for Vera lights.
|
2015-03-08 12:52:50 +00:00
|
|
|
|
2015-10-20 20:07:24 +00:00
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/light.vera.html
|
2015-03-08 12:52:50 +00:00
|
|
|
"""
|
2015-03-02 10:09:00 +00:00
|
|
|
import logging
|
2015-10-27 23:18:46 +00:00
|
|
|
import time
|
|
|
|
|
2015-03-08 21:45:20 +00:00
|
|
|
from requests.exceptions import RequestException
|
2015-03-08 20:24:34 +00:00
|
|
|
from homeassistant.components.switch.vera import VeraSwitch
|
2015-09-09 03:11:25 +00:00
|
|
|
|
2015-10-27 23:43:06 +00:00
|
|
|
from homeassistant.components.light import ATTR_BRIGHTNESS
|
2015-10-27 23:18:46 +00:00
|
|
|
|
2015-10-27 23:43:06 +00:00
|
|
|
REQUIREMENTS = ['https://github.com/pavoni/home-assistant-vera-api/archive/'
|
2015-10-30 09:30:22 +00:00
|
|
|
'efdba4e63d58a30bc9b36d9e01e69858af9130b8.zip'
|
2015-10-27 23:43:06 +00:00
|
|
|
'#python-vera==0.1.1']
|
2015-03-02 10:09:00 +00:00
|
|
|
|
2015-03-08 12:52:50 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2015-03-02 10:09:00 +00:00
|
|
|
|
2015-03-08 14:58:11 +00:00
|
|
|
|
2015-03-08 14:14:44 +00:00
|
|
|
# pylint: disable=unused-argument
|
2015-03-02 10:09:00 +00:00
|
|
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|
|
|
""" Find and return Vera lights. """
|
2015-09-09 03:11:25 +00:00
|
|
|
import pyvera as veraApi
|
2015-03-02 10:09:00 +00:00
|
|
|
|
2015-03-08 20:03:56 +00:00
|
|
|
base_url = config.get('vera_controller_url')
|
|
|
|
if not base_url:
|
|
|
|
_LOGGER.error(
|
|
|
|
"The required parameter 'vera_controller_url'"
|
|
|
|
" was not found in config"
|
|
|
|
)
|
|
|
|
return False
|
2015-03-08 12:52:50 +00:00
|
|
|
|
2015-03-08 21:34:06 +00:00
|
|
|
device_data = config.get('device_data', {})
|
2015-03-02 10:09:00 +00:00
|
|
|
|
2015-03-08 20:03:56 +00:00
|
|
|
controller = veraApi.VeraController(base_url)
|
|
|
|
devices = []
|
|
|
|
try:
|
2015-10-27 23:43:06 +00:00
|
|
|
devices = controller.get_devices([
|
|
|
|
'Switch',
|
|
|
|
'On/Off Switch',
|
|
|
|
'Dimmable Switch'])
|
2015-03-08 22:11:59 +00:00
|
|
|
except RequestException:
|
2015-03-08 20:46:26 +00:00
|
|
|
# There was a network related error connecting to the vera controller
|
2015-03-08 22:11:59 +00:00
|
|
|
_LOGGER.exception("Error communicating with Vera API")
|
2015-03-02 10:09:00 +00:00
|
|
|
return False
|
|
|
|
|
2015-03-08 20:03:56 +00:00
|
|
|
lights = []
|
|
|
|
for device in devices:
|
2015-03-08 22:11:59 +00:00
|
|
|
extra_data = device_data.get(device.deviceId, {})
|
|
|
|
exclude = extra_data.get('exclude', False)
|
2015-03-08 20:03:56 +00:00
|
|
|
|
|
|
|
if exclude is not True:
|
2015-10-27 23:18:46 +00:00
|
|
|
lights.append(VeraLight(device, extra_data))
|
2015-03-08 20:03:56 +00:00
|
|
|
|
|
|
|
add_devices_callback(lights)
|
2015-10-27 23:18:46 +00:00
|
|
|
|
2015-10-27 23:43:06 +00:00
|
|
|
|
2015-10-27 23:18:46 +00:00
|
|
|
class VeraLight(VeraSwitch):
|
|
|
|
""" Represents a Vera Light, including dimmable. """
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state_attributes(self):
|
|
|
|
attr = super().state_attributes or {}
|
|
|
|
|
|
|
|
if self.vera_device.is_dimmable:
|
|
|
|
attr[ATTR_BRIGHTNESS] = self.vera_device.get_brightness()
|
|
|
|
|
|
|
|
return attr
|
|
|
|
|
|
|
|
def turn_on(self, **kwargs):
|
|
|
|
if ATTR_BRIGHTNESS in kwargs and self.vera_device.is_dimmable:
|
|
|
|
self.vera_device.set_brightness(kwargs[ATTR_BRIGHTNESS])
|
|
|
|
else:
|
|
|
|
self.vera_device.switch_on()
|
|
|
|
|
|
|
|
self.last_command_send = time.time()
|
|
|
|
self.is_on_status = True
|