mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Implement person significant change (#45713)
This commit is contained in:
parent
8a112721fa
commit
07a4422a70
21
homeassistant/components/person/significant_change.py
Normal file
21
homeassistant/components/person/significant_change.py
Normal file
@ -0,0 +1,21 @@
|
||||
"""Helper to test significant Person state changes."""
|
||||
from typing import Any, Optional
|
||||
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
||||
|
||||
@callback
|
||||
def async_check_significant_change(
|
||||
hass: HomeAssistant,
|
||||
old_state: str,
|
||||
old_attrs: dict,
|
||||
new_state: str,
|
||||
new_attrs: dict,
|
||||
**kwargs: Any,
|
||||
) -> Optional[bool]:
|
||||
"""Test if state significantly changed."""
|
||||
|
||||
if new_state != old_state:
|
||||
return True
|
||||
|
||||
return False
|
16
tests/components/person/test_significant_change.py
Normal file
16
tests/components/person/test_significant_change.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""Test the Person significant change platform."""
|
||||
from homeassistant.components.person.significant_change import (
|
||||
async_check_significant_change,
|
||||
)
|
||||
|
||||
|
||||
async def test_significant_change():
|
||||
"""Detect Person significant changes and ensure that attribute changes do not trigger a significant change."""
|
||||
old_attrs = {"source": "device_tracker.wifi_device"}
|
||||
new_attrs = {"source": "device_tracker.gps_device"}
|
||||
assert not async_check_significant_change(
|
||||
None, "home", old_attrs, "home", new_attrs
|
||||
)
|
||||
assert async_check_significant_change(
|
||||
None, "home", new_attrs, "not_home", new_attrs
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user