hvac/backend
jtricerolph 59a3e091d8 Fix MHI room-temp race: serialize per-unit DB writes
handleMhiStatus() rewrites the whole cached row from an in-memory cumulative
state object on every single signal message, via an unawaited pool.query()
per message. When several retained signals for the same unit arrive in a
tight burst (e.g. right after a broker reconnect), their DB writes can
complete out of dispatch order — an older write, captured before a later
tempAmbientSts update was known, could land in Postgres AFTER a newer write
that already had the correct room temp, silently reverting it to stale/null.

User reported AC room temp "randomly" missing from the dashboard while the
correct value was visible in the broker's retained topic — exactly this
symptom, not an MQTT delivery gap.

Fixed by chaining each unit's writes through a per-externalRef promise queue
(mhiWriteChain) so completion order can never diverge from dispatch order.
state is read at actual write time, not snapshotted early, so a queued write
still picks up whatever's freshest by the time its turn comes up.
2026-08-25 14:34:42 +00:00
..
scripts Add Phase 2 MHI Modbus register-map profile, xlsx importer, and a 2026-07-27 14:19:58 +00:00
src Fix MHI room-temp race: serialize per-unit DB writes 2026-08-25 14:34:42 +00:00
Dockerfile Scaffold Phase 1 hvac app — NewBook-driven room TRV heating scheduler 2026-07-26 18:00:42 +00:00
package.json Add MHI aircon manual control (Phase 2, Modbus only) 2026-07-27 14:43:38 +00:00