mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Bugfix and add test coverage for zwave_js.light (#93257)
Add test coverage for zwave_js.light
This commit is contained in:
parent
18eeeaaf68
commit
3bf9eaffdf
@ -444,8 +444,8 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
|
|||||||
class ZwaveBlackIsOffLight(ZwaveLight):
|
class ZwaveBlackIsOffLight(ZwaveLight):
|
||||||
"""Representation of a Z-Wave light where setting the color to black turns it off.
|
"""Representation of a Z-Wave light where setting the color to black turns it off.
|
||||||
|
|
||||||
Currently only supports lights with RGB, no color temperature,
|
Currently only supports lights with RGB, no color temperature, and no white
|
||||||
and no white channels.
|
channels.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -471,13 +471,12 @@ class ZwaveBlackIsOffLight(ZwaveLight):
|
|||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the device on."""
|
"""Turn the device on."""
|
||||||
await super().async_turn_on(**kwargs)
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
kwargs.get(ATTR_RGBW_COLOR) is not None
|
kwargs.get(ATTR_RGBW_COLOR) is not None
|
||||||
or kwargs.get(ATTR_COLOR_TEMP) is not None
|
or kwargs.get(ATTR_COLOR_TEMP) is not None
|
||||||
or kwargs.get(ATTR_HS_COLOR) is not None
|
or kwargs.get(ATTR_HS_COLOR) is not None
|
||||||
):
|
):
|
||||||
|
await super().async_turn_on(**kwargs)
|
||||||
return
|
return
|
||||||
|
|
||||||
transition = kwargs.get(ATTR_TRANSITION)
|
transition = kwargs.get(ATTR_TRANSITION)
|
||||||
|
@ -23,6 +23,7 @@ from homeassistant.const import (
|
|||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
|
STATE_UNKNOWN,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
@ -397,6 +398,33 @@ async def test_light(
|
|||||||
}
|
}
|
||||||
assert args["value"] == 0
|
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(
|
async def test_v4_dimmer_light(
|
||||||
hass: HomeAssistant, client, eaton_rf9640_dimmer, integration
|
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}
|
assert args["value"] == {"red": 0, "green": 255, "blue": 0}
|
||||||
|
|
||||||
client.async_send_command.reset_mock()
|
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}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user