Skip to content

Commit

Permalink
feat(g4doorbell/chime_duration): make chime duration adjustable
Browse files Browse the repository at this point in the history
  • Loading branch information
mohlek committed Mar 21, 2021
1 parent 98c0364 commit b4d13c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions protectdata_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ 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
await session.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(raw_data())
loop.close()
loop.close()
2 changes: 2 additions & 0 deletions pyunifiprotect/unifi_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions pyunifiprotect/unifi_protect_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit b4d13c1

Please sign in to comment.