Fix incorrect initial state with SimpliSafe locks (#42039)

* Fix incorrect initial state with SimpliSafe locks

* Cleanup
This commit is contained in:
Aaron Bach 2020-10-18 12:21:48 -06:00 committed by GitHub
parent 941453dca9
commit 91fd59aa57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,8 +32,8 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity):
def __init__(self, simplisafe, system, lock): def __init__(self, simplisafe, system, lock):
"""Initialize.""" """Initialize."""
super().__init__(simplisafe, system, lock.name, serial=lock.serial) super().__init__(simplisafe, system, lock.name, serial=lock.serial)
self._is_locked = False
self._lock = lock self._lock = lock
self._is_locked = None
for event_type in (EVENT_LOCK_LOCKED, EVENT_LOCK_UNLOCKED): for event_type in (EVENT_LOCK_LOCKED, EVENT_LOCK_UNLOCKED):
self.websocket_events_to_listen_for.append(event_type) self.websocket_events_to_listen_for.append(event_type)
@ -51,8 +51,6 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity):
LOGGER.error('Error while locking "%s": %s', self._lock.name, err) LOGGER.error('Error while locking "%s": %s', self._lock.name, err)
return return
self._is_locked = True
async def async_unlock(self, **kwargs): async def async_unlock(self, **kwargs):
"""Unlock the lock.""" """Unlock the lock."""
try: try:
@ -61,8 +59,6 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity):
LOGGER.error('Error while unlocking "%s": %s', self._lock.name, err) LOGGER.error('Error while unlocking "%s": %s', self._lock.name, err)
return return
self._is_locked = False
@callback @callback
def async_update_from_rest_api(self): def async_update_from_rest_api(self):
"""Update the entity with the provided REST API data.""" """Update the entity with the provided REST API data."""
@ -74,6 +70,8 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity):
} }
) )
self._is_locked = self._lock.state == LockStates.locked
@callback @callback
def async_update_from_websocket_event(self, event): def async_update_from_websocket_event(self, event):
"""Update the entity with the provided websocket event data.""" """Update the entity with the provided websocket event data."""