refactor(units): route _canonicalToOutputFlow + setDemand through UnitPolicy.convert
Drop the direct convert() import — both call sites now go through this.unitPolicy.convert. setDemand keeps its try/catch around the absolute-flow branch (legitimate Bucket-2 case: % vs flow demux prevents declaring `units:` on the dispatcher). Matches the contract direction in .claude/refactor/CONTRACTS.md §6. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const { BaseDomain, UnitPolicy, POSITIONS, interpolation, convert } = require('generalFunctions');
|
||||
const { BaseDomain, UnitPolicy, POSITIONS, interpolation } = require('generalFunctions');
|
||||
const GroupOperatingPoint = require('./groupOps/groupOperatingPoint');
|
||||
const groupCurves = require('./groupOps/groupCurves');
|
||||
const TotalsCalculator = require('./totals/totalsCalculator');
|
||||
@@ -383,7 +383,7 @@ class MachineGroup extends BaseDomain {
|
||||
v, 0, 100, dt.flow.min, dt.flow.max);
|
||||
} else {
|
||||
try {
|
||||
canonical = convert(v).from(unit).to('m3/s');
|
||||
canonical = this.unitPolicy.convert(v, unit, 'm3/s', 'setDemand absolute flow');
|
||||
} catch (err) {
|
||||
this.logger?.error?.(`setDemand: cannot convert ${v} ${unit} -> m3/s: ${err?.message || err}`);
|
||||
return undefined;
|
||||
@@ -446,10 +446,12 @@ class MachineGroup extends BaseDomain {
|
||||
}
|
||||
|
||||
_canonicalToOutputFlow(value) {
|
||||
const from = this.unitPolicy.canonical.flow;
|
||||
const to = this.unitPolicy.output.flow;
|
||||
if (!from || !to || from === to) return value;
|
||||
return convert(value).from(from).to(to);
|
||||
return this.unitPolicy.convert(
|
||||
value,
|
||||
this.unitPolicy.canonical.flow,
|
||||
this.unitPolicy.output.flow,
|
||||
'canonical->output flow',
|
||||
);
|
||||
}
|
||||
|
||||
getOutput() { return io.getOutput(this); }
|
||||
|
||||
Reference in New Issue
Block a user