2020-05-15 21:48:17 +00:00
|
|
|
"""BleBox switch implementation."""
|
2022-06-29 09:57:55 +00:00
|
|
|
from datetime import timedelta
|
|
|
|
|
2022-07-11 10:24:37 +00:00
|
|
|
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
|
2022-01-03 15:31:24 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2020-05-15 21:48:17 +00:00
|
|
|
|
|
|
|
from . import BleBoxEntity, create_blebox_entities
|
|
|
|
|
2022-06-29 09:57:55 +00:00
|
|
|
SCAN_INTERVAL = timedelta(seconds=5)
|
|
|
|
|
2020-05-15 21:48:17 +00:00
|
|
|
|
2022-01-03 15:31:24 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2020-05-15 21:48:17 +00:00
|
|
|
"""Set up a BleBox switch entity."""
|
2020-05-16 15:51:37 +00:00
|
|
|
create_blebox_entities(
|
2020-05-18 20:30:15 +00:00
|
|
|
hass, config_entry, async_add_entities, BleBoxSwitchEntity, "switches"
|
2020-05-16 15:51:37 +00:00
|
|
|
)
|
2020-05-15 21:48:17 +00:00
|
|
|
|
|
|
|
|
2020-05-17 23:56:49 +00:00
|
|
|
class BleBoxSwitchEntity(BleBoxEntity, SwitchEntity):
|
2020-05-15 21:48:17 +00:00
|
|
|
"""Representation of a BleBox switch feature."""
|
|
|
|
|
2021-07-12 20:52:38 +00:00
|
|
|
def __init__(self, feature):
|
|
|
|
"""Initialize a BleBox switch feature."""
|
|
|
|
super().__init__(feature)
|
2022-07-11 10:24:37 +00:00
|
|
|
self._attr_device_class = SwitchDeviceClass.SWITCH
|
2020-05-15 21:48:17 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return whether switch is on."""
|
|
|
|
return self._feature.is_on
|
|
|
|
|
|
|
|
async def async_turn_on(self, **kwargs):
|
|
|
|
"""Turn on the switch."""
|
2020-05-17 23:56:49 +00:00
|
|
|
await self._feature.async_turn_on()
|
2020-05-15 21:48:17 +00:00
|
|
|
|
|
|
|
async def async_turn_off(self, **kwargs):
|
|
|
|
"""Turn off the switch."""
|
2020-05-17 23:56:49 +00:00
|
|
|
await self._feature.async_turn_off()
|