Config UI: device value formatting (#17258)

This commit is contained in:
Michael Geers 2024-11-20 10:43:29 +01:00 • committed by GitHub
parent 9083a846ac
commit 5bfa661247
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,11 +10,13 @@
{{ $t(`config.deviceValue.${entry.name}`) }}
</div>
<div
class="value overflow-hidden text-truncate"
class="value overflow-hidden"
:class="{
'value--error': !!entry.error,
'value--warning': entry.warning,
'value--muted': entry.muted || entry.value === false,
'text-truncate': allowTruncate(entry.name),
'flex-shrink-0': !allowTruncate(entry.name),
}"
>
{{ fmtDeviceValue(entry) }}
@ -23,7 +25,9 @@
</div>
</template>
<script>
import formatter from "../../mixins/formatter";
import formatter, { POWER_UNIT } from "../../mixins/formatter";
const NO_TRUNCATE = ["phasePowers", "phaseVoltages", "phaseCurrents"];
export default {
name: "DeviceTags",
@ -66,7 +70,7 @@ export default {
case "phaseVoltages":
return value.map((v) => this.fmtNumber(v, 0)).join(" · ") + " V";
case "phasePowers":
return value.map((v) => this.fmtW(v)).join(", ");
return value.map((v) => this.fmtW(v, POWER_UNIT.KW, false)).join(" · ") + " kW";
case "chargeStatus":
return this.$t(`config.deviceValue.chargeStatus${value}`);
case "gridPrice":
@ -86,6 +90,9 @@ export default {
}
return value;
},
allowTruncate(name) {
return !NO_TRUNCATE.includes(name);
},
},
};
</script>