Fix ozw pure rgb dimmer light (#38877)
* Fix ozw pure rgb light * Add test
This commit is contained in:
parent
9c6b019ca9
commit
0f1e70ca79
5 changed files with 238 additions and 19 deletions
|
@ -80,24 +80,24 @@ class ZwaveLight(ZWaveDeviceEntity, LightEntity):
|
|||
if self.values.dimming_duration is not None:
|
||||
self._supported_features |= SUPPORT_TRANSITION
|
||||
|
||||
if self.values.color is None or self.values.color_channels is None:
|
||||
return
|
||||
if self.values.color is not None:
|
||||
self._supported_features |= SUPPORT_COLOR
|
||||
|
||||
self._supported_features |= SUPPORT_COLOR
|
||||
if self.values.color_channels is not None:
|
||||
# Support Color Temp if both white channels
|
||||
if (self.values.color_channels.value & COLOR_CHANNEL_WARM_WHITE) and (
|
||||
self.values.color_channels.value & COLOR_CHANNEL_COLD_WHITE
|
||||
):
|
||||
self._supported_features |= SUPPORT_COLOR_TEMP
|
||||
|
||||
# Support Color Temp if both white channels
|
||||
if (self.values.color_channels.value & COLOR_CHANNEL_WARM_WHITE) and (
|
||||
self.values.color_channels.value & COLOR_CHANNEL_COLD_WHITE
|
||||
):
|
||||
self._supported_features |= SUPPORT_COLOR_TEMP
|
||||
# Support White value if only a single white channel
|
||||
if ((self.values.color_channels.value & COLOR_CHANNEL_WARM_WHITE) != 0) ^ (
|
||||
(self.values.color_channels.value & COLOR_CHANNEL_COLD_WHITE) != 0
|
||||
):
|
||||
self._supported_features |= SUPPORT_WHITE_VALUE
|
||||
|
||||
# Support White value if only a single white channel
|
||||
if ((self.values.color_channels.value & COLOR_CHANNEL_WARM_WHITE) != 0) ^ (
|
||||
(self.values.color_channels.value & COLOR_CHANNEL_COLD_WHITE) != 0
|
||||
):
|
||||
self._supported_features |= SUPPORT_WHITE_VALUE
|
||||
|
||||
self._calculate_rgb_values()
|
||||
if self.values.color is not None:
|
||||
self._calculate_color_values()
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
|
@ -248,10 +248,8 @@ class ZwaveLight(ZWaveDeviceEntity, LightEntity):
|
|||
|
||||
self.values.primary.send_value(0)
|
||||
|
||||
def _calculate_rgb_values(self):
|
||||
# Color Channels
|
||||
self._color_channels = self.values.color_channels.data[ATTR_VALUE]
|
||||
|
||||
def _calculate_color_values(self):
|
||||
"""Parse color rgb and color temperature data."""
|
||||
# Color Data String
|
||||
data = self.values.color.data[ATTR_VALUE]
|
||||
|
||||
|
@ -259,6 +257,12 @@ class ZwaveLight(ZWaveDeviceEntity, LightEntity):
|
|||
rgb = [int(data[1:3], 16), int(data[3:5], 16), int(data[5:7], 16)]
|
||||
self._hs = color_util.color_RGB_to_hs(*rgb)
|
||||
|
||||
if self.values.color_channels is None:
|
||||
return
|
||||
|
||||
# Color Channels
|
||||
self._color_channels = self.values.color_channels.data[ATTR_VALUE]
|
||||
|
||||
# Parse remaining color channels. OpenZWave appends white channels
|
||||
# that are present.
|
||||
index = 7
|
||||
|
|
|
@ -33,6 +33,12 @@ def light_new_ozw_data_fixture():
|
|||
return load_fixture("ozw/light_new_ozw_network_dump.csv")
|
||||
|
||||
|
||||
@pytest.fixture(name="light_pure_rgb_dimmer_data", scope="session")
|
||||
def light_pure_rgb_dimmer_data_fixture():
|
||||
"""Load light rgb and dimmer MQTT data and return it."""
|
||||
return load_fixture("ozw/light_pure_rgb_dimmer_dump.csv")
|
||||
|
||||
|
||||
@pytest.fixture(name="light_no_rgb_data", scope="session")
|
||||
def light_no_rgb_data_fixture():
|
||||
"""Load light dimmer MQTT data and return it."""
|
||||
|
@ -139,6 +145,17 @@ async def light_rgb_msg_fixture(hass):
|
|||
return message
|
||||
|
||||
|
||||
@pytest.fixture(name="light_pure_rgb_msg")
|
||||
async def light_pure_rgb_msg_fixture(hass):
|
||||
"""Return a mock MQTT msg with a pure rgb light actuator message."""
|
||||
light_json = json.loads(
|
||||
await hass.async_add_executor_job(load_fixture, "ozw/light_pure_rgb.json")
|
||||
)
|
||||
message = MQTTMessage(topic=light_json["topic"], payload=light_json["payload"])
|
||||
message.encode()
|
||||
return message
|
||||
|
||||
|
||||
@pytest.fixture(name="switch_msg")
|
||||
async def switch_msg_fixture(hass):
|
||||
"""Return a mock MQTT msg with a switch actuator message."""
|
||||
|
|
|
@ -350,6 +350,48 @@ async def test_light(hass, light_data, light_msg, light_rgb_msg, sent_messages):
|
|||
assert state.attributes["color_temp"] == 153
|
||||
|
||||
|
||||
async def test_pure_rgb_dimmer_light(
|
||||
hass, light_pure_rgb_dimmer_data, light_msg, light_pure_rgb_msg, sent_messages
|
||||
):
|
||||
"""Test light with no color channels command class."""
|
||||
receive_message = await setup_ozw(hass, fixture=light_pure_rgb_dimmer_data)
|
||||
|
||||
# Test loaded
|
||||
state = hass.states.get("light.kitchen_rgb_strip_level")
|
||||
assert state is not None
|
||||
assert state.state == "on"
|
||||
assert state.attributes["supported_features"] == 17
|
||||
|
||||
# Test setting hs_color
|
||||
new_color = [300, 70]
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
"turn_on",
|
||||
{"entity_id": "light.kitchen_rgb_strip_level", "hs_color": new_color},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(sent_messages) == 2
|
||||
msg = sent_messages[-1]
|
||||
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||
assert msg["payload"] == {"Value": 255, "ValueIDKey": 122257425}
|
||||
|
||||
msg = sent_messages[-2]
|
||||
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||
assert msg["payload"] == {"Value": "#ff4cff0000", "ValueIDKey": 122470423}
|
||||
|
||||
# Feedback on state
|
||||
light_pure_rgb_msg.decode()
|
||||
light_pure_rgb_msg.payload["Value"] = "#ff4cff0000"
|
||||
light_pure_rgb_msg.encode()
|
||||
receive_message(light_pure_rgb_msg)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.kitchen_rgb_strip_level")
|
||||
assert state is not None
|
||||
assert state.state == "on"
|
||||
assert state.attributes["hs_color"] == (300.0, 70.196)
|
||||
|
||||
|
||||
async def test_no_rgb_light(hass, light_no_rgb_data, light_no_rgb_msg, sent_messages):
|
||||
"""Test setting up config entry."""
|
||||
receive_message = await setup_ozw(hass, fixture=light_no_rgb_data)
|
||||
|
|
25
tests/fixtures/ozw/light_pure_rgb.json
vendored
Normal file
25
tests/fixtures/ozw/light_pure_rgb.json
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"topic": "OpenZWave/1/node/7/instance/1/commandclass/51/value/122470423/",
|
||||
"payload": {
|
||||
"Label": "Color",
|
||||
"Value": "#ff00000000",
|
||||
"Units": "#RRGGBBWW",
|
||||
"ValueSet": false,
|
||||
"ValuePolled": false,
|
||||
"ChangeVerified": false,
|
||||
"Min": 0,
|
||||
"Max": 0,
|
||||
"Type": "String",
|
||||
"Instance": 1,
|
||||
"CommandClass": "COMMAND_CLASS_COLOR",
|
||||
"Index": 0,
|
||||
"Node": 7,
|
||||
"Genre": "User",
|
||||
"Help": "Color (in RGB format)",
|
||||
"ValueIDKey": 122470423,
|
||||
"ReadOnly": false,
|
||||
"WriteOnly": false,
|
||||
"Event": "valueAdded",
|
||||
"TimeStamp": 1597142799
|
||||
}
|
||||
}
|
131
tests/fixtures/ozw/light_pure_rgb_dimmer_dump.csv
vendored
Normal file
131
tests/fixtures/ozw/light_pure_rgb_dimmer_dump.csv
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue