From e7ffe05938e6cd13a5426f8a605260056fa04de0 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Tue, 4 Feb 2020 21:48:27 -0700 Subject: [PATCH] Add connection lost and restored events --- .../components/simplisafe/alarm_control_panel.py | 13 ++++++------- homeassistant/components/simplisafe/lock.py | 14 +++++++++++--- homeassistant/components/simplisafe/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/simplisafe/alarm_control_panel.py b/homeassistant/components/simplisafe/alarm_control_panel.py index 37694f75bacea3..f02a6ac2cd7124 100644 --- a/homeassistant/components/simplisafe/alarm_control_panel.py +++ b/homeassistant/components/simplisafe/alarm_control_panel.py @@ -13,6 +13,8 @@ EVENT_ARMED_HOME, EVENT_AWAY_EXIT_DELAY_BY_KEYPAD, EVENT_AWAY_EXIT_DELAY_BY_REMOTE, + EVENT_CONNECTION_LOST, + EVENT_CONNECTION_RESTORED, EVENT_DISARMED_BY_MASTER_PIN, EVENT_DISARMED_BY_REMOTE, EVENT_HOME_EXIT_DELAY, @@ -175,11 +177,6 @@ async def async_alarm_arm_away(self, code=None): @callback def async_update_from_rest_api(self): """Update the entity with the provided REST API data.""" - if self._system.state == SystemStates.error: - self._online = False - return - self._online = True - if self._system.version == 3: self._attrs.update( { @@ -227,7 +224,9 @@ def async_update_from_websocket_event(self, event): EVENT_HOME_EXIT_DELAY, ): self._state = STATE_ALARM_ARMING - else: - self._state = None + elif event.event_type == EVENT_CONNECTION_LOST: + self._online = False + elif event.event_type == EVENT_CONNECTION_RESTORED: + self._online = True self._changed_by = event.changed_by diff --git a/homeassistant/components/simplisafe/lock.py b/homeassistant/components/simplisafe/lock.py index beebbd5b0b44ed..4772d9922dc9a3 100644 --- a/homeassistant/components/simplisafe/lock.py +++ b/homeassistant/components/simplisafe/lock.py @@ -3,7 +3,13 @@ from simplipy.errors import SimplipyError from simplipy.lock import LockStates -from simplipy.websocket import EVENT_LOCK_ERROR, EVENT_LOCK_LOCKED, EVENT_LOCK_UNLOCKED +from simplipy.websocket import ( + EVENT_CONNECTION_LOST, + EVENT_CONNECTION_RESTORED, + EVENT_LOCK_ERROR, + EVENT_LOCK_LOCKED, + EVENT_LOCK_UNLOCKED, +) from homeassistant.components.lock import LockDevice from homeassistant.const import STATE_LOCKED, STATE_UNKNOWN, STATE_UNLOCKED @@ -89,5 +95,7 @@ def async_update_from_websocket_event(self, event): self._state = STATE_UNLOCKED elif event.event_type == EVENT_LOCK_ERROR: self._state = STATE_UNKNOWN - else: - self._state = None + elif event.event_type == EVENT_CONNECTION_LOST: + self._online = False + elif event.event_type == EVENT_CONNECTION_RESTORED: + self._online = True diff --git a/homeassistant/components/simplisafe/manifest.json b/homeassistant/components/simplisafe/manifest.json index 3b04d26732ca8d..e55cb2f8b6d9ff 100644 --- a/homeassistant/components/simplisafe/manifest.json +++ b/homeassistant/components/simplisafe/manifest.json @@ -3,7 +3,7 @@ "name": "SimpliSafe", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/simplisafe", - "requirements": ["simplisafe-python==7.1.0"], + "requirements": ["simplisafe-python==7.2.0"], "dependencies": [], "codeowners": ["@bachya"] } diff --git a/requirements_all.txt b/requirements_all.txt index 5dd8978d4d5f79..88868552459a46 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1822,7 +1822,7 @@ simplehound==0.3 simplepush==1.1.4 # homeassistant.components.simplisafe -simplisafe-python==7.1.0 +simplisafe-python==7.2.0 # homeassistant.components.sisyphus sisyphus-control==2.2.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 58edcc5451291e..8b6b382026c8ce 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -600,7 +600,7 @@ sentry-sdk==0.13.5 simplehound==0.3 # homeassistant.components.simplisafe -simplisafe-python==7.1.0 +simplisafe-python==7.2.0 # homeassistant.components.sleepiq sleepyq==0.7