Skip to content

Commit

Permalink
Bugfix and add test coverage for zwave_js.light (#93257)
Browse files Browse the repository at this point in the history
Add test coverage for zwave_js.light
  • Loading branch information
raman325 committed May 22, 2023
1 parent 18eeeaa commit 3bf9eaf
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
7 changes: 3 additions & 4 deletions homeassistant/components/zwave_js/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ def _calculate_color_values(self) -> None:
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__(
Expand All @@ -471,13 +471,12 @@ def is_on(self) -> bool | None:

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)
Expand Down
75 changes: 75 additions & 0 deletions tests/components/zwave_js/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
)
from homeassistant.core import HomeAssistant

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}

0 comments on commit 3bf9eaf

Please sign in to comment.