Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
raise homeassistant error on invalid alarm state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rlippmann committed Oct 8, 2023
1 parent 4c7dc12 commit f066b41
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion custom_components/adtpulse/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
Expand Down Expand Up @@ -161,6 +162,7 @@ def device_info(self) -> DeviceInfo:
async def _perform_alarm_action(
self, arm_disarm_func: Coroutine[bool | None, None, bool], action: str
) -> None:
result = True
LOG.debug("%s: Setting Alarm to %s", ADTPULSE_DOMAIN, action)
if self.state == action:
LOG.warning("Attempting to set alarm to same state, ignoring")
Expand All @@ -170,10 +172,13 @@ async def _perform_alarm_action(
else:
self._assumed_state = STATE_ALARM_ARMING
self.async_write_ha_state()
if not await arm_disarm_func:
result = await arm_disarm_func
if not result:
LOG.warning("Could not %s ADT Pulse alarm", action)
self._assumed_state = None
self.async_write_ha_state()
if not result:
raise HomeAssistantError(f"Could not set alarm status to {action}")

async def async_alarm_disarm(self, code: str | None = None) -> None:
"""Send disarm command."""
Expand Down

0 comments on commit f066b41

Please sign in to comment.