Skip to content

Conversation

@perosb
Copy link
Owner

@perosb perosb commented Feb 11, 2026

This pull request introduces a new QvantumAccessMixin to 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 their available property logic. Additionally, test mocks are updated to support the new access control mechanism.

Access control improvements:

  • Introduced QvantumAccessMixin in entity.py to encapsulate logic for checking user write access, based on the writeAccessLevel in the coordinator's runtime data. All entity classes now inherit from this mixin to standardize access checks.
  • Updated available property in all entity types (climate.py, fan.py, number.py, select.py, switch.py, and button.py) to require write access by using the new _has_write_access property, except for the "elevate_access" button which is always available. [1] [2] [3] [4] [5] [6]

Codebase refactoring:

  • Refactored QvantumIndoorClimateEntity and QvantumEntity to inherit from QvantumAccessMixin, ensuring consistent access control logic. [1] [2]
  • Removed unused imports and updated imports to use the new mixin where appropriate.

Test updates:

  • Updated all test mock_coordinator fixtures to include mocked config_entry and maintenance_coordinator with appropriate writeAccessLevel data, ensuring tests work with the new access control logic. [1] [2] [3] [4] [5] [6]

Copilot AI review requested due to automatic review settings February 11, 2026 14:55
@github-actions github-actions bot added the enhancement New feature or request label Feb 11, 2026
Copy link
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

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 QvantumAccessMixin with _has_write_access and integrate it into the base entity class.
  • Gate available for 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_entry and QvantumIndoorClimateEntity still use the MyConfigEntry and QvantumDataUpdateCoordinator types, but those imports were removed. Without from __future__ import annotations, this will raise NameError at 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
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 56.66667% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.48%. Comparing base (d683f50) to head (71ac453).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
custom_components/qvantum/entity.py 50.00% 10 Missing ⚠️
custom_components/qvantum/button.py 25.00% 3 Missing ⚠️
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     
Flag Coverage Δ
unittests 88.48% <56.66%> (-0.63%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@perosb perosb changed the title feat: implement write access checks for Qvantum entities feat: implement write access checks for Qvantum actions Feb 11, 2026
@perosb perosb changed the title feat: implement write access checks for Qvantum actions feat: implement write access checks for Qvantum action entities Feb 11, 2026
@perosb perosb merged commit 461aa21 into main Feb 11, 2026
4 of 6 checks passed
@perosb perosb deleted the gatedaccess branch February 11, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant