fix(pumpingstation): replay child measurement value on subscribe
A measurement child that already holds a value when the pumpingStation registers it (e.g. a once:true inject that fired during startup before the parent subscribed) was never surfaced — the emitter only delivers future updates. _subscribeMeasurement now seeds from the child's current sample via getLaggedSample(0), so late subscribers pick up present state. This is what makes a measured upstream inflow register as inflow on a clean startup. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -286,7 +286,7 @@ class PumpingStation extends BaseDomain {
|
||||
const measurementType = child.config.asset.type;
|
||||
const eventName = `${measurementType}.measured.${position}`;
|
||||
|
||||
child.measurements.emitter.on(eventName, (eventData = {}) => {
|
||||
const handle = (eventData = {}) => {
|
||||
this.logger.debug(
|
||||
`Measurement update ${eventName} <- ${eventData.childName || child.config.general.name}: ${eventData.value} ${eventData.unit}`
|
||||
);
|
||||
@@ -297,7 +297,21 @@ class PumpingStation extends BaseDomain {
|
||||
this.measurements.type(measurementType).variant('measured').position(position)
|
||||
.value(eventData.value, eventData.timestamp, eventData.unit);
|
||||
this.measurementRouter.route(measurementType, eventData.value, position, eventData);
|
||||
});
|
||||
};
|
||||
|
||||
child.measurements.emitter.on(eventName, handle);
|
||||
|
||||
// Seed from the child's current value. The emitter only delivers FUTURE
|
||||
// updates, so a parent that registers after the child already emitted
|
||||
// (e.g. a once-only inject that fired during startup before this
|
||||
// subscription existed) would otherwise never see that value. Replaying
|
||||
// the last sample makes a late subscriber pick up the present state.
|
||||
const series = child.measurements
|
||||
.type(measurementType).variant('measured').position(position).get?.();
|
||||
const sample = series?.getLaggedSample?.(0);
|
||||
if (sample && sample.value != null) {
|
||||
handle({ ...sample, childName: child.config.general.name });
|
||||
}
|
||||
}
|
||||
|
||||
_subscribePredictedFlow(child) {
|
||||
|
||||
Reference in New Issue
Block a user