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';
|
'use strict';
|
||||||
|
|
||||||
const { BaseDomain, UnitPolicy, POSITIONS, interpolation, convert } = require('generalFunctions');
|
const { BaseDomain, UnitPolicy, POSITIONS, interpolation } = require('generalFunctions');
|
||||||
const GroupOperatingPoint = require('./groupOps/groupOperatingPoint');
|
const GroupOperatingPoint = require('./groupOps/groupOperatingPoint');
|
||||||
const groupCurves = require('./groupOps/groupCurves');
|
const groupCurves = require('./groupOps/groupCurves');
|
||||||
const TotalsCalculator = require('./totals/totalsCalculator');
|
const TotalsCalculator = require('./totals/totalsCalculator');
|
||||||
@@ -383,7 +383,7 @@ class MachineGroup extends BaseDomain {
|
|||||||
v, 0, 100, dt.flow.min, dt.flow.max);
|
v, 0, 100, dt.flow.min, dt.flow.max);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
canonical = convert(v).from(unit).to('m3/s');
|
canonical = this.unitPolicy.convert(v, unit, 'm3/s', 'setDemand absolute flow');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger?.error?.(`setDemand: cannot convert ${v} ${unit} -> m3/s: ${err?.message || err}`);
|
this.logger?.error?.(`setDemand: cannot convert ${v} ${unit} -> m3/s: ${err?.message || err}`);
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -446,10 +446,12 @@ class MachineGroup extends BaseDomain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_canonicalToOutputFlow(value) {
|
_canonicalToOutputFlow(value) {
|
||||||
const from = this.unitPolicy.canonical.flow;
|
return this.unitPolicy.convert(
|
||||||
const to = this.unitPolicy.output.flow;
|
value,
|
||||||
if (!from || !to || from === to) return value;
|
this.unitPolicy.canonical.flow,
|
||||||
return convert(value).from(from).to(to);
|
this.unitPolicy.output.flow,
|
||||||
|
'canonical->output flow',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getOutput() { return io.getOutput(this); }
|
getOutput() { return io.getOutput(this); }
|
||||||
|
|||||||
Reference in New Issue
Block a user