Skip to content

Commit 8a1593f

Browse files
authored
[fronius] Ignore json parse error for inverters that don't support version info api (openhab#18907)
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
1 parent ddc1c11 commit 8a1593f

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

bundles/org.openhab.binding.fronius/src/main/java/org/openhab/binding/fronius/internal/handler/FroniusSymoInverterHandler.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
import com.google.gson.JsonElement;
5656
import com.google.gson.JsonParser;
57+
import com.google.gson.JsonSyntaxException;
5758

5859
/**
5960
* The {@link FroniusSymoInverterHandler} is responsible for updating the data, which are
@@ -337,7 +338,7 @@ public void handleBridgeConfigurationUpdate(Map<String, Object> configurationPar
337338
/**
338339
* Return the value as QuantityType with the unit extracted from ValueUnit
339340
* or a zero QuantityType with the given unit argument when value is null
340-
*
341+
*
341342
* @param value The ValueUnit data
342343
* @param unit The default unit to use when value is null
343344
* @return a QuantityType from the given value
@@ -387,7 +388,7 @@ private InverterRealtimeResponse getRealtimeData(String ip, int deviceId) throws
387388

388389
/**
389390
* Calculate the power value from the given voltage and current channels
390-
*
391+
*
391392
* @param voltage the voltage ValueUnit
392393
* @param current the current ValueUnit
393394
* @return {QuantityType<>} the power value calculated by multiplying voltage and current
@@ -421,20 +422,28 @@ private InverterRealtimeResponse getRealtimeData(String ip, int deviceId) throws
421422
return null;
422423
}
423424
}
424-
JsonElement jsonElement = JsonParser.parseString(response);
425-
if (!jsonElement.isJsonObject()) {
426-
logger.warn("Invalid JSON response for version info from Fronius inverter at {}: {}", hostname, response);
427-
return null;
428-
}
429425
try {
430-
String serial = jsonElement.getAsJsonObject().get("serialNumber").getAsString();
431-
String firmware = jsonElement.getAsJsonObject().get("swrevisions").getAsJsonObject().get("GEN24")
432-
.getAsString();
433-
return new InverterInfo(serial, firmware);
434-
} catch (IllegalStateException | UnsupportedOperationException e) {
435-
logger.warn("Failed to parse version info from Fronius inverter at {}: {}", hostname, e.getMessage());
436-
return null;
426+
JsonElement jsonElement = JsonParser.parseString(response);
427+
if (!jsonElement.isJsonObject()) {
428+
logger.warn("Invalid JSON response for version info from Fronius inverter at {}: {}", hostname,
429+
response);
430+
return null;
431+
}
432+
try {
433+
String serial = jsonElement.getAsJsonObject().get("serialNumber").getAsString();
434+
String firmware = jsonElement.getAsJsonObject().get("swrevisions").getAsJsonObject().get("GEN24")
435+
.getAsString();
436+
return new InverterInfo(serial, firmware);
437+
} catch (IllegalStateException | UnsupportedOperationException e) {
438+
logger.warn("Failed to parse version info from Fronius inverter at {}: {}", hostname, e.getMessage());
439+
return null;
440+
}
441+
} catch (JsonSyntaxException e) {
442+
// 404 errors go here, as the response is not valid JSON
443+
logger.debug("Invalid JSON response for version info from Fronius inverter at {}: {}", hostname, response,
444+
e);
437445
}
446+
return null;
438447
}
439448

440449
private record InverterInfo(String serial, String firmware) {

0 commit comments

Comments
 (0)