2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Vera scenes."""
|
2017-12-07 06:47:19 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.scene import Scene
|
2019-03-21 05:56:46 +00:00
|
|
|
from homeassistant.util import slugify
|
|
|
|
|
|
|
|
from . import VERA_CONTROLLER, VERA_ID_FORMAT, VERA_SCENES
|
2017-12-07 06:47:19 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-12-07 06:47:19 +00:00
|
|
|
"""Set up the Vera scenes."""
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(
|
2019-07-31 19:25:30 +00:00
|
|
|
[
|
|
|
|
VeraScene(scene, hass.data[VERA_CONTROLLER])
|
|
|
|
for scene in hass.data[VERA_SCENES]
|
|
|
|
],
|
|
|
|
True,
|
|
|
|
)
|
2017-12-07 06:47:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VeraScene(Scene):
|
|
|
|
"""Representation of a Vera scene entity."""
|
|
|
|
|
|
|
|
def __init__(self, vera_scene, controller):
|
|
|
|
"""Initialize the scene."""
|
|
|
|
self.vera_scene = vera_scene
|
|
|
|
self.controller = controller
|
|
|
|
|
|
|
|
self._name = self.vera_scene.name
|
|
|
|
# Append device id to prevent name clashes in HA.
|
|
|
|
self.vera_id = VERA_ID_FORMAT.format(
|
2019-07-31 19:25:30 +00:00
|
|
|
slugify(vera_scene.name), vera_scene.scene_id
|
|
|
|
)
|
2017-12-07 06:47:19 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update the scene status."""
|
|
|
|
self.vera_scene.refresh()
|
|
|
|
|
2018-02-11 17:20:28 +00:00
|
|
|
def activate(self):
|
2017-12-07 06:47:19 +00:00
|
|
|
"""Activate the scene."""
|
|
|
|
self.vera_scene.activate()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the scene."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Return the state attributes of the scene."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return {"vera_scene_id": self.vera_scene.vera_scene_id}
|