Attributes In Expressions#203
Conversation
5dc5c66 to
b1869af
Compare
There was a problem hiding this comment.
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/SelfPortAttrand a newdevicesmodule withMainDeviceAttr/SlaveDeviceAttrexpression types; updates the parser, expression dependencies model, and adds newPortAttrUnavailable,DeviceAttrUnavailable,MissingAttrPrefix, andTransformNotSupportedexceptions. - Refactors
core/main.read_ports/handle_changesinto_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_onlinesohandle_online/handle_offlineactually 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 withexcept (ValueError, TypeError):to avoid aSyntaxError.
except ValueError, TypeError:
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b1869af to
5b11028
Compare
There was a problem hiding this comment.
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
exceptsyntax as on line 127. This raisesSyntaxErrorat module import and must be restored toexcept (ValueError, TypeError):.
except ValueError, TypeError:
5b11028 to
380bfbd
Compare
No description provided.