Skip to content

Commit

Permalink
Rename Other and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
cosimomeli committed Jan 25, 2024
1 parent 3a03e86 commit fc8b4aa
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
4 changes: 2 additions & 2 deletions ring_doorbell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from ring_doorbell.generic import RingGeneric
from ring_doorbell.group import RingLightGroup
from ring_doorbell.other import Other
from ring_doorbell.other import RingOther
from ring_doorbell.ring import Ring
from ring_doorbell.stickup_cam import RingStickUpCam

Expand All @@ -26,7 +26,7 @@
"RingStickUpCam",
"RingLightGroup",
"RingDoorBell",
"Other",
"RingOther",
"RingEvent",
"RingError",
"AuthenticationError",
Expand Down
4 changes: 2 additions & 2 deletions ring_doorbell/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
_LOGGER = logging.getLogger(__name__)


class Other(RingGeneric):
class RingOther(RingGeneric):
"""Implementation for Ring Intercom."""

def __init__(self, ring, device_api_id, shared=False):
Expand Down Expand Up @@ -230,7 +230,7 @@ def allowed_users(self):

return None

def open_door(self, user_id = -1):
def open_door(self, user_id=-1):
"""Open the door"""

if self.kind in INTERCOM_KINDS:
Expand Down
4 changes: 2 additions & 2 deletions ring_doorbell/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ring_doorbell.doorbot import RingDoorBell
from ring_doorbell.group import RingLightGroup
from ring_doorbell.listen import RingEventListener, can_listen
from ring_doorbell.other import Other
from ring_doorbell.other import RingOther
from ring_doorbell.stickup_cam import RingStickUpCam

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


Expand Down
14 changes: 9 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def requests_mock_fixture():
mock.put(
"https://api.ring.com/clients_api/doorbots/185036587",
status_code=204,
content=b""
content=b"",
)
mock.get(
"https://api.ring.com/devices/v1/devices/185036587/settings",
Expand All @@ -154,14 +154,18 @@ def requests_mock_fixture():
)
mock.post(
"https://api.ring.com/clients_api/locations/mock-location-id/invitations",
text="ok"
text="ok",
)
mock.delete(
"https://api.ring.com/clients_api/locations/mock-location-id/invitations/123456789",
text="ok"
(
"https://api.ring.com/clients_api/locations/"
"mock-location-id/invitations/123456789"
),
text="ok",
)
requestid = "44529542-3ed7-41da-807e-c170a01bac1d"
mock.put(
"https://api.ring.com/commands/v1/devices/185036587/device_rpc",
text='{"result": {"code": 0}, "id": "44529542-3ed7-41da-807e-c170a01bac1d", "jsonrpc": "2.0"}'
text='{"result": {"code": 0}, "id": "' + requestid + '", "jsonrpc": "2.0"}',
)
yield mock
35 changes: 25 additions & 10 deletions tests/test_other.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The tests for the Ring platform."""


def test_other_attributes(ring):
"""Test the Ring Other class and methods."""
dev = ring.devices()["other"][0]
Expand All @@ -16,18 +17,19 @@ def test_other_attributes(ring):
assert dev.doorbell_volume == 8
assert dev.mic_volume == 11
assert dev.clip_length_max == 60
assert dev.connection_status == 'online'
assert dev.connection_status == "online"
assert len(dev.allowed_users) == 2
assert dev.subscribed == True
assert dev.has_subscription == True
assert dev.unlock_duration == None
assert dev.subscribed is True
assert dev.has_subscription is True
assert dev.unlock_duration is None
assert dev.keep_alive_auto == 45.0

dev.update_health_data()
assert dev.wifi_name == "ring_mock_wifi"
assert dev.wifi_signal_category == "good"
assert dev.wifi_signal_strength != 100


def test_other_controls(ring, requests_mock):
dev = ring.devices()["other"][0]

Expand All @@ -50,27 +52,40 @@ def test_other_controls(ring, requests_mock):
assert history[3].path == "/devices/v1/devices/185036587/settings"
assert history[3].text == '{"keep_alive_settings": {"keep_alive_auto": 32.2}}'


def test_other_invitations(ring, requests_mock):
dev = ring.devices()["other"][0]

dev.invite_access("test@example.com")
history = list(filter(lambda x: x.method == "POST", requests_mock.request_history))
assert history[2].path == "/clients_api/locations/mock-location-id/invitations"
assert history[2].text == '{"invitation": {"doorbot_ids": [185036587], "invited_email": "test@example.com", "group_ids": []}}'
assert history[2].text == (
'{"invitation": {"doorbot_ids": [185036587],'
' "invited_email": "test@example.com", "group_ids": []}}'
)

dev.remove_access(123456789)
history = list(filter(lambda x: x.method == "DELETE", requests_mock.request_history))
assert history[0].path == "/clients_api/locations/mock-location-id/invitations/123456789"
history = list(
filter(lambda x: x.method == "DELETE", requests_mock.request_history)
)
assert (
history[0].path
== "/clients_api/locations/mock-location-id/invitations/123456789"
)


def test_other_open_door(ring, requests_mock):
dev = ring.devices()["other"][0]

import uuid

uuid.uuid4 = lambda: "987654321"

dev.open_door(15)
history = list(filter(lambda x: x.method == "PUT", requests_mock.request_history))
assert history[0].path == "/commands/v1/devices/185036587/device_rpc"
assert history[0].text == ('{"command_name": "device_rpc", "request": '
'{"id": "987654321", "jsonrpc": "2.0", "method": "unlock_door", "params": '
'{"door_id": 0, "user_id": 15}}}')
assert history[0].text == (
'{"command_name": "device_rpc", "request": '
'{"id": "987654321", "jsonrpc": "2.0", "method": "unlock_door", "params": '
'{"door_id": 0, "user_id": 15}}}'
)
1 change: 1 addition & 0 deletions tests/test_ring.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The tests for the Ring platform."""


def test_basic_attributes(ring):
"""Test the Ring class and methods."""
data = ring.devices()
Expand Down

0 comments on commit fc8b4aa

Please sign in to comment.