Use lock entity IDs as event_types for code slot events#788
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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_typesnow contains lock entity IDs instead of the generic "pin_used" string - Added
supports_code_slot_eventsproperty to lock providers to indicate capability - Locks without code slot event support are listed in a new
unsupported_locksattribute - Updated websocket code to read lock entity ID from
event_typeattribute instead ofATTR_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.
126ceec to
3886f5a
Compare
There was a problem hiding this comment.
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.
75cf05b to
eeb2606
Compare
0135c8f to
c76cbd3
Compare
c76cbd3 to
825633c
Compare
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>
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>
825633c to
a5e5226
Compare
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>
Breaking change
Event entity
event_typesattribute now contains lock entity IDs instead of the generic "pin_used" type.When a PIN is used to lock/unlock, the
event_typewill now be the entity ID of the lock where the PIN was used (e.g.,lock.front_door) instead of the genericpin_usedstring.What changes for users:
event_type: pin_usedwill need to be updated to trigger on the specific lock entity IDevent_typesattribute on the event entity now lists lock entity IDs that support code slot eventsunsupported_locksattributeHow to update automations:
Or trigger on a specific lock:
Accessing the lock entity ID in automations:
Use
trigger.to_state.attributes.event_typein your automation actions to get the lock entity ID:Proposed change
Updates the event entity to use lock entity IDs as
event_typesinstead of the generic "pin_used" type. This provides more granular information about which lock triggered the event.Key changes:
supports_code_slot_eventsproperty to lock providers to advertise capabilityunsupported_locksattributeType of change
Additional information
🤖 Generated with Claude Code