Add Blebox switch support (#35371)

* support BleBox switches

* fix tox py37 test failures

* refactor BleBox device class map
This commit is contained in:
gadgetmobile authored and GitHub committed 2020-05-15 16:48:17 -05:00
1 parent 064321c21e
commit 890013cecf
6 files changed
+437 -7

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
"""BleBox switch implementation."""
from homeassistant.components.switch import SwitchDevice
from . import BleBoxEntity, create_blebox_entities
from .const import BLEBOX_TO_HASS_DEVICE_CLASSES, DOMAIN, PRODUCT
async def async_setup_entry(hass, config_entry, async_add):
"""Set up a BleBox switch entity."""
product = hass.data[DOMAIN][config_entry.entry_id][PRODUCT]
create_blebox_entities(product, async_add, BleBoxSwitchEntity, "switches")
return True
class BleBoxSwitchEntity(BleBoxEntity, SwitchDevice):
"""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."""
return await self._feature.async_turn_on()
async def async_turn_off(self, **kwargs):
"""Turn off the switch."""
return await self._feature.async_turn_off()