Skip to content

Commit

Permalink
fix: default to guard mode when current mode is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
fuatakgun committed Aug 3, 2023
1 parent 62c65b2 commit 36480be
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions custom_components/eufy_security/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class CurrentModeToState(Enum):
GEOFENCE = 47
DISARMED = 63


class CurrentModeToStateValue(Enum):
"""Alarm Entity Mode to State Value"""

Expand Down Expand Up @@ -103,6 +102,11 @@ def guard_mode_metadata(self) -> Metadata:
"""Get guard mode metadata for device"""
return self.product.metadata[MessageField.GUARD_MODE.value]

@property
def guard_mode(self) -> Metadata:
"""Get guard mode for device"""
return get_child_value(self.product.properties, MessageField.GUARD_MODE.value)

async def _set_guard_mode(self, target_mode: CurrentModeToState):
await self.product.set_property(self.guard_mode_metadata, target_mode.value)

Expand Down Expand Up @@ -160,7 +164,15 @@ def state(self):
triggered = get_child_value(self.product.properties, "alarm")
if triggered is True:
return CurrentModeToStateValue.TRIGGERED.value
current_mode = get_child_value(self.product.properties, self.metadata.name, -1)
current_mode = get_child_value(self.product.properties, self.metadata.name, CurrentModeToState.NONE.value)

if current_mode == CurrentModeToState.NONE.value:
try:
_LOGGER.debug(f"alarm_control_panel current_mode {current_mode} is missing, defaulting to guard_mode {self.guard_mode}")
current_mode = CurrentModeToState(self.guard_mode)
except ValueError:
pass

if current_mode == KEYPAD_OFF_CODE:
return CurrentModeToStateValue[CurrentModeToState.DISARMED.name].value
if current_mode in CUSTOM_CODES:
Expand Down

0 comments on commit 36480be

Please sign in to comment.