mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add significant change support to lock (#45726)
This commit is contained in:
parent
07a4422a70
commit
85e6bc581f
20
homeassistant/components/lock/significant_change.py
Normal file
20
homeassistant/components/lock/significant_change.py
Normal file
@ -0,0 +1,20 @@
|
||||
"""Helper to test significant Lock 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 old_state != new_state:
|
||||
return True
|
||||
|
||||
return False
|
23
tests/components/lock/test_significant_change.py
Normal file
23
tests/components/lock/test_significant_change.py
Normal file
@ -0,0 +1,23 @@
|
||||
"""Test the Lock significant change platform."""
|
||||
from homeassistant.components.lock.significant_change import (
|
||||
async_check_significant_change,
|
||||
)
|
||||
|
||||
|
||||
async def test_significant_change():
|
||||
"""Detect Lock significant changes."""
|
||||
old_attrs = {"attr_1": "a"}
|
||||
new_attrs = {"attr_1": "b"}
|
||||
|
||||
assert (
|
||||
async_check_significant_change(None, "locked", old_attrs, "locked", old_attrs)
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
async_check_significant_change(None, "locked", old_attrs, "locked", new_attrs)
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
async_check_significant_change(None, "locked", old_attrs, "unlocked", old_attrs)
|
||||
is True
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user