2019-02-13 20:21:14 +00:00
|
|
|
"""Support for control of ElkM1 outputs (relays)."""
|
2022-01-05 11:49:13 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-04-18 00:31:37 +00:00
|
|
|
from typing import Any
|
|
|
|
|
2022-04-15 21:14:45 +00:00
|
|
|
from elkm1_lib.outputs import Output
|
|
|
|
|
2020-04-26 16:50:37 +00:00
|
|
|
from homeassistant.components.switch import SwitchEntity
|
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 switch 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.outputs, "output", ElkOutput, entities)
|
2022-07-11 07:11:37 +00:00
|
|
|
async_add_entities(entities)
|
2018-10-10 17:05:19 +00:00
|
|
|
|
|
|
|
|
2020-04-26 16:50:37 +00:00
|
|
|
class ElkOutput(ElkAttachedEntity, SwitchEntity):
|
2018-10-10 17:05:19 +00:00
|
|
|
"""Elk output as switch."""
|
|
|
|
|
2022-04-15 21:14:45 +00:00
|
|
|
_element: Output
|
|
|
|
|
2018-10-10 17:05:19 +00:00
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Get the current output status."""
|
|
|
|
return self._element.output_on
|
|
|
|
|
2022-04-18 00:31:37 +00:00
|
|
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
2018-10-10 17:05:19 +00:00
|
|
|
"""Turn on the output."""
|
|
|
|
self._element.turn_on(0)
|
|
|
|
|
2022-04-18 00:31:37 +00:00
|
|
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
2018-10-10 17:05:19 +00:00
|
|
|
"""Turn off the output."""
|
|
|
|
self._element.turn_off()
|