Skip to content

Commit

Permalink
Merge pull request #157 from natekspencer/dev
Browse files Browse the repository at this point in the history
Add reboot method for cameras
  • Loading branch information
natekspencer authored Apr 26, 2024
2 parents d17a060 + 5d49d02 commit 867553e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vivintpy/devices/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ async def get_direct_rtsp_url(
"""Return the direct rtsp url for this camera, in HD if requested, if any."""
return self.get_rtsp_access_url(RtspUrlType.LOCAL, hd)

async def reboot(self) -> None:
"""Reboot the camera."""
await self.api.reboot_camera(
self.alarm_panel.id, self.id, self.device_type.value
)

async def set_as_doorbell_chime_extender(self, state: bool) -> None:
"""Set use as doorbell chime extender."""
await self.api.set_camera_as_doorbell_chime_extender(
Expand Down
20 changes: 20 additions & 0 deletions vivintpy/vivintskyapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ async def update_panel_software(self, panel_id: int) -> None:
if not await self.__post(f"systems/{panel_id}/system-update"):
raise VivintSkyApiError("Unable to update panel software")

async def reboot_camera(
self, panel_id: int, device_id: int, device_type: str
) -> None:
"""Reboot a camera."""
creds = grpc.ssl_channel_credentials()
assert (cookie := self._get_session_cookie())

async with grpc.aio.secure_channel(GRPC_ENDPOINT, credentials=creds) as channel:
stub: beam_pb2_grpc.BeamStub = beam_pb2_grpc.BeamStub(channel) # type: ignore
response: beam_pb2.RebootCameraResponse = await stub.RebootCamera(
beam_pb2.RebootCameraRequest( # pylint: disable=no-member
panel_id=panel_id,
device_id=device_id,
device_type=device_type,
),
metadata=[("session", cookie.value)],
)

_LOGGER.debug("Response received: %s", str(response))

async def reboot_panel(self, panel_id: int) -> None:
"""Reboot a panel."""
if not await self.__post(f"systems/{panel_id}/reboot-panel"):
Expand Down

0 comments on commit 867553e

Please sign in to comment.