hass-core/homeassistant/components/light/vera.py

53 lines
1.6 KiB
Python
Raw Normal View History

2015-03-09 01:14:44 +11:00
"""
2015-08-11 14:54:23 +02:00
homeassistant.components.light.vera
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2015-10-20 22:07:24 +02:00
Support for Vera lights.
2015-10-20 22:07:24 +02:00
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.vera.html
"""
2015-03-02 21:09:00 +11:00
import logging
from requests.exceptions import RequestException
from homeassistant.components.switch.vera import VeraSwitch
2015-09-08 20:11:25 -07:00
REQUIREMENTS = ['https://github.com/balloob/home-assistant-vera-api/archive/'
'a8f823066ead6c7da6fb5e7abaf16fef62e63364.zip'
'#python-vera==0.1']
2015-03-02 21:09:00 +11:00
_LOGGER = logging.getLogger(__name__)
2015-03-02 21:09:00 +11:00
2015-03-09 01:58:11 +11:00
2015-03-09 01:14:44 +11:00
# pylint: disable=unused-argument
2015-03-02 21:09:00 +11:00
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return Vera lights. """
2015-09-08 20:11:25 -07:00
import pyvera as veraApi
2015-03-02 21:09:00 +11:00
2015-03-09 07:03:56 +11: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
device_data = config.get('device_data', {})
2015-03-02 21:09:00 +11:00
2015-03-09 07:03:56 +11:00
controller = veraApi.VeraController(base_url)
devices = []
try:
2015-10-26 10:51:23 +00:00
devices = controller.get_devices(['Switch', 'On/Off Switch', 'Dimmable Switch'])
except RequestException:
# There was a network related error connecting to the vera controller
_LOGGER.exception("Error communicating with Vera API")
2015-03-02 21:09:00 +11:00
return False
2015-03-09 07:03:56 +11:00
lights = []
for device in devices:
extra_data = device_data.get(device.deviceId, {})
exclude = extra_data.get('exclude', False)
2015-03-09 07:03:56 +11:00
if exclude is not True:
lights.append(VeraSwitch(device, extra_data))
2015-03-09 07:03:56 +11:00
add_devices_callback(lights)