This commit is contained in:
Av3m 2022-12-17 00:11:27 +01:00 committed by Thomas Vogl
parent c34a9fd911
commit af2f10bde8
2 changed files with 30 additions and 9 deletions

View File

@ -20,6 +20,7 @@ import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.HttpVersion;
import org.openhab.binding.mediolaaiogateway.internal.config.MediolaAioBridgeConfig; import org.openhab.binding.mediolaaiogateway.internal.config.MediolaAioBridgeConfig;
import org.openhab.binding.mediolaaiogateway.internal.discovery.MediolaAioDeviceDiscoveryService; import org.openhab.binding.mediolaaiogateway.internal.discovery.MediolaAioDeviceDiscoveryService;
@ -100,12 +101,17 @@ public class MediolaAioGatewayBridgeHandler extends BaseBridgeHandler {
synchronized (this) { synchronized (this) {
try { try {
response = request.send(); response = request.send();
if(!HttpStatus.isSuccess(response.getStatus())) {
throw new MediolaAioCommunicationError("invalid http result code");
}
content = response.getContent(); content = response.getContent();
} catch (InterruptedException | TimeoutException | ExecutionException e) { } catch (InterruptedException | TimeoutException | ExecutionException e) {
throw new MediolaAioCommunicationError("communication error", e); throw new MediolaAioCommunicationError("communication error", e);
} }
} }
try {
JsonObject convertedObject = new Gson().fromJson(new String(content), JsonObject.class); JsonObject convertedObject = new Gson().fromJson(new String(content), JsonObject.class);
if (!convertedObject.has("XC_SUC")) { if (!convertedObject.has("XC_SUC")) {
if (convertedObject.has("XC_ERR")) { if (convertedObject.has("XC_ERR")) {
@ -113,11 +119,12 @@ public class MediolaAioGatewayBridgeHandler extends BaseBridgeHandler {
} else { } else {
throw new MediolaAioCommandError("unknown reason."); throw new MediolaAioCommandError("unknown reason.");
} }
} }
return convertedObject.get("XC_SUC"); return convertedObject.get("XC_SUC");
} catch (Exception e) {
throw new MediolaAioCommandError("json decode of response failed.");
}
} }

View File

@ -12,7 +12,10 @@
*/ */
package org.openhab.binding.smartmeter.internal.sml; package org.openhab.binding.smartmeter.internal.sml;
import java.time.ZonedDateTime;
import java.time.temporal.WeekFields;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
@ -32,6 +35,7 @@ import org.openmuc.jsml.structures.SmlStatus;
import org.openmuc.jsml.structures.responses.SmlGetListRes; import org.openmuc.jsml.structures.responses.SmlGetListRes;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.time.temporal.ChronoUnit
/** /**
* Represents a SML capable device. * Represents a SML capable device.
@ -44,6 +48,8 @@ public final class SmlMeterReader extends MeterDevice<SmlFile> {
protected final Logger logger = LoggerFactory.getLogger(SmlMeterReader.class); protected final Logger logger = LoggerFactory.getLogger(SmlMeterReader.class);
Locale.
/** /**
* Static factory method to create a SmlDevice object with a serial connector member. * Static factory method to create a SmlDevice object with a serial connector member.
* *
@ -59,7 +65,13 @@ public final class SmlMeterReader extends MeterDevice<SmlFile> {
SmlMeterReader device = new SmlMeterReader(serialPortManagerSupplier, deviceId, serialPort, initMessage, SmlMeterReader device = new SmlMeterReader(serialPortManagerSupplier, deviceId, serialPort, initMessage,
baudrate, baudrateChangeDelay, ProtocolMode.SML); baudrate, baudrateChangeDelay, ProtocolMode.SML);
ZonedDateTime t = ZonedDateTime.now();
WeekFields
t.with()
return device; return device;
} }
/** /**
@ -122,6 +134,8 @@ public final class SmlMeterReader extends MeterDevice<SmlFile> {
smlValue = valueExtractor.getSmlValue(); smlValue = valueExtractor.getSmlValue();
} }
ZonedDateTime t = ZonedDateTime.now().toLocalDateTime().toLocalDate().atStartOfDay()
SmlStatus status = entry.getStatus(); SmlStatus status = entry.getStatus();
if (status != null) { if (status != null) {
String statusValue = readStatus(status, obis); String statusValue = readStatus(status, obis);