core/homeassistant/components/skybell/switch.py

56 lines
1.7 KiB
Python
Raw Normal View History

"""Switch support for the Skybell HD Doorbell."""
from __future__ import annotations
2022-06-05 02:37:08 +00:00
from typing import Any, cast
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
2022-06-05 02:37:08 +00:00
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
2022-06-05 02:37:08 +00:00
from .const import DOMAIN
from .entity import SkybellEntity
SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
SwitchEntityDescription(
key="do_not_disturb",
name="Do not disturb",
),
SwitchEntityDescription(
key="do_not_ring",
name="Do not ring",
),
SwitchEntityDescription(
key="motion_sensor",
name="Motion sensor",
),
)
2022-06-05 02:37:08 +00:00
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> 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]
for description in SWITCH_TYPES
2022-06-05 02:37:08 +00:00
)
2022-06-05 02:37:08 +00:00
class SkybellSwitch(SkybellEntity, SwitchEntity):
"""A switch implementation for Skybell devices."""
2022-06-05 02:37:08 +00:00
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the switch."""
2022-06-05 02:37:08 +00:00
await self._device.async_set_setting(self.entity_description.key, True)
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)
@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))