From 3bf9eaffdfaa48f053bc479a6af62c43263a065d Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 22 May 2023 12:08:29 -0400 Subject: [PATCH] Bugfix and add test coverage for zwave_js.light (#93257) Add test coverage for zwave_js.light --- homeassistant/components/zwave_js/light.py | 7 +- tests/components/zwave_js/test_light.py | 75 ++++++++++++++++++++++ 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/zwave_js/light.py b/homeassistant/components/zwave_js/light.py index 29654503f00..549685873aa 100644 --- a/homeassistant/components/zwave_js/light.py +++ b/homeassistant/components/zwave_js/light.py @@ -444,8 +444,8 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity): class ZwaveBlackIsOffLight(ZwaveLight): """Representation of a Z-Wave light where setting the color to black turns it off. - Currently only supports lights with RGB, no color temperature, - and no white channels. + Currently only supports lights with RGB, no color temperature, and no white + channels. """ def __init__( @@ -471,13 +471,12 @@ class ZwaveBlackIsOffLight(ZwaveLight): async def async_turn_on(self, **kwargs: Any) -> None: """Turn the device on.""" - await super().async_turn_on(**kwargs) - if ( kwargs.get(ATTR_RGBW_COLOR) is not None or kwargs.get(ATTR_COLOR_TEMP) is not None or kwargs.get(ATTR_HS_COLOR) is not None ): + await super().async_turn_on(**kwargs) return transition = kwargs.get(ATTR_TRANSITION) diff --git a/tests/components/zwave_js/test_light.py b/tests/components/zwave_js/test_light.py index 7546976d265..44cb9d70f76 100644 --- a/tests/components/zwave_js/test_light.py +++ b/tests/components/zwave_js/test_light.py @@ -23,6 +23,7 @@ from homeassistant.const import ( SERVICE_TURN_ON, STATE_OFF, STATE_ON, + STATE_UNKNOWN, ) from homeassistant.core import HomeAssistant @@ -397,6 +398,33 @@ async def test_light( } assert args["value"] == 0 + client.async_send_command.reset_mock() + + # Test brightness update to None from value updated event + event = Event( + type="value updated", + data={ + "source": "node", + "event": "value updated", + "nodeId": 39, + "args": { + "commandClassName": "Multilevel Switch", + "commandClass": 38, + "endpoint": 0, + "property": "currentValue", + "newValue": None, + "prevValue": 99, + "propertyName": "currentValue", + }, + }, + ) + node.receive_event(event) + + state = hass.states.get(BULB_6_MULTI_COLOR_LIGHT_ENTITY) + assert state.state == STATE_UNKNOWN + assert ATTR_COLOR_MODE not in state.attributes + assert ATTR_BRIGHTNESS not in state.attributes + async def test_v4_dimmer_light( hass: HomeAssistant, client, eaton_rf9640_dimmer, integration @@ -599,3 +627,50 @@ async def test_black_is_off( assert args["value"] == {"red": 0, "green": 255, "blue": 0} client.async_send_command.reset_mock() + + # Force the light to turn on + event = Event( + type="value updated", + data={ + "source": "node", + "event": "value updated", + "nodeId": node.node_id, + "args": { + "commandClassName": "Color Switch", + "commandClass": 51, + "endpoint": 0, + "property": "currentColor", + "newValue": None, + "prevValue": { + "red": 0, + "green": 255, + "blue": 0, + }, + "propertyName": "currentColor", + }, + }, + ) + node.receive_event(event) + await hass.async_block_till_done() + state = hass.states.get(HSM200_V1_ENTITY) + assert state.state == STATE_UNKNOWN + + client.async_send_command.reset_mock() + + # Assert that call fails if attribute is added to service call + await hass.services.async_call( + LIGHT_DOMAIN, + SERVICE_TURN_ON, + {ATTR_ENTITY_ID: HSM200_V1_ENTITY, ATTR_RGBW_COLOR: (255, 76, 255, 0)}, + blocking=True, + ) + assert len(client.async_send_command.call_args_list) == 1 + args = client.async_send_command.call_args_list[0][0][0] + assert args["command"] == "node.set_value" + assert args["nodeId"] == node.node_id + assert args["valueId"] == { + "commandClass": 51, + "endpoint": 0, + "property": "targetColor", + } + assert args["value"] == {"red": 255, "green": 76, "blue": 255}