Skip to content

Commit

Permalink
fix: add control panel State Off on keypad (#871)
Browse files Browse the repository at this point in the history
* Update alarm_control_panel.py

fixes off button in control panel....maybe.

needs some looking after

* Update alarm_control_panel.py

* Update services.yaml

add new service to eufy_security to change statte of alarm to off instead of disarmed (which are 2 states if you have a keypad)

* Update alarm_control_panel.py

Add new function if you have a keypad to turn the security off in stead of disarmed plus reflect this in HomeAssisant

Now there is Disarmed and Off stage in HA

* Update services.yaml

extra line for readability
  • Loading branch information
kvanbiesen authored Aug 9, 2023
1 parent 1ab654b commit 55a1c46
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
16 changes: 12 additions & 4 deletions custom_components/eufy_security/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
AlarmControlPanelEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED, STATE_ALARM_TRIGGERED
from homeassistant.const import STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED, STATE_ALARM_TRIGGERED, STATE_OFF
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand All @@ -22,7 +22,7 @@

_LOGGER: logging.Logger = logging.getLogger(__package__)

KEYPAD_OFF_CODE = 6
#KEYPAD_OFF_CODE = 6


class CurrentModeToState(Enum):
Expand All @@ -35,6 +35,7 @@ class CurrentModeToState(Enum):
CUSTOM_BYPASS = 3
NIGHT = 4
VACATION = 5
OFF = 6
GEOFENCE = 47
DISARMED = 63

Expand All @@ -48,6 +49,7 @@ class CurrentModeToStateValue(Enum):
NIGHT = auto()
VACATION = auto()
DISARMED = STATE_ALARM_DISARMED
OFF = STATE_OFF
TRIGGERED = STATE_ALARM_TRIGGERED
ALARM_DELAYED = "Alarm delayed"

Expand Down Expand Up @@ -78,7 +80,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
platform.async_register_entity_service("schedule", {}, "schedule")
platform.async_register_entity_service("chime", Schema.CHIME_SERVICE_SCHEMA.value, "chime")
platform.async_register_entity_service("reboot", {}, "async_reboot")
platform.async_register_entity_service("alarm_off", {}, "async_alarm_off")



class EufySecurityAlarmControlPanel(AlarmControlPanelEntity, EufySecurityEntity):
"""Base alarm control panel entity for integration"""
Expand All @@ -95,6 +99,7 @@ def __init__(self, coordinator: EufySecurityDataUpdateCoordinator, metadata: Met
| AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS
| AlarmControlPanelEntityFeature.ARM_NIGHT
| AlarmControlPanelEntityFeature.ARM_VACATION

)

@property
Expand All @@ -113,6 +118,9 @@ async def _set_guard_mode(self, target_mode: CurrentModeToState):
async def async_alarm_disarm(self, code: str | None = None) -> None:
await self._set_guard_mode(CurrentModeToState.DISARMED)

async def async_alarm_off(self, code: str | None = None) -> None:
await self._set_guard_mode(CurrentModeToState.OFF)

async def async_alarm_arm_home(self, code: str | None = None) -> None:
await self._set_guard_mode(CurrentModeToState.HOME)

Expand Down Expand Up @@ -173,8 +181,8 @@ def state(self):
except ValueError:
pass

if current_mode == KEYPAD_OFF_CODE:
return CurrentModeToStateValue[CurrentModeToState.DISARMED.name].value
#if current_mode == KEYPAD_OFF_CODE:
# return CurrentModeToStateValue[CurrentModeToState.DISARMED.name].value
if current_mode in CUSTOM_CODES:
position = CUSTOM_CODES.index(current_mode)
if position == 0:
Expand Down
12 changes: 10 additions & 2 deletions custom_components/eufy_security/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,15 @@ geofence:
entity:
domain: alarm_control_panel
integration: eufy_security


alarm_off:
name: Turn Alarm off for Alarm Panel
description: Turn Alarm off for Alarm Panel
target:
entity:
domain: alarm_control_panel
integration: eufy_security

schedule:
name: Switch to schedule mode
description: Switch to schedule mode
Expand Down Expand Up @@ -305,4 +313,4 @@ snooze:
example: False
default: False
selector:
boolean:
boolean:

0 comments on commit 55a1c46

Please sign in to comment.