Skip to content

fix: slugify lock name when generating default notification script name#586

Open
tykeal wants to merge 1 commit intoFutureTense:mainfrom
tykeal:fix_notify_scripts
Open

fix: slugify lock name when generating default notification script name#586
tykeal wants to merge 1 commit intoFutureTense:mainfrom
tykeal:fix_notify_scripts

Conversation

@tykeal
Copy link
Collaborator

@tykeal tykeal commented Mar 17, 2026

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_notify instead of script.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: Added slugify() call around the lock name when generating the default notification script name
  • tests/test_init.py: Added test_notify_script_name_slugified test verifying that lock names with spaces and uppercase are properly slugified

Root Cause

In async_setup_entry(), the default notification script name was built using raw CONF_LOCK_NAME without slugification:

# Before (bug)
f"keymaster_{updated_config.get(CONF_LOCK_NAME)}_manual_notify"

# After (fix)
f"keymaster_{slugify(updated_config.get(CONF_LOCK_NAME, ''))}_manual_notify"

Home Assistant entity IDs must be lowercase with underscores. The slugify() function was already imported and used correctly in config_flow.py, coordinator.py, and helpers.py — it was simply missing from this one code path in __init__.py.

Fixes: #506

@github-actions github-actions bot added the bugfix Fixes a bug label Mar 17, 2026
@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 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 88.47%. Comparing base (cdb4922) to head (c0371ad).
⚠️ Report is 64 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     #586      +/-   ##
==========================================
+ Coverage   84.14%   88.47%   +4.33%     
==========================================
  Files          10       26      +16     
  Lines         801     3142    +2341     
==========================================
+ Hits          674     2780    +2106     
- Misses        127      362     +235     
Flag Coverage Δ
python 88.47% <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.

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

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_NAME when generating the default CONF_NOTIFY_SCRIPT_NAME in async_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>
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

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_NAME when generating the default CONF_NOTIFY_SCRIPT_NAME in async_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.

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.

Changes look good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ISSUE: Notifications not working for device with spaces in the name

4 participants