|
54 | 54 |
|
55 | 55 | import com.google.gson.JsonElement; |
56 | 56 | import com.google.gson.JsonParser; |
| 57 | +import com.google.gson.JsonSyntaxException; |
57 | 58 |
|
58 | 59 | /** |
59 | 60 | * The {@link FroniusSymoInverterHandler} is responsible for updating the data, which are |
@@ -337,7 +338,7 @@ public void handleBridgeConfigurationUpdate(Map<String, Object> configurationPar |
337 | 338 | /** |
338 | 339 | * Return the value as QuantityType with the unit extracted from ValueUnit |
339 | 340 | * or a zero QuantityType with the given unit argument when value is null |
340 | | - * |
| 341 | + * |
341 | 342 | * @param value The ValueUnit data |
342 | 343 | * @param unit The default unit to use when value is null |
343 | 344 | * @return a QuantityType from the given value |
@@ -387,7 +388,7 @@ private InverterRealtimeResponse getRealtimeData(String ip, int deviceId) throws |
387 | 388 |
|
388 | 389 | /** |
389 | 390 | * Calculate the power value from the given voltage and current channels |
390 | | - * |
| 391 | + * |
391 | 392 | * @param voltage the voltage ValueUnit |
392 | 393 | * @param current the current ValueUnit |
393 | 394 | * @return {QuantityType<>} the power value calculated by multiplying voltage and current |
@@ -421,20 +422,28 @@ private InverterRealtimeResponse getRealtimeData(String ip, int deviceId) throws |
421 | 422 | return null; |
422 | 423 | } |
423 | 424 | } |
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 | | - } |
429 | 425 | 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); |
437 | 445 | } |
| 446 | + return null; |
438 | 447 | } |
439 | 448 |
|
440 | 449 | private record InverterInfo(String serial, String firmware) { |
|
0 commit comments