Skip to content

fix tests (#82)#83

Open
3dg1luk43 wants to merge 4 commits into
mainfrom
0.9.3
Open

fix tests (#82)#83
3dg1luk43 wants to merge 4 commits into
mainfrom
0.9.3

Conversation

@3dg1luk43
Copy link
Copy Markdown
Owner

@3dg1luk43 3dg1luk43 commented Apr 19, 2026

fix #82

Summary by CodeRabbit

  • New Features

    • Added active filament sensor to display currently selected filament source and details.
  • Bug Fixes

    • Improved WebRTC stream error handling with automatic recovery mechanism.
    • Enhanced debug logging for WebRTC offer processing.
  • Style

    • Updated card action chip layout to wrap across multiple lines.
    • Refined visual masking for ring and spool gradient displays.
  • Tests

    • Added comprehensive test coverage for WebRTC error recovery and stream configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 19, 2026

Warning

Rate limit exceeded

@3dg1luk43 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 16 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 1 minutes and 16 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 416e342e-bb47-4c0a-952a-e0fbc730590f

📥 Commits

Reviewing files that changed from the base of the PR and between b9b8d9d and 7df482f.

📒 Files selected for processing (9)
  • .gitignore
  • custom_components/ha_creality_ws/camera.py
  • custom_components/ha_creality_ws/sensor.py
  • custom_components/ha_creality_ws/www/k_cfs_card.js
  • custom_components/ha_creality_ws/www/k_printer_card.js
  • tools/requirements.txt
  • tools/tests/test_camera_recovery.py
  • tools/tests/test_camera_stream_config.py
  • tools/tests/test_camera_webrtc_repro.py
📝 Walkthrough

Walkthrough

The PR enhances WebRTC error handling and recovery in the camera component, introduces a new filament sensor entity for tracking active filament selection, updates CSS styling for UI cards with improved masking and layout, and expands the test infrastructure with additional Home Assistant mocks and new test cases for stream configuration and error recovery.

Changes

Cohort / File(s) Summary
WebRTC Stream & Error Recovery
custom_components/ha_creality_ws/camera.py
Removed #format=creality fragment from go2rtc source URL, enhanced debug logging for WebRTC offers, and added recovery logic to delete failed streams and reset state when Go2RtcClientError occurs.
Sensor Integration
custom_components/ha_creality_ws/sensor.py
Added new KActiveFilamentSensor entity with UID active_filament_slot that reports the currently selected filament source (External or Box/Slot) with additional filament attributes.
Frontend UI Styling
custom_components/ha_creality_ws/www/k_cfs_card.js, k_printer_card.js
Updated radial and conic gradient masking with webkit prefixes, changed ring/spool backgrounds to transparent, and updated chips layout to wrap across multiple lines instead of forcing single row.
Test Infrastructure & Mocking
tools/tests/conftest.py
Enhanced test setup to guard module initialization, added stub classes for HomeAssistant, callback, CoordinatorEntity, DeviceInfo, and Entity across mock Home Assistant modules.
WebRTC & Stream Configuration Tests
tools/tests/test_camera_recovery.py, test_camera_stream_config.py, test_camera_webrtc_repro.py
Added three new test modules validating WebRTC offer error handling/recovery, stream configuration without #format=creality, and error response formatting.
Configuration
.gitignore
Added three new ignore patterns: .agent, .issues, and conductor.

Sequence Diagram(s)

sequenceDiagram
    participant Client as WebRTC Client
    participant Camera as CrealityWebRTCCamera
    participant Go2RTC as Go2RTC Client
    participant Streams as Stream Manager

    Client->>Camera: async_handle_async_webrtc_offer(offer)
    Camera->>Go2RTC: forward_whep_sdp_offer(offer)
    
    alt Stream not configured
        Camera->>Camera: _ensure_stream_configured()
        Camera->>Streams: add(sources=[...])
        Streams-->>Camera: Stream created
    end
    
    Go2RTC-->>Camera: Response/Error
    
    alt Go2RtcClientError occurs
        Camera->>Camera: Log error with stream name
        Camera->>Streams: delete(stream_name)
        Streams-->>Camera: Stream deleted
        Camera->>Camera: _stream_name = None
        Camera->>Client: send_message(type="error")
    else Success
        Camera->>Client: send_message(answer)
    end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hop, a stream, now heals with grace,
When errors strike, we find our place,
New sensors track the filament's call,
CSS glows transparent through it all,
With tests robust to catch it all!

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes several out-of-scope changes beyond test fixes: WebRTC offer forwarding improvements, new KActiveFilamentSensor entity, and UI/CSS modifications to card layouts that are unrelated to the websocket reconnect test objective. Separate the functional changes (camera.py WebRTC improvements, sensor.py new entity, CSS updates, .gitignore additions) into distinct PRs from the test infrastructure fixes to maintain focus on issue #82.
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix tests (#82)' is vague and generic, using non-descriptive language that doesn't convey meaningful information about what was actually fixed or changed. Consider a more descriptive title that highlights the main changes, such as 'Fix WebRTC camera recovery and stream configuration tests' or 'Enhance test infrastructure for WebRTC and sensor functionality'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR substantially addresses issue #82 by enhancing test infrastructure with mocks for external dependencies, enabling tests to run without external packages, and adding comprehensive WebRTC camera recovery and stream configuration tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 0.9.3

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.gitignore (1)

3-16: ⚠️ Potential issue | 🔴 Critical

Unresolved merge conflict markers committed in .gitignore.

Lines 3, 8, and 13 contain raw Git conflict markers (<<<<<<< HEAD, =======, >>>>>>> 909e8e9f4f022889b6ae4043365fc0b54a8135a9). These were not resolved before committing. While .gitignore silently skips unknown patterns, this is clearly a botched merge resolution that needs to be cleaned up before this PR can land.

🛠️ Proposed fix (resolve the conflict by keeping the union of both sides)
 .venv/*
 backups/*
-<<<<<<< HEAD
-custom_components/ha_creality_ws/__pycache__/*
-ha_creality_ws.code-workspace
-tools/tests/__pycache__
-tools/test_files
-=======
 ha_creality_ws.code-workspace
 tools/test_files
 custom_components/ha_creality_ws/__pycache__
 tools/tests/__pycache__
->>>>>>> 909e8e9f4f022889b6ae4043365fc0b54a8135a9
 .agent
 .issues
 conductor
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.gitignore around lines 3 - 16, Remove the unresolved Git conflict markers
from the .gitignore file by deleting the lines starting with <<<<<<<, =======,
and >>>>>>> and keep the union of both sides' entries (ensure entries like
custom_components/ha_creality_ws/__pycache__/*, ha_creality_ws.code-workspace,
tools/tests/__pycache__, tools/test_files and the additional entries .agent,
.issues, conductor are present exactly once); save the cleaned .gitignore so
there are no conflict markers remaining.
♻️ Duplicate comments (1)
tools/tests/test_camera_stream_config.py (1)

72-72: ⚠️ Potential issue | 🟡 Minor

Remove leftover debug print.

This looks like a dev-time trace that should be dropped (or converted to a proper assertion message) before merge.

🧹 Proposed fix
-    assert "sources" in call_args.kwargs
-    source = call_args.kwargs["sources"]
-    print(f"DEBUG: source={source}")
-    assert "#format=creality" not in source
-    assert source == "webrtc:http://1.2.3.4:8000/call/webrtc_local"
+    assert "sources" in call_args.kwargs
+    source = call_args.kwargs["sources"]
+    assert "#format=creality" not in source, source
+    assert source == "webrtc:http://1.2.3.4:8000/call/webrtc_local", source

Also note: this file shares the pytest-asyncio failure already flagged on tools/tests/test_camera_recovery.py.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/tests/test_camera_stream_config.py` at line 72, Remove the leftover
debug print statement print(f"DEBUG: source={source}") from the test (or replace
it with a proper test assertion or pytest-friendly logging) so the test no
longer emits dev-time traces; locate the print by searching for the exact string
or the variable name "source" in the test_camera_stream_config.py test function
and either delete the line or convert it into an assertion that validates the
expected value of source or into a logger call if runtime information must be
preserved.
🧹 Nitpick comments (2)
custom_components/ha_creality_ws/sensor.py (1)

763-765: Naming inconsistency with sibling CFS sensors.

The displayed string uses 1-based indexing for both box and slot (Box {box_id + 1} Slot {slot_id + 1}), but KCFSBoxSensor exposes the box as CFS Box {box_id} (0-based, no offset) while KCFSSlotSensor exposes the slot as CFS Box {box_id} Slot {slot_id + 1}. As a result the active value Box 1 Slot 2 won't textually match the existing CFS Box 0 Slot 2 … entities for the same physical slot, which will be confusing in dashboards/automations. Consider aligning with the existing convention (keep box_id as-is, only +1 the slot).

♻️ Suggested change
-                    return f"Box {box_id + 1} Slot {slot_id + 1}"
+                    return f"Box {box_id} Slot {slot_id + 1}"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@custom_components/ha_creality_ws/sensor.py` around lines 763 - 765, The
display string currently offsets both box and slot (return f"Box {box_id + 1}
Slot {slot_id + 1}"), which conflicts with sibling sensors (KCFSBoxSensor shows
"CFS Box {box_id}" and KCFSSlotSensor shows "CFS Box {box_id} Slot {slot_id +
1}"); change the formatter so box_id is used as-is and only slot_id is 1-based
(i.e., use box_id without +1 and slot_id +1) to match the existing naming
convention for KCFSBoxSensor and KCFSSlotSensor.
custom_components/ha_creality_ws/camera.py (1)

784-793: Log cleanup failures at DEBUG instead of silently swallowing them.

The bare except Exception: pass on the streams.delete cleanup hides useful diagnostics if the recovery itself fails (e.g., go2rtc unreachable). A single debug line keeps the hot path quiet while preserving traceability, and also addresses Ruff's S110/BLE001 hints.

♻️ Proposed fix
-            # Attempt recovery by invalidating the stream to force reconfiguration next time
-            if self._stream_name:
-                _LOGGER.warning("ha_creality_ws: Invalidating stream '%s' due to go2rtc error", self._stream_name)
-                try:
-                    await self._go2rtc_client.streams.delete(self._stream_name)
-                except Exception:
-                    # Ignore errors during cleanup
-                    pass
-                self._stream_name = None
+            # Attempt recovery by invalidating the stream to force reconfiguration next time
+            if self._stream_name:
+                _LOGGER.warning("ha_creality_ws: Invalidating stream '%s' due to go2rtc error", self._stream_name)
+                try:
+                    await self._go2rtc_client.streams.delete(self._stream_name)
+                except Exception as cleanup_exc:  # noqa: BLE001 - best-effort cleanup
+                    _LOGGER.debug(
+                        "ha_creality_ws: stream cleanup failed for '%s': %s",
+                        self._stream_name, cleanup_exc,
+                    )
+                self._stream_name = None

As per coding guidelines: "Use logging at DEBUG level for detailed logs and WARNING level for visible diagnostics".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@custom_components/ha_creality_ws/camera.py` around lines 784 - 793, The
cleanup block swallows all exceptions when calling
self._go2rtc_client.streams.delete(self._stream_name); change the bare "except
Exception: pass" to catch the exception into a variable (e.g., except Exception
as exc:) and log it at DEBUG via _LOGGER.debug with context (include the stream
name and the exception, or use exc_info=True) so failures are traceable while
keeping the hot path quiet; keep the existing behavior of setting
self._stream_name = None after the cleanup attempt.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@custom_components/ha_creality_ws/sensor.py`:
- Around line 752-781: Guard against coordinator.data being None and ensure
zeroing logic is applied to attributes: in both the native_value and
extra_state_attributes properties, first set data = self.coordinator.data or {}
and use data.get(...) instead of self.coordinator.data.get(...); additionally
add an early return {} in extra_state_attributes when self._should_zero() is
True so attributes are zeroed like other KEntity subclasses (referencing
native_value, extra_state_attributes, _should_zero(), and coordinator.data or
{}).

In `@custom_components/ha_creality_ws/www/k_cfs_card.js`:
- Around line 254-255: The radial mask uses the default sizing so the
transparent stop spills outside the visible circle; update the two mask rules
(the lines setting "mask: radial-gradient(...)" and "-webkit-mask:
radial-gradient(...)") to use "closest-side" and replace percentage stops with
pixel stops that match the intended ring thickness (e.g.,
"radial-gradient(circle closest-side at 50% 50%, transparent 34px, black 35px)"
or values that equal the ring radius and 1px border), and make the analogous
change for the other mask occurrences around the progress ring (the second mask
pair later in the file) so both mask and -webkit-mask use closest-side with
pixel-based stops matching the ring sizes.

In `@tools/tests/test_camera_recovery.py`:
- Around line 45-86: The async test test_webrtc_recovery_on_error uses
`@pytest.mark.asyncio` but the test environment doesn't install pytest-asyncio;
either add pytest-asyncio to dev deps or convert the test to a synchronous
runner. Fix by updating tools/requirements.txt to include pytest-asyncio>=0.23
(and optionally set asyncio_mode = "auto" in test config like
pyproject.toml/pytest.ini) so `@pytest.mark.asyncio` works, or alternatively
remove `@pytest.mark.asyncio` and wrap the coroutine call in asyncio.run(...)
inside test_webrtc_recovery_on_error to drive the coroutine without the plugin.

---

Outside diff comments:
In @.gitignore:
- Around line 3-16: Remove the unresolved Git conflict markers from the
.gitignore file by deleting the lines starting with <<<<<<<, =======, and
>>>>>>> and keep the union of both sides' entries (ensure entries like
custom_components/ha_creality_ws/__pycache__/*, ha_creality_ws.code-workspace,
tools/tests/__pycache__, tools/test_files and the additional entries .agent,
.issues, conductor are present exactly once); save the cleaned .gitignore so
there are no conflict markers remaining.

---

Duplicate comments:
In `@tools/tests/test_camera_stream_config.py`:
- Line 72: Remove the leftover debug print statement print(f"DEBUG:
source={source}") from the test (or replace it with a proper test assertion or
pytest-friendly logging) so the test no longer emits dev-time traces; locate the
print by searching for the exact string or the variable name "source" in the
test_camera_stream_config.py test function and either delete the line or convert
it into an assertion that validates the expected value of source or into a
logger call if runtime information must be preserved.

---

Nitpick comments:
In `@custom_components/ha_creality_ws/camera.py`:
- Around line 784-793: The cleanup block swallows all exceptions when calling
self._go2rtc_client.streams.delete(self._stream_name); change the bare "except
Exception: pass" to catch the exception into a variable (e.g., except Exception
as exc:) and log it at DEBUG via _LOGGER.debug with context (include the stream
name and the exception, or use exc_info=True) so failures are traceable while
keeping the hot path quiet; keep the existing behavior of setting
self._stream_name = None after the cleanup attempt.

In `@custom_components/ha_creality_ws/sensor.py`:
- Around line 763-765: The display string currently offsets both box and slot
(return f"Box {box_id + 1} Slot {slot_id + 1}"), which conflicts with sibling
sensors (KCFSBoxSensor shows "CFS Box {box_id}" and KCFSSlotSensor shows "CFS
Box {box_id} Slot {slot_id + 1}"); change the formatter so box_id is used as-is
and only slot_id is 1-based (i.e., use box_id without +1 and slot_id +1) to
match the existing naming convention for KCFSBoxSensor and KCFSSlotSensor.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 45d73543-2940-4cf5-b369-76e2f3906f2c

📥 Commits

Reviewing files that changed from the base of the PR and between 6a168d8 and b9b8d9d.

📒 Files selected for processing (9)
  • .gitignore
  • custom_components/ha_creality_ws/camera.py
  • custom_components/ha_creality_ws/sensor.py
  • custom_components/ha_creality_ws/www/k_cfs_card.js
  • custom_components/ha_creality_ws/www/k_printer_card.js
  • tools/tests/conftest.py
  • tools/tests/test_camera_recovery.py
  • tools/tests/test_camera_stream_config.py
  • tools/tests/test_camera_webrtc_repro.py
📜 Review details
🧰 Additional context used
📓 Path-based instructions (5)
custom_components/ha_creality_ws/**/*.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

custom_components/ha_creality_ws/**/*.py: Use type hints throughout Python code
Use ModelDetection to read model and modelVersion codes for feature detection
Conditional features by model: box temp sensor/control (K1/K2), light (all except K1 SE/Ender 3 V3), camera type (WebRTC for K2; MJPEG for K1/Ender 3 V3)
Use HA unit constants with compatibility fallbacks
Use resolved_model() to provide stable model name for device info caching when friendly name is missing
Use logging at DEBUG level for detailed logs and WARNING level for visible diagnostics
Don't block the event loop; avoid sleep() in sync contexts
Don't alter entity unique_id or name formats
Keep public identifiers stable (unique_id/name formats)
Use async for I/O operations throughout the custom integration
Reuse helpers in utils.py and zeroing via KEntity
Add ruff-compliant imports ordering and formatting
Include concise docstrings for public classes and methods
Keep logging concise; DEBUG for detail, WARNING for visible diagnostics; hot paths should be quiet

Files:

  • custom_components/ha_creality_ws/camera.py
  • custom_components/ha_creality_ws/sensor.py
custom_components/ha_creality_ws/{sensor,button,switch,number,camera,image,light,fan}.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

custom_components/ha_creality_ws/{sensor,button,switch,number,camera,image,light,fan}.py: Entities must subclass KEntity and follow CoordinatorEntity pattern; no polling
Implement _should_zero() in KEntity subclasses to zero out when printer is off or link is stale

Files:

  • custom_components/ha_creality_ws/camera.py
  • custom_components/ha_creality_ws/sensor.py
custom_components/ha_creality_ws/camera.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

custom_components/ha_creality_ws/camera.py: MJPEG camera: extract snapshots from MJPEG stream; provide fallback tiny JPEG when unavailable
WebRTC camera (K2): auto-configure go2rtc stream; forward WebRTC offer/answer using HA WebRTC message format {"type": "answer", "answer": "...SDP..."}

Files:

  • custom_components/ha_creality_ws/camera.py
custom_components/ha_creality_ws/sensor.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

custom_components/ha_creality_ws/sensor.py: For new simple sensors, prefer adding to SPECS in sensor.py rather than creating dedicated sensor classes
Status derivation: PrintStatusSensor maps telemetry to human-readable status; do not regress this mapping
Expose new values via sensors: add a spec to SPECS or a dedicated sensor class; ensure zeroing respects _should_zero() and attributes/units are correct

Files:

  • custom_components/ha_creality_ws/sensor.py
custom_components/ha_creality_ws/{sensor,number}.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Sensor zeroing: Layer sensors show 0, text sensors show 'N/A', status shows 'off' when power is off

Files:

  • custom_components/ha_creality_ws/sensor.py
🧠 Learnings (26)
📓 Common learnings
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/camera.py : WebRTC camera (K2): auto-configure go2rtc stream; forward WebRTC offer/answer using HA WebRTC message format {"type": "answer", "answer": "...SDP..."}
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to www/ha-creality-card.js : Lovelace card: implement optimistic UI for snappy feedback on toggles; apply short-lived override and re-render

Applied to files:

  • custom_components/ha_creality_ws/www/k_cfs_card.js
  • custom_components/ha_creality_ws/www/k_printer_card.js
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to www/ha-creality-card.js : Lovelace card: keep config keys backward-compatible; entity IDs and unique_id formats must remain stable

Applied to files:

  • custom_components/ha_creality_ws/www/k_cfs_card.js
  • custom_components/ha_creality_ws/www/k_printer_card.js
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to www/ha-creality-card.js : Lovelace card: avoid forced page reloads; react to HA state updates and local optimistic overrides

Applied to files:

  • custom_components/ha_creality_ws/www/k_cfs_card.js
  • custom_components/ha_creality_ws/www/k_printer_card.js
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to www/ha-creality-card.js : Lovelace card: Power chip pinned to far right via CSS ordering; only visible when configured

Applied to files:

  • custom_components/ha_creality_ws/www/k_cfs_card.js
  • custom_components/ha_creality_ws/www/k_printer_card.js
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to www/ha-creality-card.js : Lovelace card: Light chip visibility reacts to power state and status without reload

Applied to files:

  • custom_components/ha_creality_ws/www/k_cfs_card.js
  • custom_components/ha_creality_ws/www/k_printer_card.js
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/camera.py : WebRTC camera (K2): auto-configure go2rtc stream; forward WebRTC offer/answer using HA WebRTC message format {"type": "answer", "answer": "...SDP..."}

Applied to files:

  • custom_components/ha_creality_ws/camera.py
  • tools/tests/test_camera_stream_config.py
  • tools/tests/test_camera_recovery.py
  • tools/tests/test_camera_webrtc_repro.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/camera.py : MJPEG camera: extract snapshots from MJPEG stream; provide fallback tiny JPEG when unavailable

Applied to files:

  • custom_components/ha_creality_ws/camera.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/ws_client.py : Local WebSocket telemetry with push updates (default ws://<host>:9999); no polling

Applied to files:

  • custom_components/ha_creality_ws/camera.py
  • tools/tests/conftest.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to www/ha-creality-card.js : Lovelace card: resolve entity across domains (e.g., light/switch) for Power chip configuration

Applied to files:

  • custom_components/ha_creality_ws/www/k_printer_card.js
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/**/*.py : Add ruff-compliant imports ordering and formatting

Applied to files:

  • custom_components/ha_creality_ws/www/k_printer_card.js
  • .gitignore
  • tools/tests/conftest.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/**/*.py : Keep public identifiers stable (unique_id/name formats)

Applied to files:

  • custom_components/ha_creality_ws/www/k_printer_card.js
  • .gitignore
  • tools/tests/conftest.py
  • custom_components/ha_creality_ws/sensor.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/**/*.py : Don't alter entity unique_id or name formats

Applied to files:

  • custom_components/ha_creality_ws/www/k_printer_card.js
  • custom_components/ha_creality_ws/sensor.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/**/*.py : Use HA unit constants with compatibility fallbacks

Applied to files:

  • tools/tests/conftest.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/{sensor,button,switch,number,camera,image,light,fan}.py : Entities must subclass KEntity and follow CoordinatorEntity pattern; no polling

Applied to files:

  • tools/tests/conftest.py
  • custom_components/ha_creality_ws/sensor.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/**/*.py : Reuse helpers in utils.py and zeroing via KEntity

Applied to files:

  • tools/tests/conftest.py
  • custom_components/ha_creality_ws/sensor.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/ws_client.py : KClient owns heartbeat, jittered backoff, reconnect, and periodic GETs; do not remove or modify this resilience mechanism

Applied to files:

  • tools/tests/conftest.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/**/*.py : Don't block the event loop; avoid sleep() in sync contexts

Applied to files:

  • tools/tests/conftest.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/coordinator.py : Use KCoordinator.power_is_off() to drive UI zeroing and WS client start/stop

Applied to files:

  • tools/tests/conftest.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/manifest.json : Don't add heavy dependencies or cloud calls

Applied to files:

  • tools/tests/conftest.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/**/*.py : Conditional features by model: box temp sensor/control (K1/K2), light (all except K1 SE/Ender 3 V3), camera type (WebRTC for K2; MJPEG for K1/Ender 3 V3)

Applied to files:

  • custom_components/ha_creality_ws/sensor.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/sensor.py : Expose new values via sensors: add a spec to SPECS or a dedicated sensor class; ensure zeroing respects _should_zero() and attributes/units are correct

Applied to files:

  • custom_components/ha_creality_ws/sensor.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/sensor.py : For new simple sensors, prefer adding to SPECS in sensor.py rather than creating dedicated sensor classes

Applied to files:

  • custom_components/ha_creality_ws/sensor.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/sensor.py : Status derivation: PrintStatusSensor maps telemetry to human-readable status; do not regress this mapping

Applied to files:

  • custom_components/ha_creality_ws/sensor.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/{sensor,button,switch,number,camera,image,light,fan}.py : Implement _should_zero() in KEntity subclasses to zero out when printer is off or link is stale

Applied to files:

  • custom_components/ha_creality_ws/sensor.py
📚 Learning: 2026-04-19T14:51:16.316Z
Learnt from: CR
Repo: 3dg1luk43/ha_creality_ws PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-19T14:51:16.316Z
Learning: Applies to custom_components/ha_creality_ws/image.py : Image platform (K1 family): expose entity named 'Current Print Preview' with unique_id <host>-current_print_preview; fetch PNG from http://<host>/downloads/original/current_print_image.png

Applied to files:

  • custom_components/ha_creality_ws/sensor.py
🪛 GitHub Actions: Static Tests
tools/tests/test_camera_stream_config.py

[error] 1-1: pytest failed for test_ensure_stream_configured_modern: async def functions are not natively supported. Failed: You need to install a suitable plugin for your async framework (e.g., pytest-asyncio).


[warning] 42-42: PytestUnknownMarkWarning: Unknown pytest.mark.asyncio - is this a typo? (tools/tests/test_camera_stream_config.py:42)

tools/tests/test_camera_recovery.py

[error] 1-1: pytest failed for test_webrtc_recovery_on_error: async def functions are not natively supported. Failed: You need to install a suitable plugin for your async framework (e.g., pytest-asyncio).


[warning] 45-45: PytestUnknownMarkWarning: Unknown pytest.mark.asyncio - is this a typo? (tools/tests/test_camera_recovery.py:45)

tools/tests/test_camera_webrtc_repro.py

[error] 1-1: pytest failed for test_webrtc_offer_500_error_repro: async def functions are not natively supported. Failed: You need to install a suitable plugin for your async framework (e.g., pytest-asyncio).


[warning] 42-42: PytestUnknownMarkWarning: Unknown pytest.mark.asyncio - is this a typo? (tools/tests/test_camera_webrtc_repro.py:42)

🪛 Ruff (0.15.10)
custom_components/ha_creality_ws/camera.py

[error] 790-792: try-except-pass detected, consider logging the exception

(S110)


[warning] 790-790: Do not catch blind exception: Exception

(BLE001)

tools/tests/conftest.py

[warning] 40-40: Do not call setattr with a constant attribute value. It is not any safer than normal property access.

Replace setattr with assignment

(B010)


[warning] 41-41: Do not call setattr with a constant attribute value. It is not any safer than normal property access.

Replace setattr with assignment

(B010)


[warning] 42-42: Do not call setattr with a constant attribute value. It is not any safer than normal property access.

Replace setattr with assignment

(B010)


[warning] 69-69: Do not call setattr with a constant attribute value. It is not any safer than normal property access.

Replace setattr with assignment

(B010)


[warning] 70-70: Do not call setattr with a constant attribute value. It is not any safer than normal property access.

Replace setattr with assignment

(B010)


[warning] 71-71: Do not call setattr with a constant attribute value. It is not any safer than normal property access.

Replace setattr with assignment

(B010)


[warning] 78-78: Do not call setattr with a constant attribute value. It is not any safer than normal property access.

Replace setattr with assignment

(B010)


[warning] 80-80: Do not call setattr with a constant attribute value. It is not any safer than normal property access.

Replace setattr with assignment

(B010)


[warning] 91-91: Do not call setattr with a constant attribute value. It is not any safer than normal property access.

Replace setattr with assignment

(B010)

🔇 Additional comments (3)
custom_components/ha_creality_ws/www/k_printer_card.js (1)

304-304: LGTM — wrapping preserves right alignment.

Allowing chips to wrap should improve narrow-card layouts while justify-content:flex-end keeps the action group aligned to the right.

tools/tests/test_camera_webrtc_repro.py (1)

1-41: Consolidate duplicated sys.modules stub bootstrap into conftest.py.

The ~35-line stubbing prelude (aiohttp / go2rtc_client / homeassistant.components.camera) is copy-pasted verbatim across test_camera_recovery.py, test_camera_stream_config.py, and this file. tools/tests/conftest.py already performs similar mock setup — move this block there (guarded with if ... not in sys.modules) so each test file just imports CrealityWebRTCCamera directly. This also makes the exception-identity patching less fragile across file-import ordering.

Note on the pipeline failure here: the pytest-asyncio/async-marker issue applies identically to this test — see the consolidated comment on tools/tests/test_camera_recovery.py.

custom_components/ha_creality_ws/camera.py (1)

647-649: The #format=creality removal is already documented as HA 2025.11+ requirement.

The README explicitly states: "Native WebRTC out of the box is supported only on Home Assistant Core 2025.11+ (bundled go2rtc version compatible with Creality)." This covers the go2rtc version compatibility concern. The test suite confirms the format string change is intentional (test_camera_stream_config.py:73), and the code comment references 1.9.14+ compatibility, which aligns with bundled go2rtc in HA 2025.11+. No additional documentation is needed.

			> Likely an incorrect or invalid review comment.

Comment thread custom_components/ha_creality_ws/sensor.py
Comment thread custom_components/ha_creality_ws/www/k_cfs_card.js Outdated
Comment thread tools/tests/test_camera_recovery.py Outdated
…anup

fix: update sensor data retrieval logic and adjust box ID handling
style: refine CSS mask properties in k_cfs_card and k_printer_card
chore: update requirements and pytest configuration
test: remove debug print from test_camera_stream_config
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