diff --git a/protectdata_function.py b/protectdata_function.py index 9c9e587b..d0365c72 100644 --- a/protectdata_function.py +++ b/protectdata_function.py @@ -22,7 +22,7 @@ async def raw_data(): ) await unifiprotect.update(True) - data = await unifiprotect.set_doorbell_chime(CAM_ID, True) + data = await unifiprotect.set_doorbell_chime_duration(CAM_ID, 300) print(data) # Close the Session @@ -30,4 +30,4 @@ async def raw_data(): loop = asyncio.get_event_loop() loop.run_until_complete(raw_data()) -loop.close() \ No newline at end of file +loop.close() diff --git a/pyunifiprotect/unifi_data.py b/pyunifiprotect/unifi_data.py index 21a57ed9..3e72843d 100644 --- a/pyunifiprotect/unifi_data.py +++ b/pyunifiprotect/unifi_data.py @@ -305,6 +305,7 @@ def process_camera(server_id, host, camera, include_events): # Doorbell Chime has_chime = featureflags.get("hasChime") chime_enabled = camera.get("chimeDuration") not in CHIME_DISABLED + chime_duration = camera.get("chimeDuration") # Get Microphone Volume mic_volume = camera.get("micVolume") or 0 # Get SmartDetect capabilities @@ -358,6 +359,7 @@ def process_camera(server_id, host, camera, include_events): "wdr": wdr, "has_chime": has_chime, "chime_enabled": chime_enabled, + "chime_duration": chime_duration, } if server_id is not None: diff --git a/pyunifiprotect/unifi_protect_server.py b/pyunifiprotect/unifi_protect_server.py index 9cd0d4ec..c009442e 100644 --- a/pyunifiprotect/unifi_protect_server.py +++ b/pyunifiprotect/unifi_protect_server.py @@ -688,15 +688,18 @@ async def set_camera_hdr_mode(self, camera_id: str, mode: bool) -> bool: % (response.status, response.reason) ) - async def set_doorbell_chime(self, camera_id: str, mode: bool) -> bool: - """Sets the Doorbells Mechanical/Digital Chime to On or Off. - Valid inputs for mode: False and True + async def set_doorbell_chime_duration(self, camera_id: str, duration: int) -> bool: + """Sets the Doorbells chime duration. + Valid inputs for duration: 0 to 10000 This is not the ideal solution, but the only possible. """ await self.ensure_authenticated() - chime_duration = 300 if mode else 0 + if duration < 0: + chime_duration = 0 + if duration > 10000: + chime_duration = 10000 cam_uri = f"{self._base_url}/{self.api_path}/cameras/{camera_id}" data = {"chimeDuration": chime_duration}