@@ -17,6 +17,7 @@ public class HardyBarthReadWorker extends AbstractCycleWorker {
17
17
18
18
private final EvcsHardyBarthImpl parent ;
19
19
private int chargingFinishedCounter = 0 ;
20
+ private int errorCounter = 0 ;
20
21
21
22
public HardyBarthReadWorker (EvcsHardyBarthImpl parent ) {
22
23
this .parent = parent ;
@@ -92,29 +93,29 @@ private void setEvcsChannelIds(JsonElement json) {
92
93
var powerL2 = (Long ) this .getValueForChannel (EvcsHardyBarth .ChannelId .RAW_ACTIVE_POWER_L2 , json );
93
94
var powerL3 = (Long ) this .getValueForChannel (EvcsHardyBarth .ChannelId .RAW_ACTIVE_POWER_L3 , json );
94
95
95
- Integer phases = null ;
96
+ // TODO: Handle phases, having each phase value in the Nature
97
+ // Keep last value if no power value was given
98
+ var phases = this .parent .getPhasesAsInt ();
96
99
if (powerL1 != null && powerL2 != null && powerL3 != null ) {
97
100
98
101
var sum = powerL1 + powerL2 + powerL3 ;
99
102
100
- if (sum > 900 ) {
103
+ if (sum > 300 ) {
101
104
phases = 0 ;
102
105
103
- if (powerL1 >= 300 ) {
106
+ if (powerL1 >= 100 ) {
104
107
phases += 1 ;
105
108
}
106
- if (powerL2 >= 300 ) {
109
+ if (powerL2 >= 100 ) {
107
110
phases += 1 ;
108
111
}
109
- if (powerL3 >= 300 ) {
112
+ if (powerL3 >= 100 ) {
110
113
phases += 1 ;
111
114
}
112
115
}
113
116
}
114
117
this .parent ._setPhases (phases );
115
- if (phases != null ) {
116
- this .parent .debugLog ("Used phases: " + phases );
117
- }
118
+ this .parent .debugLog ("Used phases: " + phases );
118
119
119
120
// CHARGE_POWER
120
121
var chargePowerLong = (Long ) this .getValueFromJson (Evcs .ChannelId .CHARGE_POWER , json , value -> {
@@ -129,32 +130,34 @@ private void setEvcsChannelIds(JsonElement json) {
129
130
return activePower < 100 ? 0 : activePower ;
130
131
}, "secc" , "port0" , "metering" , "power" , "active_total" , "actual" );
131
132
132
- //
133
133
this .parent ._setChargePower (chargePowerLong == null ? null : chargePowerLong .intValue ());
134
134
135
135
// STATUS
136
136
var status = (Status ) this .getValueFromJson (EvcsHardyBarth .ChannelId .RAW_CHARGE_STATUS_CHARGEPOINT , json ,
137
137
value -> {
138
+
138
139
String stringValue = TypeUtils .getAsType (OpenemsType .STRING , value );
139
140
if (stringValue == null ) {
140
- return Status .UNDEFINED ;
141
+ this .errorCounter ++;
142
+ this .parent .debugLog ("Hardy Barth RAW_STATUS would be null! Raw value: " + value );
143
+ if (this .errorCounter > 3 ) {
144
+ return Status .ERROR ;
145
+ }
146
+ return this .parent .getStatus ();
141
147
}
142
148
143
- Status rawStatus = Status .UNDEFINED ;
144
- switch (stringValue ) {
145
- case "A" :
146
- rawStatus = Status .NOT_READY_FOR_CHARGING ;
147
- break ;
148
- case "B" :
149
- rawStatus = Status .READY_FOR_CHARGING ;
149
+ Status rawStatus = switch (stringValue ) {
150
+ case "A" -> Status .NOT_READY_FOR_CHARGING ;
151
+ case "B" -> {
152
+ var tmpStatus = Status .READY_FOR_CHARGING ;
150
153
151
154
// Detect if the car is full
152
155
int chargePower = chargePowerLong == null ? 0 : chargePowerLong .intValue ();
153
156
if (this .parent .getSetChargePowerLimit ().orElse (0 ) >= this .parent .getMinimumHardwarePower ()
154
157
.orElse (0 ) && chargePower <= 0 ) {
155
158
156
159
if (this .chargingFinishedCounter >= 90 ) {
157
- rawStatus = Status .CHARGING_FINISHED ;
160
+ tmpStatus = Status .CHARGING_FINISHED ;
158
161
} else {
159
162
this .chargingFinishedCounter ++;
160
163
}
@@ -163,25 +166,34 @@ private void setEvcsChannelIds(JsonElement json) {
163
166
164
167
// Charging rejected because we are forcing to pause charging
165
168
if (this .parent .getSetChargePowerLimit ().orElse (0 ) == 0 ) {
166
- rawStatus = Status .CHARGING_REJECTED ;
169
+ tmpStatus = Status .CHARGING_REJECTED ;
167
170
}
168
171
}
169
- break ;
170
- case "C" :
171
- case "D" :
172
- rawStatus = Status .CHARGING ;
173
- break ;
174
- case "E" :
175
- case "F" :
176
- rawStatus = Status .ERROR ;
177
- break ;
178
- default :
179
- rawStatus = Status .UNDEFINED ;
180
- break ;
172
+ yield tmpStatus ;
173
+ }
174
+ case "C" , "D" -> Status .CHARGING ;
175
+ case "E" , "F" -> {
176
+ this .errorCounter ++;
177
+ this .parent .debugLog ("Hardy Barth RAW_STATUS would be an error! Raw value: " + stringValue
178
+ + " - Error counter: " + this .errorCounter );
179
+ if (this .errorCounter > 3 ) {
180
+ yield Status .ERROR ;
181
+ }
182
+ yield this .parent .getStatus ();
181
183
}
182
- if (stringValue .equals ("B" )) {
184
+ default -> {
185
+ this .parent .debugLog ("State " + stringValue + " is not a valid state" );
186
+ yield Status .UNDEFINED ;
187
+ }
188
+ };
189
+
190
+ if (!stringValue .equals ("B" )) {
183
191
this .chargingFinishedCounter = 0 ;
184
192
}
193
+ if (!stringValue .equals ("E" ) || !stringValue .equals ("F" )) {
194
+ this .errorCounter = 0 ;
195
+ }
196
+
185
197
return rawStatus ;
186
198
}, "secc" , "port0" , "ci" , "charge" , "cp" , "status" );
187
199
0 commit comments