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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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 {}
}
|