feat: permissive unit check for user-defined measurement types + measurement digital-mode schema
MeasurementContainer.isUnitCompatible now short-circuits to accept any unit when the measurement type is not in the built-in measureMap. Known types (pressure, flow, power, temperature, volume, length, mass, energy) still validate strictly. This unblocks user-defined types in the measurement node's new digital/MQTT mode — e.g. 'humidity' with unit '%', 'co2' with 'ppm' — without forcing those units into the convert-module unit system. measurement.json schema: add 'mode.current' (analog | digital) and 'channels' (array) so the validator stops stripping them from the runtime config. Ignored in analog mode. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -141,11 +141,17 @@ class MeasurementContainer {
|
||||
}
|
||||
|
||||
isUnitCompatible(measurementType, unit) {
|
||||
const desc = this._describeUnit(unit);
|
||||
if (!desc) return false;
|
||||
// Unknown type (not in measureMap): accept any unit. This lets user-
|
||||
// defined measurement types (e.g. 'humidity', 'co2', arbitrary IoT
|
||||
// channels in digital mode) pass through without being rejected just
|
||||
// because their unit string ('%', 'ppm', …) is not a known physical
|
||||
// unit to the convert module. Known types are still validated strictly.
|
||||
const normalizedType = this._normalizeType(measurementType);
|
||||
const expectedMeasure = this.measureMap[normalizedType];
|
||||
if (!expectedMeasure) return true;
|
||||
|
||||
const desc = this._describeUnit(unit);
|
||||
if (!desc) return false;
|
||||
return desc.measure === expectedMeasure;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user