Skip to content

Simplify transport and media handling - #1

Merged
alphasixtyfive merged 2 commits into
masterfrom
agent/simplify-transport-media
Jul 23, 2026
Merged

Simplify transport and media handling#1
alphasixtyfive merged 2 commits into
masterfrom
agent/simplify-transport-media

Conversation

@alphasixtyfive

@alphasixtyfive alphasixtyfive commented Jul 23, 2026

Copy link
Copy Markdown
Owner

What changed

  • Replaced the custom raw HTTP, response parsing, and Digest-authentication implementation with Home Assistant's shared aiohttp session and DigestAuthMiddleware.
  • Kept Hikvision-compatible real-time playback through a reusable, fixed-length paced audio payload.
  • Routed media source IDs, /local/... paths, and URLs through Home Assistant's standard media URL processing.
  • Restricted the media browser to audio sources.
  • Enforced the 20 MB media limit while streaming responses, including responses without Content-Length.
  • Removed the no-longer-needed direct filesystem decode path and bumped the integration version to 0.1.3.
  • Reported playing while audio is being streamed and restored idle after completion or cancellation.

Why

The former client manually implemented HTTP framing and Digest authentication, which accounted for much of the integration's complexity and could leave sockets open on request failures. Remote responses without a trustworthy Content-Length were fully buffered before their size was checked. Using Home Assistant's HTTP stack makes connection ownership and authentication clearer, while bounded streaming keeps memory use predictable.

The media player also remained idle during playback because its state was never updated. The entity now exposes the expected playback lifecycle.

Compatibility and validation

  • Ruff check and format check pass.
  • Python compilation passes.
  • HACS and hassfest GitHub checks pass.
  • Digest challenge, pre-emptive authentication, fixed Content-Length, non-chunked upload, and real-time pacing verified against a local protocol server with aiohttp 3.14.3.
  • Silent audio uploads completed successfully on both configured Hikvision devices; channel lookup, close, open, audio upload, and final close all returned HTTP 200.
  • A real Home Assistant /local/... MP3 downloaded and decoded successfully.
  • Declared-length and chunked oversized downloads were both rejected at the configured limit.
  • G.711 u-law and A-law output still matches the reference implementation for 75,536 samples per codec.
  • Home Assistant was restarted with the updated component; MP3 and TTS playback worked, no integration errors were logged, and two live tests recorded playingidle transitions.

YAML configuration remains unchanged.

@alphasixtyfive
alphasixtyfive marked this pull request as ready for review July 23, 2026 09:47
@alphasixtyfive
alphasixtyfive merged commit 2953179 into master Jul 23, 2026
2 checks passed
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