harbor-python 1.3.0__py3-none-any.whl → 1.4.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.
- harbor/__init__.py +2 -0
- harbor/core.py +28 -0
- harbor/devices/camera.py +11 -0
- harbor/events.py +21 -21
- harbor/exceptions.py +12 -0
- harbor/mqtt.py +70 -1
- {harbor_python-1.3.0.dist-info → harbor_python-1.4.0.dist-info}/METADATA +1 -1
- harbor_python-1.4.0.dist-info/RECORD +18 -0
- harbor_python-1.3.0.dist-info/RECORD +0 -17
- {harbor_python-1.3.0.dist-info → harbor_python-1.4.0.dist-info}/WHEEL +0 -0
- {harbor_python-1.3.0.dist-info → harbor_python-1.4.0.dist-info}/licenses/LICENSE +0 -0
harbor/__init__.py
CHANGED
|
@@ -27,12 +27,14 @@ from .events import (
|
|
|
27
27
|
ViewerLeftUpdate,
|
|
28
28
|
parse_message,
|
|
29
29
|
)
|
|
30
|
+
from .exceptions import HarborCommandError
|
|
30
31
|
from .mqtt import HarborMQTTClient
|
|
31
32
|
from .state import HarborDeviceState, HarborEventState, HarborSourceType, HarborViewer
|
|
32
33
|
|
|
33
34
|
__all__ = [
|
|
34
35
|
"Harbor",
|
|
35
36
|
"HarborCameraConfig",
|
|
37
|
+
"HarborCommandError",
|
|
36
38
|
"HarborMQTTClient",
|
|
37
39
|
"HarborDevice",
|
|
38
40
|
"HarborCamera",
|
harbor/core.py
CHANGED
|
@@ -85,6 +85,34 @@ class Harbor:
|
|
|
85
85
|
"""Request the camera settings payload."""
|
|
86
86
|
return await self._get_client(serial).get_settings(timeout=timeout)
|
|
87
87
|
|
|
88
|
+
async def set_camera_on(
|
|
89
|
+
self,
|
|
90
|
+
serial: str,
|
|
91
|
+
camera_on: bool,
|
|
92
|
+
*,
|
|
93
|
+
viewer_id: str | None = None,
|
|
94
|
+
timeout: float = 10.0,
|
|
95
|
+
) -> None:
|
|
96
|
+
"""Turn a camera stream on or off and refresh its settings."""
|
|
97
|
+
await self._get_client(serial).set_camera_on(
|
|
98
|
+
camera_on,
|
|
99
|
+
viewer_id=viewer_id,
|
|
100
|
+
timeout=timeout,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
async def set_night_mode(
|
|
104
|
+
self,
|
|
105
|
+
serial: str,
|
|
106
|
+
night_mode: bool,
|
|
107
|
+
*,
|
|
108
|
+
timeout: float = 10.0,
|
|
109
|
+
) -> None:
|
|
110
|
+
"""Turn camera night mode on or off and refresh its settings."""
|
|
111
|
+
await self._get_client(serial).set_night_mode(
|
|
112
|
+
night_mode,
|
|
113
|
+
timeout=timeout,
|
|
114
|
+
)
|
|
115
|
+
|
|
88
116
|
async def handle_message(self, topic: str, payload: Any) -> None:
|
|
89
117
|
"""
|
|
90
118
|
Central message handler.
|
harbor/devices/camera.py
CHANGED
|
@@ -4,11 +4,13 @@ import asyncio
|
|
|
4
4
|
import logging
|
|
5
5
|
|
|
6
6
|
from ..config import HarborCameraConfig
|
|
7
|
+
from ..data.mqtt_models import SettingsEvent
|
|
7
8
|
from ..device import HarborDevice
|
|
8
9
|
from ..events import (
|
|
9
10
|
CameraEventUpdate,
|
|
10
11
|
HarborEvent,
|
|
11
12
|
LocalLivekitHeartbeatUpdate,
|
|
13
|
+
SettingsUpdate,
|
|
12
14
|
ViewerInfo,
|
|
13
15
|
ViewerJoinedUpdate,
|
|
14
16
|
ViewerLeftUpdate,
|
|
@@ -58,6 +60,8 @@ class HarborCamera(HarborDevice):
|
|
|
58
60
|
match event:
|
|
59
61
|
case LocalLivekitHeartbeatUpdate(payload=payload, viewers=viewers):
|
|
60
62
|
self._apply_local_livekit_heartbeat(payload, viewers)
|
|
63
|
+
case SettingsUpdate(payload=payload):
|
|
64
|
+
self._apply_camera_settings(payload)
|
|
61
65
|
case ViewerJoinedUpdate(viewer=viewer):
|
|
62
66
|
self._apply_viewer_joined(viewer)
|
|
63
67
|
case ViewerLeftUpdate(viewer_id=viewer_id):
|
|
@@ -65,6 +69,13 @@ class HarborCamera(HarborDevice):
|
|
|
65
69
|
case CameraEventUpdate():
|
|
66
70
|
self._apply_camera_event(event)
|
|
67
71
|
|
|
72
|
+
def _apply_camera_settings(self, payload: SettingsEvent) -> None:
|
|
73
|
+
"""Apply camera controls exposed by a settings payload."""
|
|
74
|
+
if payload.settings is not None and payload.settings.preference_stream_paused is not None:
|
|
75
|
+
self.state.values["camera_on"] = not payload.settings.preference_stream_paused
|
|
76
|
+
if payload.state is not None and payload.state.video_night_mode is not None:
|
|
77
|
+
self.state.values["night_mode"] = payload.state.video_night_mode
|
|
78
|
+
|
|
68
79
|
def _apply_local_livekit_heartbeat(
|
|
69
80
|
self,
|
|
70
81
|
payload,
|
harbor/events.py
CHANGED
|
@@ -293,52 +293,52 @@ def parse_message(
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
if event_key == "heartbeat":
|
|
296
|
-
if
|
|
297
|
-
return HeartbeatUpdate(payload=
|
|
296
|
+
if heartbeat_payload := _validate_payload(HeartbeatEvent, raw_payload, topic):
|
|
297
|
+
return HeartbeatUpdate(payload=heartbeat_payload, **base_kwargs)
|
|
298
298
|
return RawEventUpdate(payload=raw_payload, **base_kwargs)
|
|
299
299
|
|
|
300
300
|
if event_key == "local_livekit_heartbeat":
|
|
301
|
-
if
|
|
301
|
+
if livekit_payload := _validate_payload(LocalLivekitHeartbeatEvent, raw_payload, topic):
|
|
302
302
|
return LocalLivekitHeartbeatUpdate(
|
|
303
|
-
payload=
|
|
304
|
-
viewers=_extract_viewers_from_local_livekit(
|
|
303
|
+
payload=livekit_payload,
|
|
304
|
+
viewers=_extract_viewers_from_local_livekit(livekit_payload),
|
|
305
305
|
**base_kwargs,
|
|
306
306
|
)
|
|
307
307
|
return RawEventUpdate(payload=raw_payload, **base_kwargs)
|
|
308
308
|
|
|
309
309
|
if event_key == "viewer_joined":
|
|
310
|
-
if
|
|
310
|
+
if viewer_joined_payload := _validate_payload(ViewerJoinedEvent, raw_payload, topic):
|
|
311
311
|
return ViewerJoinedUpdate(
|
|
312
|
-
payload=
|
|
312
|
+
payload=viewer_joined_payload,
|
|
313
313
|
viewer=_extract_viewer_info_from_payload(raw_payload)
|
|
314
314
|
or _extract_viewer_info(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
315
|
+
viewer_joined_payload.viewer_id,
|
|
316
|
+
viewer_joined_payload.identity,
|
|
317
|
+
viewer_joined_payload.client,
|
|
318
|
+
viewer_joined_payload.is_local,
|
|
319
|
+
viewer_joined_payload.role,
|
|
320
320
|
),
|
|
321
321
|
**base_kwargs,
|
|
322
322
|
)
|
|
323
323
|
return RawEventUpdate(payload=raw_payload, **base_kwargs)
|
|
324
324
|
|
|
325
325
|
if event_key == "viewer_left":
|
|
326
|
-
if
|
|
326
|
+
if viewer_left_payload := _validate_payload(ViewerLeftEvent, raw_payload, topic):
|
|
327
327
|
return ViewerLeftUpdate(
|
|
328
|
-
payload=
|
|
328
|
+
payload=viewer_left_payload,
|
|
329
329
|
viewer_id=_extract_viewer_id_from_payload(raw_payload)
|
|
330
330
|
or _coalesce_string(
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
331
|
+
viewer_left_payload.viewer_id,
|
|
332
|
+
viewer_left_payload.identity,
|
|
333
|
+
viewer_left_payload.client,
|
|
334
334
|
),
|
|
335
335
|
**base_kwargs,
|
|
336
336
|
)
|
|
337
337
|
return RawEventUpdate(payload=raw_payload, **base_kwargs)
|
|
338
338
|
|
|
339
339
|
if event_key in {"settings", "get_settings"}:
|
|
340
|
-
if
|
|
341
|
-
return SettingsUpdate(payload=
|
|
340
|
+
if settings_payload := _validate_payload(SettingsEvent, raw_payload, topic):
|
|
341
|
+
return SettingsUpdate(payload=settings_payload, **base_kwargs)
|
|
342
342
|
return RawEventUpdate(payload=raw_payload, **base_kwargs)
|
|
343
343
|
|
|
344
344
|
if source_type == "camera":
|
|
@@ -346,9 +346,9 @@ def parse_message(
|
|
|
346
346
|
explicit_state = extract_explicit_event_state(raw_payload)
|
|
347
347
|
|
|
348
348
|
if event_key == "motion_detection":
|
|
349
|
-
if
|
|
349
|
+
if motion_payload := _validate_payload(MotionDetectedEvent, raw_payload, topic):
|
|
350
350
|
return MotionDetectedUpdate(
|
|
351
|
-
payload=
|
|
351
|
+
payload=motion_payload,
|
|
352
352
|
active_seconds=active_seconds,
|
|
353
353
|
explicit_state=explicit_state,
|
|
354
354
|
**base_kwargs,
|
harbor/exceptions.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class HarborCommandError(Exception):
|
|
7
|
+
"""Raised when a Harbor camera rejects a command."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, command: str, response: Any) -> None:
|
|
10
|
+
self.command = command
|
|
11
|
+
self.response = response
|
|
12
|
+
super().__init__(f"Harbor camera rejected command {command!r}: {response!r}")
|
harbor/mqtt.py
CHANGED
|
@@ -12,6 +12,7 @@ from aiomqtt import Client, MqttError
|
|
|
12
12
|
|
|
13
13
|
from .config import HarborCameraConfig
|
|
14
14
|
from .data.mqtt_models import GetCameraSettingsRequest, SettingsEvent
|
|
15
|
+
from .exceptions import HarborCommandError
|
|
15
16
|
from .utils import get_camera_host, get_ssl_cache_key, get_ssl_context
|
|
16
17
|
|
|
17
18
|
if TYPE_CHECKING:
|
|
@@ -23,6 +24,9 @@ DEFAULT_CONNECTION_GRACE_PERIOD = 90.0
|
|
|
23
24
|
DEFAULT_COMMAND_QOS = 2
|
|
24
25
|
DEFAULT_REQUEST_TIMEOUT = 10.0
|
|
25
26
|
GET_SETTINGS_COMMAND = "get-settings"
|
|
27
|
+
PAUSE_STREAM_COMMAND = "pause-stream"
|
|
28
|
+
UNPAUSE_STREAM_COMMAND = "unpause-stream"
|
|
29
|
+
UPDATE_NIGHT_MODE_COMMAND = "update-night-mode"
|
|
26
30
|
DEFAULT_INITIAL_COMMANDS = (GET_SETTINGS_COMMAND,)
|
|
27
31
|
|
|
28
32
|
|
|
@@ -360,7 +364,7 @@ class HarborMQTTClient:
|
|
|
360
364
|
request = GetCameraSettingsRequest(
|
|
361
365
|
seq=seq or _generate_seq(),
|
|
362
366
|
client=client or self.client_id or f"harbor-client-{self.config.serial}",
|
|
363
|
-
|
|
367
|
+
triggeredBy=triggered_by or "harbor-python",
|
|
364
368
|
)
|
|
365
369
|
return request.model_dump(by_alias=True)
|
|
366
370
|
|
|
@@ -410,6 +414,71 @@ class HarborMQTTClient:
|
|
|
410
414
|
)
|
|
411
415
|
return SettingsEvent.model_validate(response)
|
|
412
416
|
|
|
417
|
+
async def set_camera_on(
|
|
418
|
+
self,
|
|
419
|
+
camera_on: bool,
|
|
420
|
+
*,
|
|
421
|
+
viewer_id: str | None = None,
|
|
422
|
+
timeout: float = DEFAULT_REQUEST_TIMEOUT,
|
|
423
|
+
) -> None:
|
|
424
|
+
"""Turn the camera stream on or off and refresh its settings."""
|
|
425
|
+
command = UNPAUSE_STREAM_COMMAND if camera_on else PAUSE_STREAM_COMMAND
|
|
426
|
+
await self._request_camera_control(
|
|
427
|
+
command,
|
|
428
|
+
{"viewer_id": viewer_id or self.client_id or f"harbor-client-{self.config.serial}"},
|
|
429
|
+
timeout=timeout,
|
|
430
|
+
)
|
|
431
|
+
await self._refresh_settings_after_command(command, timeout=timeout)
|
|
432
|
+
|
|
433
|
+
async def set_night_mode(
|
|
434
|
+
self,
|
|
435
|
+
night_mode: bool,
|
|
436
|
+
*,
|
|
437
|
+
timeout: float = DEFAULT_REQUEST_TIMEOUT,
|
|
438
|
+
) -> None:
|
|
439
|
+
"""Turn camera night mode on or off and refresh its settings."""
|
|
440
|
+
await self._request_camera_control(
|
|
441
|
+
UPDATE_NIGHT_MODE_COMMAND,
|
|
442
|
+
{"night_mode": night_mode},
|
|
443
|
+
timeout=timeout,
|
|
444
|
+
)
|
|
445
|
+
await self._refresh_settings_after_command(
|
|
446
|
+
UPDATE_NIGHT_MODE_COMMAND,
|
|
447
|
+
timeout=timeout,
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
async def _request_camera_control(
|
|
451
|
+
self,
|
|
452
|
+
command: str,
|
|
453
|
+
payload: dict[str, Any],
|
|
454
|
+
*,
|
|
455
|
+
timeout: float,
|
|
456
|
+
) -> Any:
|
|
457
|
+
"""Run a camera control command and reject error responses."""
|
|
458
|
+
response = await self.request_command(command, payload, timeout=timeout)
|
|
459
|
+
if isinstance(response, dict) and (
|
|
460
|
+
response.get("error") or ((status := response.get("status")) is not None and str(status).upper() != "OK")
|
|
461
|
+
):
|
|
462
|
+
raise HarborCommandError(command, response)
|
|
463
|
+
return response
|
|
464
|
+
|
|
465
|
+
async def _refresh_settings_after_command(
|
|
466
|
+
self,
|
|
467
|
+
command: str,
|
|
468
|
+
*,
|
|
469
|
+
timeout: float,
|
|
470
|
+
) -> None:
|
|
471
|
+
"""Refresh settings without turning a successful command into a failure."""
|
|
472
|
+
try:
|
|
473
|
+
await self.get_settings(timeout=timeout)
|
|
474
|
+
except (ConnectionError, MqttError, TimeoutError):
|
|
475
|
+
_LOGGER.debug(
|
|
476
|
+
"Unable to refresh settings after Harbor command %s for camera %s",
|
|
477
|
+
command,
|
|
478
|
+
self.config.serial,
|
|
479
|
+
exc_info=True,
|
|
480
|
+
)
|
|
481
|
+
|
|
413
482
|
def __del__(self) -> None:
|
|
414
483
|
if self._stop_event and not self._stop_event.is_set():
|
|
415
484
|
self._stop_event.set()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: harbor-python
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.0
|
|
4
4
|
Summary: Async local client for Harbor Sleep Cameras
|
|
5
5
|
Project-URL: Homepage, https://github.com/Harbor-Systems/harbor-python
|
|
6
6
|
Project-URL: Repository, https://github.com/Harbor-Systems/harbor-python
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
harbor/__init__.py,sha256=JDsB7r1tJEquHnUUiF2u6rqubP2cSJMzo7ntooaGyAw,1675
|
|
2
|
+
harbor/config.py,sha256=LXMDaTC_0Z9wF_vTXJG9C0vQ0XHXo4EuFL0-Kwa4-S4,1373
|
|
3
|
+
harbor/core.py,sha256=NcLvH6eFwzcggn-D1DXoPteLCSJVj66OsRYapHTjjwE,4213
|
|
4
|
+
harbor/device.py,sha256=YvaFWieXJ-EzQJU8VQo_ZERl65CynITTAnMFto-PF_I,5933
|
|
5
|
+
harbor/events.py,sha256=Q5A9Jqgc3DSsXj5tWBbyctsUE4y-l280i5y4pIDDaN0,20508
|
|
6
|
+
harbor/exceptions.py,sha256=ZuidYNY5rtd4w4f1NHPQVukHnz0nLm53jsSXTpEymw4,367
|
|
7
|
+
harbor/mqtt.py,sha256=ecXgBUsteoD4o5JcEYs9DsclDgUPoBbJBJFtVk6-rfU,19251
|
|
8
|
+
harbor/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
harbor/state.py,sha256=jQDLV8zpkLV2f6zR4LuOtk_B5BtGdp-8dq4NyGZCa-8,1210
|
|
10
|
+
harbor/utils.py,sha256=7A3Tn1aZ93SlxRKY-0b-50ntQL4Pw1j5bXwkJvnarpY,3312
|
|
11
|
+
harbor/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
harbor/data/mqtt_models.py,sha256=OF36ZoUCOeoaKp4TPggM6HCbowgtkH1zLFTozVJUZYY,4314
|
|
13
|
+
harbor/devices/camera.py,sha256=9Rlc11y6aZxEZ7tHgnUJ1r3GVWkkeYdCISC_9MBQHeA,9087
|
|
14
|
+
harbor/devices/monitor.py,sha256=hzx4lu92h3i_34QyYK392gE7CihqERiOZuLhyzDtDk0,452
|
|
15
|
+
harbor_python-1.4.0.dist-info/METADATA,sha256=kLhgfXNCvCfm7bucJz9i4fhXygNNvA6fyxXjijyTq5g,4999
|
|
16
|
+
harbor_python-1.4.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
17
|
+
harbor_python-1.4.0.dist-info/licenses/LICENSE,sha256=QEOXEfrOQetemKy4k1WN5XCApJdpiRtyV5jLMSToVVw,11344
|
|
18
|
+
harbor_python-1.4.0.dist-info/RECORD,,
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
harbor/__init__.py,sha256=F2Yo9T1Hpf0lSioVAk-m8GJnEh1tLd2En4Mzz9RxczY,1606
|
|
2
|
-
harbor/config.py,sha256=LXMDaTC_0Z9wF_vTXJG9C0vQ0XHXo4EuFL0-Kwa4-S4,1373
|
|
3
|
-
harbor/core.py,sha256=Alm6ojRBCibsQ5xGGyaAOQimi-_kE6Q6fuS2ZAxzaNM,3468
|
|
4
|
-
harbor/device.py,sha256=YvaFWieXJ-EzQJU8VQo_ZERl65CynITTAnMFto-PF_I,5933
|
|
5
|
-
harbor/events.py,sha256=4Y3JT_NP1x8rUR7U6n2-LvAENt9zpqD4jVy28AAYo4Q,20400
|
|
6
|
-
harbor/mqtt.py,sha256=43QzJrocLGBWNad7uH4mSm2M9YR15xtmSTvIviwrkXA,16832
|
|
7
|
-
harbor/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
harbor/state.py,sha256=jQDLV8zpkLV2f6zR4LuOtk_B5BtGdp-8dq4NyGZCa-8,1210
|
|
9
|
-
harbor/utils.py,sha256=7A3Tn1aZ93SlxRKY-0b-50ntQL4Pw1j5bXwkJvnarpY,3312
|
|
10
|
-
harbor/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
-
harbor/data/mqtt_models.py,sha256=OF36ZoUCOeoaKp4TPggM6HCbowgtkH1zLFTozVJUZYY,4314
|
|
12
|
-
harbor/devices/camera.py,sha256=ciq8ynsAaZgW0CWYjKiJGAZwk04pNz4uYfnsN0GT0O4,8429
|
|
13
|
-
harbor/devices/monitor.py,sha256=hzx4lu92h3i_34QyYK392gE7CihqERiOZuLhyzDtDk0,452
|
|
14
|
-
harbor_python-1.3.0.dist-info/METADATA,sha256=IP-OCKB2gCcJLnJ54YIFTRh-_EOT0va5EiIJA_BSl68,4999
|
|
15
|
-
harbor_python-1.3.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
16
|
-
harbor_python-1.3.0.dist-info/licenses/LICENSE,sha256=QEOXEfrOQetemKy4k1WN5XCApJdpiRtyV5jLMSToVVw,11344
|
|
17
|
-
harbor_python-1.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|