Skip to content

Fix: Retrieve topic_prefix from config_entry for set_config_key service#197

Open
4homeassistant wants to merge 1 commit intosyssi:mainfrom
4homeassistant:fix-service-topic-prefix
Open

Fix: Retrieve topic_prefix from config_entry for set_config_key service#197
4homeassistant wants to merge 1 commit intosyssi:mainfrom
4homeassistant:fix-service-topic-prefix

Conversation

@4homeassistant
Copy link

Fixes #159

Problem

The set_config_key service was using the hardcoded DEFAULT_TOPIC_PREFIX instead of reading the actual topic_prefix from the config entry. This caused the service to fail when the user's configured topic_prefix differed from the default value.

After version 0.24, the DEFAULT_TOPIC_PREFIX was changed from /go-eCharger to go-eCharger (without leading slash), breaking the service for users who had the leading slash in their configuration.

Solution

  • Store config entries in hass.data for service access
  • Retrieve topic_prefix from config_entry instead of using hardcoded default
  • Add debug logging to show the actual topic being published to
  • Add cleanup of stored config entries on unload

Testing

Tested successfully with topic_prefix configurations with leading slash: /go-eCharger

The service now correctly uses the user's configured topic_prefix regardless of the default value.

Fixes syssi#159

The set_config_key service was using the hardcoded DEFAULT_TOPIC_PREFIX instead of reading the actual topic_prefix from the config entry. This caused the service to fail when the user's configured topic_prefix differed from the default value.

Changes:
- Store config entries in hass.data for service access
- Retrieve topic_prefix from config_entry instead of using hardcoded default
- Add debug logging to show the actual topic being published to
- Add cleanup of stored config entries on unload

Tested with my own topic_prefix configurations:
- With leading slash: /go-eCharger
@4homeassistant
Copy link
Author

Hey @syssi, I developed and tested a fix for that issue with the help of Perplexity and Claude. I am not really aware of the code but tried a vibe coding approach and tested it on my own installation. The concept of the change makes sense to me. What do you say?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Services not working in current release (0.24.x)

1 participant