Fix white_value causing zwave-js to set non-existing values (#49799)
This commit is contained in:
parent
1e2f242220
commit
e85d58c3a1
5 changed files with 2887 additions and 6 deletions
|
@ -93,6 +93,16 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
|
||||||
self._min_mireds = 153 # 6500K as a safe default
|
self._min_mireds = 153 # 6500K as a safe default
|
||||||
self._max_mireds = 370 # 2700K as a safe default
|
self._max_mireds = 370 # 2700K as a safe default
|
||||||
self._supported_features = SUPPORT_BRIGHTNESS
|
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
|
# get additional (optional) values and set features
|
||||||
self._target_value = self.get_zwave_value("targetValue")
|
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:
|
if white_value is not None and self._supports_white_value:
|
||||||
# white led brightness is controlled by white level
|
# white led brightness is controlled by white level
|
||||||
# rgb leds (if any) can be on at the same time
|
# rgb leds (if any) can be on at the same time
|
||||||
await self._async_set_colors(
|
white_channel = {}
|
||||||
{
|
|
||||||
ColorComponent.WARM_WHITE: white_value,
|
if self._warm_white:
|
||||||
ColorComponent.COLD_WHITE: white_value,
|
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
|
# set brightness
|
||||||
await self._async_set_brightness(
|
await self._async_set_brightness(
|
||||||
|
|
|
@ -25,3 +25,4 @@ AEON_SMART_SWITCH_LIGHT_ENTITY = "light.smart_switch_6"
|
||||||
ID_LOCK_CONFIG_PARAMETER_SENSOR = (
|
ID_LOCK_CONFIG_PARAMETER_SENSOR = (
|
||||||
"sensor.z_wave_module_for_id_lock_150_and_101_config_parameter_door_lock_mode"
|
"sensor.z_wave_module_for_id_lock_150_and_101_config_parameter_door_lock_mode"
|
||||||
)
|
)
|
||||||
|
ZEN_31_ENTITY = "light.kitchen_under_cabinet_lights"
|
||||||
|
|
|
@ -343,6 +343,12 @@ def vision_security_zl7432_state_fixture():
|
||||||
return json.loads(load_fixture("zwave_js/vision_security_zl7432_state.json"))
|
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")
|
@pytest.fixture(name="client")
|
||||||
def mock_client_fixture(controller_state, version_state):
|
def mock_client_fixture(controller_state, version_state):
|
||||||
"""Mock a client."""
|
"""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))
|
node = Node(client, copy.deepcopy(vision_security_zl7432_state))
|
||||||
client.driver.controller.nodes[node.node_id] = node
|
client.driver.controller.nodes[node.node_id] = node
|
||||||
return 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
|
||||||
|
|
|
@ -9,6 +9,7 @@ from homeassistant.components.light import (
|
||||||
ATTR_MAX_MIREDS,
|
ATTR_MAX_MIREDS,
|
||||||
ATTR_MIN_MIREDS,
|
ATTR_MIN_MIREDS,
|
||||||
ATTR_RGB_COLOR,
|
ATTR_RGB_COLOR,
|
||||||
|
ATTR_WHITE_VALUE,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
|
from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ from .common import (
|
||||||
AEON_SMART_SWITCH_LIGHT_ENTITY,
|
AEON_SMART_SWITCH_LIGHT_ENTITY,
|
||||||
BULB_6_MULTI_COLOR_LIGHT_ENTITY,
|
BULB_6_MULTI_COLOR_LIGHT_ENTITY,
|
||||||
EATON_RF9640_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."""
|
"""Test a device that has an additional light endpoint being identified as light."""
|
||||||
state = hass.states.get(AEON_SMART_SWITCH_LIGHT_ENTITY)
|
state = hass.states.get(AEON_SMART_SWITCH_LIGHT_ENTITY)
|
||||||
assert state.state == STATE_ON
|
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
2787
tests/fixtures/zwave_js/zen_31_state.json
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue