python-ring 0.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_ring/__init__.py +44 -0
- python_ring/auth.py +283 -0
- python_ring/chime.py +135 -0
- python_ring/cli.py +977 -0
- python_ring/const.py +289 -0
- python_ring/doorbot.py +551 -0
- python_ring/event.py +46 -0
- python_ring/exceptions.py +17 -0
- python_ring/generic.py +267 -0
- python_ring/group.py +145 -0
- python_ring/listen/__init__.py +13 -0
- python_ring/listen/eventlistener.py +449 -0
- python_ring/listen/listenerconfig.py +21 -0
- python_ring/other.py +298 -0
- python_ring/py.typed +0 -0
- python_ring/ring.py +476 -0
- python_ring/stickup_cam.py +253 -0
- python_ring/util.py +157 -0
- python_ring/webrtcdevice.py +168 -0
- python_ring/webrtcstream.py +433 -0
- python_ring-0.10.0.dist-info/METADATA +103 -0
- python_ring-0.10.0.dist-info/RECORD +25 -0
- python_ring-0.10.0.dist-info/WHEEL +4 -0
- python_ring-0.10.0.dist-info/entry_points.txt +2 -0
- python_ring-0.10.0.dist-info/licenses/LICENSE +165 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
"""Python Ring Doorbell RTC Stream handler.
|
|
2
|
+
|
|
3
|
+
This module is currently experimental and requires a webrtc enabled client
|
|
4
|
+
to function.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
import contextlib
|
|
11
|
+
import logging
|
|
12
|
+
import re
|
|
13
|
+
import ssl
|
|
14
|
+
import time
|
|
15
|
+
import uuid
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from json import dumps as json_dumps
|
|
18
|
+
from json import loads as json_loads
|
|
19
|
+
from typing import TYPE_CHECKING, Any, Callable
|
|
20
|
+
|
|
21
|
+
from async_timeout import timeout as asyncio_timeout
|
|
22
|
+
from typing_extensions import TypeAlias
|
|
23
|
+
from websockets.asyncio.client import connect
|
|
24
|
+
|
|
25
|
+
from python_ring.const import (
|
|
26
|
+
APP_API_URI,
|
|
27
|
+
RTC_STREAMING_TICKET_ENDPOINT,
|
|
28
|
+
RTC_STREAMING_WEB_SOCKET_ENDPOINT,
|
|
29
|
+
)
|
|
30
|
+
from python_ring.exceptions import RingError
|
|
31
|
+
|
|
32
|
+
if TYPE_CHECKING:
|
|
33
|
+
from collections.abc import Coroutine
|
|
34
|
+
|
|
35
|
+
from websockets.asyncio.client import ClientConnection
|
|
36
|
+
|
|
37
|
+
from .ring import Ring
|
|
38
|
+
|
|
39
|
+
_LOGGER = logging.getLogger(__name__)
|
|
40
|
+
|
|
41
|
+
SDP_ANSWER_TIMEOUT = 1
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass
|
|
45
|
+
class RingWebRtcMessage:
|
|
46
|
+
"""Class for async on_message callback."""
|
|
47
|
+
|
|
48
|
+
answer: str | None = None
|
|
49
|
+
candidate: str | None = None
|
|
50
|
+
sdp_m_line_index: int | None = None
|
|
51
|
+
error_code: str | None = None
|
|
52
|
+
error_message: str | None = None
|
|
53
|
+
session_id: str | None = None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
RingWebRtcMessageCallback: TypeAlias = Callable[[RingWebRtcMessage], None]
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class RingWebRtcStream:
|
|
60
|
+
"""Class to handle a Web RTC Stream."""
|
|
61
|
+
|
|
62
|
+
PING_TIME_SECONDS = 5
|
|
63
|
+
|
|
64
|
+
def __init__(
|
|
65
|
+
self,
|
|
66
|
+
ring: Ring,
|
|
67
|
+
device_api_id: int,
|
|
68
|
+
*,
|
|
69
|
+
keep_alive_timeout: int | None = 30,
|
|
70
|
+
on_message_callback: RingWebRtcMessageCallback | None = None,
|
|
71
|
+
on_close_callback: Callable[[], Coroutine[Any, Any, None]] | None = None,
|
|
72
|
+
) -> None:
|
|
73
|
+
"""Initialise the class."""
|
|
74
|
+
self._ring = ring
|
|
75
|
+
self.device_api_id = device_api_id
|
|
76
|
+
self.sdp_offer: str | None = None
|
|
77
|
+
self.sdp: str | None = None
|
|
78
|
+
self.websocket: ClientConnection | None = None
|
|
79
|
+
self.is_alive = True
|
|
80
|
+
self.ping_task: asyncio.Task | None = None
|
|
81
|
+
self.read_task: asyncio.Task | None = None
|
|
82
|
+
self._close_task: asyncio.Task | None = None
|
|
83
|
+
self.ice_candidates: dict[int, list[str]] = {0: [], 1: [], 2: [], 3: []}
|
|
84
|
+
self.collect_ice_candidates = False
|
|
85
|
+
self.ssl_context: ssl.SSLContext | None = None
|
|
86
|
+
self._sdp_answer_event = asyncio.Event()
|
|
87
|
+
self._keep_alive_timeout = keep_alive_timeout
|
|
88
|
+
self._last_keep_alive: float | None = None
|
|
89
|
+
self._on_close_callback = on_close_callback
|
|
90
|
+
self._on_message_callback = on_message_callback
|
|
91
|
+
self.session_id: str | None = None
|
|
92
|
+
self._offered_event = asyncio.Event()
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
def get_sdp_session_id(sdp_offer: str) -> str | None:
|
|
96
|
+
"""Return the sdp session id from the offer."""
|
|
97
|
+
try:
|
|
98
|
+
lines = sdp_offer.split("\n")
|
|
99
|
+
for line in lines:
|
|
100
|
+
if line[0] == "o":
|
|
101
|
+
origin = line.split("=")[1]
|
|
102
|
+
break
|
|
103
|
+
return origin.split(" ")[1]
|
|
104
|
+
except Exception:
|
|
105
|
+
_LOGGER.exception("Error getting session id from offer: %s", sdp_offer)
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
async def generate(self, sdp_offer: str) -> str | None:
|
|
109
|
+
"""Generate the RTC stream."""
|
|
110
|
+
self.sdp_offer = sdp_offer
|
|
111
|
+
await self._generate(sdp_offer)
|
|
112
|
+
|
|
113
|
+
if self._on_message_callback:
|
|
114
|
+
return None
|
|
115
|
+
|
|
116
|
+
if self.collect_ice_candidates:
|
|
117
|
+
_LOGGER.debug(
|
|
118
|
+
"Waiting %s seconds for ice candidates",
|
|
119
|
+
SDP_ANSWER_TIMEOUT,
|
|
120
|
+
)
|
|
121
|
+
await asyncio.sleep(SDP_ANSWER_TIMEOUT)
|
|
122
|
+
self.insert_ice_candidates()
|
|
123
|
+
else:
|
|
124
|
+
async with asyncio_timeout(SDP_ANSWER_TIMEOUT):
|
|
125
|
+
await self._sdp_answer_event.wait()
|
|
126
|
+
|
|
127
|
+
if not self.sdp:
|
|
128
|
+
exmsg = "Unable to generate RTC stream in time"
|
|
129
|
+
await self.close()
|
|
130
|
+
raise RingError(exmsg)
|
|
131
|
+
_LOGGER.debug("Returning SDP answer: %s", self.sdp)
|
|
132
|
+
return self.sdp
|
|
133
|
+
|
|
134
|
+
async def _generate(self, sdp_offer: str) -> None:
|
|
135
|
+
"""Generate the RTC stream."""
|
|
136
|
+
try:
|
|
137
|
+
_LOGGER.debug("Generating stream with sdp offer: %s", sdp_offer)
|
|
138
|
+
req = await self._ring.async_query(
|
|
139
|
+
RTC_STREAMING_TICKET_ENDPOINT,
|
|
140
|
+
method="POST",
|
|
141
|
+
base_uri=APP_API_URI,
|
|
142
|
+
)
|
|
143
|
+
ticket = req.json()["ticket"]
|
|
144
|
+
|
|
145
|
+
_LOGGER.debug(
|
|
146
|
+
"Received RTC streaming ticket %s from endpoint, creating websocket",
|
|
147
|
+
ticket,
|
|
148
|
+
)
|
|
149
|
+
ws_uri = RTC_STREAMING_WEB_SOCKET_ENDPOINT.format(uuid.uuid4(), ticket)
|
|
150
|
+
loop = asyncio.get_running_loop()
|
|
151
|
+
|
|
152
|
+
if not self.ssl_context:
|
|
153
|
+
# create_default_context() blocks the event loop
|
|
154
|
+
self.ssl_context = await loop.run_in_executor(
|
|
155
|
+
None, ssl.create_default_context
|
|
156
|
+
)
|
|
157
|
+
self.websocket = await connect(
|
|
158
|
+
ws_uri,
|
|
159
|
+
user_agent_header="android:com.ringapp",
|
|
160
|
+
ssl=self.ssl_context,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
self.dialog_id = str(uuid.uuid4())
|
|
164
|
+
offer_msg = {
|
|
165
|
+
"method": "live_view",
|
|
166
|
+
"dialog_id": self.dialog_id,
|
|
167
|
+
"body": {
|
|
168
|
+
"doorbot_id": self.device_api_id,
|
|
169
|
+
"stream_options": {"audio_enabled": True, "video_enabled": True},
|
|
170
|
+
"sdp": sdp_offer,
|
|
171
|
+
"type": "offer",
|
|
172
|
+
},
|
|
173
|
+
}
|
|
174
|
+
_LOGGER.debug(
|
|
175
|
+
"Connected to RTC streaming websocket, sending live_view offer msg: %s",
|
|
176
|
+
offer_msg,
|
|
177
|
+
)
|
|
178
|
+
_LOGGER.debug("Starting reader task")
|
|
179
|
+
self.read_task = asyncio.create_task(self.reader())
|
|
180
|
+
|
|
181
|
+
await self.websocket.send(json_dumps(offer_msg))
|
|
182
|
+
|
|
183
|
+
self._offered_event.set()
|
|
184
|
+
|
|
185
|
+
except Exception as ex:
|
|
186
|
+
exmsg = "Error generating RTC stream"
|
|
187
|
+
raise RingError(exmsg, ex) from ex
|
|
188
|
+
|
|
189
|
+
async def _activate(self) -> None:
|
|
190
|
+
if TYPE_CHECKING:
|
|
191
|
+
assert self.websocket
|
|
192
|
+
activate_msg = self.get_session_message("activate_session", {})
|
|
193
|
+
_LOGGER.debug("Sending activate_session message: %s", activate_msg)
|
|
194
|
+
await self.websocket.send(json_dumps(activate_msg))
|
|
195
|
+
|
|
196
|
+
self._last_keep_alive = time.time()
|
|
197
|
+
self.ping_task = asyncio.create_task(self.pinger())
|
|
198
|
+
|
|
199
|
+
async def on_ice_candidate(self, candidate: str, m_line_index: int) -> None:
|
|
200
|
+
"""Send an ICE candidate."""
|
|
201
|
+
async with asyncio_timeout(10):
|
|
202
|
+
await self._offered_event.wait()
|
|
203
|
+
|
|
204
|
+
assert self.websocket # noqa: S101
|
|
205
|
+
|
|
206
|
+
body = {
|
|
207
|
+
"doorbot_id": self.device_api_id,
|
|
208
|
+
"ice": candidate,
|
|
209
|
+
"mlineindex": m_line_index,
|
|
210
|
+
}
|
|
211
|
+
# Set the session if it's been created.
|
|
212
|
+
if self.session_id:
|
|
213
|
+
body["session_id"] = self.session_id
|
|
214
|
+
ice_msg = {
|
|
215
|
+
"method": "ice",
|
|
216
|
+
"dialog_id": self.dialog_id,
|
|
217
|
+
"body": body,
|
|
218
|
+
}
|
|
219
|
+
_LOGGER.debug(
|
|
220
|
+
"Sending ice candidate for mlineindex %s: %s", m_line_index, candidate
|
|
221
|
+
)
|
|
222
|
+
await self.websocket.send(json_dumps(ice_msg))
|
|
223
|
+
|
|
224
|
+
async def keep_alive(self) -> None:
|
|
225
|
+
"""Keep alive the rtc stream."""
|
|
226
|
+
self._last_keep_alive = time.time()
|
|
227
|
+
|
|
228
|
+
def get_session_message(self, method: str, body: dict[str, Any]) -> dict[str, Any]:
|
|
229
|
+
"""Get a message to send to the session."""
|
|
230
|
+
return {
|
|
231
|
+
"method": method,
|
|
232
|
+
"dialog_id": self.dialog_id,
|
|
233
|
+
"body": {
|
|
234
|
+
**body,
|
|
235
|
+
"doorbot_id": self.device_api_id,
|
|
236
|
+
"session_id": self.session_id,
|
|
237
|
+
},
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async def reader(self) -> None:
|
|
241
|
+
"""Read messages from the websocket."""
|
|
242
|
+
if TYPE_CHECKING:
|
|
243
|
+
assert self.websocket
|
|
244
|
+
async for message in self.websocket:
|
|
245
|
+
if TYPE_CHECKING:
|
|
246
|
+
assert isinstance(message, str)
|
|
247
|
+
await self.handle_message(message)
|
|
248
|
+
|
|
249
|
+
async def pinger(self) -> None:
|
|
250
|
+
"""Ping to keep the session alive."""
|
|
251
|
+
if TYPE_CHECKING:
|
|
252
|
+
assert self.websocket
|
|
253
|
+
assert self._last_keep_alive
|
|
254
|
+
|
|
255
|
+
while self.is_alive and (
|
|
256
|
+
self._keep_alive_timeout is None
|
|
257
|
+
or (time.time() - self._last_keep_alive) <= self._keep_alive_timeout
|
|
258
|
+
):
|
|
259
|
+
await asyncio.sleep(self.PING_TIME_SECONDS)
|
|
260
|
+
ping = self.get_session_message("ping", {})
|
|
261
|
+
await self.websocket.send(json_dumps(ping))
|
|
262
|
+
|
|
263
|
+
def handle_ice_message(self, message: dict) -> None:
|
|
264
|
+
"""Handle an ice candidate message."""
|
|
265
|
+
ice_candidate = message["body"]["ice"]
|
|
266
|
+
multi_line_index = message["body"]["mlineindex"]
|
|
267
|
+
if self._on_message_callback:
|
|
268
|
+
ice_message = RingWebRtcMessage(
|
|
269
|
+
candidate=ice_candidate, sdp_m_line_index=multi_line_index
|
|
270
|
+
)
|
|
271
|
+
self._on_message_callback(ice_message)
|
|
272
|
+
elif self.collect_ice_candidates:
|
|
273
|
+
_LOGGER.debug(
|
|
274
|
+
"Ice candidate received, multi_line_index: %s candidate: %s",
|
|
275
|
+
multi_line_index,
|
|
276
|
+
ice_candidate,
|
|
277
|
+
)
|
|
278
|
+
self.ice_candidates[int(multi_line_index)].append(ice_candidate)
|
|
279
|
+
|
|
280
|
+
async def handle_answer_message(self, message: dict) -> None:
|
|
281
|
+
"""Handle an sdp answer message."""
|
|
282
|
+
sdp = message["body"]["sdp"]
|
|
283
|
+
_LOGGER.debug("SDP answer received: %s", sdp)
|
|
284
|
+
self.sdp = sdp
|
|
285
|
+
self.force_correct_sdp_answer()
|
|
286
|
+
self._sdp_answer_event.set()
|
|
287
|
+
|
|
288
|
+
if self._on_message_callback:
|
|
289
|
+
answer_message = RingWebRtcMessage(answer=self.sdp)
|
|
290
|
+
self._on_message_callback(answer_message)
|
|
291
|
+
|
|
292
|
+
await self._activate()
|
|
293
|
+
|
|
294
|
+
async def handle_close_message(self, message: dict) -> None:
|
|
295
|
+
"""Handle an sdp answer message."""
|
|
296
|
+
reason = message["body"]["reason"]
|
|
297
|
+
reason_code = reason["code"]
|
|
298
|
+
reason_message = reason["text"]
|
|
299
|
+
_LOGGER.debug("Close message received: %s", str(reason))
|
|
300
|
+
self.is_alive = False
|
|
301
|
+
await self._close(closed_by_self=True)
|
|
302
|
+
if self._on_message_callback:
|
|
303
|
+
error_message = RingWebRtcMessage(
|
|
304
|
+
error_code=reason_code, error_message=reason_message
|
|
305
|
+
)
|
|
306
|
+
self._on_message_callback(error_message)
|
|
307
|
+
|
|
308
|
+
def force_correct_sdp_answer(self) -> None:
|
|
309
|
+
"""Force the sdp response to have the valid answer.
|
|
310
|
+
|
|
311
|
+
The Ring WebRTC Stream responses to certain offers do not
|
|
312
|
+
follow the spec defined in https://www.ietf.org/rfc/rfc3264.txt
|
|
313
|
+
An offer of recvonly must be answered with sendonly or inactive.
|
|
314
|
+
"""
|
|
315
|
+
_LOGGER.debug("Attempt to fix sdp answer...")
|
|
316
|
+
if isinstance(self.sdp, str) and isinstance(self.sdp_offer, str):
|
|
317
|
+
sdp_kinds = ["audio", "video", "application"]
|
|
318
|
+
sdp_directions = ["sendrecv", "sendonly", "recvonly", "inactive"]
|
|
319
|
+
sdp_pattern = (
|
|
320
|
+
"m=(?P<kind>{})(.|\n)+?a=(?P<direction>{})(\r|\n|\r\n)".format(
|
|
321
|
+
"|".join(sdp_kinds), "|".join(sdp_directions)
|
|
322
|
+
)
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
sdp_direction_offers = re.finditer(sdp_pattern, self.sdp_offer)
|
|
326
|
+
sdp_answers = re.finditer(sdp_pattern, self.sdp)
|
|
327
|
+
|
|
328
|
+
for offer in sdp_direction_offers:
|
|
329
|
+
for answer in sdp_answers:
|
|
330
|
+
if (
|
|
331
|
+
offer.group("kind") == answer.group("kind")
|
|
332
|
+
and offer.group("direction") == "recvonly"
|
|
333
|
+
and answer.group("direction") == "sendrecv"
|
|
334
|
+
):
|
|
335
|
+
correct_answer = re.sub(
|
|
336
|
+
"a=sendrecv", "a=sendonly", answer.group(0)
|
|
337
|
+
)
|
|
338
|
+
_LOGGER.debug("Replacing answer with: %s", str(correct_answer))
|
|
339
|
+
self.sdp = self.sdp.replace(answer.group(0), correct_answer)
|
|
340
|
+
|
|
341
|
+
def insert_ice_candidates(self) -> None:
|
|
342
|
+
"""Insert an ice candidate into the sdp answer.
|
|
343
|
+
|
|
344
|
+
In 2023 the ring api did not return the ice servers in the sdp answer
|
|
345
|
+
and they had to be added as they were received on the web socket.
|
|
346
|
+
As of Sep 2024 they are coming back with the initial sdp answer.
|
|
347
|
+
"""
|
|
348
|
+
if TYPE_CHECKING:
|
|
349
|
+
assert self.sdp
|
|
350
|
+
_LOGGER.debug("Inserting ICE candidates into sdp answer")
|
|
351
|
+
self.collect_ice_candidates = False
|
|
352
|
+
for line_index, candidates in self.ice_candidates.items():
|
|
353
|
+
if not candidates:
|
|
354
|
+
continue
|
|
355
|
+
candidates_dict = {
|
|
356
|
+
int(candidate[10:12]): f"a={candidate}\r\n" for candidate in candidates
|
|
357
|
+
}
|
|
358
|
+
candidates_text = ("").join(dict(sorted(candidates_dict.items())).values())
|
|
359
|
+
multi_text = f"a=mid:{line_index}"
|
|
360
|
+
self.sdp = self.sdp.replace(multi_text, candidates_text + multi_text)
|
|
361
|
+
|
|
362
|
+
def sync_close(self) -> None:
|
|
363
|
+
"""Close a WebRTC session."""
|
|
364
|
+
if self.is_alive and not self._close_task:
|
|
365
|
+
self._close_task = asyncio.create_task(self.close())
|
|
366
|
+
|
|
367
|
+
async def close(self) -> None:
|
|
368
|
+
"""Close the rtc stream."""
|
|
369
|
+
_LOGGER.debug("Closing the RTC Stream")
|
|
370
|
+
await self._close(closed_by_self=False)
|
|
371
|
+
self._close_task = None
|
|
372
|
+
|
|
373
|
+
async def _close(self, *, closed_by_self: bool) -> None:
|
|
374
|
+
"""Close the stream."""
|
|
375
|
+
self.session_id = None
|
|
376
|
+
if closed_by_self and (close_cb := self._on_close_callback):
|
|
377
|
+
self._on_close_callback = None
|
|
378
|
+
await close_cb()
|
|
379
|
+
self.is_alive = False
|
|
380
|
+
if ping_task := self.ping_task:
|
|
381
|
+
self.ping_task = None
|
|
382
|
+
if not ping_task.done():
|
|
383
|
+
ping_task.cancel()
|
|
384
|
+
with contextlib.suppress(asyncio.CancelledError):
|
|
385
|
+
await ping_task
|
|
386
|
+
if websocket := self.websocket:
|
|
387
|
+
self.websocket = None
|
|
388
|
+
await websocket.close()
|
|
389
|
+
if read_task := self.read_task:
|
|
390
|
+
self.read_task = None
|
|
391
|
+
# When Ring ends the session, _close() runs inside the reader
|
|
392
|
+
# task itself; it exits on its own once the websocket is closed.
|
|
393
|
+
if not read_task.done() and read_task is not asyncio.current_task():
|
|
394
|
+
await read_task
|
|
395
|
+
|
|
396
|
+
async def handle_message(self, message_str: str) -> None: # noqa: C901, PLR0912
|
|
397
|
+
"""Handle a message from the web socket."""
|
|
398
|
+
if TYPE_CHECKING:
|
|
399
|
+
assert self.websocket
|
|
400
|
+
message = json_loads(message_str)
|
|
401
|
+
method = message["method"]
|
|
402
|
+
if method == "ice":
|
|
403
|
+
self.handle_ice_message(message)
|
|
404
|
+
elif method == "sdp":
|
|
405
|
+
await self.handle_answer_message(message)
|
|
406
|
+
elif method == "notification":
|
|
407
|
+
text = message["body"]["text"]
|
|
408
|
+
if text == "camera_connected":
|
|
409
|
+
_LOGGER.debug("Notification received: %s", text)
|
|
410
|
+
camera_options = self.get_session_message(
|
|
411
|
+
"camera_options", {"stealth_mode": False}
|
|
412
|
+
)
|
|
413
|
+
_LOGGER.debug("Sending camera options: %s", camera_options)
|
|
414
|
+
await self.websocket.send(json_dumps(camera_options))
|
|
415
|
+
else:
|
|
416
|
+
_LOGGER.debug("Received notification: %s", message)
|
|
417
|
+
elif method == "session_created":
|
|
418
|
+
self.session_id = message["body"]["session_id"]
|
|
419
|
+
if TYPE_CHECKING:
|
|
420
|
+
assert self.session_id
|
|
421
|
+
_LOGGER.debug(
|
|
422
|
+
"Session created: %s___%s", self.session_id[:16], self.session_id[-16:]
|
|
423
|
+
)
|
|
424
|
+
elif method == "close":
|
|
425
|
+
await self.handle_close_message(message)
|
|
426
|
+
elif method == "pong":
|
|
427
|
+
_LOGGER.debug("Pong message received")
|
|
428
|
+
elif method == "camera_started":
|
|
429
|
+
_LOGGER.debug("camera_started message received")
|
|
430
|
+
elif method == "camera_options":
|
|
431
|
+
_LOGGER.debug("camera_options message received: %s", message["body"])
|
|
432
|
+
else:
|
|
433
|
+
_LOGGER.debug("Unknown message received with method: %s", method)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: python-ring
|
|
3
|
+
Version: 0.10.0
|
|
4
|
+
Summary: Python library for Ring doorbells, cameras, chimes and intercoms
|
|
5
|
+
Project-URL: homepage, https://github.com/cyberjunky/python-ring
|
|
6
|
+
Project-URL: repository, https://github.com/cyberjunky/python-ring
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/cyberjunky/python-ring/issues
|
|
8
|
+
Author: Ron Klinkien, python-ring-doorbell developers
|
|
9
|
+
License: LGPL-3.0-or-later
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: camera,door bell,home automation,ring
|
|
12
|
+
Classifier: Environment :: Other Environment
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Home Automation
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.11.0
|
|
24
|
+
Requires-Dist: aiofiles>=23
|
|
25
|
+
Requires-Dist: aiohttp>=3.14
|
|
26
|
+
Requires-Dist: async-timeout>=3.0.0
|
|
27
|
+
Requires-Dist: asyncclick>=8.1.7.1
|
|
28
|
+
Requires-Dist: firebase-messaging>=0.4.0
|
|
29
|
+
Requires-Dist: oauthlib<5,>=4.0.1
|
|
30
|
+
Requires-Dist: pytz>=2022.0
|
|
31
|
+
Requires-Dist: typing-extensions<5.0,>=4.12.2
|
|
32
|
+
Requires-Dist: websockets>=13.0.0
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# python-ring
|
|
36
|
+
|
|
37
|
+
Python library for Ring doorbells, cameras, chimes and intercoms.
|
|
38
|
+
|
|
39
|
+
It's a maintained continuation of
|
|
40
|
+
[python-ring-doorbell](https://github.com/python-ring-doorbell/python-ring-doorbell),
|
|
41
|
+
which hasn't had a release since February 2026. It adds the newer Ring devices,
|
|
42
|
+
fixes for the event listener and WebRTC streams, and a few new features. See
|
|
43
|
+
[CHANGELOG.md](CHANGELOG.md).
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
pip install python-ring
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The import name is `python_ring`:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import asyncio
|
|
55
|
+
import getpass
|
|
56
|
+
|
|
57
|
+
from python_ring import Auth, Requires2FAError, Ring
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
async def main() -> None:
|
|
61
|
+
auth = Auth("MyProject/1.0")
|
|
62
|
+
username = input("Username: ")
|
|
63
|
+
password = getpass.getpass("Password: ")
|
|
64
|
+
try:
|
|
65
|
+
await auth.async_fetch_token(username, password)
|
|
66
|
+
except Requires2FAError:
|
|
67
|
+
await auth.async_fetch_token(username, password, input("2FA code: "))
|
|
68
|
+
|
|
69
|
+
ring = Ring(auth)
|
|
70
|
+
await ring.async_update_data()
|
|
71
|
+
for device in ring.devices().all_devices:
|
|
72
|
+
print(device.name, device.model)
|
|
73
|
+
await auth.async_close()
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
asyncio.run(main())
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
There's also a command line tool, `python-ring`. Run `python-ring --help` to
|
|
80
|
+
see what it can do.
|
|
81
|
+
|
|
82
|
+
## Home Assistant
|
|
83
|
+
|
|
84
|
+
A custom Ring integration that uses this library is available at
|
|
85
|
+
[cyberjunky/home-assistant-ring](https://github.com/cyberjunky/home-assistant-ring).
|
|
86
|
+
|
|
87
|
+
## Development
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
uv sync
|
|
91
|
+
uv run pytest
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
On Windows, add `--force-enable-socket` to the pytest command. The asyncio
|
|
95
|
+
event loop there needs a local socket.
|
|
96
|
+
|
|
97
|
+
## License and credits
|
|
98
|
+
|
|
99
|
+
LGPL-3.0-or-later, see [LICENSE](LICENSE).
|
|
100
|
+
|
|
101
|
+
This project is derived from python-ring-doorbell, copyright the
|
|
102
|
+
python-ring-doorbell developers, and is distributed under the same license. The
|
|
103
|
+
changes made since version 0.9.14 are listed in [CHANGELOG.md](CHANGELOG.md).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
python_ring/__init__.py,sha256=NGRkCBa4uAJmu8La_Zs1fmtoXeZXRQ9hS0MimTOZAuw,1151
|
|
2
|
+
python_ring/auth.py,sha256=esD0eKZ2edIjoedaxHXb9-c1eoRamRkMLnU6MSz1SRE,9418
|
|
3
|
+
python_ring/chime.py,sha256=vPMndefwB01CSJgsmP8c2kwAF41uiOOMl6msJCF508Y,4673
|
|
4
|
+
python_ring/cli.py,sha256=N51rBZV_IGp9opYW74s1iDbAg5gv8qyx3jJY60kQbUo,28224
|
|
5
|
+
python_ring/const.py,sha256=fBe_QDNQ5U4c2nEHnkVRMAfE5bn0ZP_EPRBMKESpG5w,10830
|
|
6
|
+
python_ring/doorbot.py,sha256=DeVkioDksRyvv2d4O6GKzLr8CBQQ_My8Oef7PoHY4Lo,19959
|
|
7
|
+
python_ring/event.py,sha256=tORjV1KfhllaRvUGpRWchI-oB4-N3PU4E9OSNIs-vzw,1073
|
|
8
|
+
python_ring/exceptions.py,sha256=d7z2tHs69FO8aeinn7xNFHaAbFkKKcuDUWFoyJxXMKA,373
|
|
9
|
+
python_ring/generic.py,sha256=EK3F4g5ogKZsknGkUZgHGixUFPimigczEORac0YLHX4,8341
|
|
10
|
+
python_ring/group.py,sha256=e2EB14vkEzPfeSM9qtkQA5wsBW31q7Zf_4PkIhGOPqw,4520
|
|
11
|
+
python_ring/other.py,sha256=28i8YCw_6EaeFG7NzcunoqO9zMHBgOF8gqIXiKef7DE,10207
|
|
12
|
+
python_ring/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
python_ring/ring.py,sha256=OdLv1gJVND875lBUPUfdQwHzyRky5kKXhwTlBcetI5k,16360
|
|
14
|
+
python_ring/stickup_cam.py,sha256=hyULwhwCurXCxDARVVIYT-Qcg8hLCwGLujryInmiFTg,9165
|
|
15
|
+
python_ring/util.py,sha256=NC060-tU4TjiyiFf4lC2gPiG3S0Fi33z1eUZo74XSnY,5184
|
|
16
|
+
python_ring/webrtcdevice.py,sha256=HoKQj6STidjbp9fp-iJPx75U6IOcopwyraDtFQUpTEo,5997
|
|
17
|
+
python_ring/webrtcstream.py,sha256=k3IojzIoDIXA6G3_ijBnG0sq1B_F7uT-Y960oKh1o1M,16224
|
|
18
|
+
python_ring/listen/__init__.py,sha256=Nemr9XTIgJKlqpeJ47N0OLYE-QrO36_m1-wsEniasJY,333
|
|
19
|
+
python_ring/listen/eventlistener.py,sha256=IzRj_rH-I0ft6VNtK2jdYanfvP4NtYF0XTlgliwQ2tQ,15953
|
|
20
|
+
python_ring/listen/listenerconfig.py,sha256=jUaMcOPZkS75H8p3SV8uE54OeWu97owMzccXsbPifvU,735
|
|
21
|
+
python_ring-0.10.0.dist-info/METADATA,sha256=73WCpAd1en8ixLW2yMowmRtbYbaw-siYulNmfuxKv-w,3259
|
|
22
|
+
python_ring-0.10.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
23
|
+
python_ring-0.10.0.dist-info/entry_points.txt,sha256=oEdxSzAoIvQd0JL6-wDWrAn2355_6rzntxRu4RgnZTI,52
|
|
24
|
+
python_ring-0.10.0.dist-info/licenses/LICENSE,sha256=46mU2C5kSwOnkqkw9XQAJlhBL2JAf1_uCD8lVcXyMRg,7652
|
|
25
|
+
python_ring-0.10.0.dist-info/RECORD,,
|