-
Notifications
You must be signed in to change notification settings - Fork 3
Dynamic Device Attributes #178
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
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
AttrDefDriverabstract base class providing a driver interface for device attributes with support for caching, persistence, and reconnection requirements - Implements two concrete drivers:
CmdLineAttrDeffor executing shell commands andDummyAttrDeffor 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.
qtoggleserver/core/device/attrs.py
Outdated
| 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 |
Copilot
AI
Dec 27, 2025
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.
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:
- Successful loading of dynamic attributes with valid driver paths
- Handling of invalid driver paths (NoSuchDriver exception)
- Proper parameter passing to driver constructors
- Integration of dynamic attributes with static ATTRDEFS
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.
@copilot open a new pull request to apply changes based on this feedback
No description provided.