Skip to content

feat: add device diagnostics with PIN masking#1097

Merged
raman325 merged 9 commits intomainfrom
feat/device-diagnostics
Apr 28, 2026
Merged

feat: add device diagnostics with PIN masking#1097
raman325 merged 9 commits intomainfrom
feat/device-diagnostics

Conversation

@raman325
Copy link
Copy Markdown
Owner

@raman325 raman325 commented Apr 28, 2026

Proposed change

Adds diagnostics support for troubleshooting Lock Code Manager. Implements both async_get_config_entry_diagnostics and async_get_device_diagnostics.

What it provides

Config entry diagnostics (the superset):

  • All managed locks with coordinator data, provider properties, push/sync status
  • All slots with configured state, per-lock coordinator codes
  • All entity states grouped by device

Device diagnostics (scoped by device type):

  • Slot device: configured PIN/name/enabled, per-lock coordinator code for that slot, entities
  • Lock device: coordinator data for all slots, push subscription status, entities
  • Config entry device: falls through to full config entry diagnostics

PIN masking

All PINs use the existing mask_pin function (deterministic CRC32 hash) rather than generic **REDACTED**. The salt is instance_id + slot_num + pin:

  • Same PIN on the same slot → same hash regardless of which lock or config entry → support can confirm "the configured PIN matches what the coordinator sees on lock A and lock B"
  • Same PIN on different slots → different hashes → prevents cross-slot correlation
  • Different HA instances → different hashes → prevents cross-instance correlation

This is intentional: a PIN's identity in LCM is its slot number, not its lock. The same PIN on slot 1 should hash identically across all locks in a config entry.

Sensitive entity states (PIN text, code sensor) are redacted to **REDACTED** with empty attributes to prevent plaintext PIN leakage.

Also included

  • Bug report template updated to request LCM diagnostics alongside lock integration diagnostics
  • TODO.md cleanup: removed completed items, refined diagnostics plan

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

Additional information

  • This PR fixes or closes issue:
  • This PR is related to issue:

raman325 and others added 2 commits April 27, 2026 22:29
- Remove "Direct Matter client commands" (completed)
- Remove ZHA from open PRs (merged as #1091)
- Update provider list (add ZHA, SimpliSafe candidate, ISY994 unsupported)
- Remove websocket optimization (premature)
- Refine device diagnostics TODO with per-device-level data plan
- Update live testing section (PIN change tested on ZHA)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 05f9143a90fe
Implements async_get_config_entry_diagnostics and
async_get_device_diagnostics for troubleshooting.

Config entry diagnostics return the full picture: all managed locks
with coordinator data, all slots with configuration, and all entity
states. Device diagnostics are scoped by device type:

- Slot device: configured state, per-lock coordinator code, entities
- Lock device: coordinator data, push/sync status, entities
- Config entry device: falls through to full config entry diagnostics

All PIN codes are masked using the existing deterministic CRC32
mask_pin function (not generic REDACTED), so support can correlate
duplicate PINs across slots without seeing actual values.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 15e9eab44326
Copilot AI review requested due to automatic review settings April 28, 2026 02:35
@github-actions github-actions Bot added python Pull requests that update Python code documentation Documentation changes enhancement New feature or request labels Apr 28, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 784e9bd2f2a7
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

❌ Patch coverage is 96.15385% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.71%. Comparing base (1bdaba6) to head (f800a5f).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
custom_components/lock_code_manager/diagnostics.py 96.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1097   +/-   ##
=======================================
  Coverage   95.70%   95.71%           
=======================================
  Files          47       48    +1     
  Lines        5520     5595   +75     
  Branches      503      503           
=======================================
+ Hits         5283     5355   +72     
- Misses        237      240    +3     
Flag Coverage Δ
python 97.26% <96.15%> (-0.03%) ⬇️

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

Files with missing lines Coverage Δ
...om_components/lock_code_manager/providers/_base.py 96.10% <100.00%> (ø)
custom_components/lock_code_manager/util.py 88.88% <100.00%> (ø)
custom_components/lock_code_manager/diagnostics.py 96.00% <96.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: b67c112b93e4
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Home Assistant diagnostics support for the Lock Code Manager integration, aiming to help troubleshooting while masking PINs deterministically via the existing mask_pin utility.

Changes:

  • Introduces diagnostics.py implementing config-entry and device-scoped diagnostics.
  • Adds initial test coverage for diagnostics output and PIN masking behavior.
  • Updates TODO.md provider list and diagnostics/testing notes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
custom_components/lock_code_manager/diagnostics.py Adds config-entry + device diagnostics builders and PIN masking.
tests/test_diagnostics.py Adds tests validating diagnostics structure and masked PIN outputs.
TODO.md Updates roadmap/provider notes and diagnostics plan section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_diagnostics.py Outdated
Comment thread tests/test_diagnostics.py Outdated
Comment thread custom_components/lock_code_manager/diagnostics.py Outdated
Comment thread custom_components/lock_code_manager/diagnostics.py
Comment thread custom_components/lock_code_manager/diagnostics.py Outdated
Comment thread custom_components/lock_code_manager/diagnostics.py Outdated
Comment thread tests/test_diagnostics.py
Add a separate upload field for Lock Code Manager diagnostics
alongside the existing lock integration diagnostics field. LCM
diagnostics include coordinator data, sync state, and entity states
with PINs masked — the lock integration diagnostics show the
underlying device state.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 9d70f28f7b78
@github-actions github-actions Bot added the github-config Changes to .github/ configuration files label Apr 28, 2026
raman325 and others added 2 commits April 27, 2026 22:52
The PIN's identity in LCM is the slot number — the same PIN on slot 1
should hash identically regardless of which lock it's on.  This lets
support confirm "configured PIN matches coordinator code on lock A and
lock B" by comparing masked values in diagnostics.

The salt is now instance_id + slot_num + pin.  Different slots produce
different hashes (prevents cross-slot correlation).  Different HA
instances produce different hashes (prevents cross-instance
correlation).  Lock entity ID and config entry ID are excluded because
they can change without the PIN changing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 6c709a89392a
1. Redact PIN and code entity states in diagnostics output. Entities
   with |pin or |code in their unique_id have their state replaced
   with **REDACTED** and attributes cleared.

2. Use existing instance_id from hass.data[DOMAIN] instead of
   hass.data["core.uuid"].

3. Validate config entry ID when detecting slot devices.

4. Fix sentinel value case in test assertions.

5. Make lock device test always assert. Add sensitive entity redaction test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: ac4a7a9cae2c
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_diagnostics.py Outdated
Comment thread custom_components/lock_code_manager/util.py
Comment thread custom_components/lock_code_manager/providers/_base.py
Comment thread custom_components/lock_code_manager/diagnostics.py
raman325 and others added 2 commits April 27, 2026 23:53
The previous test checked for |pin and |code in entity_id, but those
markers are in the unique_id. The _is_sensitive function correctly
checks unique_id, so the test now verifies that at least one entity
was redacted and all redacted entities have empty attributes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 9dd6bf1068d8
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: a2d79e8eb48d
@raman325 raman325 merged commit 951df01 into main Apr 28, 2026
13 checks passed
@raman325 raman325 deleted the feat/device-diagnostics branch April 28, 2026 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes enhancement New feature or request github-config Changes to .github/ configuration files python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants