Skip to content

Break the import cycle between the camera and its stream services - #556

Merged
ikalchev merged 1 commit into
devfrom
fix/circular-import
Nov 12, 2026
Merged

ikalchev merged 1 commit into
devfrom
fix/circular-import

Conversation

@ikalchev

@ikalchev ikalchev commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to the #545 review: the camera modules imported each other in a circle, hidden by deferred imports.

pyhap.camera imported the multi-tier and WebRTC stream services from a function, with a noqa: PLC0415, because pyhap.camera_multi_tier imported pyhap.camera back for parse_setup_address; and pyhap.camera_stream imported pyhap.hap_handler only for RESPONSE_TIMEOUT.

  • parse_setup_address moves to pyhap.util, which every camera module already imports. It stays importable from pyhap.camera, and the hksv3 docstring reference now points to pyhap.util.
  • RESPONSE_TIMEOUT moves to pyhap.const; hap_handler and camera_stream import it from there (patching hap_handler.RESPONSE_TIMEOUT keeps working).
  • The deferred imports in Camera._setup_stream_controllers become normal top-level ones, and the noqas go away. The camera modules now import only leaves — hksv3, const, util — and each other, in one direction. The only remaining pyhap.camera references in the stream modules are TYPE_CHECKING ones.

This PR is mostly LLM generated (GLM-5.3). Verifications mine.

pyhap.camera imported the multi-tier and WebRTC stream services from a
function, with a noqa, because they import pyhap.camera back for
parse_setup_address; and pyhap.camera_stream imported pyhap.hap_handler
only for RESPONSE_TIMEOUT.

parse_setup_address moves to pyhap.util, which every camera module
already imports, and RESPONSE_TIMEOUT moves to pyhap.const, which
hap_handler and camera_stream re-import. That turns the deferred
imports in Camera._setup_stream_controllers into normal top-level ones
and leaves the camera modules importing only leaves: hksv3, const,
util and each other, in one direction.
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.99%. Comparing base (f7406d3) to head (1cc6eb0).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #556   +/-   ##
=======================================
  Coverage   91.99%   91.99%           
=======================================
  Files          50       50           
  Lines       10822    10822           
  Branches     1402     1402           
=======================================
  Hits         9956     9956           
  Misses        579      579           
  Partials      287      287           
Files with missing lines Coverage Δ
pyhap/camera.py 92.51% <100.00%> (-0.09%) ⬇️
pyhap/camera_multi_tier.py 94.90% <100.00%> (-0.02%) ⬇️
pyhap/camera_stream.py 97.60% <100.00%> (ø)
pyhap/const.py 100.00% <100.00%> (ø)
pyhap/hap_handler.py 86.54% <ø> (-0.04%) ⬇️
pyhap/hksv3.py 100.00% <ø> (ø)
pyhap/util.py 82.47% <100.00%> (+2.47%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ikalchev ikalchev self-assigned this Nov 12, 2026
@ikalchev
ikalchev merged commit 84529d8 into dev Nov 12, 2026
14 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