From 0055b14d7bcc5a627c582defa99028353a30d34c Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:05:23 +0100 Subject: [PATCH 1/2] Do not refresh devices after calling setters --- ring_doorbell/chime.py | 1 - ring_doorbell/doorbot.py | 5 ----- ring_doorbell/listen/eventlistener.py | 6 +++++- ring_doorbell/other.py | 6 ------ ring_doorbell/stickup_cam.py | 2 -- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/ring_doorbell/chime.py b/ring_doorbell/chime.py index d3762e6..b58a1a2 100644 --- a/ring_doorbell/chime.py +++ b/ring_doorbell/chime.py @@ -75,7 +75,6 @@ async def async_set_volume(self, value: int) -> None: } url = CHIMES_ENDPOINT.format(self.device_api_id) await self._ring.async_query(url, extra_params=params, method="PUT") - await self._ring.async_update_devices() async def async_get_linked_tree(self) -> dict[str, Any]: """Return doorbell data linked to chime.""" diff --git a/ring_doorbell/doorbot.py b/ring_doorbell/doorbot.py index ce1d572..1a753ac 100644 --- a/ring_doorbell/doorbot.py +++ b/ring_doorbell/doorbot.py @@ -208,7 +208,6 @@ async def async_set_existing_doorbell_type(self, value: int) -> None: if self.existing_doorbell_type: url = DOORBELLS_ENDPOINT.format(self.device_api_id) await self._ring.async_query(url, extra_params=params, method="PUT") - await self._ring.async_update_devices() @property def existing_doorbell_type_enabled(self) -> bool | None: @@ -237,7 +236,6 @@ async def async_set_existing_doorbell_type_enabled(self, value: bool) -> None: } url = DOORBELLS_ENDPOINT.format(self.device_api_id) await self._ring.async_query(url, extra_params=params, method="PUT") - await self._ring.async_update_devices() @property def existing_doorbell_type_duration(self) -> int | None: @@ -273,7 +271,6 @@ async def async_set_existing_doorbell_type_duration(self, value: int) -> None: } url = DOORBELLS_ENDPOINT.format(self.device_api_id) await self._ring.async_query(url, extra_params=params, method="PUT") - await self._ring.async_update_devices() async def async_get_last_recording_id(self) -> int | None: """Return the last recording ID.""" @@ -388,7 +385,6 @@ async def async_set_volume(self, value: int) -> None: } url = DOORBELLS_ENDPOINT.format(self.device_api_id) await self._ring.async_query(url, extra_params=params, method="PUT") - await self._ring.async_update_devices() @property def connection_status(self) -> str | None: @@ -450,7 +446,6 @@ async def async_set_motion_detection(self, state: bool) -> None: # noqa: FBT001 payload = {"motion_settings": {"motion_detection_enabled": state}} await self._ring.async_query(url, method="PATCH", json=payload) - await self._ring.async_update_devices() async def generate_webrtc_stream( self, sdp_offer: str, keep_alive_timeout: int | None = 30 diff --git a/ring_doorbell/listen/eventlistener.py b/ring_doorbell/listen/eventlistener.py index 66e0af7..cef0ec0 100644 --- a/ring_doorbell/listen/eventlistener.py +++ b/ring_doorbell/listen/eventlistener.py @@ -65,7 +65,6 @@ def __init__( self._callbacks: dict[int, OnNotificationCallable] = {} self.subscribed = False self.started = False - self._app_id = self._ring.auth.get_hardware_id() self._device_model = self._ring.auth.get_device_model() self._credentials = credentials @@ -166,6 +165,7 @@ async def start( timeout: int = 10, ) -> bool: """Start the listener.""" + _logger.debug("Starting event listener") if not self._receiver: fcm_config = FcmRegisterConfig( FCM_PROJECT_ID, FCM_APP_ID, FCM_API_KEY, FCM_RING_SENDER_ID @@ -196,6 +196,7 @@ async def start( self.session_refresh_task = asyncio.create_task( self._periodic_session_refresh() ) + _logger.debug("Started event listener") return self.started async def _periodic_session_refresh(self) -> None: @@ -276,8 +277,11 @@ def _on_notification( ring_event = self._get_ring_event(msg_data) if ring_event: + _logger.debug("Event received %s", ring_event) for callback in self._callbacks.values(): callback(ring_event) + else: + _logger.debug("Unknown event received %s", msg_data) def _get_ring_event(self, msg_data: dict) -> RingEvent | None: if (android_config_str := msg_data.get("android_config")) is None or ( diff --git a/ring_doorbell/other.py b/ring_doorbell/other.py index 3d63c8e..eab0ae8 100644 --- a/ring_doorbell/other.py +++ b/ring_doorbell/other.py @@ -137,7 +137,6 @@ async def async_set_doorbell_volume(self, value: int) -> None: } url = DOORBELLS_ENDPOINT.format(self.device_api_id) await self._ring.async_query(url, extra_params=params, method="PUT") - await self._ring.async_update_devices() @property def keep_alive_auto(self) -> float | None: @@ -152,7 +151,6 @@ async def async_set_keep_alive_auto(self, value: float) -> None: payload = {"keep_alive_settings": {"keep_alive_auto": value}} await self._ring.async_query(url, method="PATCH", json=payload) - await self._ring.async_update_devices() @property def mic_volume(self) -> int | None: @@ -170,7 +168,6 @@ async def async_set_mic_volume(self, value: int) -> None: payload = {"volume_settings": {"mic_volume": value}} await self._ring.async_query(url, method="PATCH", json=payload) - await self._ring.async_update_devices() @property def voice_volume(self) -> int | None: @@ -188,7 +185,6 @@ async def async_set_voice_volume(self, value: int) -> None: payload = {"volume_settings": {"voice_volume": value}} await self._ring.async_query(url, method="PATCH", json=payload) - await self._ring.async_update_devices() async def async_get_clip_length_max(self) -> int | None: """Get the Maximum clip length.""" @@ -206,7 +202,6 @@ async def async_set_clip_length_max(self, value: int) -> None: url = SETTINGS_ENDPOINT.format(self.device_api_id) payload = {"video_settings": {"clip_length_max": value}} await self._ring.async_query(url, method="PATCH", json=payload) - await self._ring.async_update_devices() @property def connection_status(self) -> str | None: @@ -246,7 +241,6 @@ async def async_open_door(self, user_id: int = -1) -> bool: } resp = await self._ring.async_query(url, method="PUT", json=payload) response = resp.json() - await self._ring.async_update_devices() if response.get("result", {}).get("code", -1) == 0: return True diff --git a/ring_doorbell/stickup_cam.py b/ring_doorbell/stickup_cam.py index 68ccb5e..0db5dae 100644 --- a/ring_doorbell/stickup_cam.py +++ b/ring_doorbell/stickup_cam.py @@ -150,7 +150,6 @@ async def async_set_lights(self, state: str) -> None: url = LIGHTS_ENDPOINT.format(self.device_api_id, state) await self._ring.async_query(url, method="PUT") - await self._ring.async_update_devices() @property def siren(self) -> int: @@ -177,7 +176,6 @@ async def async_set_siren(self, duration: int) -> None: params = {} url = SIREN_ENDPOINT.format(self.device_api_id, state) await self._ring.async_query(url, extra_params=params, method="PUT") - await self._ring.async_update_devices() DEPRECATED_API_PROPERTY_SETTERS: ClassVar = { *RingDoorBell.DEPRECATED_API_PROPERTY_SETTERS, From 83da313ce1d9b336b31acedabcf01d20f3115711 Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:11:47 +0100 Subject: [PATCH 2/2] Refresh devices after cli motion_detection update --- ring_doorbell/cli.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ring_doorbell/cli.py b/ring_doorbell/cli.py index c02160d..4144eca 100644 --- a/ring_doorbell/cli.py +++ b/ring_doorbell/cli.py @@ -378,6 +378,7 @@ async def motion_detection(ctx, ring: Ring, device_name, turn_on, turn_off): return None await device.async_set_motion_detection(turn_on if turn_on else False) + await ring.async_update_devices() state = "on" if device.motion_detection else "off" echo(f"{device!s} motion detection set to {state}") return None