Skip to content

fix: control-state sync across dashboards + toggle boolean coercion#4

Merged
decoded-cipher merged 3 commits into
masterfrom
fix/control-state-sync
Jul 5, 2026
Merged

fix: control-state sync across dashboards + toggle boolean coercion#4
decoded-cipher merged 3 commits into
masterfrom
fix/control-state-sync

Conversation

@decoded-cipher

Copy link
Copy Markdown
Owner

Fixes two related control-state propagation bugs (see #3).

Bug 1 — iot-toggle reverts on a boolean echo.
isOn() compared String(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's asBool().

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 also notifyDashboards() the commanded value, so every open dashboard reflects a control write immediately. latest_state stays device-reported truth (commands aren't written to it), so automations still read actual state. Because addControl is the single choke point, this also covers automation- and API-driven writes.

Also bumps version to 1.0.1.

Closes #3

…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
Copilot AI review requested due to automatic review settings July 5, 2026 17:52
@decoded-cipher
decoded-cipher merged commit 1b8af91 into master Jul 5, 2026
1 check passed
@decoded-cipher
decoded-cipher deleted the fix/control-state-sync branch July 5, 2026 17:54

Copilot AI left a comment

Copy link
Copy Markdown

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 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);
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.

Control state doesn't sync across dashboards; toggle reverts when a device echoes a boolean

2 participants