diff options
| author | Dawid Rycerz <dawid@rycerz.xyz> | 2026-02-07 17:29:48 +0100 |
|---|---|---|
| committer | Dawid Rycerz <dawid@rycerz.xyz> | 2026-02-07 17:29:48 +0100 |
| commit | 2eda97537b63d68b2e9ba06500e3fb491894d10c (patch) | |
| tree | 52873ad380cd97f4327765aac24659a2b00079b1 /package/contents/ui/main.qml | |
feat: camper van energy monitoring widget for Plasma 6main
Pure QML KPackage widget with Rust background service for real-time
Victron energy system monitoring via MQTT and D-Bus.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'package/contents/ui/main.qml')
| -rw-r--r-- | package/contents/ui/main.qml | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/package/contents/ui/main.qml b/package/contents/ui/main.qml new file mode 100644 index 0000000..26b5045 --- /dev/null +++ b/package/contents/ui/main.qml @@ -0,0 +1,161 @@ +import QtQuick 6.0 +import org.kde.plasma.plasmoid 2.0 +import org.kde.plasma.workspace.dbus as DBus + +PlasmoidItem { + id: root + + // Exposed properties for child components + property bool connected: false + property real batterySoc: -1 + property real batteryPower: 0 + property real solarPower: -1 + property real acInputPower: -1 + property real acLoadPower: -1 + property string direction: "idle" + property string lastUpdated: "unknown" + + // Watch for service availability + DBus.DBusServiceWatcher { + id: serviceWatcher + watchedService: "org.craftknight.CamperWidget" + busType: DBus.BusType.Session + + onRegisteredChanged: { + if (registered) { + statusProps.updateAll() + batteryProps.updateAll() + solarProps.updateAll() + acInputProps.updateAll() + acLoadProps.updateAll() + } else { + root.connected = false + root.batterySoc = -1 + root.batteryPower = 0 + root.solarPower = -1 + root.acInputPower = -1 + root.acLoadPower = -1 + root.direction = "idle" + root.lastUpdated = "unknown" + } + } + } + + // Status interface - Connected property + DBus.Properties { + id: statusProps + service: "org.craftknight.CamperWidget" + path: "/org/craftknight/camper_widget" + iface: "org.craftknight.CamperWidget.Status" + busType: DBus.BusType.Session + + onPropertiesChanged: function(iface, changed, invalidated) { + if ("Connected" in changed) + root.connected = Boolean(changed["Connected"]) + updateTimestamp() + } + onRefreshed: { + var c = properties.Connected + if (c !== undefined) root.connected = Boolean(c) + } + } + + // Battery interface - Soc, Power, State + DBus.Properties { + id: batteryProps + service: "org.craftknight.CamperWidget" + path: "/org/craftknight/camper_widget/Battery" + iface: "org.craftknight.CamperWidget.Battery" + busType: DBus.BusType.Session + + onPropertiesChanged: function(iface, changed, invalidated) { + if ("Soc" in changed) + root.batterySoc = Number(changed["Soc"]) + if ("Power" in changed) + root.batteryPower = Number(changed["Power"]) + if ("State" in changed) + root.direction = mapDirection(String(changed["State"])) + updateTimestamp() + } + onRefreshed: { + var s = properties.Soc + var p = properties.Power + var st = properties.State + if (s !== undefined) root.batterySoc = Number(s) + if (p !== undefined) root.batteryPower = Number(p) + if (st !== undefined) root.direction = mapDirection(String(st)) + } + } + + // Solar interface - Power + DBus.Properties { + id: solarProps + service: "org.craftknight.CamperWidget" + path: "/org/craftknight/camper_widget/Solar" + iface: "org.craftknight.CamperWidget.Solar" + busType: DBus.BusType.Session + + onPropertiesChanged: function(iface, changed, invalidated) { + if ("Power" in changed) + root.solarPower = Number(changed["Power"]) + updateTimestamp() + } + onRefreshed: { + var p = properties.Power + if (p !== undefined) root.solarPower = Number(p) + } + } + + // AC input interface - Power + DBus.Properties { + id: acInputProps + service: "org.craftknight.CamperWidget" + path: "/org/craftknight/camper_widget/AcInput" + iface: "org.craftknight.CamperWidget.AcInput" + busType: DBus.BusType.Session + + onPropertiesChanged: function(iface, changed, invalidated) { + if ("Power" in changed) + root.acInputPower = Number(changed["Power"]) + updateTimestamp() + } + onRefreshed: { + var p = properties.Power + if (p !== undefined) root.acInputPower = Number(p) + } + } + + // AC load interface - Power + DBus.Properties { + id: acLoadProps + service: "org.craftknight.CamperWidget" + path: "/org/craftknight/camper_widget/AcLoad" + iface: "org.craftknight.CamperWidget.AcLoad" + busType: DBus.BusType.Session + + onPropertiesChanged: function(iface, changed, invalidated) { + if ("Power" in changed) + root.acLoadPower = Number(changed["Power"]) + updateTimestamp() + } + onRefreshed: { + var p = properties.Power + if (p !== undefined) root.acLoadPower = Number(p) + } + } + + function mapDirection(state) { + switch (state) { + case "charging": return "charge" + case "discharging": return "discharge" + default: return "idle" + } + } + + function updateTimestamp() { + root.lastUpdated = Qt.formatDateTime(new Date(), "hh:mm:ss") + } + + compactRepresentation: CompactRepresentation {} + fullRepresentation: FullRepresentation {} +} |
