Refactor light significant change to use kelvin attribute (#132853)

This commit is contained in:
epenet 2024-12-11 08:42:48 +01:00 committed by GitHub
parent f0f0b4b8fa
commit 4ff41ed2f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View File

@ -7,7 +7,7 @@ from typing import Any
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.significant_change import check_absolute_change
from . import ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, ATTR_HS_COLOR
from . import ATTR_BRIGHTNESS, ATTR_COLOR_TEMP_KELVIN, ATTR_EFFECT, ATTR_HS_COLOR
@callback
@ -44,10 +44,10 @@ def async_check_significant_change(
return True
if check_absolute_change(
# Default range 153..500
old_attrs.get(ATTR_COLOR_TEMP),
new_attrs.get(ATTR_COLOR_TEMP),
5,
# Default range 2000..6500
old_attrs.get(ATTR_COLOR_TEMP_KELVIN),
new_attrs.get(ATTR_COLOR_TEMP_KELVIN),
50,
):
return True

View File

@ -2,7 +2,7 @@
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_EFFECT,
ATTR_HS_COLOR,
)
@ -26,10 +26,10 @@ async def test_significant_change() -> None:
# Color temp
assert not async_check_significant_change(
None, "on", {ATTR_COLOR_TEMP: 60}, "on", {ATTR_COLOR_TEMP: 64}
None, "on", {ATTR_COLOR_TEMP_KELVIN: 2000}, "on", {ATTR_COLOR_TEMP_KELVIN: 2049}
)
assert async_check_significant_change(
None, "on", {ATTR_COLOR_TEMP: 60}, "on", {ATTR_COLOR_TEMP: 65}
None, "on", {ATTR_COLOR_TEMP_KELVIN: 2000}, "on", {ATTR_COLOR_TEMP_KELVIN: 2050}
)
# Effect