Skip to content

Conversation

@ccrisan
Copy link
Contributor

@ccrisan ccrisan commented Dec 27, 2025

No description provided.

Copy link

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

This PR introduces a dynamic device attributes system that allows attributes to be defined via drivers rather than being hardcoded. The main changes include a new AttrDefDriver base class, concrete implementations (CmdLineAttrDef and DummyAttrDef), comprehensive test coverage, and a consistent rename of the "reboot" field to "reconnect" throughout the codebase.

  • Adds AttrDefDriver abstract base class providing a driver interface for device attributes with support for caching, persistence, and reconnection requirements
  • Implements two concrete drivers: CmdLineAttrDef for executing shell commands and DummyAttrDef for simple in-memory attributes
  • Renames "reboot" terminology to "reconnect" across all device attributes for better semantic clarity

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
qtoggleserver/core/device/attrs.py Adds AttrDefDriver base class and dynamic attribute loading functions; renames "reboot" to "reconnect"; updates to_json() to include pattern field
qtoggleserver/core/device/init.py Refactors password hash handling and adds modifiable check when loading persisted attributes
qtoggleserver/core/device/exceptions.py Introduces new exception hierarchy for device attributes including DeviceAttributeException and NoSuchDriver
qtoggleserver/drivers/device_attrs/init.py Exports the new attribute driver implementations
qtoggleserver/drivers/device_attrs/cmdline.py Implements CmdLineAttrDef driver that executes shell commands to get/set attribute values
qtoggleserver/drivers/device_attrs/dummy.py Implements DummyAttrDef driver for simple in-memory string attributes
qtoggleserver/drivers/events/init.py Adds exports for event handler drivers
qtoggleserver/conf/settings.py Adds device_attrs configuration field for dynamic attribute definitions
tests/unit/qtoggleserver/core/device/test_attrs.py Adds comprehensive tests for AttrDefDriver class; updates existing tests to use "reconnect" instead of "reboot"; adds pattern field to expected outputs
tests/unit/qtoggleserver/drivers/test_device_attrs.py Adds comprehensive tests for CmdLineAttrDef covering initialization, value retrieval/conversion, and command execution

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 586 to 613
def load_dynamic_attrdef(params: dict[str, Any]) -> AttributeDefinition:
params = dict(params)
class_path = params.pop("driver")

logger.debug('creating device attribute "%s" with driver "%s"', name, class_path)
try:
peripheral_class = dynload_utils.load_attr(class_path)
except Exception:
raise NoSuchDriver(class_path)

return peripheral_class(**params).to_attrdef()


def load_dynamic_attrdefs() -> AttributeDefinitions:
attrdefs = {}

for params in settings.core.device_attrs:
name = params.pop("name")

try:
attrdef = load_dynamic_attrdef(params)
except Exception as e:
logger.error('failed to load dynamic attribute "%s": %s', name, e, exc_info=True)
continue

attrdefs[name] = attrdef

return attrdefs
Copy link

Copilot AI Dec 27, 2025

Choose a reason for hiding this comment

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

The new functions load_dynamic_attrdef() and load_dynamic_attrdefs() lack test coverage. Given that the repository has comprehensive test coverage for device attributes (as seen in tests/unit/qtoggleserver/core/device/test_attrs.py), these new functions should have corresponding tests to verify:

  1. Successful loading of dynamic attributes with valid driver paths
  2. Handling of invalid driver paths (NoSuchDriver exception)
  3. Proper parameter passing to driver constructors
  4. Integration of dynamic attributes with static ATTRDEFS

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Copy link

Copilot AI commented Dec 27, 2025

@ccrisan I've opened a new pull request, #179, to work on those changes. Once the pull request is ready, I'll request review from you.

@ccrisan ccrisan merged commit 5d057a5 into main Dec 27, 2025
7 checks passed
@ccrisan ccrisan deleted the device-attrs-driver branch December 27, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants