Skip to content

Commit 8092e63

Browse files
authored
[nikohomecontrol] Fix exception on car charger bad data (openhab#21302)
* fix exception on bad data Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
1 parent b37cd6e commit 8092e63

17 files changed

Lines changed: 124 additions & 117 deletions

bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,21 @@ private void handleBrightnessCommand(Command command) {
121121
nhcAction.execute(NHCON);
122122
}
123123
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
124-
int currentValue = nhcAction.getState();
125-
int newValue;
124+
long currentValue = nhcAction.getState();
125+
long newValue;
126126
if (IncreaseDecreaseType.INCREASE.equals(increaseDecreaseCommand)) {
127127
newValue = currentValue + stepValue;
128128
// round down to step multiple
129129
newValue = newValue - newValue % stepValue;
130-
nhcAction.execute(Integer.toString(newValue > 100 ? 100 : newValue));
130+
nhcAction.execute(Long.toString(newValue > 100 ? 100 : newValue));
131131
} else {
132132
newValue = currentValue - stepValue;
133133
// round up to step multiple
134134
newValue = newValue + newValue % stepValue;
135135
if (newValue <= 0) {
136136
nhcAction.execute(NHCOFF);
137137
} else {
138-
nhcAction.execute(Integer.toString(newValue));
138+
nhcAction.execute(Long.toString(newValue));
139139
}
140140
}
141141
} else if (command instanceof PercentType percentCommand) {
@@ -285,7 +285,7 @@ private void updateProperties(NhcAction nhcAction) {
285285
}
286286

287287
@Override
288-
public void actionEvent(int actionState) {
288+
public void actionEvent(long actionState) {
289289
NhcAction nhcAction = this.nhcAction;
290290
if (nhcAction == null) {
291291
logger.debug("action with ID {} not initialized", deviceId);
@@ -303,12 +303,12 @@ public void actionEvent(int actionState) {
303303
updateStatus(ThingStatus.ONLINE);
304304
break;
305305
case DIMMER:
306-
updateState(CHANNEL_BRIGHTNESS, new PercentType(actionState));
306+
updateState(CHANNEL_BRIGHTNESS, new PercentType((int) actionState));
307307
updateStatus(ThingStatus.ONLINE);
308308
break;
309309
case ROLLERSHUTTER:
310310
updateState(CHANNEL_ROLLERSHUTTER,
311-
!invert ? new PercentType(100 - actionState) : new PercentType(actionState));
311+
!invert ? new PercentType(100 - (int) actionState) : new PercentType((int) actionState));
312312
updateStatus(ThingStatus.ONLINE);
313313
break;
314314
default:

bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlCarChargerHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private void updateProperties(NhcCarCharger nhcCarCharger) {
282282

283283
@Override
284284
public void chargingStatusEvent(boolean status, @Nullable String chargingStatus, @Nullable String evStatus,
285-
@Nullable String couplingStatus, @Nullable Integer electricalPower) {
285+
@Nullable String couplingStatus, @Nullable Long electricalPower) {
286286
NhcCarCharger nhcCarCharger = this.nhcCarCharger;
287287
if (nhcCarCharger == null) {
288288
logger.debug("car charger device with ID {} not initialized", deviceId);
@@ -306,8 +306,8 @@ public void chargingStatusEvent(boolean status, @Nullable String chargingStatus,
306306
}
307307

308308
@Override
309-
public void chargingModeEvent(@Nullable String chargingMode, float targetDistance, @Nullable String targetTime,
310-
boolean boost, float reachableDistance, @Nullable String nextChargingTime) {
309+
public void chargingModeEvent(@Nullable String chargingMode, double targetDistance, @Nullable String targetTime,
310+
boolean boost, double reachableDistance, @Nullable String nextChargingTime) {
311311
NhcCarCharger nhcCarCharger = this.nhcCarCharger;
312312
if (nhcCarCharger == null) {
313313
logger.debug("car charger device with ID {} not initialized", deviceId);

bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlThermostatHandler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void handleCommandSelection(ChannelUID channelUID, Command command) {
9797
case CHANNEL_SETPOINT:
9898
// Always set the new setpoint temperature as an overrule
9999
// If no overrule time is given yet, set the overrule time to the configuration parameter
100-
int time = nhcThermostat.getOverruletime();
100+
long time = nhcThermostat.getOverruletime();
101101
if (time <= 0) {
102102
time = overruleTime;
103103
}
@@ -113,8 +113,8 @@ void handleCommandSelection(ChannelUID channelUID, Command command) {
113113
break;
114114
case CHANNEL_OVERRULETIME:
115115
if (command instanceof DecimalType decimalCommand) {
116-
int overruletime = decimalCommand.intValue();
117-
int overrule = nhcThermostat.getOverrule();
116+
long overruletime = decimalCommand.longValue();
117+
long overrule = nhcThermostat.getOverrule();
118118
if (overruletime <= 0) {
119119
overruletime = 0;
120120
overrule = 0;
@@ -224,7 +224,7 @@ private void updateProperties(NhcThermostat nhcThermostat) {
224224
}
225225

226226
@Override
227-
public void thermostatEvent(int measured, int setpoint, int mode, int overrule, int demand) {
227+
public void thermostatEvent(long measured, long setpoint, int mode, long overrule, int demand) {
228228
NhcThermostat nhcThermostat = this.nhcThermostat;
229229
if (nhcThermostat == null) {
230230
logger.debug("thermostat with ID {} not initialized", deviceId);
@@ -233,7 +233,7 @@ public void thermostatEvent(int measured, int setpoint, int mode, int overrule,
233233

234234
updateState(CHANNEL_MEASURED, new QuantityType<>(measured / 10.0, CELSIUS));
235235

236-
int overruletime = nhcThermostat.getRemainingOverruletime();
236+
long overruletime = nhcThermostat.getRemainingOverruletime();
237237
updateState(CHANNEL_OVERRULETIME, new DecimalType(overruletime));
238238
// refresh the remaining time every minute
239239
scheduleRefreshOverruletime(nhcThermostat);
@@ -268,7 +268,7 @@ private void scheduleRefreshOverruletime(NhcThermostat nhcThermostat) {
268268
}
269269

270270
refreshTimer = scheduler.scheduleWithFixedDelay(() -> {
271-
int remainingTime = nhcThermostat.getRemainingOverruletime();
271+
long remainingTime = nhcThermostat.getRemainingOverruletime();
272272
updateState(CHANNEL_OVERRULETIME, new DecimalType(remainingTime));
273273
if (remainingTime == 0) {
274274
cancelRefreshTimer();

bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NhcAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public abstract class NhcAction {
3838
protected ActionType type;
3939
protected @Nullable String location;
4040

41-
protected volatile int state;
41+
protected volatile long state;
4242
protected volatile int closeTime = 0;
4343
protected volatile int openTime = 0;
4444

@@ -139,7 +139,7 @@ public void setLocation(@Nullable String location) {
139139
*
140140
* @return action state
141141
*/
142-
public int getState() {
142+
public long getState() {
143143
return state;
144144
}
145145

@@ -182,7 +182,7 @@ protected void updateState() {
182182
updateState(state);
183183
}
184184

185-
protected void updateState(int state) {
185+
protected void updateState(long state) {
186186
NhcActionEvent eventHandler = this.eventHandler;
187187
if (eventHandler != null) {
188188
logger.debug("update channel state for {} with {}", id, state);
@@ -212,7 +212,7 @@ public void actionRemoved() {
212212
* dimmer action: between 0 and 100
213213
* rollershutter action: between 0 and 100
214214
*/
215-
public abstract void setState(int state);
215+
public abstract void setState(long state);
216216

217217
/**
218218
* Sends action to Niko Home Control. This method is implemented in

bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NhcActionEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ public interface NhcActionEvent extends NhcBaseEvent {
3030
*
3131
* @param state
3232
*/
33-
void actionEvent(int state);
33+
void actionEvent(long state);
3434
}

bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NhcCarCharger.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public abstract class NhcCarCharger {
4646
protected volatile @Nullable String chargingStatus;
4747
protected volatile @Nullable String evStatus;
4848
protected volatile @Nullable String couplingStatus;
49-
protected volatile @Nullable Integer electricalPower;
49+
protected volatile @Nullable Long electricalPower;
5050
protected volatile @Nullable String chargingMode;
51-
protected volatile float targetDistance;
51+
protected volatile double targetDistance;
5252
protected volatile @Nullable String targetTime;
5353
protected volatile boolean boost;
54-
protected volatile float reachableDistance;
54+
protected volatile double reachableDistance;
5555
protected volatile @Nullable String nextChargingTime;
5656
protected volatile double reading;
5757
protected volatile double dayReading;
@@ -165,7 +165,7 @@ public String getChargingMode() {
165165
*
166166
* @return the target distance in km
167167
*/
168-
public float getTargetDistance() {
168+
public double getTargetDistance() {
169169
return targetDistance;
170170
}
171171

@@ -226,7 +226,7 @@ public boolean isBoost() {
226226
*
227227
* @return the reachable distance in km
228228
*/
229-
public float getReachableDistance() {
229+
public double getReachableDistance() {
230230
return reachableDistance;
231231
}
232232

@@ -248,8 +248,8 @@ public String getNextChargingTime() {
248248
*
249249
* @return the electrical power value, or {@code 0} if not available
250250
*/
251-
public int getElectricalPower() {
252-
Integer electricalPower = this.electricalPower;
251+
public long getElectricalPower() {
252+
Long electricalPower = this.electricalPower;
253253
return electricalPower != null ? electricalPower : 0;
254254
}
255255

@@ -264,7 +264,7 @@ public int getElectricalPower() {
264264
* @param electricalPower the new electrical power value, or {@code null} to keep the current value
265265
*/
266266
public void setStatus(@Nullable Boolean status, @Nullable String chargingStatus, @Nullable String evStatus,
267-
@Nullable String couplingStatus, @Nullable Integer electricalPower) {
267+
@Nullable String couplingStatus, @Nullable Long electricalPower) {
268268
this.status = (status != null) ? status : this.status;
269269
this.chargingStatus = (chargingStatus != null) ? chargingStatus : this.chargingStatus;
270270
this.evStatus = (evStatus != null) ? evStatus : this.evStatus;
@@ -321,8 +321,8 @@ public void setReading(double reading, double dayReading, LocalDateTime lastRead
321321
* @param reachableDistance the currently reachable distance, or {@code null} to keep the current value
322322
* @param nextChargingTime the next scheduled charging time, or {@code null} or empty to keep the current value
323323
*/
324-
public void setChargingMode(@Nullable String chargingMode, @Nullable Float targetDistance,
325-
@Nullable String targetTime, @Nullable Boolean boost, @Nullable Float reachableDistance,
324+
public void setChargingMode(@Nullable String chargingMode, @Nullable Double targetDistance,
325+
@Nullable String targetTime, @Nullable Boolean boost, @Nullable Double reachableDistance,
326326
@Nullable String nextChargingTime) {
327327
this.chargingMode = (chargingMode != null) ? chargingMode : this.chargingMode;
328328
this.targetDistance = (targetDistance != null) ? targetDistance : this.targetDistance;
@@ -386,14 +386,13 @@ public void executeCarChargerStatus(boolean status) {
386386
* Changes the charging mode of the car charger in the Niko Home Control system.
387387
*
388388
* @param chargingMode The desired charging mode to set (SOLAR, NORMAL or SMART).
389-
* @param targetDistance The target distance (in kilometers) to be achieved during charging for SMART mode..
389+
* @param d The target distance (in kilometers) to be achieved during charging for SMART mode..
390390
* @param targetTime The target time (in ISO 8601 format or HH:mm) by which charging should be completed for SMART
391391
* mode.
392392
*/
393-
public void executeCarChargerChargingMode(String chargingMode, float targetDistance, String targetTime) {
394-
logger.debug("change car charger charging mode for {} to {}, target {} at {}", id, chargingMode, targetDistance,
395-
targetTime);
396-
nhcComm.executeCarChargerChargingMode(id, chargingMode, targetDistance, targetTime);
393+
public void executeCarChargerChargingMode(String chargingMode, double d, String targetTime) {
394+
logger.debug("change car charger charging mode for {} to {}, target {} at {}", id, chargingMode, d, targetTime);
395+
nhcComm.executeCarChargerChargingMode(id, chargingMode, d, targetTime);
397396
}
398397

399398
/**

bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NhcCarChargerEvent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public interface NhcCarChargerEvent extends NhcBaseEvent {
3939
* @param electricalPower the electrical power being delivered (in watts), or null if unavailable.
4040
*/
4141
void chargingStatusEvent(boolean status, @Nullable String chargingStatus, @Nullable String evStatus,
42-
@Nullable String couplingStatus, @Nullable Integer electricalPower);
42+
@Nullable String couplingStatus, @Nullable Long electricalPower);
4343

4444
/**
4545
* Handles an update event related to the car charger's charging mode.
@@ -52,8 +52,8 @@ void chargingStatusEvent(boolean status, @Nullable String chargingStatus, @Nulla
5252
* @param reachableDistance the currently reachable distance with the SMART charging mode (in kilometers)
5353
* @param nextChargingTime the next scheduled charging time, or {@code null} if not set
5454
*/
55-
void chargingModeEvent(@Nullable String chargingMode, float targetDistance, @Nullable String targetTime,
56-
boolean boost, float reachableDistance, @Nullable String nextChargingTime);
55+
void chargingModeEvent(@Nullable String chargingMode, double targetDistance, @Nullable String targetTime,
56+
boolean boost, double reachableDistance, @Nullable String nextChargingTime);
5757

5858
/**
5959
* This method is called when a meter reading is received from the Niko Home Control controller.

bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NhcThermostat.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public abstract class NhcThermostat {
4444
protected String name;
4545
protected @Nullable String location;
4646

47-
protected volatile int measured;
48-
protected volatile int setpoint;
47+
protected volatile long measured;
48+
protected volatile long setpoint;
4949
protected volatile int mode;
50-
protected volatile int overrule;
51-
protected volatile int overruletime;
50+
protected volatile long overrule;
51+
protected volatile long overruletime;
5252
protected volatile int ecosave;
5353
protected volatile int demand;
5454

@@ -76,7 +76,7 @@ protected NhcThermostat(String id, String name, @Nullable String location, NikoH
7676
* @param ecosave
7777
* @param demand 0 if no demand, > 0 if heating, &lt; 0 if cooling
7878
*/
79-
public void setState(int measured, int setpoint, int mode, int overrule, int overruletime, int ecosave,
79+
public void setState(long measured, long setpoint, int mode, long overrule, long overruletime, int ecosave,
8080
int demand) {
8181
setMeasured(measured);
8282
setSetpoint(setpoint);
@@ -179,22 +179,22 @@ public void setLocation(@Nullable String location) {
179179
*
180180
* @return measured temperature in 0.1°C multiples
181181
*/
182-
public int getMeasured() {
182+
public long getMeasured() {
183183
return measured;
184184
}
185185

186-
private void setMeasured(int measured) {
186+
private void setMeasured(long measured) {
187187
this.measured = measured;
188188
}
189189

190190
/**
191191
* @return the setpoint temperature in 0.1°C multiples
192192
*/
193-
public int getSetpoint() {
193+
public long getSetpoint() {
194194
return setpoint;
195195
}
196196

197-
private void setSetpoint(int setpoint) {
197+
private void setSetpoint(long setpoint) {
198198
this.setpoint = setpoint;
199199
}
200200

@@ -217,15 +217,15 @@ private void setMode(int mode) {
217217
*
218218
* @return the overrule temperature in 0.1°C multiples
219219
*/
220-
public int getOverrule() {
220+
public long getOverrule() {
221221
if (overrule > 0) {
222222
return overrule;
223223
} else {
224224
return setpoint;
225225
}
226226
}
227227

228-
private void setOverrule(int overrule) {
228+
private void setOverrule(long overrule) {
229229
this.overrule = overrule;
230230
if (overrule <= 0) {
231231
stopOverrule();
@@ -237,7 +237,7 @@ private void setOverrule(int overrule) {
237237
*
238238
* @return the overruletime in minutes
239239
*/
240-
public int getOverruletime() {
240+
public long getOverruletime() {
241241
return overruletime;
242242
}
243243

@@ -246,7 +246,7 @@ public int getOverruletime() {
246246
*
247247
* @param overruletime the overruletime in minutes
248248
*/
249-
private void setOverruletime(int overruletime) {
249+
private void setOverruletime(long overruletime) {
250250
if (overruletime != this.overruletime) {
251251
if (overruletime <= 0) {
252252
stopOverrule();
@@ -316,17 +316,16 @@ public void executeMode(String mode) {
316316
* @param overrule temperature to overrule the setpoint in 0.1°C multiples
317317
* @param overruletime time duration in min for overrule
318318
*/
319-
public abstract void executeOverrule(int overrule, int overruletime);
319+
public abstract void executeOverrule(long overrule, long overruletime);
320320

321321
/**
322322
* @return remaining overrule time in minutes, 0 or positive
323323
*/
324-
public int getRemainingOverruletime() {
325-
int remainingTime = 0;
324+
public long getRemainingOverruletime() {
325+
long remainingTime = 0;
326326
if (overruleStart != null) {
327-
// overruletime time max 23h59min, therefore can safely cast to int
328-
remainingTime = Math.max(0, overruletime - (int) ChronoUnit.MINUTES.between(overruleStart,
329-
LocalDateTime.now().atZone(nhcComm.getTimeZone())));
327+
remainingTime = Math.max(0, overruletime
328+
- ChronoUnit.MINUTES.between(overruleStart, LocalDateTime.now().atZone(nhcComm.getTimeZone())));
330329
}
331330
logger.trace("Getting remaining overrule time, remaining: {}", remainingTime);
332331
return remainingTime;

bundles/org.openhab.binding.nikohomecontrol/src/main/java/org/openhab/binding/nikohomecontrol/internal/protocol/NhcThermostatEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ public interface NhcThermostatEvent extends NhcBaseEvent {
3535
* @param overrule the overrule temperature in 0.1°C multiples
3636
* @param demand 0 if no demand, > 0 if heating, &lt; 0 if cooling
3737
*/
38-
void thermostatEvent(int measured, int setpoint, int mode, int overrule, int demand);
38+
void thermostatEvent(long measured, long setpoint, int mode, long overrule, int demand);
3939
}

0 commit comments

Comments
 (0)