2019-02-13 20:21:14 +00:00
|
|
|
"""Switch support for the Skybell HD Doorbell."""
|
2021-07-21 17:42:30 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
from typing import Any, cast
|
|
|
|
|
2022-08-19 08:56:01 +00:00
|
|
|
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
2022-06-05 02:37:08 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2022-01-05 16:34:47 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2017-10-08 18:14:39 +00:00
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
from .const import DOMAIN
|
|
|
|
from .entity import SkybellEntity
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2021-07-27 17:51:07 +00:00
|
|
|
SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
|
|
|
|
SwitchEntityDescription(
|
|
|
|
key="do_not_disturb",
|
2022-07-17 15:16:14 +00:00
|
|
|
name="Do not disturb",
|
2021-07-21 17:42:30 +00:00
|
|
|
),
|
2022-06-05 19:56:48 +00:00
|
|
|
SwitchEntityDescription(
|
|
|
|
key="do_not_ring",
|
2022-07-17 15:16:14 +00:00
|
|
|
name="Do not ring",
|
2022-06-05 19:56:48 +00:00
|
|
|
),
|
2021-07-27 17:51:07 +00:00
|
|
|
SwitchEntityDescription(
|
|
|
|
key="motion_sensor",
|
2022-07-17 15:16:14 +00:00
|
|
|
name="Motion sensor",
|
2021-07-21 17:42:30 +00:00
|
|
|
),
|
2021-07-27 17:51:07 +00:00
|
|
|
)
|
2017-10-08 18:14:39 +00:00
|
|
|
|
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
2022-01-05 16:34:47 +00:00
|
|
|
) -> None:
|
2022-06-05 02:37:08 +00:00
|
|
|
"""Set up the SkyBell switch."""
|
|
|
|
async_add_entities(
|
|
|
|
SkybellSwitch(coordinator, description)
|
|
|
|
for coordinator in hass.data[DOMAIN][entry.entry_id]
|
2021-07-27 17:51:07 +00:00
|
|
|
for description in SWITCH_TYPES
|
2022-06-05 02:37:08 +00:00
|
|
|
)
|
2017-10-08 18:14:39 +00:00
|
|
|
|
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
class SkybellSwitch(SkybellEntity, SwitchEntity):
|
2017-10-08 18:14:39 +00:00
|
|
|
"""A switch implementation for Skybell devices."""
|
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
2017-10-08 18:14:39 +00:00
|
|
|
"""Turn on the switch."""
|
2022-06-05 02:37:08 +00:00
|
|
|
await self._device.async_set_setting(self.entity_description.key, True)
|
2017-10-08 18:14:39 +00:00
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
2020-10-22 19:38:15 +00:00
|
|
|
"""Turn off the switch."""
|
2022-06-05 02:37:08 +00:00
|
|
|
await self._device.async_set_setting(self.entity_description.key, False)
|
2017-10-08 18:14:39 +00:00
|
|
|
|
|
|
|
@property
|
2022-06-05 02:37:08 +00:00
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Return true if entity is on."""
|
|
|
|
return cast(bool, getattr(self._device, self.entity_description.key))
|