Skip to content

Add RFID token management services to Peblar integration#169189

Open
syphernl wants to merge 13 commits intohome-assistant:devfrom
syphernl:feature/peblar-rfid-services
Open

Add RFID token management services to Peblar integration#169189
syphernl wants to merge 13 commits intohome-assistant:devfrom
syphernl:feature/peblar-rfid-services

Conversation

@syphernl
Copy link
Copy Markdown
Contributor

@syphernl syphernl commented Apr 26, 2026

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_id and will raise a ServiceValidationError for invalid inputs.

These features require peblar>=0.5.0 (already updated past that version in core).

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

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.
@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @frenck, mind taking a look at this pull request as it has been labeled with an integration (peblar) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of peblar can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign peblar Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Copy Markdown
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

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.

Comment thread homeassistant/components/peblar/__init__.py Outdated
Comment thread tests/components/peblar/test_services.py
…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
@syphernl syphernl requested a review from Copilot April 26, 2026 12:48
syphernl pushed a commit to syphernl/home-assistant.io that referenced this pull request Apr 26, 2026
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.
syphernl pushed a commit to syphernl/home-assistant.io that referenced this pull request Apr 26, 2026
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.
Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

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

Comment thread homeassistant/components/peblar/__init__.py Outdated
Comment thread homeassistant/components/peblar/__init__.py Outdated
Comment thread homeassistant/components/peblar/__init__.py Outdated
Comment thread homeassistant/components/peblar/__init__.py Outdated
"list_rfid_tokens",
_handle_list_rfid_tokens,
schema=vol.Schema({vol.Required("config_entry_id"): str}),
supports_response=SupportsResponse.ONLY,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That is the default, right?

Comment thread homeassistant/components/peblar/__init__.py Outdated
Comment thread homeassistant/components/peblar/__init__.py Outdated
@home-assistant home-assistant Bot marked this pull request as draft April 27, 2026 16:09
@home-assistant
Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

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.
syphernl pushed a commit to syphernl/home-assistant.io that referenced this pull request Apr 27, 2026
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.
Copilot AI review requested due to automatic review settings April 27, 2026 17:18
Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

- 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
Copilot AI review requested due to automatic review settings April 28, 2026 14:41
Copy link
Copy Markdown
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 6 out of 6 changed files in this pull request and generated 4 comments.

Comment thread homeassistant/components/peblar/services.py Outdated
Comment thread homeassistant/components/peblar/services.yaml
Comment thread homeassistant/components/peblar/__init__.py Outdated
Comment thread homeassistant/components/peblar/strings.json Outdated
Copilot AI review requested due to automatic review settings April 28, 2026 15:26
Copy link
Copy Markdown
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 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread homeassistant/components/peblar/__init__.py Outdated
Comment thread homeassistant/components/peblar/services.py
- Register list_rfid_tokens as admin-only service
- Update invalid_config_entry error message to cover unloaded entries
Copilot AI review requested due to automatic review settings April 28, 2026 15:58
- Unregister RFID services when last Peblar entry unloads
- Move CONF_UID constant to const.py
- Add test for service deregistration on last entry unload
Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
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 7 out of 7 changed files in this pull request and generated 1 comment.

Comment on lines +46 to +49
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Peblar domain."""
async_setup_services(hass)
return True
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@syphernl syphernl marked this pull request as ready for review April 28, 2026 21:11
Copilot AI review requested due to automatic review settings April 28, 2026 21:11
@home-assistant home-assistant Bot requested a review from frenck April 28, 2026 21:11
Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants