-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene.py
More file actions
57 lines (43 loc) · 1.81 KB
/
scene.py
File metadata and controls
57 lines (43 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Support for Nexia Automations."""
from typing import Any
from .nexiaux360.automation import NexiaAutomation
from homeassistant.components.scene import Scene
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_call_later
from .const import ATTR_DESCRIPTION
from .coordinator import NexiaDataUpdateCoordinator
from .entity import NexiaEntity
from .types import NexiaConfigEntry
SCENE_ACTIVATION_TIME = 5
async def async_setup_entry(
hass: HomeAssistant,
config_entry: NexiaConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up automations for a Nexia device."""
coordinator = config_entry.runtime_data
nexia_home = coordinator.nexia_home
async_add_entities(
NexiaAutomationScene(
coordinator, nexia_home.get_automation_by_id(automation_id)
)
for automation_id in nexia_home.get_automation_ids()
)
class NexiaAutomationScene(NexiaEntity, Scene):
"""Provides Nexia automation support."""
_attr_translation_key = "automation"
def __init__(
self, coordinator: NexiaDataUpdateCoordinator, automation: NexiaAutomation
) -> None:
"""Initialize the automation scene."""
super().__init__(coordinator, automation.automation_id)
self._attr_name = automation.name
self._automation = automation
self._attr_extra_state_attributes = {ATTR_DESCRIPTION: automation.description}
async def async_activate(self, **kwargs: Any) -> None:
"""Activate an automation scene."""
await self._automation.activate()
async def refresh_callback(_):
await self.coordinator.async_refresh()
async_call_later(self.hass, SCENE_ACTIVATION_TIME, refresh_callback)