mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix ozw color temp (#38012)
* Fix color temp math * Ran black --fast * Update test_light.py * tweaking mireds * updating comments * fixing test_light to match standards * fixing comments, need coffee
This commit is contained in:
parent
dd459a7855
commit
19870ea867
@ -30,8 +30,8 @@ COLOR_CHANNEL_COLD_WHITE = 0x02
|
|||||||
COLOR_CHANNEL_RED = 0x04
|
COLOR_CHANNEL_RED = 0x04
|
||||||
COLOR_CHANNEL_GREEN = 0x08
|
COLOR_CHANNEL_GREEN = 0x08
|
||||||
COLOR_CHANNEL_BLUE = 0x10
|
COLOR_CHANNEL_BLUE = 0x10
|
||||||
TEMP_COLOR_MAX = 500 # mireds (inverted)
|
TEMP_COLOR_MAX = 500 # mired equivalent to 2000K
|
||||||
TEMP_COLOR_MIN = 154
|
TEMP_COLOR_MIN = 154 # mired equivalent to 6500K
|
||||||
TEMP_COLOR_DIFF = TEMP_COLOR_MAX - TEMP_COLOR_MIN
|
TEMP_COLOR_DIFF = TEMP_COLOR_MAX - TEMP_COLOR_MIN
|
||||||
|
|
||||||
|
|
||||||
@ -193,10 +193,15 @@ class ZwaveLight(ZWaveDeviceEntity, LightEntity):
|
|||||||
rgbw = f"#00000000{white:02x}"
|
rgbw = f"#00000000{white:02x}"
|
||||||
|
|
||||||
elif color_temp is not None:
|
elif color_temp is not None:
|
||||||
cold = round((TEMP_COLOR_MAX - round(color_temp)) / TEMP_COLOR_DIFF * 255)
|
# Limit color temp to min/max values
|
||||||
|
cold = max(
|
||||||
|
0,
|
||||||
|
min(
|
||||||
|
255,
|
||||||
|
round((TEMP_COLOR_MAX - round(color_temp)) / TEMP_COLOR_DIFF * 255),
|
||||||
|
),
|
||||||
|
)
|
||||||
warm = 255 - cold
|
warm = 255 - cold
|
||||||
if warm < 0:
|
|
||||||
warm = 0
|
|
||||||
rgbw = f"#000000{warm:02x}{cold:02x}"
|
rgbw = f"#000000{warm:02x}{cold:02x}"
|
||||||
|
|
||||||
if rgbw and self.values.color:
|
if rgbw and self.values.color:
|
||||||
|
@ -316,6 +316,39 @@ async def test_light(hass, light_data, light_msg, light_rgb_msg, sent_messages):
|
|||||||
assert state.state == "on"
|
assert state.state == "on"
|
||||||
assert state.attributes["color_temp"] == 465
|
assert state.attributes["color_temp"] == 465
|
||||||
|
|
||||||
|
# Test setting invalid color temp
|
||||||
|
new_color = 120
|
||||||
|
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) == 19
|
||||||
|
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": "#00000000ff", "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"] = "#00000000ff"
|
||||||
|
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"] == 154
|
||||||
|
|
||||||
|
|
||||||
async def test_no_rgb_light(hass, light_no_rgb_data, light_no_rgb_msg, sent_messages):
|
async def test_no_rgb_light(hass, light_no_rgb_data, light_no_rgb_msg, sent_messages):
|
||||||
"""Test setting up config entry."""
|
"""Test setting up config entry."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user