Skip to content

Commit

Permalink
Add sync module snooze
Browse files Browse the repository at this point in the history
  • Loading branch information
austinc3030 authored Aug 8, 2024
1 parent cd3635d commit 52295e3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 34 deletions.
84 changes: 50 additions & 34 deletions blinkpy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,41 +491,57 @@ async def request_update_config(
return None
return await http_post(blink, url, json=False, data=data)


async def request_camera_snooze(
blink, network, camera_id, product_type="owl", data=None
):
"""
Update camera snooze configuration.
:param blink: Blink instance.
:param network: Sync module network id.
:param camera_id: ID of camera
:param product_type: Camera product type "owl" or "catalina"
:param data: string w/JSON dict of parameters/values to update
"""
if product_type == "catalina":
url = (
f"{blink.urls.base_url}/api/v1/accounts/{blink.account_id}/"
f"networks/{network}/cameras/{camera_id}/snooze"
)
elif product_type == "owl":
url = (
f"{blink.urls.base_url}/api/v1/accounts/{blink.account_id}/"
f"networks/{network}/owls/{camera_id}/snooze"
)
elif product_type == "doorbell":
url = (
f"{blink.urls.base_url}/api/v1/accounts/{blink.account_id}/"
f"networks/{network}/doorbells/{camera_id}/snooze"
)
else:
_LOGGER.info(
"Camera %s with product type %s snooze update not implemented.",
camera_id,
product_type,
)
return None
return await http_post(blink, url, json=False, data=data)
blink, network, camera_id, product_type="owl", data=None
):
"""
Update camera snooze configuration.
:param blink: Blink instance.
:param network: Sync module network id.
:param camera_id: ID of camera
:param product_type: Camera product type "owl" or "catalina"
:param data: string w/JSON dict of parameters/values to update
"""
if product_type == "catalina":
url = (
f"{blink.urls.base_url}/api/v1/accounts/{blink.account_id}/"
f"networks/{network}/cameras/{camera_id}/snooze"
)
elif product_type == "owl":
url = (
f"{blink.urls.base_url}/api/v1/accounts/{blink.account_id}/"
f"networks/{network}/owls/{camera_id}/snooze"
)
elif product_type == "doorbell":
url = (
f"{blink.urls.base_url}/api/v1/accounts/{blink.account_id}/"
f"networks/{network}/doorbells/{camera_id}/snooze"
)
else:
_LOGGER.info(
"Camera %s with product type %s snooze update not implemented.",
camera_id,
product_type,
)
return None
return await http_post(blink, url, json=False, data=data)


async def request_sync_snooze(blink, network, data=None):
"""
Update sync snooze configuration.
:param blink: Blink instance.
:param network: Sync module network id.
:param data: string w/JSON dict of parameters/values to update
"""
url = (
f"{blink.urls.base_url}/api/v1/accounts/{blink.account_id}"
f"/networks/{network}/snooze"
)
return await http_post(blink, url, json=False, data=data)


async def http_get(
Expand Down
25 changes: 25 additions & 0 deletions blinkpy/sync_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import string
import datetime
from json import dumps
import traceback
import asyncio
import aiofiles
Expand Down Expand Up @@ -127,6 +128,30 @@ async def async_arm(self, value):
return await api.request_system_arm(self.blink, self.network_id)
return await api.request_system_disarm(self.blink, self.network_id)

@property
async def snooze_till(self):
"""Return snooze_till status."""
res = await api.request_sync_snooze(
self.sync.blink,
self.network_id,
)
if res is None:
return None
res = res.get("camera", [{}])[0]["snooze_till"]
return res

async def async_snooze(self):
"""Set sync snooze status."""
data = dumps({"snooze_time": 240})
res = await api.request_sync_snooze(
self.sync.blink,
self.network_id,
data=data,
)
if res and res.status == 200:
return await res.json()
return None

async def start(self):
"""Initialize the system."""
_LOGGER.debug("Initializing the sync module")
Expand Down

0 comments on commit 52295e3

Please sign in to comment.