Light significant changes + sensor tweaks (#45583)
This commit is contained in:
parent
74efe78d0a
commit
352d0870e3
6 changed files with 179 additions and 15 deletions
|
@ -1,5 +1,5 @@
|
|||
"""Helper to test significant sensor state changes."""
|
||||
from typing import Any, Optional
|
||||
from typing import Any, Optional, Union
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
|
@ -28,18 +28,18 @@ def async_check_significant_change(
|
|||
|
||||
if device_class == DEVICE_CLASS_TEMPERATURE:
|
||||
if new_attrs.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_FAHRENHEIT:
|
||||
change = 0.03
|
||||
change: Union[float, int] = 1
|
||||
else:
|
||||
change = 0.05
|
||||
change = 0.5
|
||||
|
||||
old_value = float(old_state)
|
||||
new_value = float(new_state)
|
||||
return abs(1 - old_value / new_value) > change
|
||||
return abs(old_value - new_value) >= change
|
||||
|
||||
if device_class in (DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY):
|
||||
old_value = float(old_state)
|
||||
new_value = float(new_state)
|
||||
|
||||
return abs(old_value - new_value) > 2
|
||||
return abs(old_value - new_value) >= 1
|
||||
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue