mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Fix Homekit error handling alarm state unknown or unavailable (#130311)
This commit is contained in:
parent
e040eb0ff2
commit
85bf8d1374
@ -18,6 +18,8 @@ from homeassistant.const import (
|
||||
SERVICE_ALARM_ARM_HOME,
|
||||
SERVICE_ALARM_ARM_NIGHT,
|
||||
SERVICE_ALARM_DISARM,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import State, callback
|
||||
|
||||
@ -152,12 +154,12 @@ class SecuritySystem(HomeAccessory):
|
||||
@callback
|
||||
def async_update_state(self, new_state: State) -> None:
|
||||
"""Update security state after state changed."""
|
||||
hass_state = None
|
||||
if new_state and new_state.state == "None":
|
||||
# Bail out early for no state
|
||||
hass_state: str | AlarmControlPanelState = new_state.state
|
||||
if hass_state in {"None", STATE_UNKNOWN, STATE_UNAVAILABLE}:
|
||||
# Bail out early for no state, unknown or unavailable
|
||||
return
|
||||
if new_state and new_state.state is not None:
|
||||
hass_state = AlarmControlPanelState(new_state.state)
|
||||
if hass_state is not None:
|
||||
hass_state = AlarmControlPanelState(hass_state)
|
||||
if (
|
||||
hass_state
|
||||
and (current_state := HASS_TO_HOMEKIT_CURRENT.get(hass_state)) is not None
|
||||
|
@ -10,7 +10,12 @@ from homeassistant.components.alarm_control_panel import (
|
||||
)
|
||||
from homeassistant.components.homekit.const import ATTR_VALUE
|
||||
from homeassistant.components.homekit.type_security_systems import SecuritySystem
|
||||
from homeassistant.const import ATTR_CODE, ATTR_ENTITY_ID, STATE_UNKNOWN
|
||||
from homeassistant.const import (
|
||||
ATTR_CODE,
|
||||
ATTR_ENTITY_ID,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import Event, HomeAssistant
|
||||
|
||||
from tests.common import async_mock_service
|
||||
@ -307,3 +312,33 @@ async def test_supported_states(hass: HomeAssistant, hk_driver) -> None:
|
||||
|
||||
for val in valid_target_values.values():
|
||||
assert val in test_config.get("target_values")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("state"),
|
||||
[
|
||||
(None),
|
||||
("None"),
|
||||
(STATE_UNKNOWN),
|
||||
(STATE_UNAVAILABLE),
|
||||
],
|
||||
)
|
||||
async def test_handle_non_alarm_states(
|
||||
hass: HomeAssistant, hk_driver, events: list[Event], state: str
|
||||
) -> None:
|
||||
"""Test we can handle states that should not raise."""
|
||||
code = "1234"
|
||||
config = {ATTR_CODE: code}
|
||||
entity_id = "alarm_control_panel.test"
|
||||
|
||||
hass.states.async_set(entity_id, state)
|
||||
await hass.async_block_till_done()
|
||||
acc = SecuritySystem(hass, hk_driver, "SecuritySystem", entity_id, 2, config)
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 11 # AlarmSystem
|
||||
|
||||
assert acc.char_current_state.value == 3
|
||||
assert acc.char_target_state.value == 3
|
||||
|
Loading…
x
Reference in New Issue
Block a user