Skip to content

Add P3 live camera streaming and fix elapsed job time - #14

Draft
shaunbarrow wants to merge 10 commits into
thecodingdad:mainfrom
shaunbarrow:agent/p3-live-camera-stream
Draft

Add P3 live camera streaming and fix elapsed job time#14
shaunbarrow wants to merge 10 commits into
thecodingdad:mainfrom
shaunbarrow:agent/p3-live-camera-stream

Conversation

@shaunbarrow

@shaunbarrow shaunbarrow commented Aug 14, 2026

Copy link
Copy Markdown

Summary

  • add hardware-verified P3 live camera transport over the WS-V2 media_stream channel
  • map Home Assistant's P3 overview / closeup cameras to xTool Studio's far / upside live names
  • bridge Annex-B H.264 through a localhost-only TCP source into Home Assistant's native Stream integration
  • retain the existing snapshot-polled MJPEG fallback for models whose live transport has not been verified
  • fix the P3 task-time sensor so elapsed job time is polled, decoded, and preserved correctly
  • document the observed camera and progress protocols and update the camera capability table

This follows the still-image repair documented in #10. It does not add or change job-control actions or laser operation.

Camera root cause

The integration only exposed snapshot polling. Its protocol notes also assumed the media_stream channel required WebRTC signaling. Current xTool Studio code and live P3 traffic show a simpler direct path: Studio opens a same-session media_stream WebSocket, starts /v1/platform/camera/live, and receives protocol-34 frames containing a one-byte stream id followed by Annex-B H.264.

P3 job-time root cause

A hardware probe during an active P3 job returned:

{"time": 8496, "total": 100, "value": 100}

The existing task-time entity stayed unknown/zero for three reasons:

  1. The generic decoder expected workingTime or totalTime, while P3 reports elapsed job seconds in time.
  2. P3 runtime information can report P_OFF during or around an active job, so progress polling was skipped.
  3. The push-state cache could overwrite a newly polled task time with a stale zero before Home Assistant updated the entity.

The fix polls P3 progress regardless of that incorrect runtime mode, interprets time as elapsed seconds, and synchronizes the cached value so it survives the update cycle. total and value remain percentage/progress fields rather than durations.

Safety and scope

  • Live support is explicitly allowlisted for P3 only.
  • The decoder source listens on 127.0.0.1 with an ephemeral port; it is not exposed to the LAN.
  • Start/stop requests are paired in try/finally cleanup.
  • Existing still images and fallback behavior remain unchanged for other models.
  • The task-time change is read-only telemetry; it does not start, stop, pause, or otherwise control a job.

Validation

  • git diff --check
  • Python 3.12 compileall over custom_components/xtool
  • JSON parse validation for manifest.json
  • live P3 hardware probe: start and stop returned success; protocol-34 H.264 decoded as High profile, 1280x720, approximately 10 delivered packets/frames per second
  • captured Annex-B stream decoded to a valid first frame with ffmpeg
  • live P3 progress response decoded as 8,496 elapsed seconds
  • Home Assistant published sensor.xtool_p3_task_time = 8496 with unit s

HACS and hassfest validation will run in this repository's GitHub Actions workflow.

@shaunbarrow shaunbarrow changed the title Add P3 live camera streaming Add P3 live camera streaming and fix elapsed job time Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant