harbor-python 1.5.0__tar.gz → 1.6.1__tar.gz
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_python-1.5.0 → harbor_python-1.6.1}/PKG-INFO +60 -2
- {harbor_python-1.5.0 → harbor_python-1.6.1}/README.md +58 -0
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/__init__.py +4 -0
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/data/mqtt_models.py +42 -2
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/devices/camera.py +17 -37
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/events.py +37 -97
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/state.py +11 -2
- {harbor_python-1.5.0 → harbor_python-1.6.1}/pyproject.toml +9 -2
- {harbor_python-1.5.0 → harbor_python-1.6.1}/.gitignore +0 -0
- {harbor_python-1.5.0 → harbor_python-1.6.1}/LICENSE +0 -0
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/config.py +0 -0
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/core.py +0 -0
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/data/__init__.py +0 -0
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/device.py +0 -0
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/devices/monitor.py +0 -0
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/exceptions.py +0 -0
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/mqtt.py +0 -0
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/py.typed +0 -0
- {harbor_python-1.5.0 → harbor_python-1.6.1}/harbor/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: harbor-python
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.6.1
|
|
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
|
|
@@ -251,6 +251,64 @@ go2rtc:
|
|
|
251
251
|
|
|
252
252
|
Replace `CAMERA_SERIAL` with your camera serial number and `192.168.1.10` with the IP address of your go2rtc or Frigate server.
|
|
253
253
|
|
|
254
|
+
### Repairing packet loss
|
|
255
|
+
|
|
256
|
+
WHIP media runs over UDP by default, and go2rtc does not negotiate
|
|
257
|
+
retransmission. `RegisterDefaultCodecs` in `pkg/webrtc/api.go` registers no RTX
|
|
258
|
+
(RFC 4588) codec, so go2rtc strips `rtx/90000` out of its SDP answer while still
|
|
259
|
+
advertising `a=rtcp-fb:96 nack`. Harbor cameras offer RTX correctly, but the
|
|
260
|
+
answer deletes the channel those retransmissions would travel on — go2rtc asks
|
|
261
|
+
the camera to retransmit over something it just removed, so nothing is ever
|
|
262
|
+
repaired. This is true as of go2rtc 1.9.10 and current master.
|
|
263
|
+
|
|
264
|
+
The symptom is occasional blocky or smeared frames that clear on the next
|
|
265
|
+
keyframe. Each lost packet damages the frame it belonged to, so even a very low
|
|
266
|
+
loss rate is visible — 0.03% loss on a 20 fps stream is a handful of damaged
|
|
267
|
+
frames every few minutes.
|
|
268
|
+
|
|
269
|
+
Running the WHIP session over ICE-TCP sidesteps this. The kernel retransmits
|
|
270
|
+
lost segments and delivers them in order, with no SDP negotiation involved:
|
|
271
|
+
|
|
272
|
+
```yaml
|
|
273
|
+
webrtc:
|
|
274
|
+
listen: ":8555/tcp"
|
|
275
|
+
candidates:
|
|
276
|
+
- 192.168.1.10:8555
|
|
277
|
+
filters:
|
|
278
|
+
networks: [tcp4]
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Nest that block under `go2rtc:` if you are configuring Frigate.
|
|
282
|
+
|
|
283
|
+
Both settings are required. `filters` on its own is not enough: with a bare
|
|
284
|
+
`listen: ":8555"`, go2rtc registers every entry in `candidates` as **both** a TCP
|
|
285
|
+
and a UDP candidate, so it would keep advertising a UDP candidate that the filter
|
|
286
|
+
had stopped anything from listening on.
|
|
287
|
+
|
|
288
|
+
Confirm it took effect by checking the producer's transport, which should read
|
|
289
|
+
`http+tcp`:
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
curl -s "http://192.168.1.10:1984/api/streams?src=CAMERA_SERIAL" | grep protocol
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Frigate does not expose port 1984 by default — use
|
|
296
|
+
`http://FRIGATE_HOST:5000/api/go2rtc/api/streams?src=CAMERA_SERIAL` instead.
|
|
297
|
+
|
|
298
|
+
What this costs:
|
|
299
|
+
|
|
300
|
+
- Loss becomes latency instead of corruption. A sustained wifi dropout shows up
|
|
301
|
+
as a stall rather than a glitch.
|
|
302
|
+
- `filters` applies to all inbound WebRTC, so browser live view moves to TCP as
|
|
303
|
+
well. If you watch streams from outside your network, forward **8555/tcp**, not
|
|
304
|
+
only UDP.
|
|
305
|
+
- The camera's congestion control stops having an effect, since TCP handles
|
|
306
|
+
pacing. That is not a concern at the camera's bitrate on a local network, but
|
|
307
|
+
it does mean the camera will not lower quality if the link saturates.
|
|
308
|
+
|
|
309
|
+
Measured on one Harbor camera pushing 1728x1080 HEVC over wifi, video packet loss
|
|
310
|
+
over a 3 minute sample went from 0.039% to 0.000%.
|
|
311
|
+
|
|
254
312
|
## Development
|
|
255
313
|
|
|
256
314
|
```bash
|
|
@@ -222,6 +222,64 @@ go2rtc:
|
|
|
222
222
|
|
|
223
223
|
Replace `CAMERA_SERIAL` with your camera serial number and `192.168.1.10` with the IP address of your go2rtc or Frigate server.
|
|
224
224
|
|
|
225
|
+
### Repairing packet loss
|
|
226
|
+
|
|
227
|
+
WHIP media runs over UDP by default, and go2rtc does not negotiate
|
|
228
|
+
retransmission. `RegisterDefaultCodecs` in `pkg/webrtc/api.go` registers no RTX
|
|
229
|
+
(RFC 4588) codec, so go2rtc strips `rtx/90000` out of its SDP answer while still
|
|
230
|
+
advertising `a=rtcp-fb:96 nack`. Harbor cameras offer RTX correctly, but the
|
|
231
|
+
answer deletes the channel those retransmissions would travel on — go2rtc asks
|
|
232
|
+
the camera to retransmit over something it just removed, so nothing is ever
|
|
233
|
+
repaired. This is true as of go2rtc 1.9.10 and current master.
|
|
234
|
+
|
|
235
|
+
The symptom is occasional blocky or smeared frames that clear on the next
|
|
236
|
+
keyframe. Each lost packet damages the frame it belonged to, so even a very low
|
|
237
|
+
loss rate is visible — 0.03% loss on a 20 fps stream is a handful of damaged
|
|
238
|
+
frames every few minutes.
|
|
239
|
+
|
|
240
|
+
Running the WHIP session over ICE-TCP sidesteps this. The kernel retransmits
|
|
241
|
+
lost segments and delivers them in order, with no SDP negotiation involved:
|
|
242
|
+
|
|
243
|
+
```yaml
|
|
244
|
+
webrtc:
|
|
245
|
+
listen: ":8555/tcp"
|
|
246
|
+
candidates:
|
|
247
|
+
- 192.168.1.10:8555
|
|
248
|
+
filters:
|
|
249
|
+
networks: [tcp4]
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Nest that block under `go2rtc:` if you are configuring Frigate.
|
|
253
|
+
|
|
254
|
+
Both settings are required. `filters` on its own is not enough: with a bare
|
|
255
|
+
`listen: ":8555"`, go2rtc registers every entry in `candidates` as **both** a TCP
|
|
256
|
+
and a UDP candidate, so it would keep advertising a UDP candidate that the filter
|
|
257
|
+
had stopped anything from listening on.
|
|
258
|
+
|
|
259
|
+
Confirm it took effect by checking the producer's transport, which should read
|
|
260
|
+
`http+tcp`:
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
curl -s "http://192.168.1.10:1984/api/streams?src=CAMERA_SERIAL" | grep protocol
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Frigate does not expose port 1984 by default — use
|
|
267
|
+
`http://FRIGATE_HOST:5000/api/go2rtc/api/streams?src=CAMERA_SERIAL` instead.
|
|
268
|
+
|
|
269
|
+
What this costs:
|
|
270
|
+
|
|
271
|
+
- Loss becomes latency instead of corruption. A sustained wifi dropout shows up
|
|
272
|
+
as a stall rather than a glitch.
|
|
273
|
+
- `filters` applies to all inbound WebRTC, so browser live view moves to TCP as
|
|
274
|
+
well. If you watch streams from outside your network, forward **8555/tcp**, not
|
|
275
|
+
only UDP.
|
|
276
|
+
- The camera's congestion control stops having an effect, since TCP handles
|
|
277
|
+
pacing. That is not a concern at the camera's bitrate on a local network, but
|
|
278
|
+
it does mean the camera will not lower quality if the link saturates.
|
|
279
|
+
|
|
280
|
+
Measured on one Harbor camera pushing 1728x1080 HEVC over wifi, video packet loss
|
|
281
|
+
over a 3 minute sample went from 0.039% to 0.000%.
|
|
282
|
+
|
|
225
283
|
## Development
|
|
226
284
|
|
|
227
285
|
```bash
|
|
@@ -5,6 +5,7 @@ from .data.mqtt_models import (
|
|
|
5
5
|
HeartbeatEvent,
|
|
6
6
|
LocalLivekitHeartbeatEvent,
|
|
7
7
|
MotionDetectedEvent,
|
|
8
|
+
NoiseDetectedEvent,
|
|
8
9
|
Settings,
|
|
9
10
|
SettingsEvent,
|
|
10
11
|
SettingsState,
|
|
@@ -29,6 +30,7 @@ from .events import (
|
|
|
29
30
|
HeartbeatUpdate,
|
|
30
31
|
LocalLivekitHeartbeatUpdate,
|
|
31
32
|
MotionDetectedUpdate,
|
|
33
|
+
NoiseDetectedUpdate,
|
|
32
34
|
RawEventUpdate,
|
|
33
35
|
SettingsUpdate,
|
|
34
36
|
ViewerInfo,
|
|
@@ -72,6 +74,7 @@ __all__ = [
|
|
|
72
74
|
"SettingsUpdate",
|
|
73
75
|
"CameraEventUpdate",
|
|
74
76
|
"MotionDetectedUpdate",
|
|
77
|
+
"NoiseDetectedUpdate",
|
|
75
78
|
"ViewerInfo",
|
|
76
79
|
"parse_message",
|
|
77
80
|
"GetCameraSettingsRequest",
|
|
@@ -84,6 +87,7 @@ __all__ = [
|
|
|
84
87
|
"ViewerJoinedEvent",
|
|
85
88
|
"ViewerLeftEvent",
|
|
86
89
|
"MotionDetectedEvent",
|
|
90
|
+
"NoiseDetectedEvent",
|
|
87
91
|
"HarborSourceType",
|
|
88
92
|
"HarborViewer",
|
|
89
93
|
"HarborEventState",
|
|
@@ -157,13 +157,53 @@ class ViewerLeftEvent(HarborMQTTPayload):
|
|
|
157
157
|
|
|
158
158
|
|
|
159
159
|
class MotionDetectedEvent(HarborMQTTPayload):
|
|
160
|
-
"""Payload for a motion
|
|
160
|
+
"""Payload for a ``motion-detected`` event.
|
|
161
|
+
|
|
162
|
+
Keys arrive in snake_case. ``duration`` is a unit-suffixed string such as
|
|
163
|
+
``"10s"`` -- never parse it as a bare number, and never treat it as a hold
|
|
164
|
+
time; see :class:`NoiseDetectedEvent` for why.
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
active_config: str | None = None
|
|
168
|
+
duration: str | None = None
|
|
169
|
+
file_duration: str | None = None
|
|
170
|
+
filename: str | None = None
|
|
171
|
+
level: str | None = None
|
|
172
|
+
sensitivity: str | None = None
|
|
173
|
+
threshold: str | None = None
|
|
174
|
+
thumbnail: str | None = None
|
|
175
|
+
timestamp: str | None = None
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
class NoiseDetectedEvent(HarborMQTTPayload):
|
|
179
|
+
"""Payload for a ``sound-anomaly-detected`` event.
|
|
180
|
+
|
|
181
|
+
The firmware topic calls this a sound anomaly; the app presents it as an
|
|
182
|
+
alert for "sudden, loud sounds" and "sustained noises", hence the noise
|
|
183
|
+
naming used here.
|
|
184
|
+
|
|
185
|
+
Field set verified against a live camera. The audio fields are dB strings
|
|
186
|
+
(``"-36.401137dB"``) and pair with the ``volume_baseline_current`` /
|
|
187
|
+
``volume_baseline_reference`` / ``volume_threshold_effective`` values on
|
|
188
|
+
:class:`SettingsState`.
|
|
189
|
+
|
|
190
|
+
``duration`` is a unit-suffixed string (``"10s"``) that matches
|
|
191
|
+
``file_duration``, the length of the recorded clip named by ``filename``.
|
|
192
|
+
It describes a detection window that has already closed by the time this
|
|
193
|
+
message is published, so it must not be used to decide how long the
|
|
194
|
+
detection "stays on" -- the camera never publishes a cleared counterpart at
|
|
195
|
+
all.
|
|
196
|
+
"""
|
|
161
197
|
|
|
162
198
|
active_config: str | None = None
|
|
163
|
-
|
|
199
|
+
baseline: str | None = None
|
|
200
|
+
baseline_reference: str | None = None
|
|
201
|
+
duration: str | None = None
|
|
202
|
+
file_duration: str | None = None
|
|
164
203
|
filename: str | None = None
|
|
165
204
|
level: str | None = None
|
|
166
205
|
sensitivity: str | None = None
|
|
167
206
|
threshold: str | None = None
|
|
168
207
|
thumbnail: str | None = None
|
|
169
208
|
timestamp: str | None = None
|
|
209
|
+
user_offset: str | None = None
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import asyncio
|
|
4
3
|
import logging
|
|
5
4
|
|
|
6
5
|
from ..config import HarborCameraConfig
|
|
@@ -19,8 +18,10 @@ from ..state import HarborEventState, HarborViewer
|
|
|
19
18
|
|
|
20
19
|
_LOGGER = logging.getLogger(__name__)
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
#: Detection events the camera can report. The firmware publishes exactly two
|
|
22
|
+
#: detection topics (``motion-detected`` and ``sound-anomaly-detected``), so
|
|
23
|
+
#: seeding anything else would create an entity that can never fire.
|
|
24
|
+
DEFAULT_CAMERA_EVENT_KEYS = ("motion_detection", "noise_detection")
|
|
24
25
|
|
|
25
26
|
# Known values for enumerated state fields. The device reports these in
|
|
26
27
|
# mixed/upper case (e.g. "PLAYING", "GOOD"); they are normalized to the
|
|
@@ -47,7 +48,6 @@ class HarborCamera(HarborDevice):
|
|
|
47
48
|
"""Initialize the camera device."""
|
|
48
49
|
super().__init__(config.serial, "camera")
|
|
49
50
|
self.config = config
|
|
50
|
-
self._event_reset_handles: dict[str, asyncio.TimerHandle] = {}
|
|
51
51
|
self._unexpected_enum_values: set[tuple[str, str]] = set()
|
|
52
52
|
|
|
53
53
|
for event_key in DEFAULT_CAMERA_EVENT_KEYS:
|
|
@@ -221,29 +221,24 @@ class HarborCamera(HarborDevice):
|
|
|
221
221
|
self.state.values["num_viewers"] = len(self.state.viewers)
|
|
222
222
|
|
|
223
223
|
def _apply_camera_event(self, event: CameraEventUpdate) -> None:
|
|
224
|
-
"""
|
|
224
|
+
"""Record a camera detection event.
|
|
225
|
+
|
|
226
|
+
Detections are edge triggers with no cleared counterpart, so this only
|
|
227
|
+
stamps when the event last fired.
|
|
228
|
+
|
|
229
|
+
Earlier versions synthesized an ``is_on`` flag and held it open for a
|
|
230
|
+
duration parsed from the payload. That never worked: the firmware
|
|
231
|
+
reports ``"10s"``, which failed to parse and silently fell back to a
|
|
232
|
+
fixed 5s, so a 10-second detection was reported as a 5-second one and
|
|
233
|
+
every event looked identical. Holding the real value would not have
|
|
234
|
+
helped either -- the window has already closed by the time the message
|
|
235
|
+
is published.
|
|
236
|
+
"""
|
|
225
237
|
event_state = self._ensure_camera_event(event.event_key, topic=event.topic)
|
|
226
238
|
event_state.topic = event.topic
|
|
227
239
|
event_state.last_seen = event.timestamp
|
|
228
240
|
event_state.last_payload = event.raw_payload
|
|
229
241
|
|
|
230
|
-
if handle := self._event_reset_handles.pop(event.event_key, None):
|
|
231
|
-
handle.cancel()
|
|
232
|
-
|
|
233
|
-
if event.explicit_state is False:
|
|
234
|
-
event_state.is_on = False
|
|
235
|
-
return
|
|
236
|
-
|
|
237
|
-
event_state.is_on = True
|
|
238
|
-
active_seconds = event.active_seconds
|
|
239
|
-
if active_seconds <= 0:
|
|
240
|
-
active_seconds = DEFAULT_EVENT_ACTIVE_SECONDS
|
|
241
|
-
|
|
242
|
-
loop = asyncio.get_running_loop()
|
|
243
|
-
self._event_reset_handles[event.event_key] = loop.call_later(
|
|
244
|
-
active_seconds,
|
|
245
|
-
lambda: asyncio.create_task(self._async_reset_event(event.event_key)),
|
|
246
|
-
)
|
|
247
242
|
_LOGGER.debug(
|
|
248
243
|
"Camera %s received event on topic %s: %s",
|
|
249
244
|
self.serial,
|
|
@@ -251,19 +246,6 @@ class HarborCamera(HarborDevice):
|
|
|
251
246
|
event.raw_payload,
|
|
252
247
|
)
|
|
253
248
|
|
|
254
|
-
def shutdown(self) -> None:
|
|
255
|
-
"""Release camera resources."""
|
|
256
|
-
for handle in self._event_reset_handles.values():
|
|
257
|
-
handle.cancel()
|
|
258
|
-
self._event_reset_handles.clear()
|
|
259
|
-
|
|
260
|
-
async def _async_reset_event(self, event_key: str) -> None:
|
|
261
|
-
"""Reset a transient event to off after its active period."""
|
|
262
|
-
self._event_reset_handles.pop(event_key, None)
|
|
263
|
-
if event_state := self.state.events.get(event_key):
|
|
264
|
-
event_state.is_on = False
|
|
265
|
-
await self._emit_update()
|
|
266
|
-
|
|
267
249
|
def _ensure_camera_event(
|
|
268
250
|
self,
|
|
269
251
|
event_key: str,
|
|
@@ -287,8 +269,6 @@ class HarborCamera(HarborDevice):
|
|
|
287
269
|
|
|
288
270
|
def _event_name_from_key(event_key: str) -> str:
|
|
289
271
|
"""Return a user-facing event name for an event key."""
|
|
290
|
-
if event_key == "cry_detection":
|
|
291
|
-
return "Cry detected"
|
|
292
272
|
if event_key == "motion_detection":
|
|
293
273
|
return "Motion detected"
|
|
294
274
|
if event_key == "noise_detection":
|
|
@@ -16,6 +16,7 @@ from .data.mqtt_models import (
|
|
|
16
16
|
HeartbeatEvent,
|
|
17
17
|
LocalLivekitHeartbeatEvent,
|
|
18
18
|
MotionDetectedEvent,
|
|
19
|
+
NoiseDetectedEvent,
|
|
19
20
|
SettingsEvent,
|
|
20
21
|
ViewerJoinedEvent,
|
|
21
22
|
ViewerLeftEvent,
|
|
@@ -35,6 +36,7 @@ class EventType(StrEnum):
|
|
|
35
36
|
VIEWER_LEFT = "viewer_left"
|
|
36
37
|
SETTINGS = "settings"
|
|
37
38
|
MOTION_DETECTION = "motion_detection"
|
|
39
|
+
NOISE_DETECTION = "noise_detection"
|
|
38
40
|
CAMERA_EVENT = "camera_event"
|
|
39
41
|
RAW = "raw"
|
|
40
42
|
|
|
@@ -118,22 +120,33 @@ class SettingsUpdate(HarborEvent):
|
|
|
118
120
|
|
|
119
121
|
@dataclass(slots=True, frozen=True, kw_only=True)
|
|
120
122
|
class CameraEventUpdate(HarborEvent):
|
|
121
|
-
"""A camera event
|
|
123
|
+
"""A camera detection event.
|
|
124
|
+
|
|
125
|
+
These are edge triggers. The camera never publishes a matching "cleared"
|
|
126
|
+
message, so this update carries no duration or on/off state -- ``timestamp``
|
|
127
|
+
is the whole signal.
|
|
128
|
+
"""
|
|
122
129
|
|
|
123
130
|
payload: Any
|
|
124
|
-
active_seconds: float
|
|
125
|
-
explicit_state: bool | None
|
|
126
131
|
event_type: EventType = field(init=False, default=EventType.CAMERA_EVENT)
|
|
127
132
|
|
|
128
133
|
|
|
129
134
|
@dataclass(slots=True, frozen=True, kw_only=True)
|
|
130
135
|
class MotionDetectedUpdate(CameraEventUpdate):
|
|
131
|
-
"""A typed motion
|
|
136
|
+
"""A typed ``motion-detected`` update."""
|
|
132
137
|
|
|
133
138
|
payload: MotionDetectedEvent
|
|
134
139
|
event_type: EventType = field(init=False, default=EventType.MOTION_DETECTION)
|
|
135
140
|
|
|
136
141
|
|
|
142
|
+
@dataclass(slots=True, frozen=True, kw_only=True)
|
|
143
|
+
class NoiseDetectedUpdate(CameraEventUpdate):
|
|
144
|
+
"""A typed ``sound-anomaly-detected`` update."""
|
|
145
|
+
|
|
146
|
+
payload: NoiseDetectedEvent
|
|
147
|
+
event_type: EventType = field(init=False, default=EventType.NOISE_DETECTION)
|
|
148
|
+
|
|
149
|
+
|
|
137
150
|
EVENT_MESSAGE_MAP: dict[type[BaseModel], type[HarborEvent]] = {
|
|
138
151
|
HeartbeatEvent: HeartbeatUpdate,
|
|
139
152
|
LocalLivekitHeartbeatEvent: LocalLivekitHeartbeatUpdate,
|
|
@@ -141,6 +154,7 @@ EVENT_MESSAGE_MAP: dict[type[BaseModel], type[HarborEvent]] = {
|
|
|
141
154
|
ViewerLeftEvent: ViewerLeftUpdate,
|
|
142
155
|
SettingsEvent: SettingsUpdate,
|
|
143
156
|
MotionDetectedEvent: MotionDetectedUpdate,
|
|
157
|
+
NoiseDetectedEvent: NoiseDetectedUpdate,
|
|
144
158
|
}
|
|
145
159
|
|
|
146
160
|
|
|
@@ -148,13 +162,23 @@ CallbackType = Callable[[HarborEvent], Any]
|
|
|
148
162
|
EventT = TypeVar("EventT", bound=HarborEvent)
|
|
149
163
|
|
|
150
164
|
|
|
165
|
+
#: Detection topics the camera actually publishes, mapped to their event key.
|
|
166
|
+
#: The firmware emits exactly two -- ``motion-detected`` and
|
|
167
|
+
#: ``sound-anomaly-detected``. There is no ``cry-detected`` or
|
|
168
|
+
#: ``noise-detected`` topic; the sound anomaly is the noise detector, and the
|
|
169
|
+
#: app presents it as an alert for "sudden, loud sounds" and "sustained
|
|
170
|
+
#: noises", hence ``noise_detection``.
|
|
171
|
+
DETECTION_TOPIC_EVENT_KEYS = {
|
|
172
|
+
"motion_detected": "motion_detection",
|
|
173
|
+
"sound_anomaly_detected": "noise_detection",
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
151
177
|
def event_key_from_topic(event_name: str) -> str:
|
|
152
178
|
"""Normalize an event topic segment into a stable key."""
|
|
153
179
|
|
|
154
180
|
event_key = event_name.strip().replace("-", "_")
|
|
155
|
-
|
|
156
|
-
return event_key.removesuffix("_detected") + "_detection"
|
|
157
|
-
return event_key
|
|
181
|
+
return DETECTION_TOPIC_EVENT_KEYS.get(event_key, event_key)
|
|
158
182
|
|
|
159
183
|
|
|
160
184
|
def parse_payload(payload: Any) -> Any:
|
|
@@ -190,81 +214,6 @@ def parse_topic(
|
|
|
190
214
|
return None, None, None
|
|
191
215
|
|
|
192
216
|
|
|
193
|
-
def extract_event_duration_seconds(payload: Any) -> float:
|
|
194
|
-
"""Extract an event duration from a payload."""
|
|
195
|
-
|
|
196
|
-
default = 5.0
|
|
197
|
-
if not isinstance(payload, Mapping):
|
|
198
|
-
return default
|
|
199
|
-
|
|
200
|
-
duration = payload.get("duration")
|
|
201
|
-
if duration is None or isinstance(duration, bool):
|
|
202
|
-
return default
|
|
203
|
-
|
|
204
|
-
if isinstance(duration, int | float):
|
|
205
|
-
return float(duration) if duration > 0 else default
|
|
206
|
-
|
|
207
|
-
if not isinstance(duration, str):
|
|
208
|
-
return default
|
|
209
|
-
|
|
210
|
-
duration = duration.strip()
|
|
211
|
-
if not duration:
|
|
212
|
-
return default
|
|
213
|
-
|
|
214
|
-
try:
|
|
215
|
-
parsed = float(duration)
|
|
216
|
-
except ValueError:
|
|
217
|
-
parts = duration.split(":")
|
|
218
|
-
if len(parts) not in (2, 3):
|
|
219
|
-
return default
|
|
220
|
-
try:
|
|
221
|
-
numbers = [float(part) for part in parts]
|
|
222
|
-
except ValueError:
|
|
223
|
-
return default
|
|
224
|
-
if len(numbers) == 2:
|
|
225
|
-
minutes, seconds = numbers
|
|
226
|
-
total = minutes * 60 + seconds
|
|
227
|
-
else:
|
|
228
|
-
hours, minutes, seconds = numbers
|
|
229
|
-
total = hours * 3600 + minutes * 60 + seconds
|
|
230
|
-
return total if total > 0 else default
|
|
231
|
-
|
|
232
|
-
return parsed if parsed > 0 else default
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
def extract_explicit_event_state(payload: Any) -> bool | None:
|
|
236
|
-
"""Extract an explicit on/off state from a payload when available."""
|
|
237
|
-
|
|
238
|
-
if not isinstance(payload, Mapping):
|
|
239
|
-
return None
|
|
240
|
-
|
|
241
|
-
for key in (
|
|
242
|
-
"active",
|
|
243
|
-
"detected",
|
|
244
|
-
"is_active",
|
|
245
|
-
"is_detected",
|
|
246
|
-
"motion",
|
|
247
|
-
"motion_detected",
|
|
248
|
-
"cry",
|
|
249
|
-
"cry_detected",
|
|
250
|
-
"noise",
|
|
251
|
-
"noise_detected",
|
|
252
|
-
):
|
|
253
|
-
value = payload.get(key)
|
|
254
|
-
if isinstance(value, bool):
|
|
255
|
-
return value
|
|
256
|
-
|
|
257
|
-
state_value = payload.get("state")
|
|
258
|
-
if isinstance(state_value, str):
|
|
259
|
-
normalized = state_value.strip().lower()
|
|
260
|
-
if normalized in {"active", "detected", "on", "true"}:
|
|
261
|
-
return True
|
|
262
|
-
if normalized in {"inactive", "off", "false", "idle"}:
|
|
263
|
-
return False
|
|
264
|
-
|
|
265
|
-
return None
|
|
266
|
-
|
|
267
|
-
|
|
268
217
|
def parse_message(
|
|
269
218
|
topic: str,
|
|
270
219
|
payload: Any,
|
|
@@ -342,24 +291,15 @@ def parse_message(
|
|
|
342
291
|
return RawEventUpdate(payload=raw_payload, **base_kwargs)
|
|
343
292
|
|
|
344
293
|
if source_type == "camera":
|
|
345
|
-
active_seconds = extract_event_duration_seconds(raw_payload)
|
|
346
|
-
explicit_state = extract_explicit_event_state(raw_payload)
|
|
347
|
-
|
|
348
294
|
if event_key == "motion_detection":
|
|
349
295
|
if motion_payload := _validate_payload(MotionDetectedEvent, raw_payload, topic):
|
|
350
|
-
return MotionDetectedUpdate(
|
|
351
|
-
payload=motion_payload,
|
|
352
|
-
active_seconds=active_seconds,
|
|
353
|
-
explicit_state=explicit_state,
|
|
354
|
-
**base_kwargs,
|
|
355
|
-
)
|
|
296
|
+
return MotionDetectedUpdate(payload=motion_payload, **base_kwargs)
|
|
356
297
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
)
|
|
298
|
+
if event_key == "noise_detection":
|
|
299
|
+
if noise_payload := _validate_payload(NoiseDetectedEvent, raw_payload, topic):
|
|
300
|
+
return NoiseDetectedUpdate(payload=noise_payload, **base_kwargs)
|
|
301
|
+
|
|
302
|
+
return CameraEventUpdate(payload=raw_payload, **base_kwargs)
|
|
363
303
|
|
|
364
304
|
return RawEventUpdate(payload=raw_payload, **base_kwargs)
|
|
365
305
|
|
|
@@ -22,12 +22,21 @@ class HarborViewer:
|
|
|
22
22
|
|
|
23
23
|
@dataclass(slots=True)
|
|
24
24
|
class HarborEventState:
|
|
25
|
-
"""
|
|
25
|
+
"""Record of a Harbor camera detection event.
|
|
26
|
+
|
|
27
|
+
Detections are edge triggers: the camera publishes ``motion-detected`` and
|
|
28
|
+
``sound-anomaly-detected`` when something fires and never publishes a
|
|
29
|
+
counterpart to clear them. There is deliberately no ``is_on`` here -- an
|
|
30
|
+
on/off reading would have to be synthesized from a timer the device knows
|
|
31
|
+
nothing about, and the payload carries nothing that could size one.
|
|
32
|
+
``last_seen`` is the authoritative signal; consumers that
|
|
33
|
+
need a momentary entity (Home Assistant's ``event`` platform, a device
|
|
34
|
+
trigger) should drive it from a change in ``last_seen``.
|
|
35
|
+
"""
|
|
26
36
|
|
|
27
37
|
key: str
|
|
28
38
|
topic: str
|
|
29
39
|
friendly_name: str
|
|
30
|
-
is_on: bool = False
|
|
31
40
|
last_seen: datetime | None = None
|
|
32
41
|
last_payload: Any = None
|
|
33
42
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "harbor-python"
|
|
3
|
-
version = "1.
|
|
3
|
+
version = "1.6.1"
|
|
4
4
|
description = "Async local client for Harbor Sleep Cameras"
|
|
5
5
|
authors = [{name="Andres Garcia"},{name = "Lash-L"}]
|
|
6
6
|
readme = "README.md"
|
|
@@ -64,7 +64,7 @@ dev = [
|
|
|
64
64
|
[tool.semantic_release]
|
|
65
65
|
branch = "main"
|
|
66
66
|
version_toml = ["pyproject.toml:project.version"]
|
|
67
|
-
build_command = "pip install uv && uv lock --upgrade-package harbor-python && git add uv.lock && uv build"
|
|
67
|
+
build_command = "(command -v uv >/dev/null || pip install uv) && uv lock --upgrade-package harbor-python && git add uv.lock && uv build"
|
|
68
68
|
changelog_file = 'CHANGELOG.md'
|
|
69
69
|
commit = true
|
|
70
70
|
|
|
@@ -72,6 +72,13 @@ commit = true
|
|
|
72
72
|
match = "main"
|
|
73
73
|
prerelease = false
|
|
74
74
|
|
|
75
|
+
# CI's "Test Semantic Release" job dry-runs a release from this temporary branch
|
|
76
|
+
# on pull requests. Without a release group for it, semantic-release skips the
|
|
77
|
+
# version and build steps entirely, so the check passes without testing anything.
|
|
78
|
+
[tool.semantic_release.branches.temp-main-branch]
|
|
79
|
+
match = "temp-main-branch"
|
|
80
|
+
prerelease = false
|
|
81
|
+
|
|
75
82
|
[tool.semantic_release.commit_parser_options]
|
|
76
83
|
allowed_tags = [
|
|
77
84
|
"chore",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|