fix: show incomplete Symcon utility sums with Err prefix
This commit is contained in:
1 parent
a804fc8e15
commit
bb153490b0
14 files changed
+361
-293
No files matched your search
@@ -109,14 +109,14 @@ function readings(hass: HomeAssistant, sources: Source[], manual = false): Utili
|
||||
const st = hass.states[id], unit = measure(st);
|
||||
const canonicalUnit = unit?.metric === s.metric ? unit.unit : String(st?.attributes.unit_of_measurement ?? "").trim();
|
||||
const key = `${s.kind}|${s.metric}|${canonicalUnit}|${s.period}`;
|
||||
const row = groups.get(key) ?? { kind: s.kind, metric: s.metric, unit: canonicalUnit, value: 0, period: s.period, sources: [], manual, incomplete: false };
|
||||
const row = groups.get(key) ?? { kind: s.kind, metric: s.metric, unit: canonicalUnit, value: null, period: s.period, sources: [], manual, incomplete: false };
|
||||
const value = nativeNumber(st);
|
||||
if (value === null) row.incomplete = true;
|
||||
else row.value! += value * (unit?.metric === s.metric ? unit.factor : 1);
|
||||
else row.value = (row.value ?? 0) + value * (unit?.metric === s.metric ? unit.factor : 1);
|
||||
row.sources.push(id);
|
||||
groups.set(key, row);
|
||||
}
|
||||
return [...groups.values()].map((row) => row.incomplete ? { ...row, value: null } : row);
|
||||
return [...groups.values()];
|
||||
}
|
||||
|
||||
export function roomUtilityReadings(hass: HomeAssistant, room: Room, rooms: readonly Room[] = []): UtilityReading[] {
|
||||
@@ -152,9 +152,10 @@ export function utilityMetricLabel(row: UtilityReading): string {
|
||||
}
|
||||
|
||||
export function utilityText(hass: HomeAssistant | undefined, row: UtilityReading): string {
|
||||
if (row.value === null) return "–";
|
||||
const prefix = row.incomplete ? "Err: " : "";
|
||||
if (row.value === null) return `${prefix}–`;
|
||||
const value = row.unit === "W" && Math.abs(row.value) >= 1000 ? row.value / 1000 : row.value;
|
||||
const unit = row.unit === "W" && Math.abs(row.value) >= 1000 ? "kW" : row.unit;
|
||||
const digits = Number.isInteger(value) ? 0 : Math.min(6, Math.max(2, 1 - Math.floor(Math.log10(Math.abs(value)))));
|
||||
return `${formatNumber(hass, value, digits)}${unit ? ` ${unit}` : ""}`;
|
||||
return `${prefix}${formatNumber(hass, value, digits)}${unit ? ` ${unit}` : ""}`;
|
||||
}
|
||||
Reference in new issue
Block a user