Merge pull request #1490 from sander76/powerview

Powerview
pull/1511/head
Paulus Schoutsen 2016-03-07 22:42:20 -08:00
commit 9d76c58bd4
3 changed files with 73 additions and 0 deletions

View File

@ -149,6 +149,7 @@ omit =
homeassistant/components/sensor/transmission.py
homeassistant/components/sensor/twitch.py
homeassistant/components/sensor/worldclock.py
homeassistant/components/scene/powerview.py
homeassistant/components/switch/arest.py
homeassistant/components/switch/edimax.py
homeassistant/components/switch/dlink.py
@ -162,6 +163,7 @@ omit =
homeassistant/components/thermostat/proliphix.py
homeassistant/components/thermostat/radiotherm.py
[report]
# Regexes for lines to exclude from consideration
exclude_lines =

View File

@ -0,0 +1,68 @@
"""
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Gets powerview scenes from a powerview hub
defined by a Hunter Douglas powerview app.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/scene/
"""
import logging
from homeassistant.components.scene import Scene
_LOGGER = logging.getLogger(__name__)
REQUIREMENTS = [
'https://github.com/sander76/powerviewApi/'
'archive/master.zip#powerview_api==0.2']
HUB_ADDRESS = 'address'
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""sets up the powerview scenes stored in a powerview hub"""
import powerview
hub_address = config.get(HUB_ADDRESS)
_pv = powerview.PowerView(hub_address)
try:
_scenes = _pv.get_scenes()
_rooms = _pv.get_rooms()
except ConnectionError:
_LOGGER.exception("error connecting to powerview "
"hub with ip address: %s", hub_address)
return False
add_devices(PowerViewScene(hass, scene, _rooms, _pv)
for scene in _scenes['sceneData'])
return True
class PowerViewScene(Scene):
""" A scene is a group of entities and the states we want them to be. """
def __init__(self, hass, scene_data, room_data, pv_instance):
self.pv_instance = pv_instance
self.hass = hass
self.scene_data = scene_data
self._sync_room_data(room_data)
def _sync_room_data(self, room_data):
room = next((room for room in room_data["roomData"]
if room["id"] == self.scene_data["roomId"]), None)
if room is not None:
self.scene_data["roomName"] = room["name"]
@property
def name(self):
return self.scene_data["name"]
@property
def device_state_attributes(self):
return {"roomName": self.scene_data["roomName"]}
def activate(self):
""" Activates scene. Tries to get entities into requested state. """
self.pv_instance.activate_scene(self.scene_data["id"])

View File

@ -90,6 +90,9 @@ https://github.com/rkabadi/pyedimax/archive/365301ce3ff26129a7910c501ead09ea625f
# homeassistant.components.sensor.temper
https://github.com/rkabadi/temper-python/archive/3dbdaf2d87b8db9a3cd6e5585fc704537dd2d09b.zip#temperusb==1.2.3
# homeassistant.components.scene.powerview
https://github.com/sander76/powerviewApi/archive/master.zip#powerview_api==0.2
# homeassistant.components.mysensors
https://github.com/theolind/pymysensors/archive/f0c928532167fb24823efa793ec21ca646fd37a6.zip#pymysensors==0.5