Back to Feed
article 4m read

A remembered reading made the hub count a dead plug as connected

The home hub treated any remembered reading as proof a device was online, so dead plugs kept drawing power on screen. I moved presence onto the bridge verdict, chased it through every screen, and fixed a streaming box that had the opposite bug.

Article DepthPractice

Flow

Every reader had to ask

  1. 1Device list

    No power figure or toggle unless the device is online.

  2. 2Power total

    Only online devices are added up.

  3. 3Climate page

    Shows a temperature only for an online sensor.

  4. 4History writer

    Skips devices that are not online, so old values are not saved as new.

  5. 5History page

    Counts live devices apart from devices with history and labels old values as last.

  6. 6Streaming box

    Identity decides if it is there; missing detail is marked partial.

Anything the hub remembered about a device made it call that device connected. If it had a saved state for the device, or the device had ever sent a signal-strength number, that was a yes. Neither of those can ever go stale on its own.

Two memories, no verdict

My plugs and sensors talk to a bridge, and the bridge passes their messages to a broker. The broker keeps the last message for each device so that anything joining late gets a value at once. That's useful until a device dies. The broker keeps handing out its last reading, the hub keeps loading it back in, and the check keeps saying yes.

Where the wrong answer went

Every screen leaned on that one check. The live power total added up the last reading from every device, so an offline plug kept adding its old load. The climate page showed every saved temperature. The device list in the browser counted a device as connected unless it was told no, so a missing value was a yes. And a job that saves readings into history kept writing a dead sensor's last value, over and over, as if the room were simply very steady.

The verdict that was already there

The bridge already sends a separate message for each device that just says online or offline. That's a verdict from the part that can actually see the device, and it was sitting on the broker the whole time.

The hub now keeps those verdicts in their own store, apart from the readings. That way, code that only looks at readings can't mistake them for proof of life. Only online and offline are accepted, anything odd is logged and thrown away, and a device with no verdict yet is unknown. Unknown is treated as not live. After a restart I'd expect a short moment where devices show as unknown, and I'd rather have that than a dead plug drawing power.

Anything that asks which devices are live now looks only at devices with an online verdict.

Chasing every screen that said "now"

Adding the rule was easy. Getting every screen to follow it took several follow-up changes. The device list and its power and toggle controls came first. Then a devices page that had been built without the verdict at all, and which, as I read it, would have shown everything as disconnected until I fixed it. Then the power total, the climate page and its header, the history writer, and finally the history page, which now says how many devices are live out of how many have history, and marks an offline device's number as its last value.

Each change has a test that sets up the trap on purpose: a saved reading with an offline verdict next to it, and a check that the device is left out.

The streaming box had it backwards

The same day, my living-room streaming box had the opposite bug. Its status check asked who it was, what app was open and what was playing, and gave up if any answer failed. The box can refuse the last question while answering the other two, so it would look unreachable while sitting right there. Now the first answer alone decides whether the box is there. The other two are extras, and when one is missing the status says it's partial.

Where a dead plug can still look alive

The verdict only changes when the bridge notices a device is gone, so a freshly dead plug still looks fine for a little while. That delay comes from the bridge, not from the hub. And if the bridge itself stops, the hub probably just keeps the last verdicts it had.

Keep reading

Pick up a connected idea or branch into a nearby one.

5 paths forward