fix(matter): address #1246 review — log noise, fallback routing, test caplog level - #1248
Conversation
…, test caplog level Three review concerns from Copilot on #1246: 1) Success-on-fallback log was at INFO. For a lock that consistently rejects the canonical tag, BaseLock._set_credential calls async_set_user on every credential write, so an INFO log fires on every sync tick -- log spam in normal operation. Demote both the UPDATE-path and CREATE-path success-on-fallback messages to DEBUG. The full-failure warning path is unchanged. 2) CREATE fallback retry only caught MatterError. If the slot-only retry raised HomeAssistantError (transport closed) or ServiceValidationError (validation), it bubbled past as an untyped exception, reintroducing the catchall-suspend behavior the original MatterError mapping was meant to avoid. Mirror the primary CREATE attempt's typed routing on the fallback: ServiceValidationError -> LockOperationFailed, HomeAssistantError -> LockDisconnected, MatterError -> LockOperationFailed (after second attempt). 3) The two fallback-success tests asserted on log text without setting caplog's capture level, so they depended on the global pytest logging configuration. Now that the diagnostic is at DEBUG, they explicitly call caplog.set_level(logging.DEBUG, logger=_PROVIDER_MODULE) before exercising the behavior. The tests are now self-contained. Two new regression tests cover the new fallback-routing: * test_set_user_create_routes_validation_error_during_fallback: ServiceValidationError on the slot-only retry -> LockOperationFailed * test_set_user_create_routes_disconnect_during_fallback: HomeAssistantError on the slot-only retry -> LockDisconnected Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Entire-Checkpoint: ecc6001013ea
There was a problem hiding this comment.
Pull request overview
This PR follows up on review feedback from #1246 by reducing Matter provider log noise, ensuring fallback retries route exceptions consistently, and making the related tests self-contained with explicit caplog configuration.
Changes:
- Demotes “success-on-fallback” messages from
INFOtoDEBUGto avoid repeated log spam on locks that always require the slot-only fallback. - Expands CREATE fallback exception routing to mirror the primary attempt (
ServiceValidationError → LockOperationFailed,HomeAssistantError → LockDisconnected). - Updates/adds tests to explicitly set
caploglevel (DEBUG) and adds regression tests for fallback exception routing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
custom_components/lock_code_manager/providers/matter.py |
Demotes fallback-success logs to DEBUG and adds typed exception routing for CREATE fallback retries. |
tests/providers/matter/test_provider.py |
Makes fallback-success log assertions robust via caplog.set_level(...) and adds regression tests for fallback exception mapping. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1248 +/- ##
=======================================
Coverage 96.99% 96.99%
=======================================
Files 53 53
Lines 6181 6185 +4
Branches 461 461
=======================================
+ Hits 5995 5999 +4
Misses 186 186
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Proposed change
Addresses Copilot's four review comments on #1246. All four were valid.
Comment #3393233004 — INFO log spam on affected locks
Fix: demote both UPDATE-path and CREATE-path success-on-fallback messages from `LOGGER.info` to `LOGGER.debug`. The diagnostic remains available when the user enables debug logging; the full-failure warning path is unchanged.
Comment #3393232929 — Fallback exception routing was narrow
Fix: mirror the primary CREATE attempt's typed routing on the fallback retry:
Two new regression tests pin these mappings:
Comments #3393232961 + #3393232981 — Tests didn't set caplog level
Fix: both fallback-success tests now call `caplog.set_level(logging.DEBUG, logger=_PROVIDER_MODULE)` before exercising the behavior. (DEBUG, not INFO, because of fix #1 above.) The tests are now self-contained and don't depend on the global pytest logging config.
Type of change
Test plan
🤖 Generated with Claude Code