summaryrefslogtreecommitdiff
path: root/package/contents/ui/FormatUtils.qml
blob: 9fe400a383a7af58c8021f328a17dc1bea7aa663 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import QtQuick 6.0

QtObject {
    function formatSoc(soc) {
        if (soc === undefined || soc === null || isNaN(soc) || soc < 0) {
            return "--"
        }
        return Math.round(soc) + "%"
    }

    function formatPower(connected, power) {
        if (!connected) {
            return "--"
        }
        return Math.round(power) + "W"
    }

    function formatSolar(solarPower) {
        if (solarPower === undefined || solarPower === null || isNaN(solarPower) || solarPower < 0) {
            return "--"
        }
        return Math.round(solarPower) + "W"
    }

    function formatAcPower(power) {
        if (power === undefined || power === null || isNaN(power) || power < 0) {
            return "--"
        }
        return Math.round(power) + "W"
    }
}