From 5d1b9974ae7921b1f6a321af7d005f5e0b4c033b Mon Sep 17 00:00:00 2001 From: Olivier Marceau Date: Fri, 30 Apr 2021 22:18:33 +0200 Subject: [PATCH] Add things and channels for standard tic mode Signed-off-by: Olivier Marceau --- .../internal/TeleinfoBindingConstants.java | 83 +++++ .../internal/TeleinfoDiscoveryService.java | 17 +- .../binding/teleinfo/internal/data/Frame.java | 37 ++ .../teleinfo/internal/data/FrameType.java | 4 + .../TeleinfoElectricityMeterHandler.java | 51 +-- .../handler/TeleinfoThingHandlerFactory.java | 4 +- .../reader/io/TeleinfoInputStream.java | 2 +- .../internal/reader/io/serialport/Label.java | 93 ++++- .../OH-INF/config/config-description.xml | 2 +- .../OH-INF/thing/common-lsm-channel-types.xml | 351 ++++++++++++++++++ .../thing/common-lsm-prod-channel-types.xml | 87 +++++ .../common-lsm-three-phase-channel-types.xml | 127 +++++++ .../OH-INF/thing/lsmmElectricityMeter.xml | 65 ++++ .../OH-INF/thing/lsmmProdElectricityMeter.xml | 76 ++++ .../OH-INF/thing/lsmtElectricityMeter.xml | 81 ++++ .../OH-INF/thing/lsmtProdElectricityMeter.xml | 92 +++++ .../OH-INF/thing/serialController.xml | 6 +- .../reader/io/TeleinfoInputStreamTest.java | 46 +-- .../reader/io/serialport/FrameUtilTest.java | 65 ++++ ...ky-tic-mode-standard-single-phase-prod.raw | 70 ++++ ...nky-tic-mode-standard-three-phase-prod.raw | 171 +++++++++ 21 files changed, 1469 insertions(+), 61 deletions(-) create mode 100644 bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/common-lsm-channel-types.xml create mode 100644 bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/common-lsm-prod-channel-types.xml create mode 100644 bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/common-lsm-three-phase-channel-types.xml create mode 100644 bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmmElectricityMeter.xml create mode 100644 bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmmProdElectricityMeter.xml create mode 100644 bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmtElectricityMeter.xml create mode 100644 bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmtProdElectricityMeter.xml create mode 100644 bundles/org.openhab.binding.teleinfo/src/test/java/org/openhab/binding/teleinfo/internal/reader/io/serialport/FrameUtilTest.java create mode 100644 bundles/org.openhab.binding.teleinfo/src/test/resources/linky-tic-mode-standard-single-phase-prod.raw create mode 100644 bundles/org.openhab.binding.teleinfo/src/test/resources/linky-tic-mode-standard-three-phase-prod.raw diff --git a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/TeleinfoBindingConstants.java b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/TeleinfoBindingConstants.java index 3b942d2c22c39..60f1016e11ab9 100644 --- a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/TeleinfoBindingConstants.java +++ b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/TeleinfoBindingConstants.java @@ -77,6 +77,77 @@ private TeleinfoBindingConstants() { public static final String CHANNEL_CBETM_SHORT_ADIR1 = "adir1"; public static final String CHANNEL_CBETM_SHORT_ADIR2 = "adir2"; public static final String CHANNEL_CBETM_SHORT_ADIR3 = "adir3"; + // List ofLinky standard mode channel ids + public static final String CHANNEL_LSM_NGTF = "ngtf"; + public static final String CHANNEL_LSM_LTARF = "ltarf"; + public static final String CHANNEL_LSM_EAST = "east"; + public static final String CHANNEL_LSM_EASF01 = "easf01"; + public static final String CHANNEL_LSM_EASF02 = "easf02"; + public static final String CHANNEL_LSM_EASF03 = "easf03"; + public static final String CHANNEL_LSM_EASF04 = "easf04"; + public static final String CHANNEL_LSM_EASF05 = "easf05"; + public static final String CHANNEL_LSM_EASF06 = "easf06"; + public static final String CHANNEL_LSM_EASF07 = "easf07"; + public static final String CHANNEL_LSM_EASF08 = "easf08"; + public static final String CHANNEL_LSM_EASF09 = "easf09"; + public static final String CHANNEL_LSM_EASF10 = "easf10"; + public static final String CHANNEL_LSM_EASD01 = "easd01"; + public static final String CHANNEL_LSM_EASD02 = "easd02"; + public static final String CHANNEL_LSM_EASD03 = "easd03"; + public static final String CHANNEL_LSM_EASD04 = "easd04"; + public static final String CHANNEL_LSM_IRMS1 = "irms1"; + public static final String CHANNEL_LSM_URMS1 = "urms1"; + public static final String CHANNEL_LSM_PREF = "pref"; + public static final String CHANNEL_LSM_PCOUP = "pcoup"; + public static final String CHANNEL_LSM_SINSTS = "sinsts"; + public static final String CHANNEL_LSM_SMAXSN = "smaxsn"; + public static final String CHANNEL_LSM_SMAXSN_MINUS_1 = "smaxsnMinus1"; + public static final String CHANNEL_LSM_CCASN = "ccasn"; + public static final String CHANNEL_LSM_CCASN_MINUS_1 = "ccasnMinus1"; + public static final String CHANNEL_LSM_UMOY1 = "umoy1"; + public static final String CHANNEL_LSM_STGE = "stge"; + public static final String CHANNEL_LSM_DPM1 = "dpm1"; + public static final String CHANNEL_LSM_FPM1 = "fpm1"; + public static final String CHANNEL_LSM_DPM2 = "dpm2"; + public static final String CHANNEL_LSM_FPM2 = "fpm2"; + public static final String CHANNEL_LSM_DPM3 = "dpm3"; + public static final String CHANNEL_LSM_FPM3 = "fpm3"; + public static final String CHANNEL_LSM_MSG1 = "msg1"; + public static final String CHANNEL_LSM_MSG2 = "msg2"; + public static final String CHANNEL_LSM_PRM = "prm"; + public static final String CHANNEL_LSM_RELAIS = "relais"; + public static final String CHANNEL_LSM_NTARF = "ntarf"; + public static final String CHANNEL_LSM_NJOURF = "njourf"; + public static final String CHANNEL_LSM_NJOURF_PLUS_1 = "njourfPlus1"; + public static final String CHANNEL_LSM_PJOURF_PLUS_1 = "pjourfPlus1"; + public static final String CHANNEL_LSM_PPOINTE = "ppointe"; + + public static final String CHANNEL_LSM_IRMS2 = "irms2"; + public static final String CHANNEL_LSM_IRMS3 = "irms3"; + public static final String CHANNEL_LSM_URMS2 = "urms2"; + public static final String CHANNEL_LSM_URMS3 = "urms3"; + public static final String CHANNEL_LSM_SINSTS1 = "sinsts1"; + public static final String CHANNEL_LSM_SINSTS2 = "sinsts2"; + public static final String CHANNEL_LSM_SINSTS3 = "sinsts3"; + public static final String CHANNEL_LSM_SMAXSN1 = "smaxsn1"; + public static final String CHANNEL_LSM_SMAXSN2 = "smaxsn2"; + public static final String CHANNEL_LSM_SMAXSN3 = "smaxsn3"; + public static final String CHANNEL_LSM_SMAXSN1_MINUS_1 = "smaxsn1Minus1"; + public static final String CHANNEL_LSM_SMAXSN2_MINUS_1 = "smaxsn2Minus1"; + public static final String CHANNEL_LSM_SMAXSN3_MINUS_1 = "smaxsn3Minus1"; + public static final String CHANNEL_LSM_UMOY2 = "umoy2"; + public static final String CHANNEL_LSM_UMOY3 = "umoy3"; + + public static final String CHANNEL_LSM_EAIT = "eait"; + public static final String CHANNEL_LSM_ERQ1 = "erq1"; + public static final String CHANNEL_LSM_ERQ2 = "erq2"; + public static final String CHANNEL_LSM_ERQ3 = "erq3"; + public static final String CHANNEL_LSM_ERQ4 = "erq4"; + public static final String CHANNEL_LSM_SINSTI = "sinsti"; + public static final String CHANNEL_LSM_SMAXIN = "smaxin"; + public static final String CHANNEL_LSM_SMAXIN_MINUS_1 = "smaxinMinus1"; + public static final String CHANNEL_LSM_CCAIN = "ccain"; + public static final String CHANNEL_LSM_CCAIN_MINUS_1 = "ccainMinus1"; public static final String NOT_A_CHANNEL = ""; @@ -118,6 +189,18 @@ private TeleinfoBindingConstants() { public static final ThingTypeUID THING_TEMPO_CBETM_ELECTRICITY_METER_TYPE_UID = new ThingTypeUID(BINDING_ID, "cbetm_tempo_electricitymeter"); + public static final ThingTypeUID THING_LSMT_PROD_ELECTRICITY_METER_TYPE_UID = new ThingTypeUID(BINDING_ID, + "lsmt_prod_electricitymeter"); + + public static final ThingTypeUID THING_LSMM_PROD_ELECTRICITY_METER_TYPE_UID = new ThingTypeUID(BINDING_ID, + "lsmm_prod_electricitymeter"); + + public static final ThingTypeUID THING_LSMT_ELECTRICITY_METER_TYPE_UID = new ThingTypeUID(BINDING_ID, + "lsmt_electricitymeter"); + + public static final ThingTypeUID THING_LSMM_ELECTRICITY_METER_TYPE_UID = new ThingTypeUID(BINDING_ID, + "lsmm_electricitymeter"); + public static final String ERROR_OFFLINE_SERIAL_NOT_FOUND = "@text/teleinfo.thingstate.serial_notfound"; public static final String ERROR_OFFLINE_SERIAL_INUSE = "@text/teleinfo.thingstate.serial_inuse"; public static final String ERROR_OFFLINE_SERIAL_UNSUPPORTED = "@text/teleinfo.thingstate.serial_unsupported"; diff --git a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/TeleinfoDiscoveryService.java b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/TeleinfoDiscoveryService.java index f3ff6c4bcac81..c6f59a4980e6f 100644 --- a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/TeleinfoDiscoveryService.java +++ b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/TeleinfoDiscoveryService.java @@ -17,8 +17,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -47,13 +45,15 @@ public class TeleinfoDiscoveryService extends AbstractDiscoveryService implements TeleinfoControllerHandlerListener, ThingHandlerService, DiscoveryService { - private static final Set SUPPORTED_THING_TYPES = Stream.of(THING_HC_CBEMM_ELECTRICITY_METER_TYPE_UID, + private static final Set SUPPORTED_THING_TYPES = Set.of(THING_HC_CBEMM_ELECTRICITY_METER_TYPE_UID, THING_BASE_CBEMM_ELECTRICITY_METER_TYPE_UID, THING_TEMPO_CBEMM_ELECTRICITY_METER_TYPE_UID, THING_EJP_CBEMM_ELECTRICITY_METER_TYPE_UID, THING_HC_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_BASE_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_TEMPO_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_EJP_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_HC_CBETM_ELECTRICITY_METER_TYPE_UID, THING_BASE_CBETM_ELECTRICITY_METER_TYPE_UID, THING_TEMPO_CBETM_ELECTRICITY_METER_TYPE_UID, - THING_EJP_CBETM_ELECTRICITY_METER_TYPE_UID).collect(Collectors.toSet()); + THING_EJP_CBETM_ELECTRICITY_METER_TYPE_UID, THING_LSMT_PROD_ELECTRICITY_METER_TYPE_UID, + THING_LSMT_ELECTRICITY_METER_TYPE_UID, THING_LSMM_PROD_ELECTRICITY_METER_TYPE_UID, + THING_LSMM_ELECTRICITY_METER_TYPE_UID); private static final int SCAN_DURATION_IN_S = 60; @@ -140,11 +140,12 @@ private void detectNewElectricityMeterFromReceivedFrame(final Frame frameSample) TeleinfoAbstractControllerHandler controllerHandlerRef = controllerHandler; if (controllerHandlerRef != null) { logger.debug("New eletricity meter detection from frame {}", frameSample); - if (frameSample.get(Label.ADCO) == null) { - throw new IllegalStateException("Missing ADCO key"); + if (frameSample.get(Label.ADCO) == null && frameSample.get(Label.ADSC) == null) { + throw new IllegalStateException("Missing ADCO or ADSC key"); } - String adco = frameSample.get(Label.ADCO); + String adco = frameSample.get(Label.ADCO) != null ? frameSample.get(Label.ADCO) + : frameSample.get(Label.ADSC); if (adco != null) { ThingUID thingUID = new ThingUID(getThingTypeUID(frameSample), adco, controllerHandlerRef.getThing().getUID().getId()); @@ -152,7 +153,7 @@ private void detectNewElectricityMeterFromReceivedFrame(final Frame frameSample) final Map properties = getThingProperties(adco); final String representationProperty = THING_ELECTRICITY_METER_PROPERTY_ADCO; DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties) - .withLabel("Teleinfo ADCO " + adco).withThingType(getThingTypeUID(frameSample)) + .withLabel("Teleinfo ADCO/ADSC " + adco).withThingType(getThingTypeUID(frameSample)) .withBridge(controllerHandlerRef.getThing().getUID()) .withRepresentationProperty(representationProperty).build(); diff --git a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/data/Frame.java b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/data/Frame.java index 3594885198abb..04e88a407304a 100644 --- a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/data/Frame.java +++ b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/data/Frame.java @@ -20,6 +20,7 @@ import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.teleinfo.internal.reader.io.serialport.InvalidFrameException; import org.openhab.binding.teleinfo.internal.reader.io.serialport.Label; +import org.openhab.binding.teleinfo.internal.serial.TeleinfoTicMode; /** * The {@link Frame} class defines common attributes for any Teleinfo frames. @@ -54,6 +55,18 @@ public Frame() { } public FrameType getType() throws InvalidFrameException { + TeleinfoTicMode ticMode = getTicMode(); + switch (ticMode) { + case HISTORICAL: + return getHistoricalType(); + case STANDARD: + return getStandardType(); + default: + throw new InvalidFrameException(); + } + } + + public FrameType getHistoricalType() throws InvalidFrameException { Phase phase = getPhase(); Pricing pricing = getPricing(); Evolution evolution = getEvolution(); @@ -152,6 +165,30 @@ public Pricing getPricing() throws InvalidFrameException { } } + public TeleinfoTicMode getTicMode() throws InvalidFrameException { + if (labelToValues.containsKey(Label.ADCO)) { + return TeleinfoTicMode.HISTORICAL; + } else if (labelToValues.containsKey(Label.ADSC)) { + return TeleinfoTicMode.STANDARD; + } + throw new InvalidFrameException(); + } + + public FrameType getStandardType() throws InvalidFrameException { + boolean isProd = labelToValues.containsKey(Label.EAIT); + boolean isThreePhase = labelToValues.containsKey(Label.IRMS2); + if (isProd && isThreePhase) { + return FrameType.LSMT_PROD; + } + if (isProd) { + return FrameType.LSMM_PROD; + } + if (isThreePhase) { + return FrameType.LSMT; + } + return FrameType.LSMM; + } + public void clear() { labelToValues.clear(); } diff --git a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/data/FrameType.java b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/data/FrameType.java index a829805b37ffd..4c8651698b899 100644 --- a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/data/FrameType.java +++ b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/data/FrameType.java @@ -36,6 +36,10 @@ public enum FrameType { CBEMM_ICC_EJP(THING_EJP_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID), CBEMM_ICC_TEMPO(THING_TEMPO_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID), CBEMM_ICC_HC(THING_HC_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID), + LSMT_PROD(THING_LSMT_PROD_ELECTRICITY_METER_TYPE_UID), + LSMM_PROD(THING_LSMM_PROD_ELECTRICITY_METER_TYPE_UID), + LSMM(THING_LSMM_ELECTRICITY_METER_TYPE_UID), + LSMT(THING_LSMT_ELECTRICITY_METER_TYPE_UID), UNKNOWN(null); private ThingTypeUID thingTypeUid; diff --git a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/handler/TeleinfoElectricityMeterHandler.java b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/handler/TeleinfoElectricityMeterHandler.java index 67a8bd8da717b..c51a834674ded 100644 --- a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/handler/TeleinfoElectricityMeterHandler.java +++ b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/handler/TeleinfoElectricityMeterHandler.java @@ -24,6 +24,7 @@ import org.openhab.binding.teleinfo.internal.reader.io.serialport.InvalidFrameException; import org.openhab.binding.teleinfo.internal.reader.io.serialport.Label; import org.openhab.binding.teleinfo.internal.reader.io.serialport.ValueType; +import org.openhab.binding.teleinfo.internal.serial.TeleinfoTicMode; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.types.StringType; @@ -130,7 +131,7 @@ protected void updateStatus(ThingStatus status) { @Override public void onFrameReceived(Frame frame) { String adco = configuration.getAdco(); - if (adco.equalsIgnoreCase(frame.get(Label.ADCO))) { + if (adco.equalsIgnoreCase(frame.get(Label.ADCO)) || adco.equalsIgnoreCase(frame.get(Label.ADSC))) { updateStatesForChannels(frame); } } @@ -144,34 +145,42 @@ private void updateStatesForChannels(Frame frame) { } else if (label.getType() == ValueType.STRING) { updateState(label.getChannelName(), StringType.valueOf(entry.getValue())); } else if (label.getType() == ValueType.INTEGER) { - updateState(label.getChannelName(), - QuantityType.valueOf(Integer.parseInt(entry.getValue()), label.getUnit())); + updateState(label.getChannelName(), QuantityType + .valueOf(label.getFactor() * Integer.parseInt(entry.getValue()), label.getUnit())); } } } try { - if (frame.getPricing() == Pricing.TEMPO) { - updateState(CHANNEL_TEMPO_FRAME_PROGRAMME_CIRCUIT_1, StringType.valueOf(frame.getProgrammeCircuit1())); - updateState(CHANNEL_TEMPO_FRAME_PROGRAMME_CIRCUIT_2, StringType.valueOf(frame.getProgrammeCircuit2())); - } - } catch (InvalidFrameException e) { - logger.warn("Can not find pricing option."); - } + if (frame.getTicMode() == TeleinfoTicMode.HISTORICAL) { + try { + if (frame.getPricing() == Pricing.TEMPO) { + updateState(CHANNEL_TEMPO_FRAME_PROGRAMME_CIRCUIT_1, + StringType.valueOf(frame.getProgrammeCircuit1())); + updateState(CHANNEL_TEMPO_FRAME_PROGRAMME_CIRCUIT_2, + StringType.valueOf(frame.getProgrammeCircuit2())); + } + } catch (InvalidFrameException e) { + logger.warn("Can not find pricing option."); + } - try { - Phase phase = frame.getPhase(); - if (phase == Phase.ONE_PHASED) { - updateStateForMissingAlert(frame, Label.ADPS); - } else if (phase == Phase.THREE_PHASED) { - if (!wasLastFrameShort) { - updateStateForMissingAlert(frame, Label.ADIR1); - updateStateForMissingAlert(frame, Label.ADIR2); - updateStateForMissingAlert(frame, Label.ADIR3); + try { + Phase phase = frame.getPhase(); + if (phase == Phase.ONE_PHASED) { + updateStateForMissingAlert(frame, Label.ADPS); + } else if (phase == Phase.THREE_PHASED) { + if (!wasLastFrameShort) { + updateStateForMissingAlert(frame, Label.ADIR1); + updateStateForMissingAlert(frame, Label.ADIR2); + updateStateForMissingAlert(frame, Label.ADIR3); + } + wasLastFrameShort = frame.isShortFrame(); + } + } catch (InvalidFrameException e) { + logger.warn("Can not find phase."); } - wasLastFrameShort = frame.isShortFrame(); } } catch (InvalidFrameException e) { - logger.warn("Can not find phase."); + logger.warn("Can not find TIC mode."); } updateState(CHANNEL_LAST_UPDATE, new DateTimeType()); diff --git a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/handler/TeleinfoThingHandlerFactory.java b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/handler/TeleinfoThingHandlerFactory.java index bc7755c692ecb..2378dddd3b061 100644 --- a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/handler/TeleinfoThingHandlerFactory.java +++ b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/handler/TeleinfoThingHandlerFactory.java @@ -48,7 +48,9 @@ public class TeleinfoThingHandlerFactory extends BaseThingHandlerFactory { THING_HC_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_BASE_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_TEMPO_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_EJP_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_HC_CBETM_ELECTRICITY_METER_TYPE_UID, THING_BASE_CBETM_ELECTRICITY_METER_TYPE_UID, - THING_TEMPO_CBETM_ELECTRICITY_METER_TYPE_UID, THING_EJP_CBETM_ELECTRICITY_METER_TYPE_UID) + THING_TEMPO_CBETM_ELECTRICITY_METER_TYPE_UID, THING_EJP_CBETM_ELECTRICITY_METER_TYPE_UID, + THING_LSMM_ELECTRICITY_METER_TYPE_UID, THING_LSMM_PROD_ELECTRICITY_METER_TYPE_UID, + THING_LSMT_ELECTRICITY_METER_TYPE_UID, THING_LSMT_PROD_ELECTRICITY_METER_TYPE_UID) .collect(Collectors.toSet()); private final SerialPortManager serialPortManager; diff --git a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/reader/io/TeleinfoInputStream.java b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/reader/io/TeleinfoInputStream.java index 0458df9cd599c..7191f92bc336a 100644 --- a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/reader/io/TeleinfoInputStream.java +++ b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/reader/io/TeleinfoInputStream.java @@ -151,7 +151,7 @@ public void close() throws IOException { Label label; try { - label = Label.valueOf(labelStr); + label = Label.getEnum(labelStr); } catch (IllegalArgumentException e) { if (autoRepairInvalidADPSgroupLine && labelStr.startsWith(Label.ADPS.name())) { // in this hardware issue, label variable is composed by label name and value. E.g: diff --git a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/reader/io/serialport/Label.java b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/reader/io/serialport/Label.java index c4cf0e9eb70a8..4aefc23cfca3e 100644 --- a/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/reader/io/serialport/Label.java +++ b/bundles/org.openhab.binding.teleinfo/src/main/java/org/openhab/binding/teleinfo/internal/reader/io/serialport/Label.java @@ -65,16 +65,91 @@ public enum Label { // Standard TIC mode labels ADSC(ValueType.STRING, NOT_A_CHANNEL, Units.ONE), - UMOY1(ValueType.INTEGER, NOT_A_CHANNEL, Units.ONE); + VTIC(ValueType.INTEGER, NOT_A_CHANNEL, Units.ONE), + DATE(ValueType.STRING, NOT_A_CHANNEL, Units.ONE), + NGTF(ValueType.STRING, CHANNEL_LSM_NGTF, Units.ONE), + LTARF(ValueType.STRING, CHANNEL_LSM_LTARF, Units.ONE), + EAST(ValueType.INTEGER, CHANNEL_LSM_EAST, Units.WATT_HOUR), + EASF01(ValueType.INTEGER, CHANNEL_LSM_EASF01, Units.WATT_HOUR), + EASF02(ValueType.INTEGER, CHANNEL_LSM_EASF02, Units.WATT_HOUR), + EASF03(ValueType.INTEGER, CHANNEL_LSM_EASF03, Units.WATT_HOUR), + EASF04(ValueType.INTEGER, CHANNEL_LSM_EASF04, Units.WATT_HOUR), + EASF05(ValueType.INTEGER, CHANNEL_LSM_EASF05, Units.WATT_HOUR), + EASF06(ValueType.INTEGER, CHANNEL_LSM_EASF06, Units.WATT_HOUR), + EASF07(ValueType.INTEGER, CHANNEL_LSM_EASF07, Units.WATT_HOUR), + EASF08(ValueType.INTEGER, CHANNEL_LSM_EASF08, Units.WATT_HOUR), + EASF09(ValueType.INTEGER, CHANNEL_LSM_EASF09, Units.WATT_HOUR), + EASF10(ValueType.INTEGER, CHANNEL_LSM_EASF10, Units.WATT_HOUR), + EASD01(ValueType.INTEGER, CHANNEL_LSM_EASD01, Units.WATT_HOUR), + EASD02(ValueType.INTEGER, CHANNEL_LSM_EASD02, Units.WATT_HOUR), + EASD03(ValueType.INTEGER, CHANNEL_LSM_EASD03, Units.WATT_HOUR), + EASD04(ValueType.INTEGER, CHANNEL_LSM_EASD04, Units.WATT_HOUR), + EAIT(ValueType.INTEGER, CHANNEL_LSM_EAIT, Units.WATT_HOUR), + ERQ1(ValueType.INTEGER, CHANNEL_LSM_ERQ1, Units.VOLT_AMPERE_HOUR), + ERQ2(ValueType.INTEGER, CHANNEL_LSM_ERQ2, Units.VOLT_AMPERE_HOUR), + ERQ3(ValueType.INTEGER, CHANNEL_LSM_ERQ3, Units.VOLT_AMPERE_HOUR), + ERQ4(ValueType.INTEGER, CHANNEL_LSM_ERQ4, Units.VOLT_AMPERE_HOUR), + IRMS1(ValueType.INTEGER, CHANNEL_LSM_IRMS1, Units.AMPERE), + IRMS2(ValueType.INTEGER, CHANNEL_LSM_IRMS2, Units.AMPERE), + IRMS3(ValueType.INTEGER, CHANNEL_LSM_IRMS3, Units.AMPERE), + URMS1(ValueType.INTEGER, CHANNEL_LSM_URMS1, Units.VOLT), + URMS2(ValueType.INTEGER, CHANNEL_LSM_URMS2, Units.VOLT), + URMS3(ValueType.INTEGER, CHANNEL_LSM_URMS3, Units.VOLT), + PREF(ValueType.INTEGER, CHANNEL_LSM_PREF, Units.VOLT_AMPERE, 1000), + PCOUP(ValueType.INTEGER, CHANNEL_LSM_PCOUP, Units.VOLT_AMPERE, 1000), + SINSTS(ValueType.INTEGER, CHANNEL_LSM_SINSTS, Units.VOLT_AMPERE), + SINSTS1(ValueType.INTEGER, CHANNEL_LSM_SINSTS1, Units.VOLT_AMPERE), + SINSTS2(ValueType.INTEGER, CHANNEL_LSM_SINSTS2, Units.VOLT_AMPERE), + SINSTS3(ValueType.INTEGER, CHANNEL_LSM_SINSTS3, Units.VOLT_AMPERE), + SMAXSN(ValueType.INTEGER, CHANNEL_LSM_SMAXSN, Units.VOLT_AMPERE), + SMAXSN1(ValueType.INTEGER, CHANNEL_LSM_SMAXSN1, Units.VOLT_AMPERE), + SMAXSN2(ValueType.INTEGER, CHANNEL_LSM_SMAXSN2, Units.VOLT_AMPERE), + SMAXSN3(ValueType.INTEGER, CHANNEL_LSM_SMAXSN3, Units.VOLT_AMPERE), + SMAXSN_MINUS_1(ValueType.INTEGER, CHANNEL_LSM_SMAXSN_MINUS_1, Units.VOLT_AMPERE), + SMAXSN1_MINUS_1(ValueType.INTEGER, CHANNEL_LSM_SMAXSN1_MINUS_1, Units.VOLT_AMPERE), + SMAXSN2_MINUS_1(ValueType.INTEGER, CHANNEL_LSM_SMAXSN2_MINUS_1, Units.VOLT_AMPERE), + SMAXSN3_MINUS_1(ValueType.INTEGER, CHANNEL_LSM_SMAXSN3_MINUS_1, Units.VOLT_AMPERE), + SINSTI(ValueType.INTEGER, CHANNEL_LSM_SINSTI, Units.VOLT_AMPERE), + SMAXIN(ValueType.INTEGER, CHANNEL_LSM_SMAXIN, Units.VOLT_AMPERE), + SMAXIN_MINUS_1(ValueType.INTEGER, CHANNEL_LSM_SMAXIN_MINUS_1, Units.VOLT_AMPERE), + CCASN(ValueType.INTEGER, CHANNEL_LSM_CCASN, Units.WATT), + CCASN_MINUS_1(ValueType.INTEGER, CHANNEL_LSM_CCASN_MINUS_1, Units.WATT), + CCAIN(ValueType.INTEGER, CHANNEL_LSM_CCAIN, Units.WATT), + CCAIN_MINUS_1(ValueType.INTEGER, CHANNEL_LSM_CCAIN_MINUS_1, Units.WATT), + UMOY1(ValueType.INTEGER, CHANNEL_LSM_UMOY1, Units.VOLT), + UMOY2(ValueType.INTEGER, CHANNEL_LSM_UMOY2, Units.VOLT), + UMOY3(ValueType.INTEGER, CHANNEL_LSM_UMOY3, Units.VOLT), + STGE(ValueType.STRING, CHANNEL_LSM_STGE, Units.ONE), + DPM1(ValueType.STRING, CHANNEL_LSM_DPM1, Units.ONE), + FPM1(ValueType.STRING, CHANNEL_LSM_FPM1, Units.ONE), + DPM2(ValueType.STRING, CHANNEL_LSM_DPM2, Units.ONE), + FPM2(ValueType.STRING, CHANNEL_LSM_FPM2, Units.ONE), + DPM3(ValueType.STRING, CHANNEL_LSM_DPM3, Units.ONE), + FPM3(ValueType.STRING, CHANNEL_LSM_FPM3, Units.ONE), + MSG1(ValueType.STRING, CHANNEL_LSM_MSG1, Units.ONE), + MSG2(ValueType.STRING, CHANNEL_LSM_MSG2, Units.ONE), + PRM(ValueType.STRING, CHANNEL_LSM_PRM, Units.ONE), + RELAIS(ValueType.STRING, CHANNEL_LSM_RELAIS, Units.ONE), + NTARF(ValueType.STRING, CHANNEL_LSM_NTARF, Units.ONE), + NJOURF(ValueType.STRING, CHANNEL_LSM_NJOURF, Units.ONE), + NJOURF_PLUS_1(ValueType.STRING, CHANNEL_LSM_NJOURF_PLUS_1, Units.ONE), + PJOURF_PLUS_1(ValueType.STRING, CHANNEL_LSM_PJOURF_PLUS_1, Units.ONE), + PPOINTE(ValueType.STRING, CHANNEL_LSM_PPOINTE, Units.ONE); - private ValueType type; - private String channelName; - private Unit unit; + private final ValueType type; + private final String channelName; + private final Unit unit; + private final int factor; Label(ValueType type, String channelName, Unit unit) { + this(type, channelName, unit, 1); + } + + Label(ValueType type, String channelName, Unit unit, int factor) { this.type = type; this.channelName = channelName; this.unit = unit; + this.factor = factor; } public ValueType getType() { @@ -88,4 +163,14 @@ public String getChannelName() { public Unit getUnit() { return unit; } + + public int getFactor() { + return factor; + } + + public static Label getEnum(String label) { + String modifiedLabel = label.replace("-", "_MINUS_"); + modifiedLabel = modifiedLabel.replace("+", "_PLUS_"); + return valueOf(modifiedLabel); + } } diff --git a/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/config/config-description.xml b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/config/config-description.xml index 517e1a8b1205b..d3af4bca2e5f9 100644 --- a/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/config/config-description.xml +++ b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/config/config-description.xml @@ -7,7 +7,7 @@ - + Electricity meter identifier (format: 12 characters / e.g: '031528042289') false diff --git a/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/common-lsm-channel-types.xml b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/common-lsm-channel-types.xml new file mode 100644 index 0000000000000..c950e661dae18 --- /dev/null +++ b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/common-lsm-channel-types.xml @@ -0,0 +1,351 @@ + + + + + String + + Provider schedule name + Energy + + + + + String + + Current pricing label + Energy + + + + + Number:Energy + + Total active energy withdrawn + Energy + + + + + Number:Energy + + Active energy withdrawn from provider on index 01 + Energy + + + + + Number:Energy + + Active energy withdrawn from provider on index 02 + Energy + + + + + Number:Energy + + Active energy withdrawn from provider on index 03 + Energy + + + + + Number:Energy + + Active energy withdrawn from provider on index 04 + Energy + + + + + Number:Energy + + Active energy withdrawn from provider on index 05 + Energy + + + + + Number:Energy + + Active energy withdrawn from provider on index 06 + Energy + + + + + Number:Energy + + Active energy withdrawn from provider on index 07 + Energy + + + + + Number:Energy + + Active energy withdrawn from provider on index 08 + Energy + + + + + Number:Energy + + Active energy withdrawn from provider on index 09 + Energy + + + + + Number:Energy + + Active energy withdrawn from provider on index 10 + Energy + + + + + Number:Energy + + Active energy withdrawn from distributor on index 01 + Energy + + + + + Number:Energy + + Active energy withdrawn from distributor on index 02 + Energy + + + + + Number:Energy + + Active energy withdrawn from distributor on index 03 + Energy + + + + + Number:Energy + + Active energy withdrawn from distributor on index 04 + Energy + + + + + Number:ElectricCurrent + + RMS Current on phase 1 + Energy + + + + + Number:ElectricPotential + + RMS Voltage on phase 1 + Energy + + + + + Number:Power + + Reference apparent power + Energy + + + + + Number:Power + + Apparent power rupture capacity + Energy + + + + + Number:Power + + Instantaneous withdrawn apparent power + Energy + + + + + Number:Power + + Maximum withdrawn apparent power of the day + Energy + + + + + Number:Power + + Maximum withdrawn apparent power of the previous day + Energy + + + + + Number:Power + + Active charge point N + Energy + + + + + Number:Power + + Active charge point N-1 + Energy + + + + + Number:ElectricPotential + + Mean Voltage on phase 1 + Energy + + + + + String + + Status registry + Energy + + + + + String + + Start of mobile peak period 1 + Energy + + + + + String + + End of mobile peak period 1 + Energy + + + + + String + + Start of mobile peak period 2 + Energy + + + + + String + + End of mobile peak period 2 + Energy + + + + + String + + Start of mobile peak period 3 + Energy + + + + + String + + End of mobile peak period 3 + Energy + + + + + String + + Short message + Energy + + + + + String + + Very short message + Energy + + + + + String + + PRM + Energy + + + + + String + + Relays + Energy + + + + + String + + Index of current pricing + Energy + + + + + String + + Number of current provider schedule + Energy + + + + + String + + Number of next day provider schedule + Energy + + + + + String + + Profile of next day provider schedule + Energy + + + + + String + + Profile of next rush day + Energy + + + + diff --git a/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/common-lsm-prod-channel-types.xml b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/common-lsm-prod-channel-types.xml new file mode 100644 index 0000000000000..64891cfa2800f --- /dev/null +++ b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/common-lsm-prod-channel-types.xml @@ -0,0 +1,87 @@ + + + + + Number:Energy + + Total active energy injected + Energy + + + + + Number:Energy + + Total reactive energy Q1 + Energy + + + + + Number:Energy + + Total reactive energy Q2 + Energy + + + + + Number:Energy + + Total reactive energy Q3 + Energy + + + + + Number:Energy + + Total reactive energy Q4 + Energy + + + + + Number:Power + + Instantaneous injected apparent power + Energy + + + + + Number:Power + + Maximum injected apparent power of the day + Energy + + + + + Number:Power + + Maximum injected apparent power of the previous day + Energy + + + + + Number:Power + + Injected active charge point N + Energy + + + + + Number:Power + + Injected active charge point N-1 + Energy + + + + diff --git a/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/common-lsm-three-phase-channel-types.xml b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/common-lsm-three-phase-channel-types.xml new file mode 100644 index 0000000000000..7e5dc4fca3cf2 --- /dev/null +++ b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/common-lsm-three-phase-channel-types.xml @@ -0,0 +1,127 @@ + + + + + Number:ElectricCurrent + + RMS Current on phase 2 + Energy + + + + + Number:ElectricCurrent + + RMS Current on phase 3 + Energy + + + + + Number:ElectricPotential + + RMS Voltage on phase 2 + Energy + + + + + Number:ElectricPotential + + RMS Voltage on phase 3 + Energy + + + + + Number:Power + + Instantaneous withdrawn apparent power on phase 1 + Energy + + + + + Number:Power + + Instantaneous withdrawn apparent power on phase 2 + Energy + + + + + Number:Power + + Instantaneous withdrawn apparent power on phase 3 + Energy + + + + + Number:Power + + Maximum withdrawn apparent power of the day on phase 1 + Energy + + + + + Number:Power + + Maximum withdrawn apparent power of the day on phase 2 + Energy + + + + + Number:Power + + Maximum withdrawn apparent power of the day on phase 3 + Energy + + + + + Number:Power + + Maximum withdrawn apparent power of the previous day on phase 1 + Energy + + + + + Number:Power + + Maximum withdrawn apparent power of the previous day on phase 2 + Energy + + + + + Number:Power + + Maximum withdrawn apparent power of the previous day on phase 3 + Energy + + + + + Number:ElectricPotential + + Mean Voltage on phase 2 + Energy + + + + + Number:ElectricPotential + + Mean Voltage on phase 3 + Energy + + + + diff --git a/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmmElectricityMeter.xml b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmmElectricityMeter.xml new file mode 100644 index 0000000000000..e28ed2a0d38db --- /dev/null +++ b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmmElectricityMeter.xml @@ -0,0 +1,65 @@ + + + + + + + + + + Single-phase Linky Electricity meter in standard mode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmmProdElectricityMeter.xml b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmmProdElectricityMeter.xml new file mode 100644 index 0000000000000..6e59657dafdfd --- /dev/null +++ b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmmProdElectricityMeter.xml @@ -0,0 +1,76 @@ + + + + + + + + + + Single-phase producer Linky Electricity meter in standard mode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmtElectricityMeter.xml b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmtElectricityMeter.xml new file mode 100644 index 0000000000000..59f56c499b4ed --- /dev/null +++ b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmtElectricityMeter.xml @@ -0,0 +1,81 @@ + + + + + + + + + + Three-phase Linky Electricity meter in standard mode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmtProdElectricityMeter.xml b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmtProdElectricityMeter.xml new file mode 100644 index 0000000000000..66b7842404510 --- /dev/null +++ b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/lsmtProdElectricityMeter.xml @@ -0,0 +1,92 @@ + + + + + + + + + + Three-phase producer Linky Electricity meter in standard mode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/serialController.xml b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/serialController.xml index 53bbc6324db07..fad104e2a9929 100644 --- a/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/serialController.xml +++ b/bundles/org.openhab.binding.teleinfo/src/main/resources/OH-INF/thing/serialController.xml @@ -22,10 +22,10 @@ TIC Mode of the telemeter (Standard TIC mode is only available on Linky telemeters) - Historical + HISTORICAL - - + + true diff --git a/bundles/org.openhab.binding.teleinfo/src/test/java/org/openhab/binding/teleinfo/internal/reader/io/TeleinfoInputStreamTest.java b/bundles/org.openhab.binding.teleinfo/src/test/java/org/openhab/binding/teleinfo/internal/reader/io/TeleinfoInputStreamTest.java index fe761fe0ac15a..1a4008f024270 100644 --- a/bundles/org.openhab.binding.teleinfo/src/test/java/org/openhab/binding/teleinfo/internal/reader/io/TeleinfoInputStreamTest.java +++ b/bundles/org.openhab.binding.teleinfo/src/test/java/org/openhab/binding/teleinfo/internal/reader/io/TeleinfoInputStreamTest.java @@ -23,6 +23,7 @@ import org.openhab.binding.teleinfo.internal.reader.io.serialport.Label; import org.openhab.binding.teleinfo.internal.serial.TeleinfoTicMode; import org.openhab.binding.teleinfo.util.TestUtils; +import org.openhab.core.library.types.QuantityType; /** * @@ -168,40 +169,41 @@ public void testInvalidADPSgrouplineWithAutoRepairActivated() throws Exception { } @Test - public void testReadNextFrameLinkyTICModeStandard() throws Exception { + public void testReadNextFrameLinkyTICModeStandardThreePhaseProd() throws Exception { try (TeleinfoInputStream in = new TeleinfoInputStream( - new FileInputStream(TestUtils.getTestFile("linky-tic-mode-standard.raw")), false, + new FileInputStream(TestUtils.getTestFile("linky-tic-mode-standard-three-phase-prod.raw")), false, TeleinfoTicMode.STANDARD, true)) { Frame frame = in.readNextFrame(); assertNotNull(frame); - assertEquals(FrameType.CBEMM_ICC_BASE, frame.getType()); - assertEquals("031762120162", frame.get(Label.ADCO)); - assertEquals(30, frame.getAsInt(Label.ISOUSC)); - assertEquals(190575, frame.getAsInt(Label.BASE)); - assertEquals("TH..", frame.get(Label.PTEC)); - assertEquals(1, frame.getAsInt(Label.IINST)); - assertEquals(90, frame.getAsInt(Label.IMAX)); - assertEquals(270, frame.getAsInt(Label.PAPP)); - assertNull(frame.get(Label.ADPS)); + assertEquals(FrameType.LSMT_PROD, frame.getType()); + assertEquals("123456789012", frame.get(Label.ADSC)); + assertEquals("02", frame.get(Label.VTIC)); + assertEquals("", frame.get(Label.DATE)); + assertEquals(" TEMPO ", frame.get(Label.NGTF)); + assertEquals(" HP BLEU ", frame.get(Label.LTARF)); + assertEquals(11604109, frame.getAsInt(Label.EAST)); + assertEquals(2741488, frame.getAsInt(Label.EASF01)); + assertEquals(18, frame.getAsInt(Label.PCOUP)); + QuantityType quantity = QuantityType.valueOf(frame.getAsInt(Label.PCOUP), Label.PCOUP.getUnit()); } } @Test - public void testReadNextFrameLinkyTICModeStandardProd() throws Exception { + public void testReadNextFrameLinkyTICModeStandardSinglePhaseProd() throws Exception { try (TeleinfoInputStream in = new TeleinfoInputStream( - new FileInputStream(TestUtils.getTestFile("linky-tic-mode-standard-prod.raw")), + new FileInputStream(TestUtils.getTestFile("linky-tic-mode-standard-single-phase-prod.raw")), TeleinfoTicMode.STANDARD, true)) { Frame frame = in.readNextFrame(); assertNotNull(frame); - assertEquals(FrameType.CBEMM_ICC_BASE, frame.getType()); - assertEquals("031762120162", frame.get(Label.ADCO)); - assertEquals(30, frame.getAsInt(Label.ISOUSC)); - assertEquals(190575, frame.getAsInt(Label.BASE)); - assertEquals("TH..", frame.get(Label.PTEC)); - assertEquals(1, frame.getAsInt(Label.IINST)); - assertEquals(90, frame.getAsInt(Label.IMAX)); - assertEquals(270, frame.getAsInt(Label.PAPP)); - assertNull(frame.get(Label.ADPS)); + assertEquals(FrameType.LSMM_PROD, frame.getType()); + assertEquals("123456789012", frame.get(Label.ADSC)); + assertEquals("02", frame.get(Label.VTIC)); + assertEquals("", frame.get(Label.DATE)); + assertEquals("PRODUCTEUR", frame.get(Label.NGTF)); + assertEquals("INDEX NON CONSO ", frame.get(Label.LTARF)); + assertEquals(0, frame.getAsInt(Label.EAST)); + assertEquals(0, frame.getAsInt(Label.EASF01)); + assertEquals(32781, frame.getAsInt(Label.EAIT)); } } } diff --git a/bundles/org.openhab.binding.teleinfo/src/test/java/org/openhab/binding/teleinfo/internal/reader/io/serialport/FrameUtilTest.java b/bundles/org.openhab.binding.teleinfo/src/test/java/org/openhab/binding/teleinfo/internal/reader/io/serialport/FrameUtilTest.java new file mode 100644 index 0000000000000..c47e71248e383 --- /dev/null +++ b/bundles/org.openhab.binding.teleinfo/src/test/java/org/openhab/binding/teleinfo/internal/reader/io/serialport/FrameUtilTest.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.teleinfo.internal.reader.io.serialport; + +import static org.junit.jupiter.api.Assertions.*; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +import org.junit.jupiter.api.Test; +import org.openhab.binding.teleinfo.internal.reader.io.TeleinfoInputStream; +import org.openhab.binding.teleinfo.internal.serial.TeleinfoTicMode; +import org.openhab.binding.teleinfo.util.TestUtils; + +/** + * + * @author Olivier MARCEAU - Initial contribution + */ +public class FrameUtilTest { + + @Test + public void testComputeGroupLineChecksumThreePhaseProd() throws Exception { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader( + new FileInputStream(TestUtils.getTestFile("linky-tic-mode-standard-three-phase-prod.raw")))); + String groupLine; + int i = 0; + while ((groupLine = bufferedReader.readLine()) != null) { + if (i >= 1 && !TeleinfoInputStream.isHeaderFrame(groupLine)) { + char expected = groupLine.charAt(groupLine.length() - 1); + char actual = FrameUtil.computeGroupLineChecksum(groupLine.substring(0, groupLine.length() - 2), + TeleinfoTicMode.STANDARD); + assertEquals(expected, actual, i + " " + groupLine + " " + (int) expected + " " + (int) actual); + } + i++; + } + } + + @Test + public void testComputeGroupLineChecksumSinglePhaseProd() throws Exception { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader( + new FileInputStream(TestUtils.getTestFile("linky-tic-mode-standard-single-phase-prod.raw")))); + String groupLine; + int i = 0; + while ((groupLine = bufferedReader.readLine()) != null) { + if (i >= 1 && !TeleinfoInputStream.isHeaderFrame(groupLine)) { + char expected = groupLine.charAt(groupLine.length() - 1); + char actual = FrameUtil.computeGroupLineChecksum(groupLine.substring(0, groupLine.length() - 2), + TeleinfoTicMode.STANDARD); + assertEquals(expected, actual, i + " " + groupLine + " " + (int) expected + " " + (int) actual); + } + i++; + } + } +} diff --git a/bundles/org.openhab.binding.teleinfo/src/test/resources/linky-tic-mode-standard-single-phase-prod.raw b/bundles/org.openhab.binding.teleinfo/src/test/resources/linky-tic-mode-standard-single-phase-prod.raw new file mode 100644 index 0000000000000..f1057181c7905 --- /dev/null +++ b/bundles/org.openhab.binding.teleinfo/src/test/resources/linky-tic-mode-standard-single-phase-prod.raw @@ -0,0 +1,70 @@ +EP*PREF 03 B +PCOUP 03 \ +SINSTS 00000 F +SMAXSN E180716063417 00021 9 +SMAXSN-1 E180715064903 00023 Y +SINSTI 01258 L +SMAXIN E180716103316 01423 / +SMAXIN-1 E180715144229 01971 \ +CCASN E180716100000 00000 0 +CCASN-1 E180716090000 00000 V +UMOY1 E180716103000 230 + +STGE 002A0301 < +MSG1 PAS DE MESSAGE < +PRM 12345678901234 8 +RELAIS 000 B +NTARF 01 N +NJOURF 00 & +NJOURF+1 00 B +PJOURF+1 00008001 NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE 9 + +ADSC 123456789012 = +VTIC 02 J +DATE E180716103423 B +NGTF PRODUCTEUR . +LTARF INDEX NON CONSO 0 +EAST 000000000 O +EASF01 000000000 " +EASF02 000000000 # +EASF03 000000000 $ +EASF04 000000000 % +EASF05 000000000 & +EASF06 000000000 ' +EASF07 000000000 ( +EASF08 000000000 ) +EASF09 000000000 * +EASF10 000000000 " +EASD01 000000000 +EASD02 000000000 ! +EASD03 000000000 " +EASD04 000000000 # +EAIT 000032781 Z +ERQ1 000000000 ; +ERQ2 000000890 M +ERQ3 000002546 N +ERQ4 000000000 > +IRMS1 005 3 +URMS1 228 F +PREF 03 B +PCOUP 03 \ +SINSTS 00000 F +SMAXSN E180716063417 00021 9 +SMAXSN-1 E180715064903 00023 Y +SINSTI 01253 G +SMAXIN E180716103316 01423 / +SMAXIN-1 E180715144229 01971 \ +CCASN E180716100000 00000 0 +CCASN-1 E180716090000 00000 V +UMOY1 E180716103000 230 + +STGE 002A0301 < +MSG1 PAS DE MESSAGE < +PRM 12345678901234 8 +RELAIS 000 B +NTARF 01 N +NJOURF 00 & +NJOURF+1 00 B +PJOURF+1 00008001 NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE 9 + +ADSC 123456789012 = +VTIC 02 J +DATE E180716103424 C diff --git a/bundles/org.openhab.binding.teleinfo/src/test/resources/linky-tic-mode-standard-three-phase-prod.raw b/bundles/org.openhab.binding.teleinfo/src/test/resources/linky-tic-mode-standard-three-phase-prod.raw new file mode 100644 index 0000000000000..dc0225ac94057 --- /dev/null +++ b/bundles/org.openhab.binding.teleinfo/src/test/resources/linky-tic-mode-standard-three-phase-prod.raw @@ -0,0 +1,171 @@ +774332 X +IRMS1 001 / +IRMS2 002 1 +IRMS3 001 1 +URMS1 234 C +URMS2 240 A +URMS3 242 D +PREF 18 H +PCOUP 18 " +SINSTS 00046 P +SINSTS1 00000 7 +SINSTS2 00531 A +SINSTS3 00000 9 +SMAXSN E210414070239 02636 < +SMAXSN1 E210414060632 00405 ! +SMAXSN2 E210414070239 02194 - +SMAXSN3 E210414054725 00565 0 +SMAXSN-1 E210413195606 06560 _ +SMAXSN1-1 E210413111148 01084 A +SMAXSN2-1 E210413195606 03275 Q +SMAXSN3-1 E210413195814 02904 Q +SINSTI 00000 < +SMAXIN E210414000000 00000 L +SMAXIN-1 E210413141848 03861 U +CCASN E210414080000 00806 : +CCASN-1 E210414073000 01152 U +CCAIN E210414080000 00000 " +CCAIN-1 E210414073000 00000 B +UMOY1 E210414082000 230 & +UMOY2 E210414082000 239 0 +UMOY3 E210414082000 243 , +STGE 013A0501 @ +MSG1 PAS DE MESSAGE < +PRM 12345678901234 8 +RELAIS 000 B +NTARF 02 O +NJOURF 00 & +NJOURF+1 00 B +PJOURF+1 00004001 06004002 22004001 NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE . + +ADSC 123456789012 = +VTIC 02 J +DATE E210414082625 A +NGTF TEMPO F +LTARF HP BLEU + +EAST 011604109 % +EASF01 002741488 D +EASF02 005905500 ; +EASF03 000624053 8 +EASF04 001070566 > +EASF05 000524151 8 +EASF06 000738351 B +EASF07 000000000 ( +EASF08 000000000 ) +EASF09 000000000 * +EASF10 000000000 " +EASD01 011604109 6 +EASD02 000000000 ! +EASD03 000000000 " +EASD04 000000000 # +EAIT 000671631 ] +ERQ1 002970842 [ +ERQ2 000204084 N +ERQ3 000084948 ^ +ERQ4 000774332 X +IRMS1 001 / +IRMS2 002 1 +IRMS3 001 1 +URMS1 234 C +URMS2 240 A +URMS3 242 D +PREF 18 H +PCOUP 18 " +SINSTS 00013 J +SINSTS1 00000 7 +SINSTS2 00568 K +SINSTS3 00000 9 +SMAXSN E210414070239 02636 < +SMAXSN1 E210414060632 00405 ! +SMAXSN2 E210414070239 02194 - +SMAXSN3 E210414054725 00565 0 +SMAXSN-1 E210413195606 06560 _ +SMAXSN1-1 E210413111148 01084 A +SMAXSN2-1 E210413195606 03275 Q +SMAXSN3-1 E210413195814 02904 Q +SINSTI 00000 < +SMAXIN E210414000000 00000 L +SMAXIN-1 E210413141848 03861 U +CCASN E210414080000 00806 : +CCASN-1 E210414073000 01152 U +CCAIN E210414080000 00000 " +CCAIN-1 E210414073000 00000 B +UMOY1 E210414082000 230 & +UMOY2 E210414082000 239 0 +UMOY3 E210414082000 243 , +STGE 013A0501 @ +MSG1 PAS DE MESSAGE < +PRM 12345678901234 8 +RELAIS 000 B +NTARF 02 O +NJOURF 00 & +NJOURF+1 00 B +PJOURF+1 00004001 06004002 22004001 NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE . + +ADSC 123456789012 = +VTIC 02 J +DATE E210414082627 C +NGTF TEMPO F +LTARF HP BLEU + +EAST 011604109 % +EASF01 002741488 D +EASF02 005905500 ; +EASF03 000624053 8 +EASF04 001070566 > +EASF05 000524151 8 +EASF06 000738351 B +EASF07 000000000 ( +EASF08 000000000 ) +EASF09 000000000 * +EASF10 000000000 " +EASD01 011604109 6 +EASD02 000000000 ! +EASD03 000000000 " +EASD04 000000000 # +EAIT 000671631 ] +ERQ1 002970842 [ +ERQ2 000204084 N +ERQ3 000084948 ^ +ERQ4 000774332 X +IRMS1 001 / +IRMS2 002 1 +IRMS3 001 1 +URMS1 234 C +URMS2 240 A +URMS3 242 D +PREF 18 H +PCOUP 18 " +SINSTS 00018 O +SINSTS1 00000 7 +SINSTS2 00565 H +SINSTS3 00000 9 +SMAXSN E210414070239 02636 < +SMAXSN1 E210414060632 00405 ! +SMAXSN2 E210414070239 02194 - +SMAXSN3 E210414054725 00565 0 +SMAXSN-1 E210413195606 06560 _ +SMAXSN1-1 E210413111148 01084 A +SMAXSN2-1 E210413195606 03275 Q +SMAXSN3-1 E210413195814 02904 Q +SINSTI 00000 < +SMAXIN E210414000000 00000 L +SMAXIN-1 E210413141848 03861 U +CCASN E210414080000 00806 : +CCASN-1 E210414073000 01152 U +CCAIN E210414080000 00000 " +CCAIN-1 E210414073000 00000 B +UMOY1 E210414082000 230 & +UMOY2 E210414082000 239 0 +UMOY3 E210414082000 243 , +STGE 013A0501 @ +MSG1 PAS DE MESSAGE < +PRM 12345678901234 8 +RELAIS 000 B +NTARF 02 O +NJOURF 00 & +NJOURF+1 00 B +PJOURF+1 00004001 06004002 22004001 NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE NONUTILE . + +ADSC 123456789012 = +VTIC 02 J +DATE E210414082629 E \ No newline at end of file