fix: slugify lock name when generating default notification script name#586
fix: slugify lock name when generating default notification script name#586tykeal wants to merge 1 commit intoFutureTense:mainfrom
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #586 +/- ##
==========================================
+ Coverage 84.14% 88.47% +4.33%
==========================================
Files 10 26 +16
Lines 801 3142 +2341
==========================================
+ Hits 674 2780 +2106
- Misses 127 362 +235
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes default notification script naming in the Keymaster integration by ensuring lock names are slugified so generated script entity IDs are valid in Home Assistant.
Changes:
- Slugify
CONF_LOCK_NAMEwhen generating the defaultCONF_NOTIFY_SCRIPT_NAMEinasync_setup_entry. - Add a unit test to verify default notify script names are slugified for lock names with spaces/caps.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
custom_components/keymaster/__init__.py |
Uses slugify() when computing the default notification script name to avoid invalid entity IDs. |
tests/test_init.py |
Adds coverage to validate default notify script name generation for non-slug lock names. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Lock names with spaces or uppercase characters (e.g. 'Akuvox Relay A') were used directly in the notification script entity ID, producing invalid IDs like 'script.keymaster_Akuvox Relay A_manual_notify' instead of 'script.keymaster_akuvox_relay_a_manual_notify'. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
bed18eb to
c0371ad
Compare
There was a problem hiding this comment.
Pull request overview
Fixes invalid default notification script entity IDs when the configured lock name contains spaces/uppercase by slugifying the lock name during async_setup_entry, preventing mismatches like script.keymaster_Garage Outside Door_manual_notify.
Changes:
- Slugify
CONF_LOCK_NAMEwhen generating the defaultCONF_NOTIFY_SCRIPT_NAMEinasync_setup_entry. - Add a regression test ensuring lock names with spaces/uppercase produce a valid slugified notify script name.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| custom_components/keymaster/init.py | Ensures the default notify script name uses slugify(lock_name) so generated script IDs are valid and consistent with HA entity ID rules. |
| tests/test_init.py | Adds a regression test validating the slugified default notify script name for a lock name containing spaces and uppercase characters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Fixes a bug where lock names with spaces or uppercase characters (e.g. "Akuvox Relay A") were used directly in the notification script entity ID, producing invalid IDs like
script.keymaster_Akuvox Relay A_manual_notifyinstead ofscript.keymaster_akuvox_relay_a_manual_notify.This caused notification scripts to silently fail to fire since the entity ID didn't match any registered script.
Changes
custom_components/keymaster/__init__.py: Addedslugify()call around the lock name when generating the default notification script nametests/test_init.py: Addedtest_notify_script_name_slugifiedtest verifying that lock names with spaces and uppercase are properly slugifiedRoot Cause
In
async_setup_entry(), the default notification script name was built using rawCONF_LOCK_NAMEwithout slugification:Home Assistant entity IDs must be lowercase with underscores. The
slugify()function was already imported and used correctly inconfig_flow.py,coordinator.py, andhelpers.py— it was simply missing from this one code path in__init__.py.Fixes: #506