Skip to content

Commit

Permalink
feat: add new reboot service
Browse files Browse the repository at this point in the history
  • Loading branch information
fuatakgun committed Jan 4, 2023
1 parent f9e937f commit edd3555
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions custom_components/eufy_security/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
platform.async_register_entity_service("geofence", {}, "geofence")
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")


class EufySecurityAlarmControlPanel(AlarmControlPanelEntity, EufySecurityEntity):
Expand Down Expand Up @@ -147,6 +148,10 @@ async def chime(self, ringtone: int) -> None:
"""chime on alarm control panel"""
await self.product.chime(ringtone)

async def reboot(self) -> None:
"""reboot"""
await self.product.reboot()

@property
def state(self):
alarm_delayed = get_child_value(self.product.properties, "alarmDelay", 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ async def chime(self, product_type: ProductType, serial_no: str, ringtone: int)
command = product_type.name + "." + command_type.name
await self._send_message_get_response(OutgoingMessage(command_type, command=command, serial_no=serial_no, ringtone=ringtone))

async def reboot(self, product_type: ProductType, serial_no: str) -> None:
"""Process reboot call"""
command_type = OutgoingMessageType.reboot
command = product_type.name + "." + command_type.name
await self._send_message_get_response(OutgoingMessage(command_type, command=command, serial_no=serial_no))

async def snooze(
self, product_type: ProductType, serial_no: str, snooze_time: int, snooze_chime: bool, snooze_motion: bool, snooze_homebase: bool
) -> None:
Expand Down
5 changes: 3 additions & 2 deletions custom_components/eufy_security/eufy_security_api/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class PropertyType(Enum):


class ProductCommand(Enum):
"""Important Product Commands"""
"""Important Product Commands - Product function to description+remote command"""

start_livestream = CommandDescription("Start P2P Stream", "start_livestream")
stop_livestream = CommandDescription("Stop P2P Stream", "stop_livestream")
Expand All @@ -122,4 +122,5 @@ class ProductCommand(Enum):
ptz_360 = CommandDescription("PTZ 360", "pan_and_tilt")
trigger_alarm = CommandDescription("Trigger Alarm")
reset_alarm = CommandDescription("Reset Alarm")
verify_p_i_n = CommandDescription("Verify Pin")
verify_pin = CommandDescription("Verify Pin", "verify_p_i_n")
reboot = CommandDescription("Reboot", "stationReboot")
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class OutgoingMessageType(Enum):
MessageField.PIN.value: MessageField.BIND_AT_RUNTIME,
}
unlock = {MessageField.COMMAND.value: auto(), MessageField.SERIAL_NUMBER.value: MessageField.BIND_AT_RUNTIME}
reboot = {MessageField.COMMAND.value: auto(), MessageField.SERIAL_NUMBER.value: MessageField.BIND_AT_RUNTIME}


class OutgoingMessage:
Expand Down
8 changes: 6 additions & 2 deletions custom_components/eufy_security/eufy_security_api/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ async def _handle_pin_verified(self, event: Event):
@property
def is_camera(self):
"""checks if Product is camera"""
return True if ProductCommand.start_livestream.name in self.commands else False
return True if ProductCommand.start_livestream.value.command in self.commands else False

@property
def is_safe_lock(self):
"""checks if Product is safe lock"""
return True if ProductCommand.verify_p_i_n.name in self.commands else False
return True if ProductCommand.verify_pin.value.command in self.commands else False

def has(self, property_name: str) -> bool:
"""Checks if product has required property"""
Expand All @@ -139,3 +139,7 @@ def __init__(self, api, serial_no: str, properties: dict, metadata: dict, comman
async def chime(self, ringtone: int) -> None:
"""Quick response message to camera"""
await self.api.chime(self.product_type, self.serial_no, ringtone)

async def reboot(self) -> None:
"""Reboot station"""
await self.api.reboot(self.product_type, self.serial_no)
8 changes: 8 additions & 0 deletions custom_components/eufy_security/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ trigger_base_alarm_with_duration:
min: 0
max: 300

reboot:
name: Reboot station
description: Reboot station
target:
entity:
domain: alarm_control_panel
integration: eufy_security

chime:
name: Chime on Base Station
description: Only supported if no doorbell device is registered at the station where the chime is to be performed
Expand Down

0 comments on commit edd3555

Please sign in to comment.