Skip to content

fix(matter): address #1246 review — log noise, fallback routing, test caplog level - #1248

Merged
raman325 merged 1 commit into
mainfrom
fix/matter-fallback-review-fixes
Jun 11, 2026
Merged

fix(matter): address #1246 review — log noise, fallback routing, test caplog level#1248
raman325 merged 1 commit into
mainfrom
fix/matter-fallback-review-fixes

Conversation

@raman325

Copy link
Copy Markdown
Owner

Proposed change

Addresses Copilot's four review comments on #1246. All four were valid.

Comment #3393233004 — INFO log spam on affected locks

The success-on-fallback path logs at INFO every time async_set_user runs on a lock that consistently rejects the canonical tag. Since BaseLock calls async_set_user on every credential write, this can spam logs in normal operation for 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

CREATE fallback retry only catches MatterError. If the slot-only retry raises HomeAssistantError (disconnect/offline) or ServiceValidationError, it will currently bubble out as an unexpected exception type rather than being mapped to LockDisconnected/LockOperationFailed like the primary CREATE attempt. This can reintroduce the same "catchall suspend" behavior the MatterError mapping was meant to avoid.

Fix: mirror the primary CREATE attempt's typed routing on the fallback retry:

  • `ServiceValidationError → LockOperationFailed`
  • `HomeAssistantError → LockDisconnected`
  • `MatterError → LockOperationFailed` (after both attempts)

Two new regression tests pin these mappings:

  • `test_set_user_create_routes_validation_error_during_fallback`
  • `test_set_user_create_routes_disconnect_during_fallback`

Comments #3393232961 + #3393232981 — Tests didn't set caplog level

This test asserts on INFO-level log text but doesn't set caplog's capture level. Make the test self-contained by explicitly enabling INFO logging for the provider module before exercising the behavior.

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Test plan

  • Full suite passes locally (1162/1162; +2 new tests for the fallback-routing fix)
  • Existing fallback-success tests still pass with the explicit `caplog.set_level` call
  • DEBUG log path verified locally — the success-on-fallback message is only emitted at DEBUG, so locks that consistently need the fallback no longer flood the log

🤖 Generated with Claude Code

…, 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
Copilot AI review requested due to automatic review settings June 11, 2026 04:28
@github-actions github-actions Bot added python Pull requests that update Python code bug Something isn't working labels Jun 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 INFO to DEBUG to 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 caplog level (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

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.99%. Comparing base (0ae0aec) to head (a715219).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           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           
Flag Coverage Δ
python 97.53% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...m_components/lock_code_manager/providers/matter.py 99.38% <100.00%> (+<0.01%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@raman325
raman325 merged commit e16d49a into main Jun 11, 2026
19 checks passed
@raman325
raman325 deleted the fix/matter-fallback-review-fixes branch June 11, 2026 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants