Restrict homematic.set_install_mode service to admins#169203
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Hey there @pvizeli, 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
This PR tightens access control in the HomeMatic integration by making the homematic.set_install_mode service admin-only, aligning it with other integrations’ “pairing/permit” style management operations.
Changes:
- Replaces
hass.services.registerwithasync_register_admin_serviceforhomematic.set_install_mode. - Bridges the admin-service registration from the sync
setup()context into the event loop viarun_callback_threadsafe.
| run_callback_threadsafe( | ||
| hass.loop, | ||
| async_register_admin_service, | ||
| hass, | ||
| DOMAIN, |
There was a problem hiding this comment.
Add an integration test that verifies homematic.set_install_mode is rejected for non-admin users (and allowed for admin users) when called with a user context, to prevent regressions in the new admin-only behavior.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Added two integration tests in tests/components/homematic/test_init.py (commit dd6c467):
test_set_install_mode_non_admin_rejected– calls the service with a read-only user context and assertsUnauthorizedis raised.test_set_install_mode_admin_allowed– calls the service with an admin user context, asserts it succeeds, and verifiessetInstallModewas called with the correct arguments ("ccu2",t=60,mode=1,address=None).
Agent-Logs-Url: https://github.com/home-assistant/core/sessions/b24840df-5e7b-427a-9c99-c88200e713c4 Co-authored-by: balloob <1444314+balloob@users.noreply.github.com>
Agent-Logs-Url: https://github.com/home-assistant/core/sessions/b24840df-5e7b-427a-9c99-c88200e713c4 Co-authored-by: balloob <1444314+balloob@users.noreply.github.com>
Proposed change
Switch the
homematic.set_install_modeservice from a barehass.services.registertoasync_register_admin_service, so only admin users can put the HomeMatic radio interface into pairing/install mode.Pairing mode is bus management rather than raw device I/O — same shape as ZHA
permit(admin-gated) and Z-Waveadd_node(admin-gated). Aligning this service with that precedent.When adding a new admin in the UI, we mention: "The user group feature is a work in progress. The user will be unable to administer the instance via the UI. We're still auditing all management API endpoints to ensure that they correctly limit access to administrators." This PR is part of that audit.
The integration's
setupis sync, soasync_register_admin_serviceis dispatched viarun_callback_threadsafe, mirroring howhass.services.registeritself bridges into the event loop.Type of change
Additional information
Checklist
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: