Add RFID token management services to Peblar integration#169189
Add RFID token management services to Peblar integration#169189syphernl wants to merge 13 commits intohome-assistant:devfrom
Conversation
Adds three services for managing the charger's standalone RFID authorization list: - peblar.list_rfid_tokens — returns all configured tokens - peblar.add_rfid_token — adds a token (uid + description) - peblar.remove_rfid_token — removes a token by uid Services are registered once on first entry load and removed when the last Peblar entry is unloaded. Each service call validates the provided config_entry_id and raises ServiceValidationError on bad input. Requires peblar>=0.5.0.
|
Hey there @frenck, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
Adds RFID token management capabilities to the Peblar integration by introducing Home Assistant services that call into the peblar client for listing, adding, and removing standalone RFID authorization tokens.
Changes:
- Register three new domain services (
list_rfid_tokens,add_rfid_token,remove_rfid_token) and remove them when the last Peblar entry unloads. - Add service descriptions/selectors and a new translated validation error message.
- Add service-level tests covering registration/unregistration and basic request/response behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
homeassistant/components/peblar/__init__.py |
Registers/unregisters RFID management services and implements handlers. |
homeassistant/components/peblar/strings.json |
Adds service descriptions/selectors and an invalid_config_entry translated message. |
tests/components/peblar/test_services.py |
Adds tests for service registration lifecycle and handler behavior. |
…x translations
- Check ConfigEntryState.LOADED in _get_peblar to raise ServiceValidationError
for unloaded entries instead of AttributeError on runtime_data
- Add services.yaml with selectors (moved out of strings.json)
- Fix exception message placeholder (remove single quotes around {config_entry_id})
- Add service icons to icons.json
- Update strings.json to remove selectors (belong in services.yaml)
- Add test for unloaded config entry raising ServiceValidationError
Documents three new actions added in home-assistant/core#169189: peblar.list_rfid_tokens, peblar.add_rfid_token, and peblar.remove_rfid_token for managing the charger's standalone authorization list.
Documents three new actions added in home-assistant/core#169189: peblar.list_rfid_tokens, peblar.add_rfid_token, and peblar.remove_rfid_token for managing the charger's standalone authorization list.
There was a problem hiding this comment.
Oh hi there @syphernl 👋
Thanks for the pull request. I've left a few comments. Could you take a look?
Additionally, the tests aren't passing. Can you take a look and ensure the CI passes? (PS: Did you set up an development environment? As the errors showing, shouldn't happen if you have set your environment up correct, it would stop you at commit time).
../Frenck
Blogging my personal ramblings at frenck.dev
| "list_rfid_tokens", | ||
| _handle_list_rfid_tokens, | ||
| schema=vol.Schema({vol.Required("config_entry_id"): str}), | ||
| supports_response=SupportsResponse.ONLY, |
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Services are domain-level, not entry-level. Registration in async_setup_entry required a has_service guard and manual cleanup on unload. async_setup runs once per domain load, eliminating both.
Documents three new actions added in home-assistant/core#169189: peblar.list_rfid_tokens, peblar.add_rfid_token, and peblar.remove_rfid_token for managing the charger's standalone authorization list.
- Move service code to services.py module - Rename remove_rfid_token to delete_rfid_token per HA design guide - Use ATTR_CONFIG_ENTRY_ID and CONF_DESCRIPTION constants - Protect add/delete services with async_register_admin_service - Add response schema validation for list_rfid_tokens - Update icons, strings, services.yaml and tests
- Register list_rfid_tokens as admin-only service - Update invalid_config_entry error message to cover unloaded entries
- Unregister RFID services when last Peblar entry unloads - Move CONF_UID constant to const.py - Add test for service deregistration on last entry unload
| async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: | ||
| """Set up the Peblar domain.""" | ||
| async_setup_services(hass) | ||
| return True |
There was a problem hiding this comment.
Re-register the RFID services when a config entry is set up (or stop unregistering them) so they don’t disappear after an entry reload.
Right now services are registered only in async_setup(), but async_unload_entry() removes them when the last entry unloads; during an entry reload or when a new entry is added later, async_setup() won’t run again, so the services remain missing until Home Assistant restarts. A common fix is to register services from async_setup_entry() when they aren’t already present (e.g., has_service guard), and keep the last-entry unload removal logic.
Breaking change
Proposed change
This PR introduces three new services to manage the charger's standalone RFID functionality:
peblar.list_rfid_tokens: Retrieves all currently configured tokens.peblar.add_rfid_token: Adds a new token using a UID and description.peblar.delete_rfid_token: Deletes a specific token by its UID.Service management is handled globally; services are registered upon the first entry load and removed only when the final Peblar entry is unloaded.
Each service call includes validation for the
config_entry_idand will raise aServiceValidationErrorfor invalid inputs.These features require
peblar>=0.5.0(already updated past that version incore).Type of change
Additional information
peblar>=0.5.0Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: