mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Add significant change support to select entity (#51978)
This commit is contained in:
parent
98a53188f8
commit
06edc731c5
19
homeassistant/components/select/significant_change.py
Normal file
19
homeassistant/components/select/significant_change.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
"""Helper to test significant Select state changes."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
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,
|
||||||
|
) -> bool:
|
||||||
|
"""Test if state significantly changed."""
|
||||||
|
return old_state != new_state
|
20
tests/components/select/test_significant_change.py
Normal file
20
tests/components/select/test_significant_change.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
"""Test the select significant change platform."""
|
||||||
|
from homeassistant.components.select.significant_change import (
|
||||||
|
async_check_significant_change,
|
||||||
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
|
async def test_significant_change(hass: HomeAssistant) -> None:
|
||||||
|
"""Detect select significant change."""
|
||||||
|
attrs1 = {"options": ["option1", "option2"]}
|
||||||
|
attrs2 = {"options": ["option1", "option2", "option3"]}
|
||||||
|
|
||||||
|
assert not async_check_significant_change(
|
||||||
|
hass, "option1", attrs1, "option1", attrs1
|
||||||
|
)
|
||||||
|
assert not async_check_significant_change(
|
||||||
|
hass, "option1", attrs1, "option1", attrs2
|
||||||
|
)
|
||||||
|
assert async_check_significant_change(hass, "option1", attrs1, "option2", attrs1)
|
||||||
|
assert async_check_significant_change(hass, "option1", attrs1, "option2", attrs2)
|
Loading…
x
Reference in New Issue
Block a user