Fix white_value causing zwave-js to set non-existing values (#49799)

This commit is contained in:
Chris 2021-04-28 09:23:48 -07:00 committed by GitHub
parent 1e2f242220
commit e85d58c3a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 2887 additions and 6 deletions

View file

@ -93,6 +93,16 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
self._min_mireds = 153 # 6500K as a safe default
self._max_mireds = 370 # 2700K as a safe default
self._supported_features = SUPPORT_BRIGHTNESS
self._warm_white = self.get_zwave_value(
"targetColor",
CommandClass.SWITCH_COLOR,
value_property_key=ColorComponent.WARM_WHITE,
)
self._cold_white = self.get_zwave_value(
"targetColor",
CommandClass.SWITCH_COLOR,
value_property_key=ColorComponent.COLD_WHITE,
)
# get additional (optional) values and set features
self._target_value = self.get_zwave_value("targetValue")
@ -206,12 +216,15 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
if white_value is not None and self._supports_white_value:
# white led brightness is controlled by white level
# rgb leds (if any) can be on at the same time
await self._async_set_colors(
{
ColorComponent.WARM_WHITE: white_value,
ColorComponent.COLD_WHITE: white_value,
}
)
white_channel = {}
if self._warm_white:
white_channel[ColorComponent.WARM_WHITE] = white_value
if self._cold_white:
white_channel[ColorComponent.COLD_WHITE] = white_value
await self._async_set_colors(white_channel)
# set brightness
await self._async_set_brightness(

View file

@ -25,3 +25,4 @@ AEON_SMART_SWITCH_LIGHT_ENTITY = "light.smart_switch_6"
ID_LOCK_CONFIG_PARAMETER_SENSOR = (
"sensor.z_wave_module_for_id_lock_150_and_101_config_parameter_door_lock_mode"
)
ZEN_31_ENTITY = "light.kitchen_under_cabinet_lights"

View file

@ -343,6 +343,12 @@ def vision_security_zl7432_state_fixture():
return json.loads(load_fixture("zwave_js/vision_security_zl7432_state.json"))
@pytest.fixture(name="zen_31_state", scope="session")
def zem_31_state_fixture():
"""Load the zen_31 node state fixture data."""
return json.loads(load_fixture("zwave_js/zen_31_state.json"))
@pytest.fixture(name="client")
def mock_client_fixture(controller_state, version_state):
"""Mock a client."""
@ -651,3 +657,11 @@ def vision_security_zl7432_fixture(client, vision_security_zl7432_state):
node = Node(client, copy.deepcopy(vision_security_zl7432_state))
client.driver.controller.nodes[node.node_id] = node
return node
@pytest.fixture(name="zen_31")
def zen_31_fixture(client, zen_31_state):
"""Mock a bulb 6 multi-color node."""
node = Node(client, copy.deepcopy(zen_31_state))
client.driver.controller.nodes[node.node_id] = node
return node

View file

@ -9,6 +9,7 @@ from homeassistant.components.light import (
ATTR_MAX_MIREDS,
ATTR_MIN_MIREDS,
ATTR_RGB_COLOR,
ATTR_WHITE_VALUE,
)
from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
@ -16,6 +17,7 @@ from .common import (
AEON_SMART_SWITCH_LIGHT_ENTITY,
BULB_6_MULTI_COLOR_LIGHT_ENTITY,
EATON_RF9640_ENTITY,
ZEN_31_ENTITY,
)
@ -411,3 +413,67 @@ async def test_optional_light(hass, client, aeon_smart_switch_6, integration):
"""Test a device that has an additional light endpoint being identified as light."""
state = hass.states.get(AEON_SMART_SWITCH_LIGHT_ENTITY)
assert state.state == STATE_ON
async def test_white_value_light(hass, client, zen_31, integration):
"""Test the light entity."""
zen_31
state = hass.states.get(ZEN_31_ENTITY)
assert state
assert state.state == STATE_ON
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 177
# Test turning on
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": ZEN_31_ENTITY, ATTR_WHITE_VALUE: 128},
blocking=True,
)
assert len(client.async_send_command.call_args_list) == 2
args = client.async_send_command.call_args_list[0][0][0]
assert args["command"] == "node.set_value"
assert args["nodeId"] == 94
assert args["valueId"] == {
"commandClassName": "Color Switch",
"commandClass": 51,
"endpoint": 1,
"property": "targetColor",
"propertyName": "targetColor",
"ccVersion": 0,
"metadata": {
"label": "Target Color",
"type": "any",
"readable": True,
"writeable": True,
},
"value": {"blue": 70, "green": 159, "red": 255, "warmWhite": 141},
}
assert args["value"] == {"warmWhite": 128}
args = client.async_send_command.call_args_list[1][0][0]
assert args["command"] == "node.set_value"
assert args["nodeId"] == 94
assert args["valueId"] == {
"commandClassName": "Multilevel Switch",
"commandClass": 38,
"endpoint": 1,
"property": "targetValue",
"propertyName": "targetValue",
"ccVersion": 0,
"metadata": {
"label": "Target value",
"max": 99,
"min": 0,
"type": "number",
"readable": True,
"writeable": True,
"label": "Target value",
},
"value": 59,
}
assert args["value"] == 255
client.async_send_command.reset_mock()

2787
tests/fixtures/zwave_js/zen_31_state.json vendored Normal file

File diff suppressed because it is too large Load diff