Simplified Device Attributes Update Event#206
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the device attribute update mechanism away from a frontend polling loop and a backend network-config watcher toward a single periodic backend "heartbeat" that emits device-update events. The frontend code path that periodically polled the main/slave device via HTTP and emitted synthetic device-polling-update / slave-device-polling-update events is removed entirely, along with its UI plumbing. On the backend, _attrs_watch_loop (which only fired when WiFi/IP config changed) is replaced with _attrs_update_loop, which invalidates the attr cache and fires device_events.trigger_update() every ATTRS_UPDATE_INTERVAL (5s) unconditionally.
Changes:
- Backend: replace conditional network-attr watch loop with unconditional periodic
device-updateevent emission. - Frontend: remove
polledDeviceNamecache state, thepollDevicetimer, and thedevice-polling-update/slave-device-polling-updateevent handlers acrosscache.js, settings/devices sections and forms, andreboot-device-mixin.js. - Tests: add an integration test asserting the new update loop triggers
device_events.trigger_updaterepeatedly.
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| qtoggleserver/core/device/attrs.py | Replaces network-attr watch loop with a periodic loop that always invalidates attrs and triggers device-update. |
| qtoggleserver/frontend/js/cache.js | Removes polled-device state, pollDevice/setInterval, and the polling-update event cases. |
| qtoggleserver/frontend/js/settings/settings-section.js | Drops handler for the now-defunct device-polling-update event. |
| qtoggleserver/frontend/js/settings/settings-form.js | Removes onBecomeCurrent/onLeaveCurrent polling toggles. |
| qtoggleserver/frontend/js/devices/devices-section.js | Drops handler for slave-device-polling-update. |
| qtoggleserver/frontend/js/devices/device-form.js | Removes setPolledDeviceName calls; leaves empty lifecycle overrides. |
| qtoggleserver/frontend/js/common/reboot-device-mixin.js | Removes save/restore of polled device name around reboot flow. |
| tests/integration/core/device/test_attrs.py | New integration test verifying the periodic update loop fires trigger_update. |
| tests/integration/core/device/init.py, tests/integration/core/init.py | New empty package markers for the integration test path. |
Comments suppressed due to low confidence (2)
qtoggleserver/frontend/js/devices/device-form.js:138
onLeaveCurrent()is now an empty method that only callssuperimplicitly (it doesn't even do that). If there's no behaviour to add, remove the override entirely so the parent class implementation is used; otherwise this dead override will mask any future base-class behaviour silently.
throw new AssertionError(`Device with name ${this.getDeviceName()} not found in cache`)
}
qtoggleserver/frontend/js/devices/device-form.js:135
- After removing the body of
onBecomeCurrent, the method body indevice-form.jsnow ends with a stray emptyif (this._deviceRemoved) { return }guard that no longer protects any code. If nothing else is being added here, consider removing the now-emptyonBecomeCurrentoverride entirely (matching the suggestion below foronLeaveCurrent).
This issue also appears on line 137 of the same file.
* Update the entire form (fields & values) from the corresponding device.
*/
updateUI(fieldChangeWarnings = true) {
let device = Cache.getSlaveDevice(this.getDeviceName())
No description provided.