Skip to content

Attributes In Expressions#203

Merged
ccrisan merged 14 commits into
mainfrom
feature/attributes-in-expressions
May 18, 2026
Merged

Attributes In Expressions#203
ccrisan merged 14 commits into
mainfrom
feature/attributes-in-expressions

Conversation

@ccrisan
Copy link
Copy Markdown
Contributor

@ccrisan ccrisan commented May 4, 2026

No description provided.

@ccrisan ccrisan force-pushed the feature/attributes-in-expressions branch from 5dc5c66 to b1869af Compare May 18, 2026 07:35
Copy link
Copy Markdown

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 adds support for attributes in expressions, introducing a new syntax ($port_id:attr_name, $:attr_name, #:attr_name, #slave_name:attr_name) to reference port and device attributes inside qToggle expressions. It also refactors core/main.py's update loop, replaces the old NonSelfDependency constraint with a more general TransformNotSupported check, and fixes a bug in Peripheral.set_online.

Changes:

  • Introduces PortAttr / SelfPortAttr and a new devices module with MainDeviceAttr / SlaveDeviceAttr expression types; updates the parser, expression dependencies model, and adds new PortAttrUnavailable, DeviceAttrUnavailable, MissingAttrPrefix, and TransformNotSupported exceptions.
  • Refactors core/main.read_ports/handle_changes into _get_changed_time_deps + private _handle_changes, switching the changed set to plain strings and moving value-change side effects upstream; switches slave attribute key separator from . to :.
  • Fixes Peripheral.set_online so handle_online/handle_offline actually fire on transitions, and adds substantial new unit tests across expressions, main loop, peripherals, and device/port attr handling.

Reviewed changes

Copilot reviewed 19 out of 33 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
qtoggleserver/core/expressions/init.py Routes #-prefixed expressions to DeviceExpression, raises EmptyExpression explicitly.
qtoggleserver/core/expressions/base.py Adds docstring documenting new dep string format.
qtoggleserver/core/expressions/devices.py New module implementing main/slave device-attribute expressions.
qtoggleserver/core/expressions/exceptions.py Replaces NonSelfDependency with MissingAttrPrefix/TransformNotSupported; adds PortAttrUnavailable/DeviceAttrUnavailable.
qtoggleserver/core/expressions/ports.py Extends port parsing to handle :attr syntax; adds PortAttr/SelfPortAttr; enforces transform-role restrictions.
qtoggleserver/core/main.py Splits update loop into helper + private _handle_changes; reshapes changed set to strings.
qtoggleserver/core/ports.py Drops old non-self-dependency check from transform attribute setters.
qtoggleserver/utils/expressions.py Slave attribute key separator changed from . to :.
qtoggleserver/peripherals/peripheral.py Fixes set_online ordering so transition handlers actually fire.
qtoggleserver/slaves/discover/apclients.py except clause edit (regresses to invalid Python 2 syntax).
qtoggleserver/drivers/persist/json.py Same regression: except (X, Y): rewritten in invalid Python 2 form.
qtoggleserver/frontend/js/api/constants.js Drops obsolete error messages, adds missing-attr-prefix / transform-not-supported.
tests/unit/qtoggleserver/core/expressions/test_device.py New tests for MainDeviceAttr/SlaveDeviceAttr.
tests/unit/qtoggleserver/core/expressions/test_port.py New tests for PortAttr/SelfPortAttr.
tests/unit/qtoggleserver/core/expressions/test_parse.py New parse tests for attr prefix / unexpected character cases.
tests/unit/qtoggleserver/core/expressions/test_transform.py Replaces non-self-dependency tests with TransformNotSupported coverage.
tests/unit/qtoggleserver/core/expressions/functions/test_*.py Large block of restored/added function-level unit tests.
tests/unit/qtoggleserver/core/test_main.py Covers new _get_changed_time_deps, updates assertions to _handle_changes signature.
tests/unit/qtoggleserver/peripherals/test_peripheral.py New tests for the set_online transition fix.
tests/unit/qtoggleserver/utils/test_expressions.py Updates slave-attr keys to the new : separator.
Comments suppressed due to low confidence (1)

qtoggleserver/drivers/persist/json.py:236

  • Same invalid Python 3 syntax as on line 127: except ValueError, TypeError: must be replaced with except (ValueError, TypeError): to avoid a SyntaxError.
                except ValueError, TypeError:

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

Comment thread qtoggleserver/slaves/discover/apclients.py
Comment thread qtoggleserver/drivers/persist/json.py
@ccrisan ccrisan force-pushed the feature/attributes-in-expressions branch from b1869af to 5b11028 Compare May 18, 2026 20:14
@ccrisan ccrisan requested a review from Copilot May 18, 2026 20:14
Copy link
Copy Markdown

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

Copilot reviewed 21 out of 35 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

qtoggleserver/drivers/persist/json.py:236

  • Same Python 2-style except syntax as on line 127. This raises SyntaxError at module import and must be restored to except (ValueError, TypeError):.
                except ValueError, TypeError:

Comment thread qtoggleserver/drivers/persist/json.py
Comment thread qtoggleserver/slaves/discover/apclients.py
Comment thread qtoggleserver/utils/main.py Outdated
@ccrisan ccrisan force-pushed the feature/attributes-in-expressions branch from 5b11028 to 380bfbd Compare May 18, 2026 20:34
@ccrisan ccrisan merged commit fcc57f8 into main May 18, 2026
3 checks passed
@ccrisan ccrisan deleted the feature/attributes-in-expressions branch May 18, 2026 20:35
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