mirror of
https://github.com/home-assistant/core.git
synced 2026-08-14 17:23:33 +01:00
57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
"""Helper to test significant Light state changes."""
|
|
|
|
from typing import Any
|
|
|
|
from homeassistant.core import HomeAssistant, callback
|
|
from homeassistant.helpers.significant_change import check_absolute_change
|
|
|
|
from .const import LightEntityStateAttribute
|
|
|
|
|
|
@callback
|
|
def async_check_significant_change(
|
|
hass: HomeAssistant,
|
|
old_state: str,
|
|
old_attrs: dict,
|
|
new_state: str,
|
|
new_attrs: dict,
|
|
**kwargs: Any,
|
|
) -> bool | None:
|
|
"""Test if state significantly changed."""
|
|
if old_state != new_state:
|
|
return True
|
|
|
|
if old_attrs.get(LightEntityStateAttribute.EFFECT) != new_attrs.get(
|
|
LightEntityStateAttribute.EFFECT
|
|
):
|
|
return True
|
|
|
|
old_color = old_attrs.get(LightEntityStateAttribute.HS_COLOR)
|
|
new_color = new_attrs.get(LightEntityStateAttribute.HS_COLOR)
|
|
|
|
if old_color and new_color:
|
|
# Range 0..360
|
|
if check_absolute_change(old_color[0], new_color[0], 5):
|
|
return True
|
|
|
|
# Range 0..100
|
|
if check_absolute_change(old_color[1], new_color[1], 3):
|
|
return True
|
|
|
|
if check_absolute_change(
|
|
old_attrs.get(LightEntityStateAttribute.BRIGHTNESS),
|
|
new_attrs.get(LightEntityStateAttribute.BRIGHTNESS),
|
|
3,
|
|
):
|
|
return True
|
|
|
|
if check_absolute_change(
|
|
# Default range 2000..6500
|
|
old_attrs.get(LightEntityStateAttribute.COLOR_TEMP_KELVIN),
|
|
new_attrs.get(LightEntityStateAttribute.COLOR_TEMP_KELVIN),
|
|
50,
|
|
):
|
|
return True
|
|
|
|
return False
|