mirror of https://github.com/home-assistant/core
Rework Z-Wave.Me switch multilevel devices to also use light entity (#77969)
Co-authored-by: Dmitry Vlasov <kerbalspacema@gmail.com>
This commit is contained in:
parent
3941290edc
commit
003d160a96
|
@ -10,6 +10,7 @@ class ZWaveMePlatform(StrEnum):
|
|||
"""Included ZWaveMe platforms."""
|
||||
|
||||
BINARY_SENSOR = "sensorBinary"
|
||||
BRIGHTNESS_LIGHT = "lightMultilevel"
|
||||
BUTTON = "toggleButton"
|
||||
CLIMATE = "thermostat"
|
||||
COVER = "motor"
|
||||
|
|
|
@ -5,13 +5,18 @@ from typing import Any
|
|||
|
||||
from zwave_me_ws import ZWaveMeData
|
||||
|
||||
from homeassistant.components.light import ATTR_RGB_COLOR, ColorMode, LightEntity
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_RGB_COLOR,
|
||||
ColorMode,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ZWaveMeEntity
|
||||
from . import ZWaveMeController, ZWaveMeEntity
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
|
||||
|
||||
|
@ -40,13 +45,26 @@ async def async_setup_entry(
|
|||
async_dispatcher_connect(
|
||||
hass, f"ZWAVE_ME_NEW_{ZWaveMePlatform.RGBW_LIGHT.upper()}", add_new_device
|
||||
)
|
||||
async_dispatcher_connect(
|
||||
hass, f"ZWAVE_ME_NEW_{ZWaveMePlatform.BRIGHTNESS_LIGHT.upper()}", add_new_device
|
||||
)
|
||||
|
||||
|
||||
class ZWaveMeRGB(ZWaveMeEntity, LightEntity):
|
||||
"""Representation of a ZWaveMe light."""
|
||||
|
||||
_attr_supported_color_modes = {ColorMode.RGB}
|
||||
_attr_color_mode = ColorMode.RGB
|
||||
def __init__(
|
||||
self,
|
||||
controller: ZWaveMeController,
|
||||
device: ZWaveMeData,
|
||||
) -> None:
|
||||
"""Initialize the device."""
|
||||
super().__init__(controller=controller, device=device)
|
||||
if device.deviceType in [ZWaveMePlatform.RGB_LIGHT, ZWaveMePlatform.RGBW_LIGHT]:
|
||||
self._attr_color_mode = ColorMode.RGB
|
||||
else:
|
||||
self._attr_color_mode = ColorMode.BRIGHTNESS
|
||||
self._attr_supported_color_modes: set[ColorMode] = {self._attr_color_mode}
|
||||
|
||||
def turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the device on."""
|
||||
|
@ -57,8 +75,17 @@ class ZWaveMeRGB(ZWaveMeEntity, LightEntity):
|
|||
color = kwargs.get(ATTR_RGB_COLOR)
|
||||
|
||||
if color is None:
|
||||
color = (122, 122, 122)
|
||||
cmd = "exact?red={}&green={}&blue={}".format(*color)
|
||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||
if brightness is None:
|
||||
self.controller.zwave_api.send_command(self.device.id, "on")
|
||||
else:
|
||||
self.controller.zwave_api.send_command(
|
||||
self.device.id, f"exact?level={round(brightness / 2.55)}"
|
||||
)
|
||||
return
|
||||
cmd = "exact?red={}&green={}&blue={}".format(
|
||||
*color if any(color) else 255, 255, 255
|
||||
)
|
||||
self.controller.zwave_api.send_command(self.device.id, cmd)
|
||||
|
||||
@property
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "Z-Wave.Me",
|
||||
"documentation": "https://www.home-assistant.io/integrations/zwave_me",
|
||||
"iot_class": "local_push",
|
||||
"requirements": ["zwave_me_ws==0.2.4", "url-normalize==1.4.3"],
|
||||
"requirements": ["zwave_me_ws==0.2.6", "url-normalize==1.4.3"],
|
||||
"after_dependencies": ["zeroconf"],
|
||||
"zeroconf": [{ "type": "_hap._tcp.local.", "name": "*z.wave-me*" }],
|
||||
"config_flow": true,
|
||||
|
|
|
@ -2611,4 +2611,4 @@ zm-py==0.5.2
|
|||
zwave-js-server-python==0.41.1
|
||||
|
||||
# homeassistant.components.zwave_me
|
||||
zwave_me_ws==0.2.4
|
||||
zwave_me_ws==0.2.6
|
||||
|
|
|
@ -1797,4 +1797,4 @@ zigpy==0.50.3
|
|||
zwave-js-server-python==0.41.1
|
||||
|
||||
# homeassistant.components.zwave_me
|
||||
zwave_me_ws==0.2.4
|
||||
zwave_me_ws==0.2.6
|
||||
|
|
Loading…
Reference in New Issue