2019-02-13 20:21:14 +00:00
|
|
|
"""Support for control of ElkM1 tasks ("macros")."""
|
2022-01-05 11:49:13 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-04-21 01:07:50 +00:00
|
|
|
from typing import Any
|
|
|
|
|
2022-04-15 21:14:45 +00:00
|
|
|
from elkm1_lib.tasks import Task
|
|
|
|
|
2018-10-10 17:05:19 +00:00
|
|
|
from homeassistant.components.scene import Scene
|
2022-01-05 11:49:13 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2018-10-10 17:05:19 +00:00
|
|
|
|
2022-04-15 21:14:45 +00:00
|
|
|
from . import ElkAttachedEntity, ElkEntity, create_elk_entities
|
2020-03-27 20:38:35 +00:00
|
|
|
from .const import DOMAIN
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2018-10-10 17:05:19 +00:00
|
|
|
|
2022-01-05 11:49:13 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2018-10-10 17:05:19 +00:00
|
|
|
"""Create the Elk-M1 scene platform."""
|
2020-03-27 20:38:35 +00:00
|
|
|
elk_data = hass.data[DOMAIN][config_entry.entry_id]
|
2022-04-15 21:14:45 +00:00
|
|
|
entities: list[ElkEntity] = []
|
2020-03-27 20:38:35 +00:00
|
|
|
elk = elk_data["elk"]
|
|
|
|
create_elk_entities(elk_data, elk.tasks, "task", ElkTask, entities)
|
2018-10-10 17:05:19 +00:00
|
|
|
async_add_entities(entities, True)
|
|
|
|
|
|
|
|
|
2020-03-27 20:38:35 +00:00
|
|
|
class ElkTask(ElkAttachedEntity, Scene):
|
2018-10-10 17:05:19 +00:00
|
|
|
"""Elk-M1 task as scene."""
|
|
|
|
|
2022-04-15 21:14:45 +00:00
|
|
|
_element: Task
|
|
|
|
|
2020-04-21 01:07:50 +00:00
|
|
|
async def async_activate(self, **kwargs: Any) -> None:
|
2018-10-10 17:05:19 +00:00
|
|
|
"""Activate the task."""
|
|
|
|
self._element.activate()
|