Skip to content

Commit

Permalink
cleaning up per tox
Browse files Browse the repository at this point in the history
  • Loading branch information
abogaard committed Nov 29, 2023
1 parent 76f6e6c commit d9e762b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 43 deletions.
2 changes: 1 addition & 1 deletion ring_doorbell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
)
from ring_doorbell.generic import RingEvent
from ring_doorbell.group import RingLightGroup
from ring_doorbell.other import Other
from ring_doorbell.ring import Ring
from ring_doorbell.stickup_cam import RingStickUpCam
from ring_doorbell.other import Other

__all__ = [
"Ring",
Expand Down
77 changes: 37 additions & 40 deletions ring_doorbell/other.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
# coding: utf-8
# vim:sw=4:ts=4:et:
"""Python Ring Other (Intercom) wrapper."""
import json
import logging
import time
import uuid
import json

from ring_doorbell.generic import RingGeneric

from ring_doorbell.const import (
DOORBELLS_ENDPOINT,
HEALTH_DOORBELL_ENDPOINT,
INTERCOM_ALLOWED_USERS,
INTERCOM_INVITATIONS_DELETE_ENDPOINT,
INTERCOM_INVITATIONS_ENDPOINT,
INTERCOM_KINDS,
INTERCOM_OPEN_ENDPOINT,
OTHER_DOORBELL_VOL_MIN,
OTHER_DOORBELL_VOL_MAX,
MIC_VOL_MIN,
MIC_VOL_MAX,
DOORBELLS_ENDPOINT,
SETTINGS_ENDPOINT,
MSG_VOL_OUTBOUND,
MIC_VOL_MIN,
MSG_GENERIC_FAIL,
MSG_VOL_OUTBOUND,
OTHER_DOORBELL_VOL_MAX,
OTHER_DOORBELL_VOL_MIN,
SETTINGS_ENDPOINT,
VOICE_VOL_MAX,
VOICE_VOL_MIN,
VOICE_VOL_MAX
)
from ring_doorbell.generic import RingGeneric

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -104,18 +102,9 @@ def has_subscription(self):
@property
def unlock_duration(self):
"""Return time unlock switch is held closed"""
json.loads(self._attrs.get("settings").get("intercom_settings").get("config")).get('analog').get('unlock_duration')

#TODO regex swap out on the string below
# @unlock_duration.setter
# def unlock_duration(self, value):

# url = SETTINGS_ENDPOINT.format(self.id)
# #payload = {"intercom_settings":{"config":{"analog":{"unlock_duration":value}}}}
# payload = {"intercom_settings":{"config":"{\"intercom_type\":0,\"number_of_wires\":5,\"autounlock_enabled\":false,\"analog\":{\"unlock_duration\":1000,\"common_audio\":false,\"audio_term_io\":3,\"audio_term_out\":3,\"control_data_unlock1\":\"0x0880\",\"control_type_unlock1\":1,\"control_data_unlock2\":\"0x0000\",\"control_type_unlock2\":0,\"control_data_talk\":\"0x0000\",\"control_type_talk\":0,\"control_data_listen\":\"0x0000\",\"control_type_listen\":0,\"min_edge_count\":0,\"ring_detect\":0,\"off_hk_tm\":0}}"}}
# self._ring.query(url, method="PATCH", json=payload)
# self._ring.update_devices()
# return True
json.loads(
self._attrs.get("settings").get("intercom_settings").get("config")
).get("analog").get("unlock_duration")

@property
def doorbell_volume(self):
Expand All @@ -126,10 +115,16 @@ def doorbell_volume(self):

@doorbell_volume.setter
def doorbell_volume(self, value):
if not ((isinstance(value, int)) and (OTHER_DOORBELL_VOL_MIN <= value <= OTHER_DOORBELL_VOL_MAX)):
_LOGGER.error("%s", MSG_VOL_OUTBOUND.format(OTHER_DOORBELL_VOL_MIN, OTHER_DOORBELL_VOL_MAX))
if not (
(isinstance(value, int))
and (OTHER_DOORBELL_VOL_MIN <= value <= OTHER_DOORBELL_VOL_MAX)
):
_LOGGER.error(
"%s",
MSG_VOL_OUTBOUND.format(OTHER_DOORBELL_VOL_MIN, OTHER_DOORBELL_VOL_MAX),
)
return False

params = {
"doorbot[description]": self.name,
"doorbot[settings][doorbell_volume]": str(value),
Expand All @@ -147,7 +142,6 @@ def keep_alive_auto(self):

@keep_alive_auto.setter
def keep_alive_auto(self, value):

url = SETTINGS_ENDPOINT.format(self.id)
payload = {"keep_alive_settings": {"keep_alive_auto": value}}

Expand All @@ -164,11 +158,10 @@ def mic_volume(self):

@mic_volume.setter
def mic_volume(self, value):

if not ((isinstance(value, int)) and (MIC_VOL_MIN <= value <= MIC_VOL_MAX)):
_LOGGER.error("%s", MSG_VOL_OUTBOUND.format(MIC_VOL_MIN, MIC_VOL_MAX))
return False

url = SETTINGS_ENDPOINT.format(self.id)
payload = {"volume_settings": {"mic_volume": value}}

Expand All @@ -185,11 +178,10 @@ def voice_volume(self):

@voice_volume.setter
def voice_volume(self, value):

if not ((isinstance(value, int)) and (VOICE_VOL_MIN <= value <= VOICE_VOL_MAX)):
_LOGGER.error("%s", MSG_VOL_OUTBOUND.format(VOICE_VOL_MIN, VOICE_VOL_MAX))
return False

url = SETTINGS_ENDPOINT.format(self.id)
payload = {"volume_settings": {"voice_volume": value}}

Expand All @@ -200,23 +192,28 @@ def voice_volume(self, value):
@property
def clip_length_max(self):
# this value sets an effective refractory period on consecutive rigns
# eg if set to default value of 60, rings occuring with 60 seconds of first will not be detected
# eg if set to default value of 60, rings occuring with 60 seconds of
# first will not be detected

url = SETTINGS_ENDPOINT.format(self.id)

return self._ring.query(url, method="GET").json().get('video_settings').get('clip_length_max')

return (
self._ring.query(url, method="GET")
.json()
.get("video_settings")
.get("clip_length_max")
)

@clip_length_max.setter
def clip_length_max(self, value):

url = SETTINGS_ENDPOINT.format(self.id)
payload = {"video_settings": {"clip_length_max": value}}
try:
self._ring.query(url, method="PATCH", json=payload)
self._ring.update_devices()
return True
except Exception as E:
_LOGGER.error("%s", '{}: {}'.format(MSG_GENERIC_FAIL, E))
_LOGGER.error("%s", "{}: {}".format(MSG_GENERIC_FAIL, E))
return False

@property
Expand Down Expand Up @@ -248,17 +245,17 @@ def open_door(self):
if self.kind in INTERCOM_KINDS:
url = INTERCOM_OPEN_ENDPOINT.format(self.id)
request_id = str(uuid.uuid4())
request_timestamp = int(time.time() * 1000)
# request_timestamp = int(time.time() * 1000)
payload = {
"command_name": "device_rpc",
"request": {
"id": request_id,
"jsonrpc": "2.0",
"method": "unlock_door",
"params": {
#"command_timeout": 5,
# "command_timeout": 5,
"door_id": 0,
#"issue_time": request_timestamp,
# "issue_time": request_timestamp,
"user_id": 64658594,
},
},
Expand Down Expand Up @@ -296,4 +293,4 @@ def remove_access(self, user_id):
self._ring.query(url, method="DELETE")
return True

return False
return False
4 changes: 2 additions & 2 deletions ring_doorbell/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from ring_doorbell.generic import RingEvent
from ring_doorbell.group import RingLightGroup
from ring_doorbell.listen import RingEventListener, can_listen
from ring_doorbell.stickup_cam import RingStickUpCam
from ring_doorbell.other import Other
from ring_doorbell.stickup_cam import RingStickUpCam

from .const import (
API_URI,
Expand All @@ -32,7 +32,7 @@
"authorized_doorbots": lambda ring, description: RingDoorBell(
ring, description, shared=True
),
"other": Other
"other": Other,
}


Expand Down

0 comments on commit d9e762b

Please sign in to comment.