Skip to content

Conversation

@raman325
Copy link
Owner

@raman325 raman325 commented Jan 14, 2026

Breaking change

Event entity event_types attribute now contains lock entity IDs instead of the generic "pin_used" type.

When a PIN is used to lock/unlock, the event_type will now be the entity ID of the lock where the PIN was used (e.g., lock.front_door) instead of the generic pin_used string.

What changes for users:

  • Automations triggering on event_type: pin_used will need to be updated to trigger on the specific lock entity ID
  • The event_types attribute on the event entity now lists lock entity IDs that support code slot events
  • Locks that don't support code slot events (e.g., Virtual locks) are listed in a new unsupported_locks attribute

How to update automations:

# Before
trigger:
  - platform: state
    entity_id: event.lock_code_manager_code_slot_1
    attribute: event_type
    to: pin_used

# After (to trigger on any lock)
trigger:
  - platform: state
    entity_id: event.lock_code_manager_code_slot_1

Or trigger on a specific lock:

trigger:
  - platform: state
    entity_id: event.lock_code_manager_code_slot_1
    attribute: event_type
    to: lock.front_door

Accessing the lock entity ID in automations:

Use trigger.to_state.attributes.event_type in your automation actions to get the lock entity ID:

trigger:
  - platform: state
    entity_id: event.lock_code_manager_code_slot_1
action:
  - service: notify.mobile_app
    data:
      message: "Code slot 1 was used on {{ trigger.to_state.attributes.event_type }}"

Proposed change

Updates the event entity to use lock entity IDs as event_types instead of the generic "pin_used" type. This provides more granular information about which lock triggered the event.

Key changes:

  • Adds supports_code_slot_events property to lock providers to advertise capability
  • Event types are now the entity IDs of locks that support code slot events
  • When a PIN is used, the event type is the lock entity ID where it was used
  • Locks without code slot event support are listed in unsupported_locks attribute
  • Handles dynamic capability discovery (providers can change support status)
  • Preserves last event type from removed locks until next valid event

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: fixes #
  • This PR is related to issue:

🤖 Generated with Claude Code

@raman325 raman325 added the breaking-change Pull requests that break existing functionality label Jan 14, 2026
Copilot AI review requested due to automatic review settings January 14, 2026 04:14
@raman325 raman325 added the breaking-change Pull requests that break existing functionality label Jan 14, 2026
@github-actions github-actions bot added the python Pull requests that update Python code label Jan 14, 2026
@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

❌ Patch coverage is 97.72727% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.45%. Comparing base (a55da1f) to head (f47520a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...components/lock_code_manager/providers/zwave_js.py 66.66% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #788      +/-   ##
==========================================
+ Coverage   95.20%   95.45%   +0.24%     
==========================================
  Files          29       29              
  Lines        2359     2397      +38     
  Branches       83       83              
==========================================
+ Hits         2246     2288      +42     
+ Misses        113      109       -4     
Flag Coverage Δ
python 95.34% <97.72%> (+0.27%) ⬆️
typescript 96.44% <ø> (ø)

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

Files with missing lines Coverage Δ
custom_components/lock_code_manager/event.py 100.00% <100.00%> (ø)
...om_components/lock_code_manager/providers/_base.py 91.23% <100.00%> (+0.10%) ⬆️
..._components/lock_code_manager/providers/virtual.py 100.00% <100.00%> (ø)
custom_components/lock_code_manager/websocket.py 95.47% <100.00%> (+1.75%) ⬆️
...components/lock_code_manager/providers/zwave_js.py 82.22% <66.66%> (-0.22%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
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

This PR introduces a breaking change to event entities, replacing the generic "pin_used" event type with specific lock entity IDs. This provides more granular information about which lock triggered a PIN-used event.

Changes:

  • Event entity event_types now contains lock entity IDs instead of the generic "pin_used" string
  • Added supports_code_slot_events property to lock providers to indicate capability
  • Locks without code slot event support are listed in a new unsupported_locks attribute
  • Updated websocket code to read lock entity ID from event_type attribute instead of ATTR_LOCK_ENTITY_ID

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
custom_components/lock_code_manager/event.py Implements dynamic event_types computation based on supported locks, handles lock entity IDs as event types, adds unsupported_locks attribute, and preserves last event type on state restoration
custom_components/lock_code_manager/providers/_base.py Adds supports_code_slot_events property with default value of True and comprehensive documentation
custom_components/lock_code_manager/providers/virtual.py Overrides supports_code_slot_events to return False for virtual locks
custom_components/lock_code_manager/websocket.py Updates to read lock entity ID from event_type attribute instead of removed ATTR_LOCK_ENTITY_ID
tests/test_event.py Adds comprehensive tests for new event_types behavior, event_type attribute values, and unsupported_locks attribute
tests/common.py Adds SLOT_1_EVENT_ENTITY constant for test consistency

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

@raman325 raman325 force-pushed the feat/event-entity-lock-types branch 3 times, most recently from 126ceec to 3886f5a Compare January 15, 2026 02:57
@raman325 raman325 requested a review from Copilot January 15, 2026 03:11
Copy link
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 6 comments.


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

@github-actions github-actions bot added the javascript Pull requests that update javascript code label Jan 15, 2026
@raman325 raman325 force-pushed the feat/event-entity-lock-types branch from 75cf05b to eeb2606 Compare January 15, 2026 07:47
@raman325 raman325 removed the breaking-change Pull requests that break existing functionality label Jan 15, 2026
@github-actions github-actions bot added the breaking-change Pull requests that break existing functionality label Jan 15, 2026
@raman325 raman325 force-pushed the feat/event-entity-lock-types branch from 0135c8f to c76cbd3 Compare January 15, 2026 19:23
@raman325 raman325 force-pushed the feat/event-entity-lock-types branch from c76cbd3 to 825633c Compare January 15, 2026 19:44
raman325 and others added 10 commits January 15, 2026 16:02
BREAKING CHANGE: Event entity event_types now contain lock entity IDs
instead of the generic "pin_used" type. When a PIN is used, the event
type will be the lock entity ID where it was used.

Changes:
- Add `supports_code_slot_events` property to BaseLock (default: True)
- VirtualLock returns False since it can't detect PIN usage
- Event entity now uses lock entity IDs as event_types for locks that
  support code slot events
- Add `unsupported_locks` attribute listing locks that can't fire events
- Event entity updates event_types when locks are added/removed
- Handle edge case: last event type from removed lock is preserved until
  next valid event
- Update websocket to get last_used_lock from event_type attribute
- Add tests for new event entity behavior

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Event entity is unavailable when no locks support code slot events
- Restore unsupported_locks from state on startup
- Update tests for new behavior

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Replace custom state restoration with ExtraStoredData pattern
- Remove _last_event_type variable, read from state_attributes instead
- Call EventEntity.async_added_to_hass to restore internal event type
- Simplify by leveraging existing EventEntity persistence

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Since the event entity becomes unavailable when no locks support
code slot events, the fallback to EVENT_PIN_USED was never visible.

- Remove fallback in _compute_event_types() - return empty list instead
- Remove fallback in _handle_event() - log warning and return early
  if event data is missing lock entity ID

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tests for:
- Warning when event has no lock entity ID
- ExtraStoredData.from_dict with invalid data
- unsupported_locks attribute with mixed lock support

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add defensive check for state_attributes being None during initialization
- Add test verifying removed lock's entity ID is preserved in event_types

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Test that VirtualLock.supports_code_slot_events returns False
- Test websocket event_type attribute flow for last_used_lock_name

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Test LockCodeManagerEventExtraStoredData.as_dict() method
- Test _handle_add_locks updates state correctly

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Removed caching and restoration logic for unsupported_locks since it's
computed on-demand from current lock capabilities. This supports lazy
discovery of code slot event support on IoT platforms.

Removed:
- LockCodeManagerEventExtraStoredData class
- _unsupported_locks instance variable
- _update_unsupported_locks() method
- extra_restore_state_data property
- _async_get_last_extra_data() method
- Related tests for removed functionality

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
raman325 and others added 3 commits January 15, 2026 16:02
Removed _get_unsupported_locks() and _compute_event_types() methods,
inlining their logic directly into the properties that use them.
Keeps _get_supported_locks() since it's used in two places.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Removed logic that preserved last_event_type in event_types when a
lock was removed. The event_types attribute in history already captures
how available locks changed over time, so this preservation was redundant.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…d pill when unavailable

- Z-Wave JS: Explicitly set supports_code_slot_events = True for clarity
- Slot card: Hide the last-used pill when event entity is unavailable
  (no locks support code slot events)
- Added tests for last-used pill visibility logic

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@raman325 raman325 force-pushed the feat/event-entity-lock-types branch from 825633c to a5e5226 Compare January 15, 2026 21:03
Instead of navigating to history page, clicking the "last used" pill
now opens the entity's more-info dialog. This allows users to see
event attributes directly and access history/logbook from within
the dialog.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@raman325 raman325 merged commit 865ee91 into main Jan 15, 2026
13 of 14 checks passed
@raman325 raman325 deleted the feat/event-entity-lock-types branch January 15, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Pull requests that break existing functionality javascript Pull requests that update javascript code python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants