mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[goecharger] Avoid potential NullPointerException (#14933)
Also include change from PR #14632 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
aa3d6b0dc9
commit
cd4879a315
@ -154,13 +154,13 @@ public class GoEChargerHandler extends GoEChargerBaseHandler {
|
|||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (goeResponse.energy[4] > 0) { // current P1
|
if (goeResponse.energy.length >= 5 && goeResponse.energy[4] > 0) { // current P1
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (goeResponse.energy[5] > 0) { // current P2
|
if (goeResponse.energy.length >= 6 && goeResponse.energy[5] > 0) { // current P2
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (goeResponse.energy[6] > 0) { // current P3
|
if (goeResponse.energy.length >= 7 && goeResponse.energy[6] > 0) { // current P3
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
return new DecimalType(count);
|
return new DecimalType(count);
|
||||||
@ -173,68 +173,66 @@ public class GoEChargerHandler extends GoEChargerBaseHandler {
|
|||||||
if (goeResponse.sessionChargeConsumption == null) {
|
if (goeResponse.sessionChargeConsumption == null) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>((Double) (goeResponse.sessionChargeConsumption / 360000d),
|
return new QuantityType<>(goeResponse.sessionChargeConsumption / 360000d, Units.KILOWATT_HOUR);
|
||||||
Units.KILOWATT_HOUR);
|
|
||||||
case SESSION_CHARGE_CONSUMPTION_LIMIT:
|
case SESSION_CHARGE_CONSUMPTION_LIMIT:
|
||||||
if (goeResponse.sessionChargeConsumptionLimit == null) {
|
if (goeResponse.sessionChargeConsumptionLimit == null) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>((Double) (goeResponse.sessionChargeConsumptionLimit / 10d),
|
return new QuantityType<>(goeResponse.sessionChargeConsumptionLimit / 10d, Units.KILOWATT_HOUR);
|
||||||
Units.KILOWATT_HOUR);
|
|
||||||
case TOTAL_CONSUMPTION:
|
case TOTAL_CONSUMPTION:
|
||||||
if (goeResponse.totalChargeConsumption == null) {
|
if (goeResponse.totalChargeConsumption == null) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>((Double) (goeResponse.totalChargeConsumption / 10d), Units.KILOWATT_HOUR);
|
return new QuantityType<>(goeResponse.totalChargeConsumption / 10d, Units.KILOWATT_HOUR);
|
||||||
case CURRENT_L1:
|
case CURRENT_L1:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 5) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
// values come in as A*10, 41 means 4.1A
|
// values come in as A*10, 41 means 4.1A
|
||||||
return new QuantityType<>((Double) (goeResponse.energy[4] / 10d), Units.AMPERE);
|
return new QuantityType<>(goeResponse.energy[4] / 10d, Units.AMPERE);
|
||||||
case CURRENT_L2:
|
case CURRENT_L2:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 6) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>((Double) (goeResponse.energy[5] / 10d), Units.AMPERE);
|
return new QuantityType<>(goeResponse.energy[5] / 10d, Units.AMPERE);
|
||||||
case CURRENT_L3:
|
case CURRENT_L3:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 7) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>((Double) (goeResponse.energy[6] / 10d), Units.AMPERE);
|
return new QuantityType<>(goeResponse.energy[6] / 10d, Units.AMPERE);
|
||||||
case POWER_L1:
|
case POWER_L1:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 8) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
// values come in as kW*10, 41 means 4.1kW
|
// values come in as kW*10, 41 means 4.1kW
|
||||||
return new QuantityType<>(goeResponse.energy[7] * 100, Units.WATT);
|
return new QuantityType<>(goeResponse.energy[7] * 100, Units.WATT);
|
||||||
case POWER_L2:
|
case POWER_L2:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 9) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[8] * 100, Units.WATT);
|
return new QuantityType<>(goeResponse.energy[8] * 100, Units.WATT);
|
||||||
case POWER_L3:
|
case POWER_L3:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 10) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[9] * 100, Units.WATT);
|
return new QuantityType<>(goeResponse.energy[9] * 100, Units.WATT);
|
||||||
case VOLTAGE_L1:
|
case VOLTAGE_L1:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 1) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[0], Units.VOLT);
|
return new QuantityType<>(goeResponse.energy[0], Units.VOLT);
|
||||||
case VOLTAGE_L2:
|
case VOLTAGE_L2:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 2) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[1], Units.VOLT);
|
return new QuantityType<>(goeResponse.energy[1], Units.VOLT);
|
||||||
case VOLTAGE_L3:
|
case VOLTAGE_L3:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 3) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[2], Units.VOLT);
|
return new QuantityType<>(goeResponse.energy[2], Units.VOLT);
|
||||||
case POWER_ALL:
|
case POWER_ALL:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 12) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[11] * 10, Units.WATT);
|
return new QuantityType<>(goeResponse.energy[11] * 10, Units.WATT);
|
||||||
@ -392,7 +390,7 @@ public class GoEChargerHandler extends GoEChargerBaseHandler {
|
|||||||
allChannels.forEach(channel -> updateState(channel, UnDefType.UNDEF));
|
allChannels.forEach(channel -> updateState(channel, UnDefType.UNDEF));
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
|
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
|
||||||
allChannels.forEach(channel -> updateState(channel, getValue(channel, (GoEStatusResponseDTO) goeResponse)));
|
allChannels.forEach(channel -> updateState(channel, getValue(channel, goeResponse)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,12 +145,14 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler {
|
|||||||
case ALLOW_CHARGING:
|
case ALLOW_CHARGING:
|
||||||
return goeResponse.allowCharging == true ? OnOffType.ON : OnOffType.OFF;
|
return goeResponse.allowCharging == true ? OnOffType.ON : OnOffType.OFF;
|
||||||
case TEMPERATURE_TYPE2_PORT:
|
case TEMPERATURE_TYPE2_PORT:
|
||||||
if (goeResponse.temperatures == null) {
|
// It was reported that the temperature is invalid when only one value is returned
|
||||||
|
// That's why it is checked that at least 2 values are returned
|
||||||
|
if (goeResponse.temperatures == null || goeResponse.temperatures.length < 2) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.temperatures[0], SIUnits.CELSIUS);
|
return new QuantityType<>(goeResponse.temperatures[0], SIUnits.CELSIUS);
|
||||||
case TEMPERATURE_CIRCUIT_BOARD:
|
case TEMPERATURE_CIRCUIT_BOARD:
|
||||||
if (goeResponse.temperatures == null) {
|
if (goeResponse.temperatures == null || goeResponse.temperatures.length < 2) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.temperatures[1], SIUnits.CELSIUS);
|
return new QuantityType<>(goeResponse.temperatures[1], SIUnits.CELSIUS);
|
||||||
@ -168,54 +170,54 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler {
|
|||||||
if (goeResponse.totalChargeConsumption == null) {
|
if (goeResponse.totalChargeConsumption == null) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>((Double) (goeResponse.totalChargeConsumption / 1000d), Units.KILOWATT_HOUR);
|
return new QuantityType<>(goeResponse.totalChargeConsumption / 1000d, Units.KILOWATT_HOUR);
|
||||||
case VOLTAGE_L1:
|
case VOLTAGE_L1:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 1) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[0], Units.VOLT);
|
return new QuantityType<>(goeResponse.energy[0], Units.VOLT);
|
||||||
case VOLTAGE_L2:
|
case VOLTAGE_L2:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 2) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[1], Units.VOLT);
|
return new QuantityType<>(goeResponse.energy[1], Units.VOLT);
|
||||||
case VOLTAGE_L3:
|
case VOLTAGE_L3:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 3) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[2], Units.VOLT);
|
return new QuantityType<>(goeResponse.energy[2], Units.VOLT);
|
||||||
case CURRENT_L1:
|
case CURRENT_L1:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 5) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[4], Units.AMPERE);
|
return new QuantityType<>(goeResponse.energy[4], Units.AMPERE);
|
||||||
case CURRENT_L2:
|
case CURRENT_L2:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 6) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[5], Units.AMPERE);
|
return new QuantityType<>(goeResponse.energy[5], Units.AMPERE);
|
||||||
case CURRENT_L3:
|
case CURRENT_L3:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 7) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[6], Units.AMPERE);
|
return new QuantityType<>(goeResponse.energy[6], Units.AMPERE);
|
||||||
case POWER_L1:
|
case POWER_L1:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 8) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[7], Units.WATT);
|
return new QuantityType<>(goeResponse.energy[7], Units.WATT);
|
||||||
case POWER_L2:
|
case POWER_L2:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 9) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[8], Units.WATT);
|
return new QuantityType<>(goeResponse.energy[8], Units.WATT);
|
||||||
case POWER_L3:
|
case POWER_L3:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 10) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[9], Units.WATT);
|
return new QuantityType<>(goeResponse.energy[9], Units.WATT);
|
||||||
case POWER_ALL:
|
case POWER_ALL:
|
||||||
if (goeResponse.energy == null) {
|
if (goeResponse.energy == null || goeResponse.energy.length < 12) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
return new QuantityType<>(goeResponse.energy[11], Units.WATT);
|
return new QuantityType<>(goeResponse.energy[11], Units.WATT);
|
||||||
@ -374,14 +376,14 @@ public class GoEChargerV2Handler extends GoEChargerBaseHandler {
|
|||||||
return gson.fromJson(response, GoEStatusResponseV2DTO.class);
|
return gson.fromJson(response, GoEStatusResponseV2DTO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void updateChannelsAndStatus(@Nullable GoEStatusResponseBaseDTO goeResponse, @Nullable String message) {
|
protected void updateChannelsAndStatus(@Nullable GoEStatusResponseBaseDTO goeResponse, @Nullable String message) {
|
||||||
if (goeResponse == null) {
|
if (goeResponse == null) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, message);
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, message);
|
||||||
allChannels.forEach(channel -> updateState(channel, UnDefType.UNDEF));
|
allChannels.forEach(channel -> updateState(channel, UnDefType.UNDEF));
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
allChannels
|
allChannels.forEach(channel -> updateState(channel, getValue(channel, goeResponse)));
|
||||||
.forEach(channel -> updateState(channel, getValue(channel, (GoEStatusResponseV2DTO) goeResponse)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user