Skip to content

Commit

Permalink
Make SimpliSafe entities unavailable when wifi is lost (#32154)
Browse files Browse the repository at this point in the history
* Make SimpliSafe entities unavailable when wifi is lost

* Remove online status from REST API

* Comments

* Mispelling
  • Loading branch information
bachya committed Feb 26, 2020
1 parent 4c33a9d commit b5c1afc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
28 changes: 26 additions & 2 deletions homeassistant/components/simplisafe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from simplipy.errors import InvalidCredentialsError, SimplipyError
from simplipy.websocket import (
EVENT_CAMERA_MOTION_DETECTED,
EVENT_CONNECTION_LOST,
EVENT_CONNECTION_RESTORED,
EVENT_DOORBELL_DETECTED,
EVENT_ENTRY_DETECTED,
EVENT_LOCK_LOCKED,
Expand Down Expand Up @@ -528,7 +530,10 @@ def __init__(self, simplisafe, system, name, *, serial=None):
self._online = True
self._simplisafe = simplisafe
self._system = system
self.websocket_events_to_listen_for = []
self.websocket_events_to_listen_for = [
EVENT_CONNECTION_LOST,
EVENT_CONNECTION_RESTORED,
]

if serial:
self._serial = serial
Expand Down Expand Up @@ -655,13 +660,32 @@ async def async_update(self):
ATTR_LAST_EVENT_TIMESTAMP: last_websocket_event.timestamp,
}
)
self.async_update_from_websocket_event(last_websocket_event)
self._async_internal_update_from_websocket_event(last_websocket_event)

@callback
def async_update_from_rest_api(self):
"""Update the entity with the provided REST API data."""
pass

@callback
def _async_internal_update_from_websocket_event(self, event):
"""Check for connection events and set offline appropriately.
Should not be called directly.
"""
if event.event_type == EVENT_CONNECTION_LOST:
self._online = False
elif event.event_type == EVENT_CONNECTION_RESTORED:
self._online = True

# It's uncertain whether SimpliSafe events will still propagate down the
# websocket when the base station is offline. Just in case, we guard against
# further action until connection is restored:
if not self._online:
return

self.async_update_from_websocket_event(event)

@callback
def async_update_from_websocket_event(self, event):
"""Update the entity with the provided websocket API data."""
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/simplisafe/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,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(
{
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/simplisafe/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ async def async_unlock(self, **kwargs):
@callback
def async_update_from_rest_api(self):
"""Update the entity with the provided REST API data."""
if self._lock.offline or self._lock.disabled:
self._online = False
return

self._online = True
self._attrs.update(
{
ATTR_LOCK_LOW_BATTERY: self._lock.lock_low_battery,
Expand Down

0 comments on commit b5c1afc

Please sign in to comment.