Add Blebox switch support (#35371)
* support BleBox switches * fix tox py37 test failures * refactor BleBox device class map
This commit is contained in:
1 parent
064321c21e
commit
890013cecf
6 files changed
+437
-7
No files matched your search
@@ -17,7 +17,7 @@ from .const import DEFAULT_SETUP_TIMEOUT, DOMAIN, PRODUCT
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORMS = ["cover", "sensor"]
|
||||
PLATFORMS = ["cover", "sensor", "switch"]
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from homeassistant.components.cover import (
|
||||
STATE_OPEN,
|
||||
STATE_OPENING,
|
||||
)
|
||||
from homeassistant.components.switch import DEVICE_CLASS_SWITCH
|
||||
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS
|
||||
|
||||
DOMAIN = "blebox"
|
||||
@@ -26,6 +27,8 @@ BLEBOX_TO_HASS_DEVICE_CLASSES = {
|
||||
"shutter": DEVICE_CLASS_SHUTTER,
|
||||
"gatebox": DEVICE_CLASS_DOOR,
|
||||
"gate": DEVICE_CLASS_GATE,
|
||||
"relay": DEVICE_CLASS_SWITCH,
|
||||
"temperature": DEVICE_CLASS_TEMPERATURE,
|
||||
}
|
||||
|
||||
BLEBOX_TO_HASS_COVER_STATES = {
|
||||
@@ -43,7 +46,6 @@ BLEBOX_TO_HASS_COVER_STATES = {
|
||||
}
|
||||
|
||||
BLEBOX_TO_UNIT_MAP = {"celsius": TEMP_CELSIUS}
|
||||
BLEBOX_DEV_CLASS_MAP = {"temperature": DEVICE_CLASS_TEMPERATURE}
|
||||
|
||||
DEFAULT_HOST = "192.168.0.2"
|
||||
DEFAULT_PORT = 80
|
||||
@@ -3,7 +3,7 @@
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from . import BleBoxEntity, create_blebox_entities
|
||||
from .const import BLEBOX_DEV_CLASS_MAP, BLEBOX_TO_UNIT_MAP, DOMAIN, PRODUCT
|
||||
from .const import BLEBOX_TO_HASS_DEVICE_CLASSES, BLEBOX_TO_UNIT_MAP, DOMAIN, PRODUCT
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add):
|
||||
@@ -30,4 +30,4 @@ class BleBoxSensorEntity(BleBoxEntity, Entity):
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class."""
|
||||
return BLEBOX_DEV_CLASS_MAP[self._feature.device_class]
|
||||
return BLEBOX_TO_HASS_DEVICE_CLASSES[self._feature.device_class]
|
||||
@@ -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()
|
||||
Reference in new issue
Block a user