Only check known attributes in significant change support (#106572)
only check known attributes
This commit is contained in:
parent
648afe121d
commit
756847eea8
9 changed files with 72 additions and 47 deletions
|
@ -26,13 +26,16 @@ def async_check_significant_change(
|
||||||
if old_state != new_state:
|
if old_state != new_state:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
old_attrs_s = set(old_attrs.items())
|
old_attrs_s = set(
|
||||||
new_attrs_s = set(new_attrs.items())
|
{k: v for k, v in old_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
|
new_attrs_s = set(
|
||||||
|
{k: v for k, v in new_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
||||||
|
|
||||||
for attr_name in changed_attrs:
|
if changed_attrs:
|
||||||
if attr_name in SIGNIFICANT_ATTRIBUTES:
|
return True
|
||||||
return True
|
|
||||||
|
|
||||||
# no significant attribute change detected
|
# no significant attribute change detected
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -52,15 +52,17 @@ def async_check_significant_change(
|
||||||
if old_state != new_state:
|
if old_state != new_state:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
old_attrs_s = set(old_attrs.items())
|
old_attrs_s = set(
|
||||||
new_attrs_s = set(new_attrs.items())
|
{k: v for k, v in old_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
|
new_attrs_s = set(
|
||||||
|
{k: v for k, v in new_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
|
|
||||||
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
||||||
ha_unit = hass.config.units.temperature_unit
|
ha_unit = hass.config.units.temperature_unit
|
||||||
|
|
||||||
for attr_name in changed_attrs:
|
for attr_name in changed_attrs:
|
||||||
if attr_name not in SIGNIFICANT_ATTRIBUTES:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if attr_name in [
|
if attr_name in [
|
||||||
ATTR_AUX_HEAT,
|
ATTR_AUX_HEAT,
|
||||||
ATTR_FAN_MODE,
|
ATTR_FAN_MODE,
|
||||||
|
|
|
@ -30,14 +30,15 @@ def async_check_significant_change(
|
||||||
if old_state != new_state:
|
if old_state != new_state:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
old_attrs_s = set(old_attrs.items())
|
old_attrs_s = set(
|
||||||
new_attrs_s = set(new_attrs.items())
|
{k: v for k, v in old_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
|
new_attrs_s = set(
|
||||||
|
{k: v for k, v in new_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
||||||
|
|
||||||
for attr_name in changed_attrs:
|
for attr_name in changed_attrs:
|
||||||
if attr_name not in SIGNIFICANT_ATTRIBUTES:
|
|
||||||
continue
|
|
||||||
|
|
||||||
old_attr_value = old_attrs.get(attr_name)
|
old_attr_value = old_attrs.get(attr_name)
|
||||||
new_attr_value = new_attrs.get(attr_name)
|
new_attr_value = new_attrs.get(attr_name)
|
||||||
if new_attr_value is None or not check_valid_float(new_attr_value):
|
if new_attr_value is None or not check_valid_float(new_attr_value):
|
||||||
|
|
|
@ -9,9 +9,14 @@ from homeassistant.helpers.significant_change import (
|
||||||
check_valid_float,
|
check_valid_float,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import ATTR_PERCENTAGE, ATTR_PERCENTAGE_STEP
|
from . import ATTR_DIRECTION, ATTR_OSCILLATING, ATTR_PERCENTAGE, ATTR_PRESET_MODE
|
||||||
|
|
||||||
INSIGNIFICANT_ATTRIBUTES: set[str] = {ATTR_PERCENTAGE_STEP}
|
SIGNIFICANT_ATTRIBUTES: set[str] = {
|
||||||
|
ATTR_DIRECTION,
|
||||||
|
ATTR_OSCILLATING,
|
||||||
|
ATTR_PERCENTAGE,
|
||||||
|
ATTR_PRESET_MODE,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -27,14 +32,15 @@ def async_check_significant_change(
|
||||||
if old_state != new_state:
|
if old_state != new_state:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
old_attrs_s = set(old_attrs.items())
|
old_attrs_s = set(
|
||||||
new_attrs_s = set(new_attrs.items())
|
{k: v for k, v in old_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
|
new_attrs_s = set(
|
||||||
|
{k: v for k, v in new_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
||||||
|
|
||||||
for attr_name in changed_attrs:
|
for attr_name in changed_attrs:
|
||||||
if attr_name in INSIGNIFICANT_ATTRIBUTES:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if attr_name != ATTR_PERCENTAGE:
|
if attr_name != ATTR_PERCENTAGE:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -32,14 +32,15 @@ def async_check_significant_change(
|
||||||
if old_state != new_state:
|
if old_state != new_state:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
old_attrs_s = set(old_attrs.items())
|
old_attrs_s = set(
|
||||||
new_attrs_s = set(new_attrs.items())
|
{k: v for k, v in old_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
|
new_attrs_s = set(
|
||||||
|
{k: v for k, v in new_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
||||||
|
|
||||||
for attr_name in changed_attrs:
|
for attr_name in changed_attrs:
|
||||||
if attr_name not in SIGNIFICANT_ATTRIBUTES:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if attr_name in [ATTR_ACTION, ATTR_MODE]:
|
if attr_name in [ATTR_ACTION, ATTR_MODE]:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -43,14 +43,23 @@ def async_check_significant_change(
|
||||||
if old_state != new_state:
|
if old_state != new_state:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
old_attrs_s = set(old_attrs.items())
|
old_attrs_s = set(
|
||||||
new_attrs_s = set(new_attrs.items())
|
{
|
||||||
|
k: v
|
||||||
|
for k, v in old_attrs.items()
|
||||||
|
if k in SIGNIFICANT_ATTRIBUTES - INSIGNIFICANT_ATTRIBUTES
|
||||||
|
}.items()
|
||||||
|
)
|
||||||
|
new_attrs_s = set(
|
||||||
|
{
|
||||||
|
k: v
|
||||||
|
for k, v in new_attrs.items()
|
||||||
|
if k in SIGNIFICANT_ATTRIBUTES - INSIGNIFICANT_ATTRIBUTES
|
||||||
|
}.items()
|
||||||
|
)
|
||||||
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
||||||
|
|
||||||
for attr_name in changed_attrs:
|
for attr_name in changed_attrs:
|
||||||
if attr_name not in SIGNIFICANT_ATTRIBUTES - INSIGNIFICANT_ATTRIBUTES:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if attr_name != ATTR_MEDIA_VOLUME_LEVEL:
|
if attr_name != ATTR_MEDIA_VOLUME_LEVEL:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,15 @@ def async_check_significant_change(
|
||||||
if old_state != new_state:
|
if old_state != new_state:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
old_attrs_s = set(old_attrs.items())
|
old_attrs_s = set(
|
||||||
new_attrs_s = set(new_attrs.items())
|
{k: v for k, v in old_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
|
new_attrs_s = set(
|
||||||
|
{k: v for k, v in new_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
||||||
|
|
||||||
for attr_name in changed_attrs:
|
for attr_name in changed_attrs:
|
||||||
if attr_name not in SIGNIFICANT_ATTRIBUTES:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if attr_name != ATTR_BATTERY_LEVEL:
|
if attr_name != ATTR_BATTERY_LEVEL:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -42,15 +42,16 @@ def async_check_significant_change(
|
||||||
if old_state != new_state:
|
if old_state != new_state:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
old_attrs_s = set(old_attrs.items())
|
old_attrs_s = set(
|
||||||
new_attrs_s = set(new_attrs.items())
|
{k: v for k, v in old_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
|
new_attrs_s = set(
|
||||||
|
{k: v for k, v in new_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
||||||
ha_unit = hass.config.units.temperature_unit
|
ha_unit = hass.config.units.temperature_unit
|
||||||
|
|
||||||
for attr_name in changed_attrs:
|
for attr_name in changed_attrs:
|
||||||
if attr_name not in SIGNIFICANT_ATTRIBUTES:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if attr_name in [ATTR_OPERATION_MODE, ATTR_AWAY_MODE]:
|
if attr_name in [ATTR_OPERATION_MODE, ATTR_AWAY_MODE]:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -88,14 +88,15 @@ def async_check_significant_change(
|
||||||
if old_state != new_state:
|
if old_state != new_state:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
old_attrs_s = set(old_attrs.items())
|
old_attrs_s = set(
|
||||||
new_attrs_s = set(new_attrs.items())
|
{k: v for k, v in old_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
|
new_attrs_s = set(
|
||||||
|
{k: v for k, v in new_attrs.items() if k in SIGNIFICANT_ATTRIBUTES}.items()
|
||||||
|
)
|
||||||
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
changed_attrs: set[str] = {item[0] for item in old_attrs_s ^ new_attrs_s}
|
||||||
|
|
||||||
for attr_name in changed_attrs:
|
for attr_name in changed_attrs:
|
||||||
if attr_name not in SIGNIFICANT_ATTRIBUTES:
|
|
||||||
continue
|
|
||||||
|
|
||||||
old_attr_value = old_attrs.get(attr_name)
|
old_attr_value = old_attrs.get(attr_name)
|
||||||
new_attr_value = new_attrs.get(attr_name)
|
new_attr_value = new_attrs.get(attr_name)
|
||||||
absolute_change: float | None = None
|
absolute_change: float | None = None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue