fix(ptz): stop-on-loss — ONVIF dead-man's-switch + VISCA halt-on-reconnect#115
Merged
Conversation
…nnect ONVIF: set Timeout=PT1S on every ContinuousMove so the camera self-stops if no new command arrives (connection loss/hang). Wrap move_velocity and stop in try/except with throttled WARNING so transport errors never crash the control loop. Import time in the module so the throttle clock can be patched in tests. VISCA (IP + USB): always send a pantilt+zoom stop immediately after a successful reconnect, before retrying the pending command. A camera that was mid-pan when the link dropped halts instead of continuing a stale continuous-move. Sending stop to an already-stopped camera is a safe no-op. Tests: 12 new tests in tests/test_ptz_stop_on_loss.py covering all three backends with mocked transports; all 1218 suite tests pass; ruff/mypy/selftest green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What / Why
A PTZ camera must not run away when its connection drops. This PR adds two backend-local safety mechanisms:
ONVIF dead-man's switch (
onvif_ptz.py)Timeout=timedelta(seconds=1)on everyContinuousMoverequest so the camera self-stops if no new command arrives within ~1 s (connection loss, hung network). Uses Pythondatetime.timedeltawhich zeep accepts directly.move_velocityintry/exceptwith a throttled WARNING (one per 5 s) so a sustained transport outage logs once and never crashes the control loop.stop()already had a bareexcept Exception: pass; unchanged.VISCA halt-on-reconnect (
visca_ip.py,visca_usb.py)_send, always sends pantilt-stop + zoom-stop before retrying the pending command. A camera that was mid-pan when the link dropped halts rather than continuing a stale continuous-move. Sending stop to an already-stopped camera is a safe no-op.reconnect.pyorbase.py; no changes tocamera_worker.py/controller.py(those get the complementary heartbeat in a later PR).Tests
12 new tests in
tests/test_ptz_stop_on_loss.py:Timeoutfield present and correct value; velocity fields intact; transport errors caught (move + stop); log throttleNo real hardware/network — all transports mocked (same style as
test_ptz_reconnect.py).Gate results
🤖 Generated with Claude Code