Add RGB light support to ozw (#37636)

This commit is contained in:
Chris authored and GitHub committed 2020-07-16 18:10:36 -07:00
1 parent 93919dea88
commit a6129467aa
10 files changed
+766 -5

No files matched your search

+46
View File
@@ -27,6 +27,30 @@ def light_data_fixture():
return load_fixture("ozw/light_network_dump.csv")
@pytest.fixture(name="light_no_rgb_data", scope="session")
def light_no_rgb_data_fixture():
"""Load light dimmer MQTT data and return it."""
return load_fixture("ozw/light_no_rgb_network_dump.csv")
@pytest.fixture(name="light_no_ww_data", scope="session")
def light_no_ww_data_fixture():
"""Load light dimmer MQTT data and return it."""
return load_fixture("ozw/light_no_ww_network_dump.csv")
@pytest.fixture(name="light_no_cw_data", scope="session")
def light_no_cw_data_fixture():
"""Load light dimmer MQTT data and return it."""
return load_fixture("ozw/light_no_cw_network_dump.csv")
@pytest.fixture(name="light_wc_data", scope="session")
def light_wc_only_data_fixture():
"""Load light dimmer MQTT data and return it."""
return load_fixture("ozw/light_wc_network_dump.csv")
@pytest.fixture(name="cover_data", scope="session")
def cover_data_fixture():
"""Load cover MQTT data and return it."""
@@ -87,6 +111,28 @@ async def light_msg_fixture(hass):
return message
@pytest.fixture(name="light_no_rgb_msg")
async def light_no_rgb_msg_fixture(hass):
"""Return a mock MQTT msg with a light actuator message."""
light_json = json.loads(
await hass.async_add_executor_job(load_fixture, "ozw/light_no_rgb.json")
)
message = MQTTMessage(topic=light_json["topic"], payload=light_json["payload"])
message.encode()
return message
@pytest.fixture(name="light_rgb_msg")
async def light_rgb_msg_fixture(hass):
"""Return a mock MQTT msg with a light actuator message."""
light_json = json.loads(
await hass.async_add_executor_job(load_fixture, "ozw/light_rgb.json")
)
message = MQTTMessage(topic=light_json["topic"], payload=light_json["payload"])
message.encode()
return message
@pytest.fixture(name="switch_msg")
async def switch_msg_fixture(hass):
"""Return a mock MQTT msg with a switch actuator message."""
+333 -1
View File
@@ -4,7 +4,7 @@ from homeassistant.components.ozw.light import byte_to_zwave_brightness
from .common import setup_ozw
async def test_light(hass, light_data, light_msg, sent_messages):
async def test_light(hass, light_data, light_msg, light_rgb_msg, sent_messages):
"""Test setting up config entry."""
receive_message = await setup_ozw(hass, fixture=light_data)
@@ -149,3 +149,335 @@ async def test_light(hass, light_data, light_msg, sent_messages):
state = hass.states.get("light.led_bulb_6_multi_colour_level")
assert state is not None
assert state.state == "off"
# Test setting color_name
new_color = "blue"
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": "light.led_bulb_6_multi_colour_level", "color_name": new_color},
blocking=True,
)
assert len(sent_messages) == 9
msg = sent_messages[-2]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": "#0000ff0000", "ValueIDKey": 659341335}
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": 255, "ValueIDKey": 659128337}
# Feedback on state
light_msg.decode()
light_msg.payload["Value"] = byte_to_zwave_brightness(255)
light_msg.encode()
light_rgb_msg.decode()
light_rgb_msg.payload["Value"] = "#0000ff0000"
light_rgb_msg.encode()
receive_message(light_msg)
receive_message(light_rgb_msg)
await hass.async_block_till_done()
state = hass.states.get("light.led_bulb_6_multi_colour_level")
assert state is not None
assert state.state == "on"
assert state.attributes["rgb_color"] == (0, 0, 255)
# Test setting hs_color
new_color = [300, 70]
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": "light.led_bulb_6_multi_colour_level", "hs_color": new_color},
blocking=True,
)
assert len(sent_messages) == 11
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": 255, "ValueIDKey": 659128337}
msg = sent_messages[-2]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": "#ff4cff0000", "ValueIDKey": 659341335}
# Feedback on state
light_msg.decode()
light_msg.payload["Value"] = byte_to_zwave_brightness(255)
light_msg.encode()
light_rgb_msg.decode()
light_rgb_msg.payload["Value"] = "#ff4cff0000"
light_rgb_msg.encode()
receive_message(light_msg)
receive_message(light_rgb_msg)
await hass.async_block_till_done()
state = hass.states.get("light.led_bulb_6_multi_colour_level")
assert state is not None
assert state.state == "on"
assert state.attributes["hs_color"] == (300.0, 70.196)
# Test setting rgb_color
new_color = [255, 154, 0]
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": "light.led_bulb_6_multi_colour_level", "rgb_color": new_color},
blocking=True,
)
assert len(sent_messages) == 13
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": 255, "ValueIDKey": 659128337}
msg = sent_messages[-2]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": "#ff99000000", "ValueIDKey": 659341335}
# Feedback on state
light_msg.decode()
light_msg.payload["Value"] = byte_to_zwave_brightness(255)
light_msg.encode()
light_rgb_msg.decode()
light_rgb_msg.payload["Value"] = "#ff99000000"
light_rgb_msg.encode()
receive_message(light_msg)
receive_message(light_rgb_msg)
await hass.async_block_till_done()
state = hass.states.get("light.led_bulb_6_multi_colour_level")
assert state is not None
assert state.state == "on"
assert state.attributes["rgb_color"] == (255, 153, 0)
# Test setting xy_color
new_color = [0.52, 0.43]
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": "light.led_bulb_6_multi_colour_level", "xy_color": new_color},
blocking=True,
)
assert len(sent_messages) == 15
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": 255, "ValueIDKey": 659128337}
msg = sent_messages[-2]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": "#ffbb370000", "ValueIDKey": 659341335}
# Feedback on state
light_msg.decode()
light_msg.payload["Value"] = byte_to_zwave_brightness(255)
light_msg.encode()
light_rgb_msg.decode()
light_rgb_msg.payload["Value"] = "#ffbb370000"
light_rgb_msg.encode()
receive_message(light_msg)
receive_message(light_rgb_msg)
await hass.async_block_till_done()
state = hass.states.get("light.led_bulb_6_multi_colour_level")
assert state is not None
assert state.state == "on"
assert state.attributes["xy_color"] == (0.519, 0.429)
# Test setting color temp
new_color = 465
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": "light.led_bulb_6_multi_colour_level", "color_temp": new_color},
blocking=True,
)
assert len(sent_messages) == 17
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": 255, "ValueIDKey": 659128337}
msg = sent_messages[-2]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": "#000000e51a", "ValueIDKey": 659341335}
# Feedback on state
light_msg.decode()
light_msg.payload["Value"] = byte_to_zwave_brightness(255)
light_msg.encode()
light_rgb_msg.decode()
light_rgb_msg.payload["Value"] = "#000000e51a"
light_rgb_msg.encode()
receive_message(light_msg)
receive_message(light_rgb_msg)
await hass.async_block_till_done()
state = hass.states.get("light.led_bulb_6_multi_colour_level")
assert state is not None
assert state.state == "on"
assert state.attributes["color_temp"] == 465
async def test_no_rgb_light(hass, light_no_rgb_data, light_no_rgb_msg, sent_messages):
"""Test setting up config entry."""
receive_message = await setup_ozw(hass, fixture=light_no_rgb_data)
# Test loaded no RGBW support (dimmer only)
state = hass.states.get("light.master_bedroom_l_level")
assert state is not None
assert state.state == "off"
# Turn on the light
new_brightness = 44
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": "light.master_bedroom_l_level", "brightness": new_brightness},
blocking=True,
)
assert len(sent_messages) == 1
msg = sent_messages[-1]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {
"Value": byte_to_zwave_brightness(new_brightness),
"ValueIDKey": 38371345,
}
# Feedback on state
light_no_rgb_msg.decode()
light_no_rgb_msg.payload["Value"] = byte_to_zwave_brightness(new_brightness)
light_no_rgb_msg.encode()
receive_message(light_no_rgb_msg)
await hass.async_block_till_done()
state = hass.states.get("light.master_bedroom_l_level")
assert state is not None
assert state.state == "on"
assert state.attributes["brightness"] == new_brightness
async def test_no_ww_light(
hass, light_no_ww_data, light_msg, light_rgb_msg, sent_messages
):
"""Test setting up config entry."""
receive_message = await setup_ozw(hass, fixture=light_no_ww_data)
# Test loaded no ww support
state = hass.states.get("light.led_bulb_6_multi_colour_level")
assert state is not None
assert state.state == "off"
# Turn on the light
white_color = 190
await hass.services.async_call(
"light",
"turn_on",
{
"entity_id": "light.led_bulb_6_multi_colour_level",
"white_value": white_color,
},
blocking=True,
)
assert len(sent_messages) == 2
msg = sent_messages[-2]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": "#00000000be", "ValueIDKey": 659341335}
# Feedback on state
light_msg.decode()
light_msg.payload["Value"] = byte_to_zwave_brightness(255)
light_msg.encode()
light_rgb_msg.decode()
light_rgb_msg.payload["Value"] = "#00000000be"
light_rgb_msg.encode()
receive_message(light_msg)
receive_message(light_rgb_msg)
await hass.async_block_till_done()
state = hass.states.get("light.led_bulb_6_multi_colour_level")
assert state is not None
assert state.state == "on"
assert state.attributes["white_value"] == 190
async def test_no_cw_light(
hass, light_no_cw_data, light_msg, light_rgb_msg, sent_messages
):
"""Test setting up config entry."""
receive_message = await setup_ozw(hass, fixture=light_no_cw_data)
# Test loaded no cw support
state = hass.states.get("light.led_bulb_6_multi_colour_level")
assert state is not None
assert state.state == "off"
# Turn on the light
white_color = 190
await hass.services.async_call(
"light",
"turn_on",
{
"entity_id": "light.led_bulb_6_multi_colour_level",
"white_value": white_color,
},
blocking=True,
)
assert len(sent_messages) == 2
msg = sent_messages[-2]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": "#000000be00", "ValueIDKey": 659341335}
# Feedback on state
light_msg.decode()
light_msg.payload["Value"] = byte_to_zwave_brightness(255)
light_msg.encode()
light_rgb_msg.decode()
light_rgb_msg.payload["Value"] = "#000000be00"
light_rgb_msg.encode()
receive_message(light_msg)
receive_message(light_rgb_msg)
await hass.async_block_till_done()
state = hass.states.get("light.led_bulb_6_multi_colour_level")
assert state is not None
assert state.state == "on"
assert state.attributes["white_value"] == 190
async def test_wc_light(hass, light_wc_data, light_msg, light_rgb_msg, sent_messages):
"""Test setting up config entry."""
receive_message = await setup_ozw(hass, fixture=light_wc_data)
# Test loaded only white LED support
state = hass.states.get("light.led_bulb_6_multi_colour_level")
assert state is not None
assert state.state == "off"
# Turn on the light
new_color = 190
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": "light.led_bulb_6_multi_colour_level", "color_temp": new_color},
blocking=True,
)
assert len(sent_messages) == 2
msg = sent_messages[-2]
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
assert msg["payload"] == {"Value": "#0000001be4", "ValueIDKey": 659341335}
# Feedback on state
light_msg.decode()
light_msg.payload["Value"] = byte_to_zwave_brightness(255)
light_msg.encode()
light_rgb_msg.decode()
light_rgb_msg.payload["Value"] = "#0000001be4"
light_rgb_msg.encode()
receive_message(light_msg)
receive_message(light_rgb_msg)
await hass.async_block_till_done()
state = hass.states.get("light.led_bulb_6_multi_colour_level")
assert state is not None
assert state.state == "on"
assert state.attributes["color_temp"] == 191