Restore manual alarm-control-panel state using async_get_last_state (#17521)
* Restore manual alarm-control-panel state using async_get_last_state This is to address issue #10793 * Added tests for restoring manual alarm state on startup * Cleaned up test formatting * Fixed more linting errors * Changed async methods to use asynch/await syntax * Removed unused asyncio import
This commit is contained in:
parent
544a3b929f
commit
3c68db32d6
2 changed files with 58 additions and 5 deletions
|
@ -21,6 +21,7 @@ from homeassistant.const import (
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.event import track_point_in_time
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.helpers.restore_state import async_get_last_state
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -306,3 +307,10 @@ class ManualAlarm(alarm.AlarmControlPanel):
|
|||
state_attr[ATTR_POST_PENDING_STATE] = self._state
|
||||
|
||||
return state_attr
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Run when entity about to be added to hass."""
|
||||
state = await async_get_last_state(self.hass, self.entity_id)
|
||||
if state:
|
||||
self._state = state.state
|
||||
self._state_ts = state.last_updated
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue