From 45238295dfe4f52d2ec9b8a0e5411f254b9d76b9 Mon Sep 17 00:00:00 2001 From: liaanvdm <43240119+liaanvdm@users.noreply.github.com> Date: Fri, 14 Dec 2018 15:04:04 +0200 Subject: [PATCH] Fix restore state for manual alarm control panel (#19284) * Fixed manual alarm control panel restore state * Revert "Fixed manual alarm control panel restore state" This reverts commit 61c9faf434a8bb276133578a0811100a796784ca. * Fixed manual alarm control panel's state restore --- .../components/alarm_control_panel/manual.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/alarm_control_panel/manual.py b/homeassistant/components/alarm_control_panel/manual.py index 0a79d74d686..0bbbd0689e2 100644 --- a/homeassistant/components/alarm_control_panel/manual.py +++ b/homeassistant/components/alarm_control_panel/manual.py @@ -310,7 +310,15 @@ class ManualAlarm(alarm.AlarmControlPanel, RestoreEntity): async def async_added_to_hass(self): """Run when entity about to be added to hass.""" + await super().async_added_to_hass() state = await self.async_get_last_state() if state: - self._state = state.state - self._state_ts = state.last_updated + if state.state == STATE_ALARM_PENDING and \ + hasattr(state, 'attributes') and \ + state.attributes['pre_pending_state']: + # If in pending state, we return to the pre_pending_state + self._state = state.attributes['pre_pending_state'] + self._state_ts = dt_util.utcnow() + else: + self._state = state.state + self._state_ts = state.last_updated