Add significant Change support for camera (#105866)

This commit is contained in:
Michael 2023-12-18 14:40:55 +01:00 committed by GitHub
parent 0972dc5867
commit 58070e14a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,22 @@
"""Helper to test significant Camera 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 | None:
"""Test if state significantly changed."""
if old_state != new_state:
return True
return None

View file

@ -0,0 +1,19 @@
"""Test the Camera significant change platform."""
from homeassistant.components.camera import STATE_IDLE, STATE_RECORDING
from homeassistant.components.camera.significant_change import (
async_check_significant_change,
)
async def test_significant_change() -> None:
"""Detect Camera significant changes."""
attrs = {}
assert not async_check_significant_change(
None, STATE_IDLE, attrs, STATE_IDLE, attrs
)
assert not async_check_significant_change(
None, STATE_IDLE, attrs, STATE_IDLE, {"dummy": "dummy"}
)
assert async_check_significant_change(
None, STATE_IDLE, attrs, STATE_RECORDING, attrs
)