2019-02-14 04:35:12 +00:00
|
|
|
"""Support for KNX scenes."""
|
2020-04-21 01:07:50 +00:00
|
|
|
from typing import Any
|
|
|
|
|
2019-10-22 05:38:21 +00:00
|
|
|
from xknx.devices import Scene as XknxScene
|
2018-02-26 07:44:09 +00:00
|
|
|
|
2020-08-26 16:03:03 +00:00
|
|
|
from homeassistant.components.scene import Scene
|
2018-02-26 07:44:09 +00:00
|
|
|
|
2020-08-30 18:13:47 +00:00
|
|
|
from . import DATA_KNX
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2018-02-26 07:44:09 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2018-02-26 07:44:09 +00:00
|
|
|
"""Set up the scenes for KNX platform."""
|
|
|
|
entities = []
|
2020-08-30 18:13:47 +00:00
|
|
|
for device in hass.data[DATA_KNX].xknx.devices:
|
|
|
|
if isinstance(device, XknxScene):
|
|
|
|
entities.append(KNXScene(device))
|
2018-08-24 14:37:30 +00:00
|
|
|
async_add_entities(entities)
|
2018-02-26 07:44:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class KNXScene(Scene):
|
|
|
|
"""Representation of a KNX scene."""
|
|
|
|
|
2020-08-26 16:03:03 +00:00
|
|
|
def __init__(self, scene: XknxScene):
|
2018-02-26 07:44:09 +00:00
|
|
|
"""Init KNX scene."""
|
|
|
|
self.scene = scene
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the scene."""
|
|
|
|
return self.scene.name
|
|
|
|
|
2020-04-21 01:07:50 +00:00
|
|
|
async def async_activate(self, **kwargs: Any) -> None:
|
2018-02-26 07:44:09 +00:00
|
|
|
"""Activate the scene."""
|
2018-03-03 21:55:24 +00:00
|
|
|
await self.scene.run()
|