Skip to content

feat: add Akuvox lock provider with event routing fixes#578

Merged
tykeal merged 1 commit intoFutureTense:mainfrom
tykeal:akuvox_provider
Mar 12, 2026
Merged

feat: add Akuvox lock provider with event routing fixes#578
tykeal merged 1 commit intoFutureTense:mainfrom
tykeal:akuvox_provider

Conversation

@tykeal
Copy link
Collaborator

@tykeal tykeal commented Mar 7, 2026

Summary

Add Local Akuvox (local_akuvox) as a supported lock provider for keymaster, enabling code slot management and event handling for Akuvox door controllers.

Changes

Akuvox provider (providers/akuvox.py)

  • Maps keymaster slots to Akuvox users via [KM:<slot>] name tags
  • Handles webhook events: valid_code_entered, relay triggered/closed, input triggered/closed, invalid_code_entered
  • CRUD operations for user codes via local_akuvox service calls
  • Filters cloud-sourced users (source_type '2') from management
  • Accesses Akuvox coordinator via hass.data (not runtime_data)

Provider registration

  • Added AkuvoxLockProvider to PROVIDER_MAP in providers/__init__.py
  • Added local_akuvox to after_dependencies in manifest.json

Coordinator event routing fix

  • Fixed race condition where provider events arrive before entity state updates (e.g., Akuvox webhooks fire before lock entity shows unlocked)
  • Event label semantics now take priority: 'unlock' in label → unlocked, 'lock' in label → locked, ambiguous labels fall back to entity state
  • Compatible with existing Z-Wave labels (Manual Unlock, RF Lock, etc.)

Binary sensor startup fix

  • Replaced hard assert on kmlock.provider with graceful None check
  • Added provider creation in add_lock 'already exists' path to ensure provider is available before platform setup during concurrent entry init
  • Fixes AssertionError crash when HA sets up config entries concurrently

Tests

  • 48 tests for Akuvox provider (connect, codes, events, CRUD, diagnostics)
  • 3 tests for event label inference (label overrides stale state, fallback)
  • 3 tests for add_lock provider creation (None, already set, no config)
  • 3 tests for binary sensor setup (provider None, supported, unsupported)
  • All 456 tests pass, 83.27% coverage

@codecov-commenter
Copy link

codecov-commenter commented Mar 7, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.06%. Comparing base (cdb4922) to head (c190b46).
⚠️ Report is 46 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #578      +/-   ##
==========================================
+ Coverage   84.14%   87.06%   +2.91%     
==========================================
  Files          10       26      +16     
  Lines         801     3038    +2237     
==========================================
+ Hits          674     2645    +1971     
- Misses        127      393     +266     
Flag Coverage Δ
python 87.06% <100.00%> (?)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

@tykeal tykeal force-pushed the akuvox_provider branch from 57403c9 to 437ad76 Compare March 7, 2026 03:20
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 adds support for the local_akuvox integration as a new Keymaster lock provider, while also hardening coordinator event routing and startup behavior for concurrent config-entry initialization.

Changes:

  • Added AkuvoxLockProvider with code-slot tagging ([KM:<slot>]) and webhook event translation, backed by local_akuvox service calls.
  • Updated coordinator event handling to infer lock/unlock from event labels (to avoid races with stale entity state), and ensured provider creation in an “already exists” add_lock path.
  • Expanded test coverage for the new provider and the concurrency/event-routing fixes.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
custom_components/keymaster/providers/akuvox.py New provider implementation for local_akuvox including code CRUD + webhook event subscription/translation.
custom_components/keymaster/providers/__init__.py Registers AkuvoxLockProvider in PROVIDER_MAP.
custom_components/keymaster/manifest.json Adds local_akuvox to after_dependencies for startup ordering.
custom_components/keymaster/coordinator.py Adds label-based lock/unlock inference for provider events; ensures provider creation in add_lock when lock already exists.
custom_components/keymaster/binary_sensor.py Replaces a hard assert on provider existence with a None check before adding the connectivity sensor.
tests/providers/test_akuvox.py Comprehensive unit tests for Akuvox provider behavior (connect, CRUD, tagging, events, diagnostics).
tests/test_coordinator_events.py Tests for label-overrides-stale-state behavior in provider event handling.
tests/test_coordinator_lifecycle.py Tests that add_lock creates a provider when missing in the “already exists” path.
tests/test_binary_sensor.py Tests binary-sensor setup behavior when provider is None / supported / unsupported.

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

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 9 out of 9 changed files in this pull request and generated 3 comments.


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

Add Local Akuvox (local_akuvox) as a supported lock provider for keymaster,
enabling code slot management and event handling for Akuvox door controllers.

Akuvox provider (providers/akuvox.py):
- Maps keymaster slots to Akuvox users via [KM:<slot>] name tags
- Handles webhook events: valid_code_entered, relay triggered/closed,
  input triggered/closed, invalid_code_entered
- CRUD operations for user codes via local_akuvox service calls
- Filters cloud-sourced users (source_type '2') from management
- Accesses Akuvox coordinator via hass.data (not runtime_data)

Provider registration:
- Added AkuvoxLockProvider to PROVIDER_MAP in providers/__init__.py
- Added local_akuvox to after_dependencies in manifest.json

Coordinator event routing fix:
- Fixed race condition where provider events arrive before entity state
  updates (e.g., Akuvox webhooks fire before lock entity shows unlocked)
- Event label semantics now take priority: 'unlock' in label -> unlocked,
  'lock' in label -> locked, ambiguous labels fall back to entity state
- Compatible with existing Z-Wave labels (Manual Unlock, RF Lock, etc.)

Binary sensor startup fix:
- Replaced hard assert on kmlock.provider with graceful None check
- Added provider creation in add_lock 'already exists' path to ensure
  provider is available before platform setup during concurrent entry init
- Fixes AssertionError crash when HA sets up config entries concurrently

Tests:
- 48 tests for Akuvox provider (connect, codes, events, CRUD, diagnostics)
- 3 tests for event label inference (label overrides stale state, fallback)
- 3 tests for add_lock provider creation (None, already set, no config)
- 3 tests for binary sensor setup (provider None, supported, unsupported)

Co-authored-by: Copilot <copilot@github.com>
Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
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 9 out of 9 changed files in this pull request and generated no new comments.


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

Copy link
Collaborator

@firstof9 firstof9 left a comment

Choose a reason for hiding this comment

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

Looks good.

@tykeal tykeal merged commit 7d70b2b into FutureTense:main Mar 12, 2026
11 checks passed
@tykeal tykeal deleted the akuvox_provider branch March 12, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants