Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion homeassistant/components/simplisafe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@

DEFAULT_ENTITY_MODEL = "alarm_control_panel"
DEFAULT_ENTITY_NAME = "Alarm Control Panel"
DEFAULT_REST_API_ERROR_COUNT = 2
DEFAULT_SCAN_INTERVAL = timedelta(seconds=30)
DEFAULT_SOCKET_MIN_RETRY = 15


DISPATCHER_TOPIC_WEBSOCKET_EVENT = "simplisafe_websocket_event_{0}"

EVENT_SIMPLISAFE_EVENT = "SIMPLISAFE_EVENT"
Expand Down Expand Up @@ -553,6 +555,8 @@ def __init__(
assert simplisafe.coordinator
super().__init__(simplisafe.coordinator)

self._rest_api_errors = 0

if device:
model = device.type.name
device_name = device.name
Expand Down Expand Up @@ -615,11 +619,24 @@ def available(self) -> bool:
else:
system_offline = False

return super().available and self._online and not system_offline
return (
self._rest_api_errors < DEFAULT_REST_API_ERROR_COUNT
and self._online
and not system_offline
)

@callback
def _handle_coordinator_update(self) -> None:
"""Update the entity with new REST API data."""
# SimpliSafe can incorrectly return an error state when there isn't any
# error. This can lead to the system having an unknown state frequently.
# To protect against that, we measure how many "error states" we receive
# and only alter the state if we detect a few in a row:
if self.coordinator.last_update_success:
self._rest_api_errors = 0
else:
self._rest_api_errors += 1

self.async_update_from_rest_api()
self.async_write_ha_state()

Expand Down
17 changes: 0 additions & 17 deletions homeassistant/components/simplisafe/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@
ATTR_WALL_POWER_LEVEL = "wall_power_level"
ATTR_WIFI_STRENGTH = "wifi_strength"

DEFAULT_ERRORS_TO_ACCOMMODATE = 2

VOLUME_STRING_MAP = {
VOLUME_HIGH: "high",
VOLUME_LOW: "low",
Expand Down Expand Up @@ -140,8 +138,6 @@ def __init__(self, simplisafe: SimpliSafe, system: SystemV2 | SystemV3) -> None:
additional_websocket_events=WEBSOCKET_EVENTS_TO_LISTEN_FOR,
)

self._errors = 0

if code := self._simplisafe.entry.options.get(CONF_CODE):
if code.isdigit():
self._attr_code_format = FORMAT_NUMBER
Expand Down Expand Up @@ -248,19 +244,6 @@ def async_update_from_rest_api(self) -> None:
}
)

# SimpliSafe can incorrectly return an error state when there isn't any
# error. This can lead to the system having an unknown state frequently.
# To protect against that, we measure how many "error states" we receive
# and only alter the state if we detect a few in a row:
if self._system.state == SystemStates.error:
if self._errors > DEFAULT_ERRORS_TO_ACCOMMODATE:
self._attr_state = None
else:
self._errors += 1
return

self._errors = 0

self._set_state_from_system_data()

@callback
Expand Down