Home Assistant Unofficial Reference 2024.12.1
homeassistant.helpers.significant_change Namespace Reference

Classes

class  SignificantChangeProtocol
 
class  SignificantlyChangedChecker
 

Functions

bool _check_numeric_change (float|None old_state, float|None new_state, float change, Callable[[int|float, int|float], int|float] metric)
 
None _initialize (HomeAssistant hass)
 
bool check_absolute_change (float|None val1, float|None val2, float change)
 
bool check_percentage_change (float|None old_state, float|None new_state, float change)
 
bool check_valid_float (str|float value)
 
SignificantlyChangedChecker create_checker (HomeAssistant hass, str _domain, ExtraCheckTypeFunc|None extra_significant_check=None)
 
bool either_one_none (Any|None val1, Any|None val2)
 

Variables

 CheckTypeFunc
 
 ExtraCheckTypeFunc
 
string PLATFORM = "significant_change"
 

Detailed Description

Helpers to help find if an entity has changed significantly.

Does this with help of the integration. Looks at significant_change.py
platform for a function `async_check_significant_change`:

```python
from typing import Optional
from homeassistant.core import HomeAssistant

async def async_check_significant_change(
    hass: HomeAssistant,
    old_state: str,
    old_attrs: dict,
    new_state: str,
    new_attrs: dict,
    **kwargs,
) -> bool | None
```

Return boolean to indicate if significantly changed. If don't know, return None.

**kwargs will allow us to expand this feature in the future, like passing in a
level of significance.

The following cases will never be passed to your function:
- if either state is unknown/unavailable
- state adding/removing

Function Documentation

◆ _check_numeric_change()

bool homeassistant.helpers.significant_change._check_numeric_change ( float | None  old_state,
float | None  new_state,
float  change,
Callable[[int | float, int | float], int | float]  metric 
)
private
Check if two numeric values have changed.

Definition at line 118 of file significant_change.py.

◆ _initialize()

None homeassistant.helpers.significant_change._initialize ( HomeAssistant  hass)
private
Initialize the functions.

Definition at line 94 of file significant_change.py.

◆ check_absolute_change()

bool homeassistant.helpers.significant_change.check_absolute_change ( float | None  val1,
float | None  val2,
float  change 
)
Check if two numeric values have changed.

Definition at line 140 of file significant_change.py.

◆ check_percentage_change()

bool homeassistant.helpers.significant_change.check_percentage_change ( float | None  old_state,
float | None  new_state,
float  change 
)
Check if two numeric values have changed.

Definition at line 151 of file significant_change.py.

◆ check_valid_float()

bool homeassistant.helpers.significant_change.check_valid_float ( str | float  value)
Check if given value is a valid float.

Definition at line 169 of file significant_change.py.

◆ create_checker()

SignificantlyChangedChecker homeassistant.helpers.significant_change.create_checker ( HomeAssistant  hass,
str  _domain,
ExtraCheckTypeFunc | None   extra_significant_check = None 
)
Create a significantly changed checker for a domain.

Definition at line 83 of file significant_change.py.

◆ either_one_none()

bool homeassistant.helpers.significant_change.either_one_none ( Any | None  val1,
Any | None  val2 
)
Test if exactly one value is None.

Definition at line 113 of file significant_change.py.

Variable Documentation

◆ CheckTypeFunc

homeassistant.helpers.significant_change.CheckTypeFunc

Definition at line 44 of file significant_change.py.

◆ ExtraCheckTypeFunc

homeassistant.helpers.significant_change.ExtraCheckTypeFunc

Definition at line 55 of file significant_change.py.

◆ PLATFORM

string homeassistant.helpers.significant_change.PLATFORM = "significant_change"

Definition at line 42 of file significant_change.py.