2020-05-15 21:48:17 +00:00
|
|
|
"""BleBox switch implementation."""
|
2020-05-17 23:56:49 +00:00
|
|
|
from homeassistant.components.switch import SwitchEntity
|
2020-05-15 21:48:17 +00:00
|
|
|
|
|
|
|
from . import BleBoxEntity, create_blebox_entities
|
2020-05-16 15:51:37 +00:00
|
|
|
from .const import BLEBOX_TO_HASS_DEVICE_CLASSES
|
2020-05-15 21:48:17 +00:00
|
|
|
|
|
|
|
|
2020-05-18 20:30:15 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
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."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the device class."""
|
|
|
|
return BLEBOX_TO_HASS_DEVICE_CLASSES[self._feature.device_class]
|
|
|
|
|
|
|
|
@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()
|