fix: control-state sync across dashboards + toggle boolean coercion#4
Merged
Conversation
…t it Compared String(current) to the configured on-value, so a device echoing a JSON boolean read as off and flipped the switch back. Honor the on/off value, then coerce boolean/number/string forms like the device's asBool(). Refs #3
addControl only pushed to connected hardware, so other open dashboards updated only when the device echoed telemetry. Fan the commanded value out via notifyDashboards. Refs #3
There was a problem hiding this comment.
Pull request overview
This PR fixes two control-state propagation issues affecting real-time dashboard UX: toggle widgets misreading boolean telemetry echoes, and control writes not being broadcast to other open dashboards. It also bumps the package version.
Changes:
- Broadcast control writes from
ProjectDO.addControl()to subscribed dashboards immediately (without waiting for device telemetry echo). - Improve
iot-toggle’s ON/OFF detection to honor configured on/off values and coerce booleans/numbers/common truthy strings. - Bump version to
1.0.1.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| worker/src/platform/durable-objects/project-do.ts | Fan out control writes to dashboards via notifyDashboards() for immediate cross-dashboard sync. |
| shared/widgets/iot-toggle/widget.ts | Make isOn() robust to boolean/number/truthy string device echoes while honoring explicit on/off values. |
| package.json | Version bump to 1.0.1. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try { ws.send(payload); } catch { /* dead socket; ignore */ } | ||
| } | ||
|
|
||
| this.notifyDashboards([{ variable, value: value as IngestPoint['value'] }], now); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two related control-state propagation bugs (see #3).
Bug 1 —
iot-togglereverts on a boolean echo.isOn()comparedString(current)to the configured on-value, so a device echoing a JSON boolean (true) read as OFF and flipped the switch back. It now honors the explicit on/off value, then coerces boolean / non-zero number /"on"/"1"/"true"/"yes"like the device library'sasBool().Bug 2 — control changes didn't reach other open dashboards.
ProjectDO.addControl()pushed to connected hardware only, so peer dashboards updated solely off the device's telemetry echo. It now alsonotifyDashboards()the commanded value, so every open dashboard reflects a control write immediately.latest_statestays device-reported truth (commands aren't written to it), so automations still read actual state. BecauseaddControlis the single choke point, this also covers automation- and API-driven writes.Also bumps version to 1.0.1.
Closes #3