Skip to content

Commit

Permalink
Powerview hub implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sander76 committed Mar 7, 2016
1 parent b16c17f commit 40be9f4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 =
Expand Down
68 changes: 68 additions & 0 deletions homeassistant/components/scene/powerview.py
Original file line number Diff line number Diff line change
@@ -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"])
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 40be9f4

Please sign in to comment.