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