-
Notifications
You must be signed in to change notification settings - Fork 1
feat: implement write access checks for Qvantum action entities #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Implements write-access gating for Qvantum “control” entities by introducing a shared access-check mixin and updating entity availability logic to depend on the current writeAccessLevel (from the maintenance coordinator). Tests are updated to mock access-level runtime data.
Changes:
- Add
QvantumAccessMixinwith_has_write_accessand integrate it into the base entity class. - Gate
availablefor switch/select/number/fan/climate/button entities based on write access. - Update multiple “working” tests to mock
config_entry.runtime_data.maintenance_coordinator.data["access_level"].
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_switch_working.py | Mock maintenance coordinator access level for write-access gating. |
| tests/test_select_working.py | Mock maintenance coordinator access level for write-access gating. |
| tests/test_number_working.py | Mock maintenance coordinator access level for write-access gating. |
| tests/test_fan_working.py | Mock maintenance coordinator access level for write-access gating. |
| tests/test_climate_working.py | Mock maintenance coordinator access level for write-access gating. |
| tests/test_button_working.py | Mock maintenance coordinator access level for write-access gating. |
| custom_components/qvantum/entity.py | Introduce access mixin and make it part of the base entity inheritance. |
| custom_components/qvantum/switch.py | Require write access for switch entity availability. |
| custom_components/qvantum/select.py | Require write access for select entity availability. |
| custom_components/qvantum/number.py | Require write access for number entity availability. |
| custom_components/qvantum/fan.py | Require write access for fan entity availability. |
| custom_components/qvantum/climate.py | Add access mixin to climate entity and gate availability on write access. |
| custom_components/qvantum/button.py | Make non-elevate buttons require write access to be available. |
Comments suppressed due to low confidence (1)
custom_components/qvantum/climate.py:45
async_setup_entryandQvantumIndoorClimateEntitystill use theMyConfigEntryandQvantumDataUpdateCoordinatortypes, but those imports were removed. Withoutfrom __future__ import annotations, this will raiseNameErrorat import time. Re-add the missing imports (or add future-annotations / quote the annotations) so the module loads.
async def async_setup_entry(
hass: HomeAssistant,
config_entry: MyConfigEntry,
async_add_entities: AddEntitiesCallback,
):
"""Set up the Sensors."""
# This gets the data update coordinator from the config entry runtime data as specified in your __init__.py
coordinator: QvantumDataUpdateCoordinator = config_entry.runtime_data.coordinator
device: DeviceInfo = config_entry.runtime_data.device
sensors = []
sensors.append(QvantumIndoorClimateEntity(coordinator, device))
async_add_entities(sensors)
_LOGGER.debug(f"Setting up platform CLIMATE")
class QvantumIndoorClimateEntity(QvantumAccessMixin, CoordinatorEntity, ClimateEntity):
"""Sensor for qvantum."""
def __init__(
self, coordinator: QvantumDataUpdateCoordinator, device: DeviceInfo
) -> None:
super().__init__(coordinator)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #80 +/- ##
==========================================
- Coverage 89.11% 88.48% -0.63%
==========================================
Files 16 16
Lines 1470 1494 +24
==========================================
+ Hits 1310 1322 +12
- Misses 160 172 +12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This pull request introduces a new
QvantumAccessMixinto centralize and enforce write access checks across all Qvantum entities. The mixin ensures that entities requiring write access are only available to users with sufficient permissions, improving security and consistency. The PR also updates all relevant entity types to use this mixin and adjusts theiravailableproperty logic. Additionally, test mocks are updated to support the new access control mechanism.Access control improvements:
QvantumAccessMixininentity.pyto encapsulate logic for checking user write access, based on thewriteAccessLevelin the coordinator's runtime data. All entity classes now inherit from this mixin to standardize access checks.availableproperty in all entity types (climate.py,fan.py,number.py,select.py,switch.py, andbutton.py) to require write access by using the new_has_write_accessproperty, except for the "elevate_access" button which is always available. [1] [2] [3] [4] [5] [6]Codebase refactoring:
QvantumIndoorClimateEntityandQvantumEntityto inherit fromQvantumAccessMixin, ensuring consistent access control logic. [1] [2]Test updates:
mock_coordinatorfixtures to include mockedconfig_entryandmaintenance_coordinatorwith appropriatewriteAccessLeveldata, ensuring tests work with the new access control logic. [1] [2] [3] [4] [5] [6]