[teleinfo] code cleanup and remove timeout (#9902)

* Remove timeout when waiting frame

Signed-off-by: Olivier Marceau <hollysaiqs@marceau.ovh>

* Add olivierkeke to code owners list

Signed-off-by: Olivier Marceau <hollysaiqs@marceau.ovh>

* Code cleanup

Signed-off-by: Olivier Marceau <hollysaiqs@marceau.ovh>

* Refactor data objects

Signed-off-by: Olivier Marceau <hollysaiqs@marceau.ovh>

* Apply some sonarlint suggestions

Signed-off-by: Olivier Marceau <hollysaiqs@marceau.ovh>

* Fix typo

Signed-off-by: Olivier Marceau <hollysaiqs@marceau.ovh>

* Simplify thing compatibility test

Co-authored-by: Connor Petty <mistercpp2000@gmail.com>
Signed-off-by: Olivier Marceau <hollysaiqs@marceau.ovh>

* Remove dot from PTEC values

Signed-off-by: Olivier Marceau <hollysaiqs@marceau.ovh>

Co-authored-by: Connor Petty <mistercpp2000@gmail.com>
This commit is contained in:
olivierkeke 2021-04-10 22:36:06 +02:00 committed by GitHub
parent b675160486
commit 217f25fff6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
66 changed files with 618 additions and 3630 deletions

View File

@ -267,7 +267,7 @@
/bundles/org.openhab.binding.tado/ @dfrommi
/bundles/org.openhab.binding.tankerkoenig/ @dolic @JueBag
/bundles/org.openhab.binding.telegram/ @ZzetT
/bundles/org.openhab.binding.teleinfo/ @Nokyyz
/bundles/org.openhab.binding.teleinfo/ @Nokyyz @olivierkeke
/bundles/org.openhab.binding.tellstick/ @openhab/add-ons-maintainers
/bundles/org.openhab.binding.tesla/ @kgoderis
/bundles/org.openhab.binding.tibber/ @kjoglum

View File

@ -24,6 +24,9 @@ import org.openhab.core.thing.ThingTypeUID;
@NonNullByDefault
public class TeleinfoBindingConstants {
private TeleinfoBindingConstants() {
}
private static final String BINDING_ID = "teleinfo";
// List of all Thing Type UIDs
@ -35,7 +38,7 @@ public class TeleinfoBindingConstants {
// List of HC frames channel ids
public static final String CHANNEL_HC_FRAME_HCHC = "hchc";
public static final String CHANNEL_HC_FRAME_HCHP = "hchp";
public static final String CHANNEL_HC_FRAME_HHPHC = "hhphc";
public static final String CHANNEL_HHPHC = "hhphc";
// List of BASE frames channel ids
public static final String CHANNEL_BASE_FRAME_BASE = "base";
// List of TEMPO frames channel ids
@ -46,7 +49,6 @@ public class TeleinfoBindingConstants {
public static final String CHANNEL_TEMPO_FRAME_BBRHPJB = "bbrhpjb";
public static final String CHANNEL_TEMPO_FRAME_BBRHCJB = "bbrhcjb";
public static final String CHANNEL_TEMPO_FRAME_DEMAIN = "demain";
public static final String CHANNEL_TEMPO_FRAME_HHPHC = "hhphc";
public static final String CHANNEL_TEMPO_FRAME_PROGRAMME_CIRCUIT_1 = "programmeCircuit1";
public static final String CHANNEL_TEMPO_FRAME_PROGRAMME_CIRCUIT_2 = "programmeCircuit2";
// List of EJP frames channel ids
@ -54,32 +56,30 @@ public class TeleinfoBindingConstants {
public static final String CHANNEL_EJP_FRAME_EJPHPM = "ejphpm";
public static final String CHANNEL_EJP_FRAME_EJPHN = "ejphn";
// List of CBEMM Channel ids
public static final String CHANNEL_CBEMM_ISOUSC = "isousc";
public static final String CHANNEL_CBEMM_PTEC = "ptec";
public static final String CHANNEL_ISOUSC = "isousc";
public static final String CHANNEL_PTEC = "ptec";
public static final String CHANNEL_CBEMM_IMAX = "imax";
public static final String CHANNEL_CBEMM_ADPS = "adps";
public static final String CHANNEL_CBEMM_IINST = "iinst";
public static final String CHANNEL_CBEMM_MOTDETAT = "motdetat";
public static final String CHANNEL_MOTDETAT = "motdetat";
// List of CBEMM EVOLUTION ICC Channel ids
public static final String CHANNEL_CBEMM_EVOLUTION_ICC_PAPP = "papp";
public static final String CHANNEL_PAPP = "papp";
// List of CBETM Channel ids
public static final String CHANNEL_CBETM_IINST1 = "iinst1";
public static final String CHANNEL_CBETM_IINST2 = "iinst2";
public static final String CHANNEL_CBETM_IINST3 = "iinst3";
public static final String CHANNEL_CBETM_FRAME_TYPE = "frameType";
public static final String CHANNEL_CBETM_LONG_ISOUSC = "isousc";
public static final String CHANNEL_CBETM_LONG_IMAX1 = "imax1";
public static final String CHANNEL_CBETM_LONG_IMAX2 = "imax2";
public static final String CHANNEL_CBETM_LONG_IMAX3 = "imax3";
public static final String CHANNEL_CBETM_LONG_PTEC = "ptec";
public static final String CHANNEL_CBETM_LONG_PMAX = "pmax";
public static final String CHANNEL_CBETM_LONG_PAPP = "papp";
public static final String CHANNEL_CBETM_LONG_MOTDETAT = "motdetat";
public static final String CHANNEL_CBETM_LONG_PPOT = "ppot";
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";
public static final String NOT_A_CHANNEL = "";
public static final String THING_ELECTRICITY_METER_PROPERTY_ADCO = "adco";
public static final ThingTypeUID THING_HC_CBEMM_ELECTRICITY_METER_TYPE_UID = new ThingTypeUID(BINDING_ID,

View File

@ -22,22 +22,11 @@ import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemmBaseOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemmEjpOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemmHcOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemmTempoOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccBaseOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccEjpOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccHcOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccTempoOption;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongBaseOption;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongEjpOption;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongHcOption;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongTempoOption;
import org.openhab.binding.teleinfo.internal.dto.common.FrameAdco;
import org.openhab.binding.teleinfo.internal.data.Frame;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoControllerHandlerListener;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.InvalidFrameException;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.Label;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
@ -85,6 +74,7 @@ public class TeleinfoDiscoveryService extends AbstractDiscoveryService
return SUPPORTED_THING_TYPES;
}
@Override
public void activate() {
TeleinfoAbstractControllerHandler controllerHandlerRef = controllerHandler;
if (controllerHandlerRef != null) {
@ -142,75 +132,56 @@ public class TeleinfoDiscoveryService extends AbstractDiscoveryService
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
public void onFrameReceived(Frame frame) {
detectNewElectricityMeterFromReceivedFrame(frame);
}
private void detectNewElectricityMeterFromReceivedFrame(final Frame frameSample) {
TeleinfoAbstractControllerHandler controllerHandlerRef = controllerHandler;
if (controllerHandlerRef != null) {
logger.debug("New eletricity meter detection from frame {}", frameSample.getId());
if (!(frameSample instanceof FrameAdco)) {
throw new IllegalStateException("Teleinfo frame type not supported: " + frameSample.getClass());
logger.debug("New eletricity meter detection from frame {}", frameSample);
if (frameSample.get(Label.ADCO) == null) {
throw new IllegalStateException("Missing ADCO key");
}
final FrameAdco frameAdco = (FrameAdco) frameSample;
ThingUID thingUID = new ThingUID(getThingTypeUID(frameAdco), frameAdco.getAdco(),
controllerHandlerRef.getThing().getUID().getId());
String adco = frameSample.get(Label.ADCO);
if (adco != null) {
ThingUID thingUID = new ThingUID(getThingTypeUID(frameSample), adco,
controllerHandlerRef.getThing().getUID().getId());
final Map<String, Object> properties = getThingProperties(frameAdco);
final String representationProperty = THING_ELECTRICITY_METER_PROPERTY_ADCO;
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties)
.withLabel("Teleinfo ADCO " + frameAdco.getAdco()).withThingType(getThingTypeUID(frameAdco))
.withBridge(controllerHandlerRef.getThing().getUID())
.withRepresentationProperty(representationProperty).build();
final Map<String, Object> 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))
.withBridge(controllerHandlerRef.getThing().getUID())
.withRepresentationProperty(representationProperty).build();
thingDiscovered(discoveryResult);
thingDiscovered(discoveryResult);
}
} else {
logNullControllerHandler();
}
}
private ThingTypeUID getThingTypeUID(final Frame teleinfoFrame) {
if (teleinfoFrame instanceof FrameCbemmHcOption) {
return THING_HC_CBEMM_ELECTRICITY_METER_TYPE_UID;
} else if (teleinfoFrame instanceof FrameCbemmBaseOption) {
return THING_BASE_CBEMM_ELECTRICITY_METER_TYPE_UID;
} else if (teleinfoFrame instanceof FrameCbemmEjpOption) {
return THING_EJP_CBEMM_ELECTRICITY_METER_TYPE_UID;
} else if (teleinfoFrame instanceof FrameCbemmTempoOption) {
return THING_TEMPO_CBEMM_ELECTRICITY_METER_TYPE_UID;
} else if (teleinfoFrame instanceof FrameCbemmEvolutionIccHcOption) {
return THING_HC_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID;
} else if (teleinfoFrame instanceof FrameCbemmEvolutionIccBaseOption) {
return THING_BASE_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID;
} else if (teleinfoFrame instanceof FrameCbemmEvolutionIccEjpOption) {
return THING_EJP_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID;
} else if (teleinfoFrame instanceof FrameCbemmEvolutionIccTempoOption) {
return THING_TEMPO_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID;
} else if (teleinfoFrame instanceof FrameCbetmLongHcOption) {
return THING_HC_CBETM_ELECTRICITY_METER_TYPE_UID;
} else if (teleinfoFrame instanceof FrameCbetmLongBaseOption) {
return THING_BASE_CBETM_ELECTRICITY_METER_TYPE_UID;
} else if (teleinfoFrame instanceof FrameCbetmLongEjpOption) {
return THING_EJP_CBETM_ELECTRICITY_METER_TYPE_UID;
} else if (teleinfoFrame instanceof FrameCbetmLongTempoOption) {
return THING_TEMPO_CBETM_ELECTRICITY_METER_TYPE_UID;
ThingTypeUID thingTypeUID;
try {
thingTypeUID = teleinfoFrame.getType().getThingTypeUid();
} catch (InvalidFrameException e) {
throw new IllegalStateException("Frame type can not be evaluated");
}
if (thingTypeUID != null) {
return thingTypeUID;
} else {
throw new IllegalStateException("Teleinfo frame type not supported: " + teleinfoFrame.getClass());
}
}
private Map<String, Object> getThingProperties(final Frame teleinfoFrame) {
Map<String, Object> properties = new HashMap<String, Object>();
if (teleinfoFrame instanceof FrameAdco) {
final FrameAdco frameAdco = (FrameAdco) teleinfoFrame;
properties.put(THING_ELECTRICITY_METER_PROPERTY_ADCO, frameAdco.getAdco());
private Map<String, Object> getThingProperties(String adco) {
Map<String, Object> properties = new HashMap<>();
properties.put(THING_ELECTRICITY_METER_PROPERTY_ADCO, adco);
return properties;
}
throw new IllegalStateException("Teleinfo frame type not supported: " + teleinfoFrame.getClass());
return properties;
}
@Override

View File

@ -10,17 +10,15 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.teleinfo.internal.dto.common;
package org.openhab.binding.teleinfo.internal.data;
/**
* The {@link Hhphc} enumeration defines all HHPHC values.
* Define the evolution option values
*
* @author Olivier MARCEAU - Initial contribution
*
* @author Nicolas SIBERIL - Initial contribution
*/
public enum Hhphc {
A,
C,
D,
E,
Y
public enum Evolution {
ICC,
NONE
}

View File

@ -0,0 +1,224 @@
/**
* 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.data;
import java.io.Serializable;
import java.util.EnumMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
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;
/**
* The {@link Frame} class defines common attributes for any Teleinfo frames.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public class Frame implements Serializable {
private static final long serialVersionUID = -1934715078822532494L;
private Map<Label, String> labelToValues = new EnumMap<>(Label.class);
public void put(Label label, String value) {
labelToValues.put(label, value);
}
public @Nullable String get(Label label) {
return labelToValues.get(label);
}
public @Nullable Integer getAsInt(Label label) {
String value = labelToValues.get(label);
if (value != null) {
return Integer.parseInt(value);
}
return null;
}
public Frame() {
// default constructor
}
public FrameType getType() throws InvalidFrameException {
Phase phase = getPhase();
Pricing pricing = getPricing();
Evolution evolution = getEvolution();
switch (phase) {
case ONE_PHASED:
switch (evolution) {
case ICC:
switch (pricing) {
case BASE:
return FrameType.CBEMM_ICC_BASE;
case EJP:
return FrameType.CBEMM_ICC_EJP;
case HC:
return FrameType.CBEMM_ICC_HC;
case TEMPO:
return FrameType.CBEMM_ICC_TEMPO;
default:
return FrameType.UNKNOWN;
}
case NONE:
switch (pricing) {
case BASE:
return FrameType.CBEMM_BASE;
case EJP:
return FrameType.CBEMM_EJP;
case HC:
return FrameType.CBEMM_HC;
case TEMPO:
return FrameType.CBEMM_TEMPO;
default:
return FrameType.UNKNOWN;
}
default:
return FrameType.UNKNOWN;
}
case THREE_PHASED:
if (isShortFrame()) {
return FrameType.CBETM_SHORT;
} else {
switch (pricing) {
case BASE:
return FrameType.CBETM_LONG_BASE;
case EJP:
return FrameType.CBETM_LONG_EJP;
case HC:
return FrameType.CBETM_LONG_HC;
case TEMPO:
return FrameType.CBETM_LONG_TEMPO;
default:
return FrameType.UNKNOWN;
}
}
default:
return FrameType.UNKNOWN;
}
}
public Phase getPhase() throws InvalidFrameException {
if (labelToValues.containsKey(Label.IINST)) {
return Phase.ONE_PHASED;
} else if (labelToValues.containsKey(Label.IINST1)) {
return Phase.THREE_PHASED;
}
throw new InvalidFrameException();
}
public boolean isShortFrame() {
return !labelToValues.containsKey(Label.ISOUSC);
}
public Evolution getEvolution() {
if (labelToValues.containsKey(Label.PAPP)) {
return Evolution.ICC;
}
return Evolution.NONE;
}
public Pricing getPricing() throws InvalidFrameException {
String optarif = labelToValues.get(Label.OPTARIF);
if (optarif == null) {
throw new InvalidFrameException();
}
switch (optarif) {
case "BASE":
return Pricing.BASE;
case "EJP.":
return Pricing.EJP;
case "HC..":
return Pricing.HC;
default:
if (optarif.matches("BBR.")) {
return Pricing.TEMPO;
}
throw new InvalidFrameException();
}
}
public void clear() {
labelToValues.clear();
}
public Map<Label, String> getLabelToValues() {
return labelToValues;
}
private char getProgrammeChar() {
String optarif = labelToValues.get(Label.OPTARIF);
if (optarif == null) {
throw new IllegalStateException("No OPTARIF field in frame");
}
return optarif.charAt(3);
}
public String getProgrammeCircuit1() {
char program = getProgrammeChar();
return convertProgrammeCircuit1(program);
}
public String getProgrammeCircuit2() {
char program = getProgrammeChar();
return convertProgrammeCircuit2(program);
}
private String convertProgrammeCircuit1(char value) {
String prgCircuit1 = computeProgrammeCircuitBinaryValue(value).substring(3, 5);
switch (prgCircuit1) {
case "01":
return "A";
case "10":
return "B";
case "11":
return "C";
default:
final String error = String.format("Programme circuit 1 '%s' is unknown", prgCircuit1);
throw new IllegalStateException(error);
}
}
private String convertProgrammeCircuit2(char value) {
String prgCircuit2 = computeProgrammeCircuitBinaryValue(value).substring(5, 8);
switch (prgCircuit2) {
case "000":
return "P0";
case "001":
return "P1";
case "010":
return "P2";
case "011":
return "P3";
case "100":
return "P4";
case "101":
return "P5";
case "110":
return "P6";
case "111":
return "P7";
default:
final String error = String.format("Programme circuit 2 '%s' is unknown", prgCircuit2);
throw new IllegalStateException(error);
}
}
private String computeProgrammeCircuitBinaryValue(char value) {
return String.format("%8s", Integer.toBinaryString(value)).replace(' ', '0');
}
}

View File

@ -0,0 +1,50 @@
/**
* 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.data;
import static org.openhab.binding.teleinfo.internal.TeleinfoBindingConstants.*;
import org.openhab.core.thing.ThingTypeUID;
/**
* Define all the frame type values
*
* @author Olivier MARCEAU - Initial contribution
*
*/
public enum FrameType {
CBETM_SHORT(null),
CBETM_LONG_BASE(THING_BASE_CBETM_ELECTRICITY_METER_TYPE_UID),
CBETM_LONG_EJP(THING_EJP_CBETM_ELECTRICITY_METER_TYPE_UID),
CBETM_LONG_HC(THING_HC_CBETM_ELECTRICITY_METER_TYPE_UID),
CBETM_LONG_TEMPO(THING_TEMPO_CBETM_ELECTRICITY_METER_TYPE_UID),
CBEMM_BASE(THING_BASE_CBEMM_ELECTRICITY_METER_TYPE_UID),
CBEMM_EJP(THING_EJP_CBEMM_ELECTRICITY_METER_TYPE_UID),
CBEMM_HC(THING_HC_CBEMM_ELECTRICITY_METER_TYPE_UID),
CBEMM_TEMPO(THING_TEMPO_CBEMM_ELECTRICITY_METER_TYPE_UID),
CBEMM_ICC_BASE(THING_BASE_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID),
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),
UNKNOWN(null);
private ThingTypeUID thingTypeUid;
FrameType(ThingTypeUID thingTypeUid) {
this.thingTypeUid = thingTypeUid;
}
public ThingTypeUID getThingTypeUid() {
return thingTypeUid;
}
}

View File

@ -10,16 +10,15 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.teleinfo.internal.dto.common;
package org.openhab.binding.teleinfo.internal.data;
/**
* The {@link FrameBaseOption} interface defines common attributes for Base option.
* Define all the phase values
*
* @author Olivier MARCEAU - Initial contribution
*
* @author Nicolas SIBERIL - Initial contribution
*/
public interface FrameBaseOption {
int getBase();
void setBase(int base);
public enum Phase {
ONE_PHASED,
THREE_PHASED
}

View File

@ -10,23 +10,17 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.teleinfo.internal.dto.common;
package org.openhab.binding.teleinfo.internal.data;
/**
* The {@link Ptec} enumeration defines all PTEC values.
* Define all the pricing option values
*
* @author Olivier MARCEAU - Initial contribution
*
* @author Nicolas SIBERIL - Initial contribution
*/
public enum Ptec {
TH,
public enum Pricing {
BASE,
TEMPO,
HC,
HP,
HN,
PM,
HCJB,
HCJW,
HCJR,
HPJB,
HPJW,
HPJR
EJP
}

View File

@ -1,50 +0,0 @@
/**
* 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.dto;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.UUID;
/**
* The {@link Frame} class defines common attributes for any Teleinfo frames.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public abstract class Frame implements Serializable {
private static final long serialVersionUID = -1934715078822532494L;
private UUID id;
private LocalDate timestamp; // UTC timestamp
public Frame() {
// default constructor
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public LocalDate getTimestamp() {
return timestamp;
}
public void setTimestamp(LocalDate timestamp) {
this.timestamp = timestamp;
}
}

View File

@ -1,85 +0,0 @@
/**
* 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.dto.cbemm;
import org.openhab.binding.teleinfo.internal.dto.common.FrameAdco;
import org.openhab.binding.teleinfo.internal.dto.common.Ptec;
/**
* The {@link FrameCbemm} class defines common attributes for CBEMM Teleinfo frames.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public abstract class FrameCbemm extends FrameAdco {
private static final long serialVersionUID = -8500010131430582841L;
private int isousc;
private int iinst; // ampères
private Integer adps; // ampères
private Integer imax; // ampères
private Ptec ptec;
private String motdetat;
public FrameCbemm() {
// default constructor
}
public int getIsousc() {
return isousc;
}
public void setIsousc(int isousc) {
this.isousc = isousc;
}
public int getIinst() {
return iinst;
}
public void setIinst(int iinst) {
this.iinst = iinst;
}
public Integer getAdps() {
return adps;
}
public void setAdps(Integer adps) {
this.adps = adps;
}
public Integer getImax() {
return imax;
}
public void setImax(Integer imax) {
this.imax = imax;
}
public Ptec getPtec() {
return ptec;
}
public void setPtec(Ptec ptec) {
this.ptec = ptec;
}
public String getMotdetat() {
return motdetat;
}
public void setMotdetat(String motdetat) {
this.motdetat = motdetat;
}
}

View File

@ -1,41 +0,0 @@
/**
* 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.dto.cbemm;
import org.openhab.binding.teleinfo.internal.dto.common.FrameBaseOption;
/**
* The {@link FrameCbemmBaseOption} class defines a CBEMM Teleinfo frame with Base option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbemmBaseOption extends FrameCbemm implements FrameBaseOption {
private static final long serialVersionUID = 5560141193379363335L;
private int base;
public FrameCbemmBaseOption() {
// default constructor
}
@Override
public int getBase() {
return base;
}
@Override
public void setBase(int base) {
this.base = base;
}
}

View File

@ -1,63 +0,0 @@
/**
* 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.dto.cbemm;
import org.openhab.binding.teleinfo.internal.dto.common.FrameEjpOption;
/**
* The {@link FrameCbemmEjpOption} class defines a CBEMM Teleinfo frame with EJP option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbemmEjpOption extends FrameCbemm implements FrameEjpOption {
private static final long serialVersionUID = -1934715078822532494L;
private int ejphpm;
private int ejphn;
private Integer pejp;
public FrameCbemmEjpOption() {
// default constructor
}
@Override
public int getEjphpm() {
return ejphpm;
}
@Override
public int getEjphn() {
return ejphn;
}
@Override
public Integer getPejp() {
return pejp;
}
@Override
public void setEjphpm(int ejphpm) {
this.ejphpm = ejphpm;
}
@Override
public void setEjphn(int ejphn) {
this.ejphn = ejphn;
}
@Override
public void setPejp(Integer pejp) {
this.pejp = pejp;
}
}

View File

@ -1,64 +0,0 @@
/**
* 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.dto.cbemm;
import org.openhab.binding.teleinfo.internal.dto.common.FrameHcOption;
import org.openhab.binding.teleinfo.internal.dto.common.Hhphc;
/**
* The {@link FrameCbemmHcOption} class defines a CBEMM Teleinfo frame with HC/HP option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbemmHcOption extends FrameCbemm implements FrameHcOption {
private static final long serialVersionUID = -1934715078822532494L;
private int hchc;
private int hchp;
private Hhphc hhphc;
public FrameCbemmHcOption() {
// default constructor
}
@Override
public int getHchc() {
return hchc;
}
@Override
public void setHchc(int hchc) {
this.hchc = hchc;
}
@Override
public int getHchp() {
return hchp;
}
@Override
public void setHchp(int hchp) {
this.hchp = hchp;
}
@Override
public Hhphc getHhphc() {
return hhphc;
}
@Override
public void setHhphc(Hhphc hhphc) {
this.hhphc = hhphc;
}
}

View File

@ -1,141 +0,0 @@
/**
* 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.dto.cbemm;
import org.openhab.binding.teleinfo.internal.dto.common.FrameTempoOption;
import org.openhab.binding.teleinfo.internal.dto.common.Hhphc;
/**
* The {@link FrameCbemmTempoOption} class defines a CBEMM Teleinfo frame with Tempo option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbemmTempoOption extends FrameCbemm implements FrameTempoOption {
private static final long serialVersionUID = 6423861816467362730L;
private int bbrhpjr;
private int bbrhcjr;
private int bbrhpjw;
private int bbrhcjw;
private int bbrhpjb;
private int bbrhcjb;
private CouleurDemain demain;
private Hhphc hhphc;
private ProgrammeCircuit1 programmeCircuit1;
private ProgrammeCircuit2 programmeCircuit2;
public FrameCbemmTempoOption() {
// default constructor
}
@Override
public int getBbrhpjr() {
return bbrhpjr;
}
@Override
public int getBbrhcjr() {
return bbrhcjr;
}
@Override
public int getBbrhpjw() {
return bbrhpjw;
}
@Override
public int getBbrhcjw() {
return bbrhcjw;
}
@Override
public int getBbrhpjb() {
return bbrhpjb;
}
@Override
public int getBbrhcjb() {
return bbrhcjb;
}
@Override
public CouleurDemain getDemain() {
return demain;
}
@Override
public void setBbrhpjr(int bbrhpjr) {
this.bbrhpjr = bbrhpjr;
}
@Override
public void setBbrhcjr(int bbrhcjr) {
this.bbrhcjr = bbrhcjr;
}
@Override
public void setBbrhpjw(int bbrhpjw) {
this.bbrhpjw = bbrhpjw;
}
@Override
public void setBbrhcjw(int bbrhcjw) {
this.bbrhcjw = bbrhcjw;
}
@Override
public void setBbrhpjb(int bbrhpjb) {
this.bbrhpjb = bbrhpjb;
}
@Override
public void setBbrhcjb(int bbrhcjb) {
this.bbrhcjb = bbrhcjb;
}
@Override
public void setDemain(CouleurDemain demain) {
this.demain = demain;
}
@Override
public Hhphc getHhphc() {
return hhphc;
}
@Override
public void setHhphc(Hhphc hhphc) {
this.hhphc = hhphc;
}
@Override
public ProgrammeCircuit1 getProgrammeCircuit1() {
return programmeCircuit1;
}
@Override
public void setProgrammeCircuit1(ProgrammeCircuit1 programmeCircuit1) {
this.programmeCircuit1 = programmeCircuit1;
}
@Override
public ProgrammeCircuit2 getProgrammeCircuit2() {
return programmeCircuit2;
}
@Override
public void setProgrammeCircuit2(ProgrammeCircuit2 programmeCircuit2) {
this.programmeCircuit2 = programmeCircuit2;
}
}

View File

@ -1,39 +0,0 @@
/**
* 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.dto.cbemm.evoicc;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemm;
/**
* The {@link FrameCbemmEvolutionIcc} class defines CBEMM Evolution ICC Teleinfo frames.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public abstract class FrameCbemmEvolutionIcc extends FrameCbemm {
private static final long serialVersionUID = 5532008316299149750L;
private int papp; // Volt.ampères
public FrameCbemmEvolutionIcc() {
// default constructor
}
public int getPapp() {
return papp;
}
public void setPapp(int papp) {
this.papp = papp;
}
}

View File

@ -1,41 +0,0 @@
/**
* 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.dto.cbemm.evoicc;
import org.openhab.binding.teleinfo.internal.dto.common.FrameBaseOption;
/**
* The {@link FrameCbemmEvolutionIccBaseOption} class defines a CBEMM Evolution ICC Teleinfo frame with Base option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbemmEvolutionIccBaseOption extends FrameCbemmEvolutionIcc implements FrameBaseOption {
private static final long serialVersionUID = 1623781914779495089L;
private int base;
public FrameCbemmEvolutionIccBaseOption() {
// default constructor
}
@Override
public int getBase() {
return base;
}
@Override
public void setBase(int base) {
this.base = base;
}
}

View File

@ -1,63 +0,0 @@
/**
* 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.dto.cbemm.evoicc;
import org.openhab.binding.teleinfo.internal.dto.common.FrameEjpOption;
/**
* The {@link FrameCbemmEvolutionIccEjpOption} class defines a CBEMM Evolution ICC Teleinfo frame with EJP option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbemmEvolutionIccEjpOption extends FrameCbemmEvolutionIcc implements FrameEjpOption {
private static final long serialVersionUID = -5053572570767309239L;
private int ejphpm;
private int ejphn;
private Integer pejp;
public FrameCbemmEvolutionIccEjpOption() {
// default constructor
}
@Override
public int getEjphpm() {
return ejphpm;
}
@Override
public int getEjphn() {
return ejphn;
}
@Override
public Integer getPejp() {
return pejp;
}
@Override
public void setEjphpm(int ejphpm) {
this.ejphpm = ejphpm;
}
@Override
public void setEjphn(int ejphn) {
this.ejphn = ejphn;
}
@Override
public void setPejp(Integer pejp) {
this.pejp = pejp;
}
}

View File

@ -1,64 +0,0 @@
/**
* 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.dto.cbemm.evoicc;
import org.openhab.binding.teleinfo.internal.dto.common.FrameHcOption;
import org.openhab.binding.teleinfo.internal.dto.common.Hhphc;
/**
* The {@link FrameCbemmEvolutionIccHcOption} class defines a CBEMM Evolution ICC Teleinfo frame with HC option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbemmEvolutionIccHcOption extends FrameCbemmEvolutionIcc implements FrameHcOption {
private static final long serialVersionUID = 3133144820515675037L;
private int hchc;
private int hchp;
private Hhphc hhphc;
public FrameCbemmEvolutionIccHcOption() {
// default constructor
}
@Override
public int getHchc() {
return hchc;
}
@Override
public void setHchc(int hchc) {
this.hchc = hchc;
}
@Override
public int getHchp() {
return hchp;
}
@Override
public void setHchp(int hchp) {
this.hchp = hchp;
}
@Override
public Hhphc getHhphc() {
return hhphc;
}
@Override
public void setHhphc(Hhphc hhphc) {
this.hhphc = hhphc;
}
}

View File

@ -1,141 +0,0 @@
/**
* 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.dto.cbemm.evoicc;
import org.openhab.binding.teleinfo.internal.dto.common.FrameTempoOption;
import org.openhab.binding.teleinfo.internal.dto.common.Hhphc;
/**
* The {@link FrameCbemmEvolutionIccTempoOption} class defines a CBEMM Evolution ICC Teleinfo frame with Tempo option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbemmEvolutionIccTempoOption extends FrameCbemmEvolutionIcc implements FrameTempoOption {
private static final long serialVersionUID = -1606685089266015480L;
private int bbrhpjr;
private int bbrhcjr;
private int bbrhpjw;
private int bbrhcjw;
private int bbrhpjb;
private int bbrhcjb;
private CouleurDemain demain;
private Hhphc hhphc;
private ProgrammeCircuit1 programmeCircuit1;
private ProgrammeCircuit2 programmeCircuit2;
public FrameCbemmEvolutionIccTempoOption() {
// default constructor
}
@Override
public int getBbrhpjr() {
return bbrhpjr;
}
@Override
public int getBbrhcjr() {
return bbrhcjr;
}
@Override
public int getBbrhpjw() {
return bbrhpjw;
}
@Override
public int getBbrhcjw() {
return bbrhcjw;
}
@Override
public int getBbrhpjb() {
return bbrhpjb;
}
@Override
public int getBbrhcjb() {
return bbrhcjb;
}
@Override
public CouleurDemain getDemain() {
return demain;
}
@Override
public void setBbrhpjr(int bbrhpjr) {
this.bbrhpjr = bbrhpjr;
}
@Override
public void setBbrhcjr(int bbrhcjr) {
this.bbrhcjr = bbrhcjr;
}
@Override
public void setBbrhpjw(int bbrhpjw) {
this.bbrhpjw = bbrhpjw;
}
@Override
public void setBbrhcjw(int bbrhcjw) {
this.bbrhcjw = bbrhcjw;
}
@Override
public void setBbrhpjb(int bbrhpjb) {
this.bbrhpjb = bbrhpjb;
}
@Override
public void setBbrhcjb(int bbrhcjb) {
this.bbrhcjb = bbrhcjb;
}
@Override
public void setDemain(CouleurDemain demain) {
this.demain = demain;
}
@Override
public Hhphc getHhphc() {
return hhphc;
}
@Override
public void setHhphc(Hhphc hhphc) {
this.hhphc = hhphc;
}
@Override
public ProgrammeCircuit1 getProgrammeCircuit1() {
return programmeCircuit1;
}
@Override
public void setProgrammeCircuit1(ProgrammeCircuit1 programmeCircuit1) {
this.programmeCircuit1 = programmeCircuit1;
}
@Override
public ProgrammeCircuit2 getProgrammeCircuit2() {
return programmeCircuit2;
}
@Override
public void setProgrammeCircuit2(ProgrammeCircuit2 programmeCircuit2) {
this.programmeCircuit2 = programmeCircuit2;
}
}

View File

@ -1,57 +0,0 @@
/**
* 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.dto.cbetm;
import org.openhab.binding.teleinfo.internal.dto.common.FrameAdco;
/**
* The {@link FrameCbetm} class defines common attributes for CBETM Teleinfo frames.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public abstract class FrameCbetm extends FrameAdco {
private static final long serialVersionUID = 2083723009359732507L;
private int iinst1; // ampères
private int iinst2; // ampères
private int iinst3; // ampères
public FrameCbetm() {
// default constructor
}
public int getIinst1() {
return iinst1;
}
public void setIinst1(int iinst1) {
this.iinst1 = iinst1;
}
public int getIinst2() {
return iinst2;
}
public void setIinst2(int iinst2) {
this.iinst2 = iinst2;
}
public int getIinst3() {
return iinst3;
}
public void setIinst3(int iinst3) {
this.iinst3 = iinst3;
}
}

View File

@ -1,111 +0,0 @@
/**
* 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.dto.cbetm;
import org.openhab.binding.teleinfo.internal.dto.common.Ptec;
/**
* The {@link FrameCbetmLong} class defines common attributes for CBETM Long Teleinfo frames.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public abstract class FrameCbetmLong extends FrameCbetm {
private static final long serialVersionUID = -2527584397688316017L;
private int isousc;
private Integer imax1; // ampères
private Integer imax2; // ampères
private Integer imax3; // ampères
private Ptec ptec;
private int pmax; // W
private int papp; // Volt.ampères
private String motdetat;
private String ppot;
public FrameCbetmLong() {
// default constructor
}
public int getIsousc() {
return isousc;
}
public void setIsousc(int isousc) {
this.isousc = isousc;
}
public Integer getImax1() {
return imax1;
}
public void setImax1(Integer imax1) {
this.imax1 = imax1;
}
public Integer getImax2() {
return imax2;
}
public void setImax2(Integer imax2) {
this.imax2 = imax2;
}
public Integer getImax3() {
return imax3;
}
public void setImax3(Integer imax3) {
this.imax3 = imax3;
}
public Ptec getPtec() {
return ptec;
}
public void setPtec(Ptec ptec) {
this.ptec = ptec;
}
public int getPmax() {
return pmax;
}
public void setPmax(int pmax) {
this.pmax = pmax;
}
public int getPapp() {
return papp;
}
public void setPapp(int papp) {
this.papp = papp;
}
public String getMotdetat() {
return motdetat;
}
public void setMotdetat(String motdetat) {
this.motdetat = motdetat;
}
public String getPpot() {
return ppot;
}
public void setPpot(String ppot) {
this.ppot = ppot;
}
}

View File

@ -1,41 +0,0 @@
/**
* 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.dto.cbetm;
import org.openhab.binding.teleinfo.internal.dto.common.FrameBaseOption;
/**
* The {@link FrameCbetmLongBaseOption} class defines a CBETM Teleinfo frame with Base option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbetmLongBaseOption extends FrameCbetmLong implements FrameBaseOption {
private static final long serialVersionUID = 7248276012515193856L;
private int base;
public FrameCbetmLongBaseOption() {
// default constructor
}
@Override
public int getBase() {
return base;
}
@Override
public void setBase(int base) {
this.base = base;
}
}

View File

@ -1,63 +0,0 @@
/**
* 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.dto.cbetm;
import org.openhab.binding.teleinfo.internal.dto.common.FrameEjpOption;
/**
* The {@link FrameCbetmLongEjpOption} class defines a CBETM Teleinfo frame with EJP option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbetmLongEjpOption extends FrameCbetmLong implements FrameEjpOption {
private static final long serialVersionUID = 1104569000621483323L;
private int ejphpm;
private int ejphn;
private Integer pejp;
public FrameCbetmLongEjpOption() {
// default constructor
}
@Override
public int getEjphpm() {
return ejphpm;
}
@Override
public int getEjphn() {
return ejphn;
}
@Override
public Integer getPejp() {
return pejp;
}
@Override
public void setEjphpm(int ejphpm) {
this.ejphpm = ejphpm;
}
@Override
public void setEjphn(int ejphn) {
this.ejphn = ejphn;
}
@Override
public void setPejp(Integer pejp) {
this.pejp = pejp;
}
}

View File

@ -1,64 +0,0 @@
/**
* 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.dto.cbetm;
import org.openhab.binding.teleinfo.internal.dto.common.FrameHcOption;
import org.openhab.binding.teleinfo.internal.dto.common.Hhphc;
/**
* The {@link FrameCbetmLongHcOption} class defines a CBETM Teleinfo frame with HC/HP option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbetmLongHcOption extends FrameCbetmLong implements FrameHcOption {
private static final long serialVersionUID = -590729310348196198L;
private int hchc;
private int hchp;
private Hhphc hhphc;
public FrameCbetmLongHcOption() {
// default constructor
}
@Override
public int getHchc() {
return hchc;
}
@Override
public void setHchc(int hchc) {
this.hchc = hchc;
}
@Override
public int getHchp() {
return hchp;
}
@Override
public void setHchp(int hchp) {
this.hchp = hchp;
}
@Override
public Hhphc getHhphc() {
return hhphc;
}
@Override
public void setHhphc(Hhphc hhphc) {
this.hhphc = hhphc;
}
}

View File

@ -1,141 +0,0 @@
/**
* 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.dto.cbetm;
import org.openhab.binding.teleinfo.internal.dto.common.FrameTempoOption;
import org.openhab.binding.teleinfo.internal.dto.common.Hhphc;
/**
* The {@link FrameCbetmLongTempoOption} class defines a CBETM Teleinfo frame with Tempo option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbetmLongTempoOption extends FrameCbetmLong implements FrameTempoOption {
private static final long serialVersionUID = 333018110121838463L;
private int bbrhpjr;
private int bbrhcjr;
private int bbrhpjw;
private int bbrhcjw;
private int bbrhpjb;
private int bbrhcjb;
private CouleurDemain demain;
private Hhphc hhphc;
private ProgrammeCircuit1 programmeCircuit1;
private ProgrammeCircuit2 programmeCircuit2;
public FrameCbetmLongTempoOption() {
// default constructor
}
@Override
public int getBbrhpjr() {
return bbrhpjr;
}
@Override
public int getBbrhcjr() {
return bbrhcjr;
}
@Override
public int getBbrhpjw() {
return bbrhpjw;
}
@Override
public int getBbrhcjw() {
return bbrhcjw;
}
@Override
public int getBbrhpjb() {
return bbrhpjb;
}
@Override
public int getBbrhcjb() {
return bbrhcjb;
}
@Override
public CouleurDemain getDemain() {
return demain;
}
@Override
public void setBbrhpjr(int bbrhpjr) {
this.bbrhpjr = bbrhpjr;
}
@Override
public void setBbrhcjr(int bbrhcjr) {
this.bbrhcjr = bbrhcjr;
}
@Override
public void setBbrhpjw(int bbrhpjw) {
this.bbrhpjw = bbrhpjw;
}
@Override
public void setBbrhcjw(int bbrhcjw) {
this.bbrhcjw = bbrhcjw;
}
@Override
public void setBbrhpjb(int bbrhpjb) {
this.bbrhpjb = bbrhpjb;
}
@Override
public void setBbrhcjb(int bbrhcjb) {
this.bbrhcjb = bbrhcjb;
}
@Override
public void setDemain(CouleurDemain demain) {
this.demain = demain;
}
@Override
public Hhphc getHhphc() {
return hhphc;
}
@Override
public void setHhphc(Hhphc hhphc) {
this.hhphc = hhphc;
}
@Override
public ProgrammeCircuit1 getProgrammeCircuit1() {
return programmeCircuit1;
}
@Override
public void setProgrammeCircuit1(ProgrammeCircuit1 programmeCircuit1) {
this.programmeCircuit1 = programmeCircuit1;
}
@Override
public ProgrammeCircuit2 getProgrammeCircuit2() {
return programmeCircuit2;
}
@Override
public void setProgrammeCircuit2(ProgrammeCircuit2 programmeCircuit2) {
this.programmeCircuit2 = programmeCircuit2;
}
}

View File

@ -1,55 +0,0 @@
/**
* 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.dto.cbetm;
/**
* The {@link FrameCbetmShort} class defines a CBETM Short Teleinfo frames.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public class FrameCbetmShort extends FrameCbetm {
private static final long serialVersionUID = 4269743289079544119L;
private Integer adir1; // ampères
private Integer adir2; // ampères
private Integer adir3; // ampères
public FrameCbetmShort() {
// default constructor
}
public Integer getAdir1() {
return adir1;
}
public void setAdir1(Integer adir1) {
this.adir1 = adir1;
}
public Integer getAdir2() {
return adir2;
}
public void setAdir2(Integer adir2) {
this.adir2 = adir2;
}
public Integer getAdir3() {
return adir3;
}
public void setAdir3(Integer adir3) {
this.adir3 = adir3;
}
}

View File

@ -1,39 +0,0 @@
/**
* 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.dto.common;
import org.openhab.binding.teleinfo.internal.dto.Frame;
/**
* The {@link FrameAdco} class defines common attributes for CBEMM and CBETM Teleinfo frames.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public abstract class FrameAdco extends Frame {
private static final long serialVersionUID = 1384731471611580773L;
private String adco;
public FrameAdco() {
// default constructor
}
public String getAdco() {
return adco;
}
public void setAdco(String adco) {
this.adco = adco;
}
}

View File

@ -1,33 +0,0 @@
/**
* 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.dto.common;
/**
* The {@link FrameEjpOption} interface defines common attributes for EJP option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public interface FrameEjpOption {
int getEjphpm();
void setEjphpm(int ejphpm);
int getEjphn();
void setEjphn(int ejphn);
Integer getPejp();
void setPejp(Integer pejp);
}

View File

@ -1,84 +0,0 @@
/**
* 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.dto.common;
/**
* The {@link FrameTempoOption} interface defines common attributes for Tempo option.
*
* @author Nicolas SIBERIL - Initial contribution
*/
public interface FrameTempoOption {
public static enum CouleurDemain {
Bleu,
Blanc,
Rouge
}
public static enum ProgrammeCircuit1 {
A,
B,
C
}
public static enum ProgrammeCircuit2 {
P0,
P1,
P2,
P3,
P4,
P5,
P6,
P7
}
int getBbrhpjr();
void setBbrhpjr(int bbrhpjr);
int getBbrhcjr();
void setBbrhcjr(int bbrhcjr);
int getBbrhpjw();
void setBbrhpjw(int bbrhpjw);
int getBbrhcjw();
void setBbrhcjw(int bbrhcjw);
int getBbrhpjb();
void setBbrhpjb(int bbrhpjb);
int getBbrhcjb();
void setBbrhcjb(int bbrhcjb);
CouleurDemain getDemain();
void setDemain(CouleurDemain couleurDemain);
Hhphc getHhphc();
void setHhphc(Hhphc hhphc);
ProgrammeCircuit1 getProgrammeCircuit1();
void setProgrammeCircuit1(ProgrammeCircuit1 programmeCircuit1);
ProgrammeCircuit2 getProgrammeCircuit2();
void setProgrammeCircuit2(ProgrammeCircuit2 programmeCircuit2);
}

View File

@ -19,7 +19,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.TeleinfoDiscoveryService;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.data.Frame;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.binding.BaseBridgeHandler;
import org.openhab.core.thing.binding.ThingHandlerService;
@ -34,7 +34,7 @@ public abstract class TeleinfoAbstractControllerHandler extends BaseBridgeHandle
private Set<TeleinfoControllerHandlerListener> listeners = new CopyOnWriteArraySet<>();
public TeleinfoAbstractControllerHandler(Bridge bridge) {
protected TeleinfoAbstractControllerHandler(Bridge bridge) {
super(bridge);
}
@ -47,7 +47,7 @@ public abstract class TeleinfoAbstractControllerHandler extends BaseBridgeHandle
}
protected void fireOnFrameReceivedEvent(final Frame frame) {
listeners.forEach(l -> l.onFrameReceived(this, frame));
listeners.forEach(l -> l.onFrameReceived(frame));
}
@Override

View File

@ -13,7 +13,7 @@
package org.openhab.binding.teleinfo.internal.handler;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.data.Frame;
/**
* The {@link TeleinfoControllerHandlerListener} interface defines all events pushed by a
@ -24,5 +24,5 @@ import org.openhab.binding.teleinfo.internal.dto.Frame;
@NonNullByDefault
public interface TeleinfoControllerHandlerListener {
void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, final Frame frame);
void onFrameReceived(final Frame frame);
}

View File

@ -14,15 +14,19 @@ package org.openhab.binding.teleinfo.internal.handler;
import static org.openhab.binding.teleinfo.internal.TeleinfoBindingConstants.*;
import java.util.Map.Entry;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.dto.common.FrameBaseOption;
import org.openhab.binding.teleinfo.internal.dto.common.FrameEjpOption;
import org.openhab.binding.teleinfo.internal.dto.common.FrameHcOption;
import org.openhab.binding.teleinfo.internal.dto.common.FrameTempoOption;
import org.openhab.binding.teleinfo.internal.data.Frame;
import org.openhab.binding.teleinfo.internal.data.Phase;
import org.openhab.binding.teleinfo.internal.data.Pricing;
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.core.library.types.DateTimeType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
@ -37,17 +41,18 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link TeleinfoAbstractElectricityMeterHandler} class defines a skeleton for Electricity Meters handlers.
* The {@link TeleinfoElectricityMeterHandler} class defines a skeleton for Electricity Meters handlers.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public abstract class TeleinfoAbstractElectricityMeterHandler extends BaseThingHandler
implements TeleinfoControllerHandlerListener {
private final Logger logger = LoggerFactory.getLogger(TeleinfoAbstractElectricityMeterHandler.class);
protected TeleinfoElectricityMeterConfiguration configuration = new TeleinfoElectricityMeterConfiguration();
public class TeleinfoElectricityMeterHandler extends BaseThingHandler implements TeleinfoControllerHandlerListener {
public TeleinfoAbstractElectricityMeterHandler(Thing thing) {
private final Logger logger = LoggerFactory.getLogger(TeleinfoElectricityMeterHandler.class);
protected TeleinfoElectricityMeterConfiguration configuration = new TeleinfoElectricityMeterConfiguration();
private boolean wasLastFrameShort = false;
public TeleinfoElectricityMeterHandler(Thing thing) {
super(thing);
}
@ -99,47 +104,6 @@ public abstract class TeleinfoAbstractElectricityMeterHandler extends BaseThingH
// no commands supported
}
protected void updateStatesForBaseFrameOption(FrameBaseOption frameBaseOption) {
updateState(CHANNEL_BASE_FRAME_BASE, QuantityType.valueOf(frameBaseOption.getBase(), Units.WATT_HOUR));
}
protected void updateStatesForHcFrameOption(FrameHcOption frameHcOption) {
updateState(CHANNEL_HC_FRAME_HCHC, QuantityType.valueOf(frameHcOption.getHchc(), Units.WATT_HOUR));
updateState(CHANNEL_HC_FRAME_HCHP, QuantityType.valueOf(frameHcOption.getHchp(), Units.WATT_HOUR));
updateState(CHANNEL_HC_FRAME_HHPHC, new StringType(frameHcOption.getHhphc().name()));
}
protected void updateStatesForTempoFrameOption(FrameTempoOption frameTempoOption) {
updateState(CHANNEL_TEMPO_FRAME_BBRHPJR, QuantityType.valueOf(frameTempoOption.getBbrhpjr(), Units.WATT_HOUR));
updateState(CHANNEL_TEMPO_FRAME_BBRHCJR, QuantityType.valueOf(frameTempoOption.getBbrhcjr(), Units.WATT_HOUR));
updateState(CHANNEL_TEMPO_FRAME_BBRHPJW, QuantityType.valueOf(frameTempoOption.getBbrhpjw(), Units.WATT_HOUR));
updateState(CHANNEL_TEMPO_FRAME_BBRHCJW, QuantityType.valueOf(frameTempoOption.getBbrhcjw(), Units.WATT_HOUR));
updateState(CHANNEL_TEMPO_FRAME_BBRHPJB, QuantityType.valueOf(frameTempoOption.getBbrhpjb(), Units.WATT_HOUR));
updateState(CHANNEL_TEMPO_FRAME_BBRHCJB, QuantityType.valueOf(frameTempoOption.getBbrhcjb(), Units.WATT_HOUR));
updateState(CHANNEL_TEMPO_FRAME_HHPHC, new StringType(frameTempoOption.getHhphc().name()));
updateState(CHANNEL_TEMPO_FRAME_PROGRAMME_CIRCUIT_1,
new StringType(frameTempoOption.getProgrammeCircuit1().name()));
updateState(CHANNEL_TEMPO_FRAME_PROGRAMME_CIRCUIT_2,
new StringType(frameTempoOption.getProgrammeCircuit2().name()));
if (frameTempoOption.getDemain() == null) {
updateState(CHANNEL_TEMPO_FRAME_DEMAIN, UnDefType.NULL);
} else {
updateState(CHANNEL_TEMPO_FRAME_DEMAIN, new StringType(frameTempoOption.getDemain().name()));
}
}
protected void updateStatesForEjpFrameOption(FrameEjpOption frameEjpOption) {
updateState(CHANNEL_EJP_FRAME_EJPHN, QuantityType.valueOf(frameEjpOption.getEjphn(), Units.WATT_HOUR));
updateState(CHANNEL_EJP_FRAME_EJPHPM, QuantityType.valueOf(frameEjpOption.getEjphpm(), Units.WATT_HOUR));
if (frameEjpOption.getPejp() == null) {
updateState(CHANNEL_EJP_FRAME_PEJP, UnDefType.NULL);
} else {
updateState(CHANNEL_EJP_FRAME_PEJP, QuantityType.valueOf(frameEjpOption.getPejp(), Units.MINUTE));
}
}
@Override
protected void updateStatus(ThingStatus status, ThingStatusDetail statusDetail, @Nullable String description) {
super.updateStatus(status, statusDetail, description);
@ -162,4 +126,60 @@ public abstract class TeleinfoAbstractElectricityMeterHandler extends BaseThingH
protected void updateStatus(ThingStatus status) {
this.updateStatus(status, ThingStatusDetail.NONE, null);
}
@Override
public void onFrameReceived(Frame frame) {
String adco = configuration.getAdco();
if (adco.equalsIgnoreCase(frame.get(Label.ADCO))) {
updateStatesForChannels(frame);
}
}
private void updateStatesForChannels(Frame frame) {
for (Entry<Label, String> entry : frame.getLabelToValues().entrySet()) {
Label label = entry.getKey();
if (!label.getChannelName().equals(NOT_A_CHANNEL)) {
if (label == Label.PTEC) {
updateState(label.getChannelName(), StringType.valueOf(entry.getValue().replace(".", "")));
} 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()));
}
}
}
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);
}
wasLastFrameShort = frame.isShortFrame();
}
} catch (InvalidFrameException e) {
logger.warn("Can not find phase.");
}
updateState(CHANNEL_LAST_UPDATE, new DateTimeType());
}
private void updateStateForMissingAlert(Frame frame, Label label) {
if (!frame.getLabelToValues().containsKey(label)) {
updateState(label.getChannelName(), UnDefType.NULL);
}
}
}

View File

@ -20,18 +20,6 @@ import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.handler.cbemm.TeleinfoBaseCbemmElectricityMeterHandler;
import org.openhab.binding.teleinfo.internal.handler.cbemm.TeleinfoEjpCbemmElectricityMeterHandler;
import org.openhab.binding.teleinfo.internal.handler.cbemm.TeleinfoHcCbemmElectricityMeterHandler;
import org.openhab.binding.teleinfo.internal.handler.cbemm.TeleinfoTempoCbemmElectricityMeterHandler;
import org.openhab.binding.teleinfo.internal.handler.cbemm.evoicc.TeleinfoBaseCbemmEvoIccElectricityMeterHandler;
import org.openhab.binding.teleinfo.internal.handler.cbemm.evoicc.TeleinfoEjpCbemmEvoIccElectricityMeterHandler;
import org.openhab.binding.teleinfo.internal.handler.cbemm.evoicc.TeleinfoHcCbemmEvoIccElectricityMeterHandler;
import org.openhab.binding.teleinfo.internal.handler.cbemm.evoicc.TeleinfoTempoCbemmEvoIccElectricityMeterHandler;
import org.openhab.binding.teleinfo.internal.handler.cbetm.TeleinfoBaseCbetmLongElectricityMeterHandler;
import org.openhab.binding.teleinfo.internal.handler.cbetm.TeleinfoEjpCbetmLongElectricityMeterHandler;
import org.openhab.binding.teleinfo.internal.handler.cbetm.TeleinfoHcCbetmLongElectricityMeterHandler;
import org.openhab.binding.teleinfo.internal.handler.cbetm.TeleinfoTempoCbetmLongElectricityMeterHandler;
import org.openhab.binding.teleinfo.internal.serial.TeleinfoSerialControllerHandler;
import org.openhab.core.io.transport.serial.SerialPortManager;
import org.openhab.core.thing.Bridge;
@ -83,30 +71,8 @@ public class TeleinfoThingHandlerFactory extends BaseThingHandlerFactory {
return new TeleinfoSerialControllerHandler((Bridge) thing, serialPortManager);
}
if (THING_BASE_CBEMM_ELECTRICITY_METER_TYPE_UID.equals(thing.getThingTypeUID())) {
return new TeleinfoBaseCbemmElectricityMeterHandler(thing);
} else if (THING_HC_CBEMM_ELECTRICITY_METER_TYPE_UID.equals(thing.getThingTypeUID())) {
return new TeleinfoHcCbemmElectricityMeterHandler(thing);
} else if (THING_TEMPO_CBEMM_ELECTRICITY_METER_TYPE_UID.equals(thing.getThingTypeUID())) {
return new TeleinfoTempoCbemmElectricityMeterHandler(thing);
} else if (THING_EJP_CBEMM_ELECTRICITY_METER_TYPE_UID.equals(thing.getThingTypeUID())) {
return new TeleinfoEjpCbemmElectricityMeterHandler(thing);
} else if (THING_BASE_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID.equals(thing.getThingTypeUID())) {
return new TeleinfoBaseCbemmEvoIccElectricityMeterHandler(thing);
} else if (THING_HC_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID.equals(thing.getThingTypeUID())) {
return new TeleinfoHcCbemmEvoIccElectricityMeterHandler(thing);
} else if (THING_TEMPO_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID.equals(thing.getThingTypeUID())) {
return new TeleinfoTempoCbemmEvoIccElectricityMeterHandler(thing);
} else if (THING_EJP_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID.equals(thing.getThingTypeUID())) {
return new TeleinfoEjpCbemmEvoIccElectricityMeterHandler(thing);
} else if (THING_BASE_CBETM_ELECTRICITY_METER_TYPE_UID.equals(thing.getThingTypeUID())) {
return new TeleinfoBaseCbetmLongElectricityMeterHandler(thing);
} else if (THING_HC_CBETM_ELECTRICITY_METER_TYPE_UID.equals(thing.getThingTypeUID())) {
return new TeleinfoHcCbetmLongElectricityMeterHandler(thing);
} else if (THING_TEMPO_CBETM_ELECTRICITY_METER_TYPE_UID.equals(thing.getThingTypeUID())) {
return new TeleinfoTempoCbetmLongElectricityMeterHandler(thing);
} else if (THING_EJP_CBETM_ELECTRICITY_METER_TYPE_UID.equals(thing.getThingTypeUID())) {
return new TeleinfoEjpCbetmLongElectricityMeterHandler(thing);
if (SUPPORTED_THING_TYPES_UIDS.contains(thing.getThingTypeUID())) {
return new TeleinfoElectricityMeterHandler(thing);
} else {
throw new IllegalStateException("Teleinfo frame type not supported: " + thing.getThingTypeUID());
}

View File

@ -1,59 +0,0 @@
/**
* 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.handler.cbemm;
import static org.openhab.binding.teleinfo.internal.TeleinfoBindingConstants.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemm;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractElectricityMeterHandler;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Thing;
import org.openhab.core.types.UnDefType;
/**
* The {@link TeleinfoAbstractCbemmElectricityMeterHandler} class defines a skeleton for CBEMM Electricity Meters
* handlers.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public abstract class TeleinfoAbstractCbemmElectricityMeterHandler extends TeleinfoAbstractElectricityMeterHandler {
public TeleinfoAbstractCbemmElectricityMeterHandler(Thing thing) {
super(thing);
}
protected void updateStatesForCommonCbemmChannels(FrameCbemm frame) {
// update common channels
updateState(CHANNEL_CBEMM_ISOUSC, QuantityType.valueOf(frame.getIsousc(), Units.AMPERE));
updateState(CHANNEL_CBEMM_PTEC, new StringType(frame.getPtec().name()));
if (frame.getImax() == null) {
updateState(CHANNEL_CBEMM_IMAX, UnDefType.NULL);
} else {
updateState(CHANNEL_CBEMM_IMAX, QuantityType.valueOf(frame.getImax(), Units.AMPERE));
}
if (frame.getAdps() == null) {
updateState(CHANNEL_CBEMM_ADPS, UnDefType.NULL);
} else {
updateState(CHANNEL_CBEMM_ADPS, QuantityType.valueOf(frame.getAdps(), Units.AMPERE));
}
updateState(CHANNEL_CBEMM_IINST, QuantityType.valueOf(frame.getIinst(), Units.AMPERE));
updateState(CHANNEL_LAST_UPDATE, new DateTimeType());
}
}

View File

@ -1,45 +0,0 @@
/**
* 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.handler.cbemm;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemmBaseOption;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoBaseCbemmElectricityMeterHandler} class defines a handler for a BASE CBEMM Electricity Meters
* thing.
*
* @author Nicolas SIBERIL - Initial contribution
* @author Olivier MARCEAU - Change ADCO property to parameter
*/
@NonNullByDefault
public class TeleinfoBaseCbemmElectricityMeterHandler extends TeleinfoAbstractCbemmElectricityMeterHandler {
public TeleinfoBaseCbemmElectricityMeterHandler(Thing thing) {
super(thing);
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
final FrameCbemmBaseOption frameCbemmBaseOption = (FrameCbemmBaseOption) frame;
String adco = configuration.getAdco();
if (frameCbemmBaseOption.getAdco().equalsIgnoreCase(adco)) {
updateStatesForCommonCbemmChannels(frameCbemmBaseOption);
updateStatesForBaseFrameOption(frameCbemmBaseOption);
}
}
}

View File

@ -1,45 +0,0 @@
/**
* 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.handler.cbemm;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemmEjpOption;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoEjpCbemmElectricityMeterHandler} class defines a handler for a EJB CBEMM Electricity Meters
* thing.
*
* @author Nicolas SIBERIL - Initial contribution
* @author Olivier MARCEAU - Change ADCO property to parameter
*/
@NonNullByDefault
public class TeleinfoEjpCbemmElectricityMeterHandler extends TeleinfoAbstractCbemmElectricityMeterHandler {
public TeleinfoEjpCbemmElectricityMeterHandler(Thing thing) {
super(thing);
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
final FrameCbemmEjpOption frameCbemmEjpOption = (FrameCbemmEjpOption) frame;
String adco = configuration.getAdco();
if (frameCbemmEjpOption.getAdco().equalsIgnoreCase(adco)) {
updateStatesForCommonCbemmChannels(frameCbemmEjpOption);
updateStatesForEjpFrameOption(frameCbemmEjpOption);
}
}
}

View File

@ -1,44 +0,0 @@
/**
* 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.handler.cbemm;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemmHcOption;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoHcCbemmElectricityMeterHandler} class defines a handler for a HC CBEMM Electricity Meters thing.
*
* @author Nicolas SIBERIL - Initial contribution
* @author Olivier MARCEAU - Change ADCO property to parameter
*/
@NonNullByDefault
public class TeleinfoHcCbemmElectricityMeterHandler extends TeleinfoAbstractCbemmElectricityMeterHandler {
public TeleinfoHcCbemmElectricityMeterHandler(Thing thing) {
super(thing);
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
final FrameCbemmHcOption frameCbemmHcOption = (FrameCbemmHcOption) frame;
String adco = configuration.getAdco();
if (frameCbemmHcOption.getAdco().equalsIgnoreCase(adco)) {
updateStatesForCommonCbemmChannels(frameCbemmHcOption);
updateStatesForHcFrameOption(frameCbemmHcOption);
}
}
}

View File

@ -1,45 +0,0 @@
/**
* 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.handler.cbemm;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemmTempoOption;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoTempoCbemmElectricityMeterHandler} class defines a handler for a TEMPO CBEMM Electricity Meters
* thing.
*
* @author Nicolas SIBERIL - Initial contribution
* @author Olivier MARCEAU - Change ADCO property to parameter
*/
@NonNullByDefault
public class TeleinfoTempoCbemmElectricityMeterHandler extends TeleinfoAbstractCbemmElectricityMeterHandler {
public TeleinfoTempoCbemmElectricityMeterHandler(Thing thing) {
super(thing);
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
final FrameCbemmTempoOption frameCbemmTempoOption = (FrameCbemmTempoOption) frame;
String adco = configuration.getAdco();
if (frameCbemmTempoOption.getAdco().equalsIgnoreCase(adco)) {
updateStatesForCommonCbemmChannels(frameCbemmTempoOption);
updateStatesForTempoFrameOption(frameCbemmTempoOption);
}
}
}

View File

@ -1,43 +0,0 @@
/**
* 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.handler.cbemm.evoicc;
import static org.openhab.binding.teleinfo.internal.TeleinfoBindingConstants.CHANNEL_CBEMM_EVOLUTION_ICC_PAPP;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIcc;
import org.openhab.binding.teleinfo.internal.handler.cbemm.TeleinfoAbstractCbemmElectricityMeterHandler;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoAbstractCbemmEvoIccElectricityMeterHandler} class defines a skeleton for CBEMM Evolution ICC
* Electricity Meters
* handlers.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public abstract class TeleinfoAbstractCbemmEvoIccElectricityMeterHandler
extends TeleinfoAbstractCbemmElectricityMeterHandler {
public TeleinfoAbstractCbemmEvoIccElectricityMeterHandler(Thing thing) {
super(thing);
}
protected void updateStatesForCommonCbemmEvolutionIccChannels(FrameCbemmEvolutionIcc frame) {
updateStatesForCommonCbemmChannels(frame);
updateState(CHANNEL_CBEMM_EVOLUTION_ICC_PAPP, QuantityType.valueOf(frame.getPapp(), Units.VOLT_AMPERE));
}
}

View File

@ -1,45 +0,0 @@
/**
* 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.handler.cbemm.evoicc;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccBaseOption;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoBaseCbemmEvoIccElectricityMeterHandler} class defines a handler for a BASE CBEMM Evolution ICC
* Electricity Meters thing.
*
* @author Nicolas SIBERIL - Initial contribution
* @author Olivier MARCEAU - Change ADCO property to parameter
*/
@NonNullByDefault
public class TeleinfoBaseCbemmEvoIccElectricityMeterHandler extends TeleinfoAbstractCbemmEvoIccElectricityMeterHandler {
public TeleinfoBaseCbemmEvoIccElectricityMeterHandler(Thing thing) {
super(thing);
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
final FrameCbemmEvolutionIccBaseOption frameCbemmEvoIccBaseOption = (FrameCbemmEvolutionIccBaseOption) frame;
String adco = configuration.getAdco();
if (frameCbemmEvoIccBaseOption.getAdco().equalsIgnoreCase(adco)) {
updateStatesForCommonCbemmEvolutionIccChannels(frameCbemmEvoIccBaseOption);
updateStatesForBaseFrameOption(frameCbemmEvoIccBaseOption);
}
}
}

View File

@ -1,45 +0,0 @@
/**
* 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.handler.cbemm.evoicc;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccEjpOption;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoEjpCbemmEvoIccElectricityMeterHandler} class defines a handler for a EJP CBEMM Evolution ICC
* Electricity Meters thing.
*
* @author Nicolas SIBERIL - Initial contribution
* @author Olivier MARCEAU - Change ADCO property to parameter
*/
@NonNullByDefault
public class TeleinfoEjpCbemmEvoIccElectricityMeterHandler extends TeleinfoAbstractCbemmEvoIccElectricityMeterHandler {
public TeleinfoEjpCbemmEvoIccElectricityMeterHandler(Thing thing) {
super(thing);
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
final FrameCbemmEvolutionIccEjpOption frameCbemmEvoIccEjpOption = (FrameCbemmEvolutionIccEjpOption) frame;
String adco = configuration.getAdco();
if (frameCbemmEvoIccEjpOption.getAdco().equalsIgnoreCase(adco)) {
updateStatesForCommonCbemmEvolutionIccChannels(frameCbemmEvoIccEjpOption);
updateStatesForEjpFrameOption(frameCbemmEvoIccEjpOption);
}
}
}

View File

@ -1,45 +0,0 @@
/**
* 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.handler.cbemm.evoicc;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccHcOption;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoHcCbemmEvoIccElectricityMeterHandler} class defines a handler for a HC CBEMM Evolution ICC
* Electricity Meters thing.
*
* @author Nicolas SIBERIL - Initial contribution
* @author Olivier MARCEAU - Change ADCO property to parameter
*/
@NonNullByDefault
public class TeleinfoHcCbemmEvoIccElectricityMeterHandler extends TeleinfoAbstractCbemmEvoIccElectricityMeterHandler {
public TeleinfoHcCbemmEvoIccElectricityMeterHandler(Thing thing) {
super(thing);
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
final FrameCbemmEvolutionIccHcOption frameCbemmEvoIccHcOption = (FrameCbemmEvolutionIccHcOption) frame;
String adco = configuration.getAdco();
if (frameCbemmEvoIccHcOption.getAdco().equalsIgnoreCase(adco)) {
updateStatesForCommonCbemmEvolutionIccChannels(frameCbemmEvoIccHcOption);
updateStatesForHcFrameOption(frameCbemmEvoIccHcOption);
}
}
}

View File

@ -1,46 +0,0 @@
/**
* 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.handler.cbemm.evoicc;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccTempoOption;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoTempoCbemmEvoIccElectricityMeterHandler} class defines a handler for a TEMPO CBEMM Evolution ICC
* Electricity Meters thing.
*
* @author Nicolas SIBERIL - Initial contribution
* @author Olivier MARCEAU - Change ADCO property to parameter
*/
@NonNullByDefault
public class TeleinfoTempoCbemmEvoIccElectricityMeterHandler
extends TeleinfoAbstractCbemmEvoIccElectricityMeterHandler {
public TeleinfoTempoCbemmEvoIccElectricityMeterHandler(Thing thing) {
super(thing);
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
final FrameCbemmEvolutionIccTempoOption frameCbemmEvoIccTempoOption = (FrameCbemmEvolutionIccTempoOption) frame;
String adco = configuration.getAdco();
if (frameCbemmEvoIccTempoOption.getAdco().equalsIgnoreCase(adco)) {
updateStatesForCommonCbemmEvolutionIccChannels(frameCbemmEvoIccTempoOption);
updateStatesForTempoFrameOption(frameCbemmEvoIccTempoOption);
}
}
}

View File

@ -1,112 +0,0 @@
/**
* 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.handler.cbetm;
import static org.openhab.binding.teleinfo.internal.TeleinfoBindingConstants.*;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetm;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLong;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmShort;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractElectricityMeterHandler;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Thing;
import org.openhab.core.types.UnDefType;
/**
* The {@link TeleinfoAbstractCbetmElectricityMeterHandler} class defines a skeleton for CBETM Electricity Meters
* handlers.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public abstract class TeleinfoAbstractCbetmElectricityMeterHandler extends TeleinfoAbstractElectricityMeterHandler {
public TeleinfoAbstractCbetmElectricityMeterHandler(Thing thing) {
super(thing);
}
protected void updateStatesForCommonCbetmChannels(FrameCbetm frameCbetm) {
updateState(CHANNEL_CBETM_IINST1, QuantityType.valueOf(frameCbetm.getIinst1(), Units.AMPERE));
updateState(CHANNEL_CBETM_IINST2, QuantityType.valueOf(frameCbetm.getIinst2(), Units.AMPERE));
updateState(CHANNEL_CBETM_IINST3, QuantityType.valueOf(frameCbetm.getIinst3(), Units.AMPERE));
if (frameCbetm instanceof FrameCbetmLong) {
FrameCbetmLong frameCbetmLong = (FrameCbetmLong) frameCbetm;
updateState(CHANNEL_CBETM_FRAME_TYPE, new StringType("LONG"));
updateState(CHANNEL_CBETM_LONG_ISOUSC, QuantityType.valueOf(frameCbetmLong.getIsousc(), Units.AMPERE));
updateState(CHANNEL_CBETM_LONG_PTEC, new StringType(frameCbetmLong.getPtec().name()));
if (frameCbetmLong.getImax1() == null) {
updateState(CHANNEL_CBETM_LONG_IMAX1, UnDefType.NULL);
} else {
updateState(CHANNEL_CBETM_LONG_IMAX1, QuantityType.valueOf(frameCbetmLong.getImax1(), Units.AMPERE));
}
if (frameCbetmLong.getImax2() == null) {
updateState(CHANNEL_CBETM_LONG_IMAX2, UnDefType.NULL);
} else {
updateState(CHANNEL_CBETM_LONG_IMAX2, QuantityType.valueOf(frameCbetmLong.getImax2(), Units.AMPERE));
}
if (frameCbetmLong.getImax3() == null) {
updateState(CHANNEL_CBETM_LONG_IMAX3, UnDefType.NULL);
} else {
updateState(CHANNEL_CBETM_LONG_IMAX3, QuantityType.valueOf(frameCbetmLong.getImax3(), Units.AMPERE));
}
updateState(CHANNEL_CBETM_LONG_PMAX, QuantityType.valueOf(frameCbetmLong.getPmax(), Units.WATT));
updateState(CHANNEL_CBETM_LONG_PAPP, QuantityType.valueOf(frameCbetmLong.getPapp(), Units.VOLT_AMPERE));
updateState(CHANNEL_CBETM_LONG_PPOT, new StringType(frameCbetmLong.getPpot()));
updateState(CHANNEL_CBETM_SHORT_ADIR1, UnDefType.NULL);
updateState(CHANNEL_CBETM_SHORT_ADIR2, UnDefType.NULL);
updateState(CHANNEL_CBETM_SHORT_ADIR3, UnDefType.NULL);
} else { // FrameCbetmShort
FrameCbetmShort frameCbetmShort = (FrameCbetmShort) frameCbetm;
updateState(CHANNEL_CBETM_FRAME_TYPE, new StringType("SHORT"));
if (frameCbetmShort.getAdir1() == null) {
updateState(CHANNEL_CBETM_SHORT_ADIR1, UnDefType.NULL);
} else {
updateState(CHANNEL_CBETM_SHORT_ADIR1, QuantityType.valueOf(frameCbetmShort.getAdir1(), Units.AMPERE));
}
if (frameCbetmShort.getAdir2() == null) {
updateState(CHANNEL_CBETM_SHORT_ADIR2, UnDefType.NULL);
} else {
updateState(CHANNEL_CBETM_SHORT_ADIR2, QuantityType.valueOf(frameCbetmShort.getAdir2(), Units.AMPERE));
}
if (frameCbetmShort.getAdir3() == null) {
updateState(CHANNEL_CBETM_SHORT_ADIR3, UnDefType.NULL);
} else {
updateState(CHANNEL_CBETM_SHORT_ADIR3, QuantityType.valueOf(frameCbetmShort.getAdir3(), Units.AMPERE));
}
updateState(CHANNEL_CBETM_LONG_ISOUSC, UnDefType.NULL);
updateState(CHANNEL_CBETM_LONG_PTEC, UnDefType.NULL);
updateState(CHANNEL_CBETM_LONG_IMAX1, UnDefType.NULL);
updateState(CHANNEL_CBETM_LONG_IMAX2, UnDefType.NULL);
updateState(CHANNEL_CBETM_LONG_IMAX3, UnDefType.NULL);
updateState(CHANNEL_CBETM_LONG_PMAX, UnDefType.NULL);
updateState(CHANNEL_CBETM_LONG_PAPP, UnDefType.NULL);
updateState(CHANNEL_CBETM_LONG_PPOT, UnDefType.NULL);
}
updateState(CHANNEL_LAST_UPDATE, new DateTimeType());
}
}

View File

@ -1,48 +0,0 @@
/**
* 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.handler.cbetm;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetm;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongBaseOption;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoBaseCbetmLongElectricityMeterHandler} class defines a handler for a BASE CBETM Electricity Meters
* thing.
*
* @author Nicolas SIBERIL - Initial contribution
* @author Olivier MARCEAU - Change ADCO property to parameter
*/
@NonNullByDefault
public class TeleinfoBaseCbetmLongElectricityMeterHandler extends TeleinfoAbstractCbetmElectricityMeterHandler {
public TeleinfoBaseCbetmLongElectricityMeterHandler(Thing thing) {
super(thing);
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
final FrameCbetm frameCbetm = (FrameCbetm) frame;
String adco = configuration.getAdco();
if (frameCbetm.getAdco().equalsIgnoreCase(adco)) {
updateStatesForCommonCbetmChannels(frameCbetm);
if (frameCbetm instanceof FrameCbetmLongBaseOption) {
updateStatesForBaseFrameOption((FrameCbetmLongBaseOption) frameCbetm);
}
}
}
}

View File

@ -1,48 +0,0 @@
/**
* 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.handler.cbetm;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetm;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongEjpOption;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoEjpCbetmLongElectricityMeterHandler} class defines a handler for a EJP CBETM Electricity Meters
* thing.
*
* @author Nicolas SIBERIL - Initial contribution
* @author Olivier MARCEAU - Change ADCO property to parameter
*/
@NonNullByDefault
public class TeleinfoEjpCbetmLongElectricityMeterHandler extends TeleinfoAbstractCbetmElectricityMeterHandler {
public TeleinfoEjpCbetmLongElectricityMeterHandler(Thing thing) {
super(thing);
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
final FrameCbetm frameCbetm = (FrameCbetm) frame;
String adco = configuration.getAdco();
if (frameCbetm.getAdco().equalsIgnoreCase(adco)) {
updateStatesForCommonCbetmChannels(frameCbetm);
if (frameCbetm instanceof FrameCbetmLongEjpOption) {
updateStatesForEjpFrameOption((FrameCbetmLongEjpOption) frameCbetm);
}
}
}
}

View File

@ -1,49 +0,0 @@
/**
* 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.handler.cbetm;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetm;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongHcOption;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoHcCbetmLongElectricityMeterHandler} class defines a handler for a HC CBETM Electricity Meters
* thing.
*
* @author Nicolas SIBERIL - Initial contribution
* @author Olivier MARCEAU - Change ADCO property to parameter
*/
@NonNullByDefault
public class TeleinfoHcCbetmLongElectricityMeterHandler extends TeleinfoAbstractCbetmElectricityMeterHandler {
public TeleinfoHcCbetmLongElectricityMeterHandler(Thing thing) {
super(thing);
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
final FrameCbetm frameCbetm = (FrameCbetm) frame;
String adco = configuration.getAdco();
if (frameCbetm.getAdco().equalsIgnoreCase(adco)) {
updateStatesForCommonCbetmChannels(frameCbetm);
if (frameCbetm instanceof FrameCbetmLongHcOption) {
updateStatesForHcFrameOption((FrameCbetmLongHcOption) frameCbetm);
}
}
}
}

View File

@ -1,50 +0,0 @@
/**
* 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.handler.cbetm;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetm;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongTempoOption;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.core.thing.Thing;
/**
* The {@link TeleinfoTempoCbetmLongElectricityMeterHandler} class defines a handler for a TEMPO CBETM Electricity
* Meters
* thing.
*
* @author Nicolas SIBERIL - Initial contribution
* @author Olivier MARCEAU - Change ADCO property to parameter
*/
@NonNullByDefault
public class TeleinfoTempoCbetmLongElectricityMeterHandler extends TeleinfoAbstractCbetmElectricityMeterHandler {
public TeleinfoTempoCbetmLongElectricityMeterHandler(Thing thing) {
super(thing);
}
@Override
public void onFrameReceived(TeleinfoAbstractControllerHandler controllerHandler, Frame frame) {
final FrameCbetm frameCbetm = (FrameCbetm) frame;
String adco = configuration.getAdco();
if (frameCbetm.getAdco().equalsIgnoreCase(adco)) {
updateStatesForCommonCbetmChannels(frameCbetm);
if (frameCbetm instanceof FrameCbetmLongTempoOption) {
updateStatesForTempoFrameOption((FrameCbetmLongTempoOption) frameCbetm);
}
}
}
}

View File

@ -17,7 +17,7 @@ import java.util.Collections;
import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.data.Frame;
/**
* The {@link TeleinfoReaderAdaptor} class defines an adaptor at {@link TeleinfoReader} interface.

View File

@ -13,7 +13,7 @@
package org.openhab.binding.teleinfo.internal.reader;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.data.Frame;
/**
* The {@link TeleinfoReaderListener} interface defines all events pushed by a {@link TeleinfoReader}.

View File

@ -17,57 +17,13 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemm;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemmBaseOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemmEjpOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemmHcOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.FrameCbemmTempoOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIcc;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccBaseOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccEjpOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccHcOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccTempoOption;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLong;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongBaseOption;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongEjpOption;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongHcOption;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongTempoOption;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmShort;
import org.openhab.binding.teleinfo.internal.dto.common.FrameBaseOption;
import org.openhab.binding.teleinfo.internal.dto.common.FrameEjpOption;
import org.openhab.binding.teleinfo.internal.dto.common.FrameHcOption;
import org.openhab.binding.teleinfo.internal.dto.common.FrameTempoOption;
import org.openhab.binding.teleinfo.internal.dto.common.FrameTempoOption.CouleurDemain;
import org.openhab.binding.teleinfo.internal.dto.common.FrameTempoOption.ProgrammeCircuit1;
import org.openhab.binding.teleinfo.internal.dto.common.FrameTempoOption.ProgrammeCircuit2;
import org.openhab.binding.teleinfo.internal.dto.common.Hhphc;
import org.openhab.binding.teleinfo.internal.dto.common.Ptec;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.ConversionException;
import org.openhab.binding.teleinfo.internal.data.Frame;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.FrameUtil;
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.converter.Converter;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.converter.CouleurDemainConverter;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.converter.FloatConverter;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.converter.HhphcConverter;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.converter.IntegerConverter;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.converter.PtecConverter;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.converter.StringConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -82,63 +38,24 @@ import org.slf4j.LoggerFactory;
@NonNullByDefault
public class TeleinfoInputStream extends InputStream {
public static final long DEFAULT_TIMEOUT_NEXT_HEADER_FRAME_US = 33400;
public static final long DEFAULT_TIMEOUT_READING_FRAME_US = 33400;
private final Logger logger = LoggerFactory.getLogger(TeleinfoInputStream.class);
private static final Map<Class<?>, Converter> LABEL_VALUE_CONVERTERS;
private BufferedReader bufferedReader;
private @Nullable String groupLine;
private ExecutorService executorService;
private long waitNextHeaderFrameTimeoutInUs;
private long readingFrameTimeoutInUs;
private boolean autoRepairInvalidADPSgroupLine;
private boolean useOwnScheduler;
static {
LABEL_VALUE_CONVERTERS = new HashMap<>();
LABEL_VALUE_CONVERTERS.put(Integer.class, new IntegerConverter());
LABEL_VALUE_CONVERTERS.put(String.class, new StringConverter());
LABEL_VALUE_CONVERTERS.put(Float.class, new FloatConverter());
LABEL_VALUE_CONVERTERS.put(Ptec.class, new PtecConverter());
LABEL_VALUE_CONVERTERS.put(Hhphc.class, new HhphcConverter());
LABEL_VALUE_CONVERTERS.put(CouleurDemain.class, new CouleurDemainConverter());
}
private final Frame frame = new Frame();
public TeleinfoInputStream(final InputStream teleinfoInputStream) {
this(teleinfoInputStream, DEFAULT_TIMEOUT_NEXT_HEADER_FRAME_US, DEFAULT_TIMEOUT_READING_FRAME_US, false);
this(teleinfoInputStream, false);
}
public TeleinfoInputStream(final InputStream teleinfoInputStream, boolean autoRepairInvalidADPSgroupLine) {
this(teleinfoInputStream, DEFAULT_TIMEOUT_NEXT_HEADER_FRAME_US, DEFAULT_TIMEOUT_READING_FRAME_US,
autoRepairInvalidADPSgroupLine);
}
public TeleinfoInputStream(final @Nullable InputStream teleinfoInputStream, long waitNextHeaderFrameTimeoutInUs,
long readingFrameTimeoutInUs, boolean autoRepairInvalidADPSgroupLine) {
this(teleinfoInputStream, waitNextHeaderFrameTimeoutInUs, readingFrameTimeoutInUs,
autoRepairInvalidADPSgroupLine, null);
}
public TeleinfoInputStream(final @Nullable InputStream teleinfoInputStream, long waitNextHeaderFrameTimeoutInUs,
long readingFrameTimeoutInUs, boolean autoRepairInvalidADPSgroupLine,
@Nullable ExecutorService executorService) {
public TeleinfoInputStream(final @Nullable InputStream teleinfoInputStream,
boolean autoRepairInvalidADPSgroupLine) {
if (teleinfoInputStream == null) {
throw new IllegalArgumentException("Teleinfo inputStream is null");
}
this.waitNextHeaderFrameTimeoutInUs = waitNextHeaderFrameTimeoutInUs;
this.readingFrameTimeoutInUs = readingFrameTimeoutInUs;
this.autoRepairInvalidADPSgroupLine = autoRepairInvalidADPSgroupLine;
if (executorService == null) {
this.executorService = Executors.newFixedThreadPool(2);
this.useOwnScheduler = true;
} else {
this.executorService = executorService;
this.useOwnScheduler = false;
}
this.bufferedReader = new BufferedReader(new InputStreamReader(teleinfoInputStream, StandardCharsets.US_ASCII));
groupLine = null;
@ -148,9 +65,6 @@ public class TeleinfoInputStream extends InputStream {
public void close() throws IOException {
logger.debug("close() [start]");
bufferedReader.close();
if (useOwnScheduler) {
executorService.shutdownNow();
}
super.close();
logger.debug("close() [end]");
}
@ -164,137 +78,65 @@ public class TeleinfoInputStream extends InputStream {
* @throws InvalidFrameException
* @throws Exception
*/
public synchronized @Nullable Frame readNextFrame() throws TimeoutException, InvalidFrameException, IOException {
public synchronized @Nullable Frame readNextFrame() throws InvalidFrameException, IOException {
// seek the next header frame
Future<@Nullable Void> seekNextHeaderFrameTask = executorService.submit(() -> {
while (!isHeaderFrame(groupLine)) {
groupLine = bufferedReader.readLine();
if (logger.isTraceEnabled()) {
logger.trace("groupLine = {}", groupLine);
}
if (groupLine == null) { // end of stream
logger.trace("end of stream reached !");
return null;
}
while (!isHeaderFrame(groupLine)) {
groupLine = bufferedReader.readLine();
if (logger.isTraceEnabled()) {
logger.trace("groupLine = {}", groupLine);
}
logger.trace("header frame found !");
return null;
});
try {
logger.debug("seeking the next header frame...");
logger.trace("waitNextHeaderFrameTimeoutInUs = {}", waitNextHeaderFrameTimeoutInUs);
seekNextHeaderFrameTask.get(waitNextHeaderFrameTimeoutInUs, TimeUnit.MICROSECONDS);
if (groupLine == null) { // end of stream
logger.trace("end of stream reached !");
return null;
}
} catch (InterruptedException e) {
logger.debug("Got interrupted exception", e);
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
rethrowTaskExecutionException(e);
}
Future<Map<Label, Object>> nextFrameFuture = executorService.submit(new Callable<Map<Label, Object>>() {
@Override
public Map<Label, Object> call() throws Exception {
// read label values
Map<Label, Object> frameValues = new HashMap<>();
while ((groupLine = bufferedReader.readLine()) != null && !isHeaderFrame(groupLine)) {
logger.trace("groupLine = {}", groupLine);
String groupLineRef = groupLine;
if (groupLineRef != null) {
String[] groupLineTokens = groupLineRef.split("\\s");
if (groupLineTokens.length != 2 && groupLineTokens.length != 3) {
final String error = String.format("The groupLine '%1$s' is incomplete", groupLineRef);
throw new InvalidFrameException(error);
}
String labelStr = groupLineTokens[0];
String valueString = groupLineTokens[1];
frame.clear();
while ((groupLine = bufferedReader.readLine()) != null && !isHeaderFrame(groupLine)) {
logger.trace("groupLine = {}", groupLine);
String groupLineRef = groupLine;
if (groupLineRef != null) {
String[] groupLineTokens = groupLineRef.split("\\s");
if (groupLineTokens.length != 2 && groupLineTokens.length != 3) {
final String error = String.format("The groupLine '%1$s' is incomplete", groupLineRef);
throw new InvalidFrameException(error);
}
String labelStr = groupLineTokens[0];
String valueString = groupLineTokens[1];
// verify integrity (through checksum)
char checksum = (groupLineTokens.length == 3 ? groupLineTokens[2].charAt(0) : ' ');
char computedChecksum = FrameUtil.computeGroupLineChecksum(labelStr, valueString);
if (computedChecksum != checksum) {
logger.trace("computedChecksum = {}", computedChecksum);
logger.trace("checksum = {}", checksum);
final String error = String.format(
"The groupLine '%s' is corrupted (integrity not checked). Actual checksum: '%s' / Expected checksum: '%s'",
groupLineRef, checksum, computedChecksum);
throw new InvalidFrameException(error);
}
// verify integrity (through checksum)
char checksum = (groupLineTokens.length == 3 ? groupLineTokens[2].charAt(0) : ' ');
char computedChecksum = FrameUtil.computeGroupLineChecksum(labelStr, valueString);
if (computedChecksum != checksum) {
logger.trace("computedChecksum = {}", computedChecksum);
logger.trace("checksum = {}", checksum);
final String error = String.format(
"The groupLine '%s' is corrupted (integrity not checked). Actual checksum: '%s' / Expected checksum: '%s'",
groupLineRef, checksum, computedChecksum);
throw new InvalidFrameException(error);
}
Label label;
try {
label = Label.valueOf(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:
// ADPS032
logger.warn("Try to auto repair malformed ADPS groupLine '{}'", labelStr);
label = Label.ADPS;
valueString = labelStr.substring(Label.ADPS.name().length());
} else {
final String error = String.format("The label '%s' is unknown", labelStr);
throw new InvalidFrameException(error);
}
}
Class<?> labelType = label.getType();
Converter converter = LABEL_VALUE_CONVERTERS.get(labelType);
try {
Object value = converter.convert(valueString);
if (value != null) {
frameValues.put(label, value);
}
} catch (ConversionException e) {
final String error = String.format("An error occurred during '%s' value conversion",
valueString);
throw new InvalidFrameException(error, e);
}
Label label;
try {
label = Label.valueOf(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:
// ADPS032
logger.warn("Try to auto repair malformed ADPS groupLine '{}'", labelStr);
label = Label.ADPS;
valueString = labelStr.substring(Label.ADPS.name().length());
} else {
final String error = String.format("The label '%s' is unknown", labelStr);
throw new InvalidFrameException(error);
}
}
return frameValues;
frame.put(label, valueString);
}
});
try {
logger.debug("reading data frame...");
logger.trace("readingFrameTimeoutInUs = {}", readingFrameTimeoutInUs);
Map<Label, Object> frameValues = nextFrameFuture.get(readingFrameTimeoutInUs, TimeUnit.MICROSECONDS);
// build the frame from map values
final Frame frame = buildFrame(frameValues);
frame.setTimestamp(LocalDate.now());
frame.setId(UUID.randomUUID());
return frame;
} catch (InterruptedException e) {
logger.debug("Got interrupted exception", e);
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
} catch (ExecutionException e) {
rethrowTaskExecutionException(e);
}
return null;
}
public long getWaitNextHeaderFrameTimeoutInUs() {
return waitNextHeaderFrameTimeoutInUs;
}
public void setWaitNextHeaderFrameTimeoutInUs(long waitNextHeaderFrameTimeoutInUs) {
this.waitNextHeaderFrameTimeoutInUs = waitNextHeaderFrameTimeoutInUs;
}
public long getReadingFrameTimeoutInUs() {
return readingFrameTimeoutInUs;
}
public void setReadingFrameTimeoutInUs(long readingFrameTimeoutInUs) {
this.readingFrameTimeoutInUs = readingFrameTimeoutInUs;
return frame;
}
public boolean isAutoRepairInvalidADPSgroupLine() {
@ -314,377 +156,4 @@ public class TeleinfoInputStream extends InputStream {
// A new teleinfo trame begin with '3' and '2' bytes (END OF TEXT et START OF TEXT)
return (line != null && line.length() > 1 && line.codePointAt(0) == 3 && line.codePointAt(1) == 2);
}
private Frame buildFrame(final Map<Label, Object> frameValues) throws InvalidFrameException {
if (frameValues.containsKey(Label.IINST1)) {
if (frameValues.containsKey(Label.IMAX1)) {
return buildFrameCbetmLong(frameValues);
} else {
return buildFrameCbetmShort(frameValues);
}
} else if (frameValues.containsKey(Label.PAPP)) {
return buildFrameCbemmEvolutionIcc(frameValues);
} else {
return buildFrameCbemm(frameValues);
}
}
private FrameCbetmLong buildFrameCbetmLong(final Map<Label, Object> frameValues) throws InvalidFrameException {
logger.trace("buildFrameCbetmLong(Map<Label, Object>) [start]");
final FrameCbetmLong frameCbetm;
String optionTarif = getRequiredLabelValue(Label.OPTARIF, frameValues);
if ("BASE".equals(optionTarif)) {
frameCbetm = buildFrameCbetmLongBaseOption(frameValues);
} else if ("HC..".equals(optionTarif)) {
frameCbetm = buildFrameCbetmLongHcOption(frameValues);
} else if ("EJP.".equals(optionTarif)) {
frameCbetm = buildFrameCbetmLongEjpOption(frameValues);
} else if (optionTarif.startsWith("BBR") && optionTarif.length() == 4) {
ProgrammeCircuit1 prgCircuit1 = convertProgrammeCircuit1(optionTarif.charAt(3));
ProgrammeCircuit2 prgCircuit2 = convertProgrammeCircuit2(optionTarif.charAt(3));
frameCbetm = buildFrameCbetmLongTempoOption(frameValues, prgCircuit1, prgCircuit2);
} else {
final String error = String.format("The option Tarif '%s' is not supported", optionTarif);
throw new InvalidFrameException(error);
}
logger.trace("buildFrameCbetmLong(Map<Label, Object>) [end]");
return frameCbetm;
}
private void setCbetmCommonFrameFields(final FrameCbetmLong frame, final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("setCbetmCommonFrameFields(Frame, Map<Label, Object>) [start]");
frame.setAdco(getRequiredLabelValue(Label.ADCO, frameValues));
frame.setIsousc(getRequiredLabelValue(Label.ISOUSC, frameValues));
frame.setIinst1(getRequiredLabelValue(Label.IINST1, frameValues));
frame.setIinst2(getRequiredLabelValue(Label.IINST2, frameValues));
frame.setIinst3(getRequiredLabelValue(Label.IINST3, frameValues));
frame.setImax1(getRequiredLabelValue(Label.IMAX1, frameValues));
frame.setImax2(getRequiredLabelValue(Label.IMAX2, frameValues));
frame.setImax3(getRequiredLabelValue(Label.IMAX3, frameValues));
frame.setPtec(getRequiredLabelValue(Label.PTEC, frameValues));
frame.setPmax(getRequiredLabelValue(Label.PMAX, frameValues));
frame.setPapp(getRequiredLabelValue(Label.PAPP, frameValues));
frame.setMotdetat(getRequiredLabelValue(Label.MOTDETAT, frameValues));
frame.setPpot(getRequiredLabelValue(Label.PPOT, frameValues));
logger.trace("setCbetmCommonFrameFields(Frame, Map<Label, Object>) [end]");
}
private FrameCbetmLongBaseOption buildFrameCbetmLongBaseOption(final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("buildFrameCbetmBaseOption(Map<Label, Object>) [start]");
FrameCbetmLongBaseOption frame = new FrameCbetmLongBaseOption();
setCbetmCommonFrameFields(frame, frameValues);
setFrameBaseOptionFields(frame, frameValues);
logger.trace("buildFrameCbetmBaseOption(Map<Label, Object>) [end]");
return frame;
}
private FrameCbetmLongHcOption buildFrameCbetmLongHcOption(final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("buildFrameCbetmHcOption(Map<Label, Object>) [start]");
FrameCbetmLongHcOption frame = new FrameCbetmLongHcOption();
setCbetmCommonFrameFields(frame, frameValues);
setFrameHcOptionFields(frame, frameValues);
logger.trace("buildFrameCbetmHcOption(Map<Label, Object>) [end]");
return frame;
}
private FrameCbetmLongEjpOption buildFrameCbetmLongEjpOption(final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("buildFrameCbetmEjpOption(Map<Label, Object>) [start]");
FrameCbetmLongEjpOption frame = new FrameCbetmLongEjpOption();
setCbetmCommonFrameFields(frame, frameValues);
setFrameEjpOptionFields(frame, frameValues);
logger.trace("buildFrameCbetmEjpOption(Map<Label, Object>) [end]");
return frame;
}
private FrameCbetmLongTempoOption buildFrameCbetmLongTempoOption(final Map<Label, Object> frameValues,
ProgrammeCircuit1 prgCircuit1, ProgrammeCircuit2 prgCircuit2) throws InvalidFrameException {
logger.trace("buildFrameCbetmTempoOption(Map<Label, Object>) [start]");
FrameCbetmLongTempoOption frame = new FrameCbetmLongTempoOption();
setCbetmCommonFrameFields(frame, frameValues);
setFrameTempoOptionFields(frame, frameValues, prgCircuit1, prgCircuit2);
logger.trace("buildFrameCbetmTempoOption(Map<Label, Object>) [end]");
return frame;
}
private FrameCbetmShort buildFrameCbetmShort(final Map<Label, Object> frameValues) throws InvalidFrameException {
logger.trace("buildFrameCbetmShort(Map<Label, Object>) [start]");
FrameCbetmShort frame = new FrameCbetmShort();
frame.setAdco(getRequiredLabelValue(Label.ADCO, frameValues));
frame.setIinst1(getRequiredLabelValue(Label.IINST1, frameValues));
frame.setIinst2(getRequiredLabelValue(Label.IINST2, frameValues));
frame.setIinst3(getRequiredLabelValue(Label.IINST3, frameValues));
frame.setAdir1(getOptionalLabelValue(Label.ADIR1, frameValues));
frame.setAdir2(getOptionalLabelValue(Label.ADIR2, frameValues));
frame.setAdir3(getOptionalLabelValue(Label.ADIR3, frameValues));
logger.trace("buildFrameCbetmShort(Map<Label, Object>) [end]");
return frame;
}
private FrameCbemm buildFrameCbemm(final Map<Label, Object> frameValues) throws InvalidFrameException {
logger.trace("buildFrameCbemm(Map<Label, Object>) [start]");
final FrameCbemm frameCbemm;
String optionTarif = getRequiredLabelValue(Label.OPTARIF, frameValues);
if ("BASE".equals(optionTarif)) {
frameCbemm = buildFrameCbemmBaseOption(frameValues);
} else if ("HC..".equals(optionTarif)) {
frameCbemm = buildFrameCbemmHcOption(frameValues);
} else if ("EJP.".equals(optionTarif)) {
frameCbemm = buildFrameCbemmEjpOption(frameValues);
} else if (optionTarif.startsWith("BBR") && optionTarif.length() == 4) {
ProgrammeCircuit1 prgCircuit1 = convertProgrammeCircuit1(optionTarif.charAt(3));
ProgrammeCircuit2 prgCircuit2 = convertProgrammeCircuit2(optionTarif.charAt(3));
frameCbemm = buildFrameCbemmTempoOption(frameValues, prgCircuit1, prgCircuit2);
} else {
final String error = String.format("The option Tarif '%s' is not supported", optionTarif);
throw new InvalidFrameException(error);
}
logger.trace("buildFrameCbemm(Map<Label, Object>) [end]");
return frameCbemm;
}
private void setCbemmCommonFrameFields(final FrameCbemm frame, final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("setCbemmCommonFrameFields(Frame, Map<Label, Object>) [start]");
frame.setAdco(getRequiredLabelValue(Label.ADCO, frameValues));
frame.setIsousc(getRequiredLabelValue(Label.ISOUSC, frameValues));
frame.setIinst(getRequiredLabelValue(Label.IINST, frameValues));
frame.setImax(getOptionalLabelValue(Label.IMAX, frameValues));
frame.setPtec(getRequiredLabelValue(Label.PTEC, frameValues));
frame.setAdps(getOptionalLabelValue(Label.ADPS, frameValues));
frame.setMotdetat(getRequiredLabelValue(Label.MOTDETAT, frameValues));
logger.trace("setCbemmCommonFrameFields(Frame, Map<Label, Object>) [end]");
}
private FrameCbemmBaseOption buildFrameCbemmBaseOption(final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("buildFrameCbemmBaseOption(Map<Label, Object>) [start]");
FrameCbemmBaseOption frame = new FrameCbemmBaseOption();
setCbemmCommonFrameFields(frame, frameValues);
setFrameBaseOptionFields(frame, frameValues);
logger.trace("buildFrameCbemmBaseOption(Map<Label, Object>) [end]");
return frame;
}
private FrameCbemmHcOption buildFrameCbemmHcOption(final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("buildFrameCbemmHcOption(Map<Label, Object>) [start]");
FrameCbemmHcOption frame = new FrameCbemmHcOption();
setCbemmCommonFrameFields(frame, frameValues);
setFrameHcOptionFields(frame, frameValues);
logger.trace("buildFrameCbemmHcOption(Map<Label, Object>) [end]");
return frame;
}
private FrameCbemmEjpOption buildFrameCbemmEjpOption(final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("buildFrameCbemmEjpOption(Map<Label, Object>) [start]");
FrameCbemmEjpOption frame = new FrameCbemmEjpOption();
setCbemmCommonFrameFields(frame, frameValues);
setFrameEjpOptionFields(frame, frameValues);
logger.trace("buildFrameCbemmEjpOption(Map<Label, Object>) [end]");
return frame;
}
private FrameCbemmTempoOption buildFrameCbemmTempoOption(final Map<Label, Object> frameValues,
ProgrammeCircuit1 prgCircuit1, ProgrammeCircuit2 prgCircuit2) throws InvalidFrameException {
logger.trace("buildFrameCbemmTempoOption(Map<Label, Object>) [start]");
FrameCbemmTempoOption frame = new FrameCbemmTempoOption();
setCbemmCommonFrameFields(frame, frameValues);
setFrameTempoOptionFields(frame, frameValues, prgCircuit1, prgCircuit2);
logger.trace("buildFrameCbemmTempoOption(Map<Label, Object>) [end]");
return frame;
}
private FrameCbemmEvolutionIcc buildFrameCbemmEvolutionIcc(final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("buildFrameCbemmEvolutionIcc(Map<Label, Object>) [start]");
final FrameCbemmEvolutionIcc frameCbemmEvoIcc;
String optionTarif = getRequiredLabelValue(Label.OPTARIF, frameValues);
if ("BASE".equals(optionTarif)) {
frameCbemmEvoIcc = buildFrameCbemmEvolutionIccBaseOption(frameValues);
} else if ("HC..".equals(optionTarif)) {
frameCbemmEvoIcc = buildFrameCbemmEvolutionIccHcOption(frameValues);
} else if ("EJP.".equals(optionTarif)) {
frameCbemmEvoIcc = buildFrameCbemmEvolutionIccEjpOption(frameValues);
} else if (optionTarif.startsWith("BBR") && optionTarif.length() == 4) {
ProgrammeCircuit1 prgCircuit1 = convertProgrammeCircuit1(optionTarif.charAt(3));
ProgrammeCircuit2 prgCircuit2 = convertProgrammeCircuit2(optionTarif.charAt(3));
frameCbemmEvoIcc = buildFrameCbemmEvolutionIccTempoOption(frameValues, prgCircuit1, prgCircuit2);
} else {
final String error = String.format("The option Tarif '%s' is not supported", optionTarif);
throw new InvalidFrameException(error);
}
logger.trace("buildFrameCbemmEvolutionIcc(Map<Label, Object>) [end]");
return frameCbemmEvoIcc;
}
private void setCbemmEvolutionIccCommonFrameFields(final FrameCbemmEvolutionIcc frame,
final Map<Label, Object> frameValues) throws InvalidFrameException {
logger.trace("setCbemmEvolutionIccCommonFrameFields(Frame, Map<Label, Object>) [start]");
setCbemmCommonFrameFields(frame, frameValues);
frame.setPapp(getRequiredLabelValue(Label.PAPP, frameValues));
logger.trace("setCbemmEvolutionIccCommonFrameFields(Frame, Map<Label, Object>) [end]");
}
private FrameCbemmEvolutionIccBaseOption buildFrameCbemmEvolutionIccBaseOption(final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("buildFrameCbemmEvolutionIccBaseOption(Map<Label, Object>) [start]");
FrameCbemmEvolutionIccBaseOption frame = new FrameCbemmEvolutionIccBaseOption();
setCbemmEvolutionIccCommonFrameFields(frame, frameValues);
setFrameBaseOptionFields(frame, frameValues);
logger.trace("buildFrameCbemmEvolutionIccBaseOption(Map<Label, Object>) [end]");
return frame;
}
private FrameCbemmEvolutionIccHcOption buildFrameCbemmEvolutionIccHcOption(final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("buildFrameCbemmEvolutionIccHcOption(Map<Label, Object>) [start]");
FrameCbemmEvolutionIccHcOption frame = new FrameCbemmEvolutionIccHcOption();
setCbemmEvolutionIccCommonFrameFields(frame, frameValues);
setFrameHcOptionFields(frame, frameValues);
logger.trace("buildFrameCbemmEvolutionIccHcOption(Map<Label, Object>) [end]");
return frame;
}
private FrameCbemmEvolutionIccTempoOption buildFrameCbemmEvolutionIccTempoOption(
final Map<Label, Object> frameValues, ProgrammeCircuit1 prgCircuit1, ProgrammeCircuit2 prgCircuit2)
throws InvalidFrameException {
logger.trace("buildFrameCbemmEvolutionIccTempoOption(Map<Label, Object>) [start]");
FrameCbemmEvolutionIccTempoOption frame = new FrameCbemmEvolutionIccTempoOption();
setCbemmEvolutionIccCommonFrameFields(frame, frameValues);
setFrameTempoOptionFields(frame, frameValues, prgCircuit1, prgCircuit2);
logger.trace("buildFrameCbemmEvolutionIccTempoOption(Map<Label, Object>) [end]");
return frame;
}
private FrameCbemmEvolutionIccEjpOption buildFrameCbemmEvolutionIccEjpOption(final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("buildFrameCbemmEvolutionIccEjpOption(Map<Label, Object>) [start]");
FrameCbemmEvolutionIccEjpOption frame = new FrameCbemmEvolutionIccEjpOption();
setCbemmEvolutionIccCommonFrameFields(frame, frameValues);
setFrameEjpOptionFields(frame, frameValues);
logger.trace("buildFrameCbemmEvolutionIccEjpOption(Map<Label, Object>) [end]");
return frame;
}
private void setFrameBaseOptionFields(final FrameBaseOption frameBaseOption, final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("setFrameBaseOptionFields(FrameBaseOption) [start]");
frameBaseOption.setBase(getRequiredLabelValue(Label.BASE, frameValues));
logger.trace("setFrameBaseOptionFields(FrameBaseOption) [end]");
}
private void setFrameHcOptionFields(final FrameHcOption frameHcOption, final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("setFrameHcOptionFields(FrameHcOption) [start]");
frameHcOption.setHchc(getRequiredLabelValue(Label.HCHC, frameValues));
frameHcOption.setHchp(getRequiredLabelValue(Label.HCHP, frameValues));
frameHcOption.setHhphc(getRequiredLabelValue(Label.HHPHC, frameValues));
logger.trace("setFrameHcOptionFields(FrameHcOption) [end]");
}
private void setFrameEjpOptionFields(final FrameEjpOption frameEjpOption, final Map<Label, Object> frameValues)
throws InvalidFrameException {
logger.trace("setFrameEjpOptionFields(FrameEjpOption) [start]");
frameEjpOption.setEjphn(getRequiredLabelValue(Label.EJPHN, frameValues));
frameEjpOption.setEjphpm(getRequiredLabelValue(Label.EJPHPM, frameValues));
frameEjpOption.setPejp(getOptionalLabelValue(Label.PEJP, frameValues));
logger.trace("setFrameEjpOptionFields(FrameEjpOption) [end]");
}
private void setFrameTempoOptionFields(final FrameTempoOption frameTempoOption,
final Map<Label, Object> frameValues, ProgrammeCircuit1 prgCircuit1, ProgrammeCircuit2 prgCircuit2)
throws InvalidFrameException {
logger.trace("setFrameTempoOptionFields(FrameTempoOption) [start]");
frameTempoOption.setBbrhpjr(getRequiredLabelValue(Label.BBRHPJR, frameValues));
frameTempoOption.setBbrhcjr(getRequiredLabelValue(Label.BBRHCJR, frameValues));
frameTempoOption.setBbrhpjw(getRequiredLabelValue(Label.BBRHPJW, frameValues));
frameTempoOption.setBbrhcjw(getRequiredLabelValue(Label.BBRHCJW, frameValues));
frameTempoOption.setBbrhpjb(getRequiredLabelValue(Label.BBRHPJB, frameValues));
frameTempoOption.setBbrhcjb(getRequiredLabelValue(Label.BBRHCJB, frameValues));
frameTempoOption.setDemain(getOptionalLabelValue(Label.DEMAIN, frameValues));
frameTempoOption.setHhphc(getRequiredLabelValue(Label.HHPHC, frameValues));
frameTempoOption.setProgrammeCircuit1(prgCircuit1);
frameTempoOption.setProgrammeCircuit2(prgCircuit2);
logger.trace("setFrameTempoOptionFields(FrameTempoOption) [end]");
}
@SuppressWarnings("unchecked")
private <T> T getRequiredLabelValue(Label label, final Map<Label, Object> frameValues)
throws InvalidFrameException {
if (!frameValues.containsKey(label)) {
final String error = String.format("The required label '%1$s' is missing in frame", label);
throw new InvalidFrameException(error);
}
return (T) frameValues.get(label);
}
@SuppressWarnings("unchecked")
private <T> T getOptionalLabelValue(Label label, final Map<Label, Object> frameValues) {
return (T) frameValues.get(label);
}
private ProgrammeCircuit1 convertProgrammeCircuit1(char value) {
String prgCircuit1 = computeProgrammeCircuitBinaryValue(value).substring(3, 5);
switch (prgCircuit1) {
case "01":
return ProgrammeCircuit1.A;
case "10":
return ProgrammeCircuit1.B;
case "11":
return ProgrammeCircuit1.C;
default:
final String error = String.format("Programme circuit 1 '%s' is unknown", prgCircuit1);
throw new IllegalStateException(error);
}
}
private ProgrammeCircuit2 convertProgrammeCircuit2(char value) {
String prgCircuit2 = computeProgrammeCircuitBinaryValue(value).substring(5, 8);
switch (prgCircuit2) {
case "000":
return ProgrammeCircuit2.P0;
case "001":
return ProgrammeCircuit2.P1;
case "010":
return ProgrammeCircuit2.P2;
case "011":
return ProgrammeCircuit2.P3;
case "100":
return ProgrammeCircuit2.P4;
case "101":
return ProgrammeCircuit2.P5;
case "110":
return ProgrammeCircuit2.P6;
case "111":
return ProgrammeCircuit2.P7;
default:
final String error = String.format("Programme circuit 2 '%s' is unknown", prgCircuit2);
throw new IllegalStateException(error);
}
}
private String computeProgrammeCircuitBinaryValue(char value) {
return String.format("%8s", Integer.toBinaryString(value)).replace(' ', '0');
}
private void rethrowTaskExecutionException(ExecutionException e)
throws InvalidFrameException, IOException, TimeoutException {
Throwable cause = e.getCause();
if (cause instanceof InvalidFrameException) {
throw (InvalidFrameException) cause;
} else if (cause instanceof IOException) {
throw (IOException) cause;
} else if (cause instanceof TimeoutException) {
throw (TimeoutException) cause;
} else {
throw new IllegalStateException(e);
}
}
}

View File

@ -1,43 +0,0 @@
/**
* 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 org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link ConversionException} class defines a conversion exception.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public class ConversionException extends Exception {
private static final long serialVersionUID = -1109821041874271681L;
private static final String ERROR_MESSAGE = "Unable to convert '%1$s' value";
private String valueToConvert;
public ConversionException(String valueToConvert) {
this(valueToConvert, null);
}
public ConversionException(String valueToConvert, @Nullable Throwable cause) {
super(String.format(ERROR_MESSAGE, valueToConvert), cause);
this.valueToConvert = valueToConvert;
}
public String getValueToConvert() {
return valueToConvert;
}
}

View File

@ -26,7 +26,7 @@ public class InvalidFrameException extends Exception {
private static final long serialVersionUID = 4729529258857792922L;
private Date timestamp;
private final Date timestamp;
public InvalidFrameException() {
timestamp = new Date();

View File

@ -12,10 +12,12 @@
*/
package org.openhab.binding.teleinfo.internal.reader.io.serialport;
import static org.openhab.binding.teleinfo.internal.TeleinfoBindingConstants.*;
import javax.measure.Unit;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.common.FrameTempoOption.CouleurDemain;
import org.openhab.binding.teleinfo.internal.dto.common.Hhphc;
import org.openhab.binding.teleinfo.internal.dto.common.Ptec;
import org.openhab.core.library.unit.Units;
/**
* The {@link Label} enum defines all Teleinfo labels and their format.
@ -25,56 +27,60 @@ import org.openhab.binding.teleinfo.internal.dto.common.Ptec;
@NonNullByDefault
public enum Label {
ADCO(String.class, 12),
OPTARIF(String.class, 4),
BASE(Integer.class, 9),
HCHC(Integer.class, 9),
HCHP(Integer.class, 9),
EJPHN(Integer.class, 9),
EJPHPM(Integer.class, 9),
GAZ(Integer.class, 7),
AUTRE(Integer.class, 7),
PTEC(Ptec.class, 4),
MOTDETAT(String.class, 6),
ISOUSC(Integer.class, 2),
IINST(Integer.class, 3),
IINST1(Integer.class, 3),
IINST2(Integer.class, 3),
IINST3(Integer.class, 3),
ADIR1(Integer.class, 3),
ADIR2(Integer.class, 3),
ADIR3(Integer.class, 3),
ADPS(Integer.class, 3),
IMAX(Integer.class, 3),
IMAX1(Integer.class, 3),
IMAX2(Integer.class, 3),
IMAX3(Integer.class, 3),
PMAX(Integer.class, 5),
PPOT(String.class, 2),
HHPHC(Hhphc.class, 1),
PAPP(Integer.class, 5),
BBRHCJB(Integer.class, 9),
BBRHPJB(Integer.class, 9),
BBRHCJW(Integer.class, 9),
BBRHPJW(Integer.class, 9),
BBRHCJR(Integer.class, 9),
BBRHPJR(Integer.class, 9),
PEJP(Integer.class, 2),
DEMAIN(CouleurDemain.class, 4);
ADCO(ValueType.STRING, NOT_A_CHANNEL, Units.ONE),
OPTARIF(ValueType.STRING, NOT_A_CHANNEL, Units.ONE),
BASE(ValueType.INTEGER, CHANNEL_BASE_FRAME_BASE, Units.WATT_HOUR),
HCHC(ValueType.INTEGER, CHANNEL_HC_FRAME_HCHC, Units.WATT_HOUR),
HCHP(ValueType.INTEGER, CHANNEL_HC_FRAME_HCHP, Units.WATT_HOUR),
EJPHN(ValueType.INTEGER, CHANNEL_EJP_FRAME_EJPHN, Units.WATT_HOUR),
EJPHPM(ValueType.INTEGER, CHANNEL_EJP_FRAME_EJPHN, Units.WATT_HOUR),
PTEC(ValueType.STRING, CHANNEL_PTEC, Units.ONE),
MOTDETAT(ValueType.STRING, CHANNEL_MOTDETAT, Units.AMPERE),
ISOUSC(ValueType.INTEGER, CHANNEL_ISOUSC, Units.AMPERE),
IINST(ValueType.INTEGER, CHANNEL_CBEMM_IINST, Units.AMPERE),
IINST1(ValueType.INTEGER, CHANNEL_CBETM_IINST1, Units.AMPERE),
IINST2(ValueType.INTEGER, CHANNEL_CBETM_IINST2, Units.AMPERE),
IINST3(ValueType.INTEGER, CHANNEL_CBETM_IINST3, Units.AMPERE),
ADIR1(ValueType.INTEGER, CHANNEL_CBETM_SHORT_ADIR1, Units.AMPERE),
ADIR2(ValueType.INTEGER, CHANNEL_CBETM_SHORT_ADIR2, Units.AMPERE),
ADIR3(ValueType.INTEGER, CHANNEL_CBETM_SHORT_ADIR3, Units.AMPERE),
ADPS(ValueType.INTEGER, CHANNEL_CBEMM_ADPS, Units.AMPERE),
IMAX(ValueType.INTEGER, CHANNEL_CBEMM_IMAX, Units.AMPERE),
IMAX1(ValueType.INTEGER, CHANNEL_CBETM_LONG_IMAX1, Units.AMPERE),
IMAX2(ValueType.INTEGER, CHANNEL_CBETM_LONG_IMAX2, Units.AMPERE),
IMAX3(ValueType.INTEGER, CHANNEL_CBETM_LONG_IMAX3, Units.AMPERE),
PMAX(ValueType.INTEGER, CHANNEL_CBETM_LONG_PMAX, Units.WATT),
HHPHC(ValueType.STRING, CHANNEL_HHPHC, Units.ONE),
PPOT(ValueType.STRING, CHANNEL_CBETM_LONG_PPOT, Units.ONE),
PAPP(ValueType.INTEGER, CHANNEL_PAPP, Units.VOLT_AMPERE),
BBRHCJB(ValueType.INTEGER, CHANNEL_TEMPO_FRAME_BBRHCJB, Units.WATT_HOUR),
BBRHPJB(ValueType.INTEGER, CHANNEL_TEMPO_FRAME_BBRHPJB, Units.WATT_HOUR),
BBRHCJW(ValueType.INTEGER, CHANNEL_TEMPO_FRAME_BBRHCJW, Units.WATT_HOUR),
BBRHPJW(ValueType.INTEGER, CHANNEL_TEMPO_FRAME_BBRHPJW, Units.WATT_HOUR),
BBRHCJR(ValueType.INTEGER, CHANNEL_TEMPO_FRAME_BBRHCJR, Units.WATT_HOUR),
BBRHPJR(ValueType.INTEGER, CHANNEL_TEMPO_FRAME_BBRHPJR, Units.WATT_HOUR),
PEJP(ValueType.INTEGER, CHANNEL_EJP_FRAME_PEJP, Units.MINUTE),
DEMAIN(ValueType.STRING, CHANNEL_TEMPO_FRAME_DEMAIN, Units.ONE);
private Class<?> type;
private int size;
private ValueType type;
private String channelName;
private Unit<?> unit;
Label(Class<?> type, int size) {
Label(ValueType type, String channelName, Unit<?> unit) {
this.type = type;
this.size = size;
this.channelName = channelName;
this.unit = unit;
}
public Class<?> getType() {
public ValueType getType() {
return type;
}
public int getSize() {
return size;
public String getChannelName() {
return channelName;
}
public Unit<?> getUnit() {
return unit;
}
}

View File

@ -10,24 +10,15 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.teleinfo.internal.dto.common;
package org.openhab.binding.teleinfo.internal.reader.io.serialport;
/**
* The {@link FrameHcOption} interface defines common attributes for HC option.
* Defines all the type of values
*
* @author Olivier MARCEAU - Initial contribution
*
* @author Nicolas SIBERIL - Initial contribution
*/
public interface FrameHcOption {
int getHchc();
void setHchc(int hchc);
int getHchp();
void setHchp(int hchp);
Hhphc getHhphc();
void setHhphc(Hhphc hhphc);
public enum ValueType {
INTEGER,
STRING
}

View File

@ -1,28 +0,0 @@
/**
* 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.converter;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.ConversionException;
/**
* The {@link Converter} interface defines a converter to translate a Teleinfo String value into Java object.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public interface Converter {
public @Nullable Object convert(String value) throws ConversionException;
}

View File

@ -1,61 +0,0 @@
/**
* 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.converter;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.dto.common.FrameTempoOption.CouleurDemain;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.ConversionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link CouleurDemainConverter} class defines a converter to translate a Teleinfo String value into
* {@link org.openhab.binding.teleinfo.internal.dto.common.Ptec} object.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public class CouleurDemainConverter implements Converter {
private final Logger logger = LoggerFactory.getLogger(CouleurDemainConverter.class);
@Override
public @Nullable Object convert(String value) throws ConversionException {
logger.debug("convert(String) [start]");
if (logger.isTraceEnabled()) {
logger.trace("value = {}", value);
}
CouleurDemain convertedValue = null;
switch (value) {
case "----":
// convertedValue = null;
break;
case "BLEU":
convertedValue = CouleurDemain.Bleu;
break;
case "BLAN":
convertedValue = CouleurDemain.Blanc;
break;
case "ROUG":
convertedValue = CouleurDemain.Rouge;
break;
default:
throw new ConversionException(value);
}
logger.debug("convert(String) [end]");
return convertedValue;
}
}

View File

@ -1,48 +0,0 @@
/**
* 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.converter;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.ConversionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link FloatConverter} class defines a converter to translate a Teleinfo String value into Float object.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public class FloatConverter implements Converter {
private final Logger logger = LoggerFactory.getLogger(FloatConverter.class);
@Override
public @Nullable Object convert(String value) throws ConversionException {
logger.debug("convert(String) [start]");
if (logger.isTraceEnabled()) {
logger.trace("value = {}", value);
}
Object convertedValue = null;
try {
convertedValue = Float.parseFloat(value);
} catch (NumberFormatException e) {
throw new ConversionException(value, e);
}
logger.debug("convert(String) [end]");
return convertedValue;
}
}

View File

@ -1,64 +0,0 @@
/**
* 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.converter;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.dto.common.Hhphc;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.ConversionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link HhphcConverter} class defines a converter to translate a Teleinfo String value into
* {@link Hhphc} object.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public class HhphcConverter implements Converter {
private final Logger logger = LoggerFactory.getLogger(HhphcConverter.class);
@Override
public @Nullable Object convert(String value) throws ConversionException {
logger.debug("convert(String) [start]");
if (logger.isTraceEnabled()) {
logger.trace("value = {}", value);
}
Hhphc convertedValue = null;
switch (value) {
case "A":
convertedValue = Hhphc.A;
break;
case "C":
convertedValue = Hhphc.C;
break;
case "D":
convertedValue = Hhphc.D;
break;
case "E":
convertedValue = Hhphc.E;
break;
case "Y":
convertedValue = Hhphc.Y;
break;
default:
throw new ConversionException(value);
}
logger.debug("convert(String) [end]");
return convertedValue;
}
}

View File

@ -1,48 +0,0 @@
/**
* 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.converter;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.ConversionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link IntegerConverter} class defines a converter to translate a Teleinfo String value into Integer object.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public class IntegerConverter implements Converter {
private final Logger logger = LoggerFactory.getLogger(IntegerConverter.class);
@Override
public @Nullable Object convert(String value) throws ConversionException {
logger.debug("convert(String) [start]");
if (logger.isTraceEnabled()) {
logger.trace("value = {}", value);
}
Object convertedValue = null;
try {
convertedValue = Integer.parseInt(value, 10);
} catch (NumberFormatException e) {
throw new ConversionException(value, e);
}
logger.debug("convert(String) [end]");
return convertedValue;
}
}

View File

@ -1,82 +0,0 @@
/**
* 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.converter;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.dto.common.Ptec;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.ConversionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link PtecConverter} class defines a converter to translate a Teleinfo String value into
* {@link Ptec} object.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public class PtecConverter implements Converter {
private final Logger logger = LoggerFactory.getLogger(PtecConverter.class);
@Override
public @Nullable Object convert(String value) throws ConversionException {
logger.debug("convert(String) [start]");
if (logger.isTraceEnabled()) {
logger.trace("value = {}", value);
}
Ptec convertedValue = null;
switch (value) {
case "TH..":
convertedValue = Ptec.TH;
break;
case "HC..":
convertedValue = Ptec.HC;
break;
case "HP..":
convertedValue = Ptec.HP;
break;
case "HN..":
convertedValue = Ptec.HN;
break;
case "PM..":
convertedValue = Ptec.PM;
break;
case "HCJB":
convertedValue = Ptec.HCJB;
break;
case "HCJW":
convertedValue = Ptec.HCJW;
break;
case "HCJR":
convertedValue = Ptec.HCJR;
break;
case "HPJB":
convertedValue = Ptec.HPJB;
break;
case "HPJW":
convertedValue = Ptec.HPJW;
break;
case "HPJR":
convertedValue = Ptec.HPJR;
break;
default:
throw new ConversionException(value);
}
logger.debug("convert(String) [end]");
return convertedValue;
}
}

View File

@ -1,41 +0,0 @@
/**
* 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.converter;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.ConversionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link StringConverter} class defines a converter to translate a Teleinfo String value into String object.
*
* @author Nicolas SIBERIL - Initial contribution
*/
@NonNullByDefault
public class StringConverter implements Converter {
private final Logger logger = LoggerFactory.getLogger(StringConverter.class);
@Override
public @Nullable Object convert(String value) throws ConversionException {
logger.debug("convert(String) [start]");
if (logger.isTraceEnabled()) {
logger.trace("value = {}", value);
}
logger.debug("convert(String) [end]");
return value;
}
}

View File

@ -13,12 +13,10 @@
package org.openhab.binding.teleinfo.internal.serial;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeoutException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.data.Frame;
import org.openhab.binding.teleinfo.internal.reader.io.TeleinfoInputStream;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.InvalidFrameException;
import org.openhab.core.io.transport.serial.SerialPort;
@ -33,52 +31,35 @@ import org.slf4j.LoggerFactory;
@NonNullByDefault
public class TeleinfoReceiveThread extends Thread {
private static final int SERIAL_PORT_DELAY_RETRY_IN_SECONDS = 60;
private final Logger logger = LoggerFactory.getLogger(TeleinfoReceiveThread.class);
private SerialPort serialPort;
private @Nullable TeleinfoReceiveThreadListener listener;
private boolean autoRepairInvalidADPSgroupLine;
private ExecutorService executorService;
public TeleinfoReceiveThread(SerialPort serialPort, final TeleinfoSerialControllerHandler listener,
boolean autoRepairInvalidADPSgroupLine, ExecutorService scheduler) {
boolean autoRepairInvalidADPSgroupLine) {
super("OH-binding-TeleinfoReceiveThread-" + listener.getThing().getUID().getId());
setDaemon(true);
this.serialPort = serialPort;
this.listener = listener;
this.autoRepairInvalidADPSgroupLine = autoRepairInvalidADPSgroupLine;
this.executorService = scheduler;
}
@Override
public void run() {
try (TeleinfoInputStream teleinfoStream = new TeleinfoInputStream(serialPort.getInputStream(),
TeleinfoInputStream.DEFAULT_TIMEOUT_NEXT_HEADER_FRAME_US * 100,
TeleinfoInputStream.DEFAULT_TIMEOUT_READING_FRAME_US * 100, autoRepairInvalidADPSgroupLine,
executorService)) {
autoRepairInvalidADPSgroupLine)) {
while (!interrupted()) {
TeleinfoReceiveThreadListener listener = this.listener;
if (listener != null) {
try {
Frame nextFrame = teleinfoStream.readNextFrame();
if (nextFrame != null)
listener.onFrameReceived(this, nextFrame);
listener.onFrameReceived(nextFrame);
} catch (InvalidFrameException e) {
logger.warn("Got invalid frame. Detail: \"{}\"", e.getLocalizedMessage());
listener.onInvalidFrameReceived(this, e);
} catch (TimeoutException e) {
logger.warn("Got timeout during frame reading", e);
logger.warn("Retry in progress. Next retry in {} seconds...",
SERIAL_PORT_DELAY_RETRY_IN_SECONDS);
listener.continueOnReadNextFrameTimeoutException();
try {
Thread.sleep(SERIAL_PORT_DELAY_RETRY_IN_SECONDS * 1000);
} catch (InterruptedException e1) {
break;
}
} catch (IOException e) {
logger.warn("Got I/O exception. Detail: \"{}\"", e.getLocalizedMessage(), e);
listener.onSerialPortInputStreamIOException(this, e);

View File

@ -15,7 +15,7 @@ package org.openhab.binding.teleinfo.internal.serial;
import java.io.IOException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.data.Frame;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.InvalidFrameException;
/**
@ -26,7 +26,7 @@ import org.openhab.binding.teleinfo.internal.reader.io.serialport.InvalidFrameEx
@NonNullByDefault
public interface TeleinfoReceiveThreadListener {
void onFrameReceived(final TeleinfoReceiveThread receiveThread, final Frame frame);
void onFrameReceived(final Frame frame);
void onInvalidFrameReceived(final TeleinfoReceiveThread receiveThread, final InvalidFrameException error);

View File

@ -20,7 +20,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.data.Frame;
import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractControllerHandler;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.InvalidFrameException;
import org.openhab.core.io.transport.serial.PortInUseException;
@ -103,7 +103,7 @@ public class TeleinfoSerialControllerHandler extends TeleinfoAbstractControllerH
}
@Override
public void onFrameReceived(TeleinfoReceiveThread receiveThread, Frame frame) {
public void onFrameReceived(Frame frame) {
updateStatus(ThingStatus.ONLINE);
fireOnFrameReceivedEvent(frame);
}
@ -161,7 +161,7 @@ public class TeleinfoSerialControllerHandler extends TeleinfoAbstractControllerH
}
logger.debug("Starting receive thread");
TeleinfoReceiveThread receiveThread = new TeleinfoReceiveThread(commPort, this,
config.autoRepairInvalidADPSgroupLine, scheduler);
config.autoRepairInvalidADPSgroupLine);
this.receiveThread = receiveThread;
receiveThread.start();

View File

@ -18,16 +18,9 @@ import java.io.FileInputStream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
import org.openhab.binding.teleinfo.internal.dto.Frame;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccBaseOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccHcOption;
import org.openhab.binding.teleinfo.internal.dto.cbemm.evoicc.FrameCbemmEvolutionIccTempoOption;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongBaseOption;
import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLongEjpOption;
import org.openhab.binding.teleinfo.internal.dto.common.FrameTempoOption.ProgrammeCircuit1;
import org.openhab.binding.teleinfo.internal.dto.common.FrameTempoOption.ProgrammeCircuit2;
import org.openhab.binding.teleinfo.internal.dto.common.Hhphc;
import org.openhab.binding.teleinfo.internal.dto.common.Ptec;
import org.openhab.binding.teleinfo.internal.data.Frame;
import org.openhab.binding.teleinfo.internal.data.FrameType;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.Label;
import org.openhab.binding.teleinfo.util.TestUtils;
/**
@ -36,144 +29,134 @@ import org.openhab.binding.teleinfo.util.TestUtils;
*/
@NonNullByDefault
public class TeleinfoInputStreamTest {
private static final int TIMEOUT_US = 5000000;
@Test
public void testReadNextFrameCbetmBase1() throws Exception {
try (TeleinfoInputStream in = new TeleinfoInputStream(
new FileInputStream(TestUtils.getTestFile("cbetm-base-option-1.raw")), TIMEOUT_US, TIMEOUT_US, false)) {
new FileInputStream(TestUtils.getTestFile("cbetm-base-option-1.raw")), false)) {
Frame frame = in.readNextFrame();
assertNotNull(frame);
assertEquals(FrameCbetmLongBaseOption.class, frame.getClass());
FrameCbetmLongBaseOption frameCbetmLongBaseOption = (FrameCbetmLongBaseOption) frame;
assertEquals("XXXXXXXXXXXX", frameCbetmLongBaseOption.getAdco());
assertEquals(20, frameCbetmLongBaseOption.getIsousc());
assertEquals(1181243, frameCbetmLongBaseOption.getBase());
assertEquals(Ptec.TH, frameCbetmLongBaseOption.getPtec());
assertEquals(0, frameCbetmLongBaseOption.getIinst1());
assertEquals(2, frameCbetmLongBaseOption.getIinst2());
assertEquals(0, frameCbetmLongBaseOption.getIinst3());
assertEquals(26, frameCbetmLongBaseOption.getImax1().intValue());
assertEquals(18, frameCbetmLongBaseOption.getImax2().intValue());
assertEquals(27, frameCbetmLongBaseOption.getImax3().intValue());
assertEquals(7990, frameCbetmLongBaseOption.getPmax());
assertEquals(540, frameCbetmLongBaseOption.getPapp());
assertEquals("00", frameCbetmLongBaseOption.getPpot());
assertEquals(FrameType.CBETM_LONG_BASE, frame.getType());
assertEquals("XXXXXXXXXXXX", frame.get(Label.ADCO));
assertEquals(20, frame.getAsInt(Label.ISOUSC));
assertEquals(1181243, frame.getAsInt(Label.BASE));
assertEquals("TH..", frame.get(Label.PTEC));
assertEquals(0, frame.getAsInt(Label.IINST1));
assertEquals(2, frame.getAsInt(Label.IINST2));
assertEquals(0, frame.getAsInt(Label.IINST3));
assertEquals(26, frame.getAsInt(Label.IMAX1));
assertEquals(18, frame.getAsInt(Label.IMAX2));
assertEquals(27, frame.getAsInt(Label.IMAX3));
assertEquals(7990, frame.getAsInt(Label.PMAX));
assertEquals(540, frame.getAsInt(Label.PAPP));
assertEquals("00", frame.get(Label.PPOT));
}
}
@Test
public void testReadNextFrameCbemmEvoIccHc1() throws Exception {
try (TeleinfoInputStream in = new TeleinfoInputStream(
new FileInputStream(TestUtils.getTestFile("cbemm-evo-icc-hc-option-1.raw")), TIMEOUT_US, TIMEOUT_US,
false)) {
new FileInputStream(TestUtils.getTestFile("cbemm-evo-icc-hc-option-1.raw")), false)) {
Frame frame = in.readNextFrame();
assertNotNull(frame);
assertEquals(FrameCbemmEvolutionIccHcOption.class, frame.getClass());
FrameCbemmEvolutionIccHcOption frameCbemmEvolutionIccHcOption = (FrameCbemmEvolutionIccHcOption) frame;
assertEquals("XXXXXXXXXXXX", frameCbemmEvolutionIccHcOption.getAdco());
assertEquals(30, frameCbemmEvolutionIccHcOption.getIsousc());
assertEquals(6906827, frameCbemmEvolutionIccHcOption.getHchc());
assertEquals(7617931, frameCbemmEvolutionIccHcOption.getHchp());
assertEquals(Ptec.HP, frameCbemmEvolutionIccHcOption.getPtec());
assertEquals(3, frameCbemmEvolutionIccHcOption.getIinst());
assertEquals(44, frameCbemmEvolutionIccHcOption.getImax().intValue());
assertEquals(680, frameCbemmEvolutionIccHcOption.getPapp());
assertNull(frameCbemmEvolutionIccHcOption.getAdps());
assertEquals(Hhphc.A, frameCbemmEvolutionIccHcOption.getHhphc());
assertEquals(FrameType.CBEMM_ICC_HC, frame.getType());
assertEquals("XXXXXXXXXXXX", frame.get(Label.ADCO));
assertEquals(30, frame.getAsInt(Label.ISOUSC));
assertEquals(6906827, frame.getAsInt(Label.HCHC));
assertEquals(7617931, frame.getAsInt(Label.HCHP));
assertEquals("HP..", frame.get(Label.PTEC));
assertEquals(3, frame.getAsInt(Label.IINST));
assertEquals(44, frame.getAsInt(Label.IMAX));
assertEquals(680, frame.getAsInt(Label.PAPP));
assertNull(frame.get(Label.ADPS));
assertEquals("A", frame.get(Label.HHPHC));
}
}
@Test
public void testReadNextFrameCbetmEjp1() throws Exception {
try (TeleinfoInputStream in = new TeleinfoInputStream(
new FileInputStream(TestUtils.getTestFile("cbetm-ejp-option-1.raw")), TIMEOUT_US, TIMEOUT_US, false)) {
new FileInputStream(TestUtils.getTestFile("cbetm-ejp-option-1.raw")), false)) {
Frame frame = in.readNextFrame();
assertNotNull(frame);
assertEquals(FrameCbetmLongEjpOption.class, frame.getClass());
FrameCbetmLongEjpOption frameCbetmLongEjpOption = (FrameCbetmLongEjpOption) frame;
assertEquals("XXXXXXXXXX", frameCbetmLongEjpOption.getAdco());
assertEquals(30, frameCbetmLongEjpOption.getIsousc());
assertEquals(1111111, frameCbetmLongEjpOption.getEjphn());
assertEquals(2222222, frameCbetmLongEjpOption.getEjphpm());
assertNull(frameCbetmLongEjpOption.getPejp());
assertEquals(Ptec.HN, frameCbetmLongEjpOption.getPtec());
assertEquals(10, frameCbetmLongEjpOption.getIinst1());
assertEquals(5, frameCbetmLongEjpOption.getIinst2());
assertEquals(8, frameCbetmLongEjpOption.getIinst3());
assertEquals(38, frameCbetmLongEjpOption.getImax1().intValue());
assertEquals(42, frameCbetmLongEjpOption.getImax2().intValue());
assertEquals(44, frameCbetmLongEjpOption.getImax3().intValue());
assertEquals(17480, frameCbetmLongEjpOption.getPmax());
assertEquals(5800, frameCbetmLongEjpOption.getPapp());
assertEquals("00", frameCbetmLongEjpOption.getPpot());
assertEquals(FrameType.CBETM_LONG_EJP, frame.getType());
assertEquals("XXXXXXXXXX", frame.get(Label.ADCO));
assertEquals(30, frame.getAsInt(Label.ISOUSC));
assertEquals(1111111, frame.getAsInt(Label.EJPHN));
assertEquals(2222222, frame.getAsInt(Label.EJPHPM));
assertNull(frame.get(Label.PEJP));
assertEquals("HN..", frame.get(Label.PTEC));
assertEquals(10, frame.getAsInt(Label.IINST1));
assertEquals(5, frame.getAsInt(Label.IINST2));
assertEquals(8, frame.getAsInt(Label.IINST3));
assertEquals(38, frame.getAsInt(Label.IMAX1));
assertEquals(42, frame.getAsInt(Label.IMAX2));
assertEquals(44, frame.getAsInt(Label.IMAX3));
assertEquals(17480, frame.getAsInt(Label.PMAX));
assertEquals(5800, frame.getAsInt(Label.PAPP));
assertEquals("00", frame.get(Label.PPOT));
}
}
@Test
public void testReadNextFrameCbemmEvoIccTempo1() throws Exception {
try (TeleinfoInputStream in = new TeleinfoInputStream(
new FileInputStream(TestUtils.getTestFile("cbemm-evo-icc-tempo-option-1.raw")), TIMEOUT_US, TIMEOUT_US,
false)) {
new FileInputStream(TestUtils.getTestFile("cbemm-evo-icc-tempo-option-1.raw")), false)) {
Frame frame = in.readNextFrame();
assertNotNull(frame);
assertEquals(FrameCbemmEvolutionIccTempoOption.class, frame.getClass());
FrameCbemmEvolutionIccTempoOption frameCbemmEvolutionIccTempoOption = (FrameCbemmEvolutionIccTempoOption) frame;
assertEquals("XXXXXXXXXXXX", frameCbemmEvolutionIccTempoOption.getAdco());
assertEquals(45, frameCbemmEvolutionIccTempoOption.getIsousc());
assertEquals(2697099, frameCbemmEvolutionIccTempoOption.getBbrhcjb());
assertEquals(3494559, frameCbemmEvolutionIccTempoOption.getBbrhpjb());
assertEquals(41241, frameCbemmEvolutionIccTempoOption.getBbrhcjw());
assertEquals(194168, frameCbemmEvolutionIccTempoOption.getBbrhpjw());
assertEquals(0, frameCbemmEvolutionIccTempoOption.getBbrhcjr());
assertEquals(89736, frameCbemmEvolutionIccTempoOption.getBbrhpjr());
assertEquals(Ptec.HPJR, frameCbemmEvolutionIccTempoOption.getPtec());
assertNull(frameCbemmEvolutionIccTempoOption.getDemain());
assertEquals(3, frameCbemmEvolutionIccTempoOption.getIinst());
assertEquals(37, frameCbemmEvolutionIccTempoOption.getImax().intValue());
assertEquals(620, frameCbemmEvolutionIccTempoOption.getPapp());
assertNull(frameCbemmEvolutionIccTempoOption.getAdps());
assertEquals(Hhphc.Y, frameCbemmEvolutionIccTempoOption.getHhphc());
assertEquals(ProgrammeCircuit1.B, frameCbemmEvolutionIccTempoOption.getProgrammeCircuit1());
assertEquals(ProgrammeCircuit2.P2, frameCbemmEvolutionIccTempoOption.getProgrammeCircuit2());
assertEquals(FrameType.CBEMM_ICC_TEMPO, frame.getType());
assertEquals("XXXXXXXXXXXX", frame.get(Label.ADCO));
assertEquals(45, frame.getAsInt(Label.ISOUSC));
assertEquals(2697099, frame.getAsInt(Label.BBRHCJB));
assertEquals(3494559, frame.getAsInt(Label.BBRHPJB));
assertEquals(41241, frame.getAsInt(Label.BBRHCJW));
assertEquals(194168, frame.getAsInt(Label.BBRHPJW));
assertEquals(0, frame.getAsInt(Label.BBRHCJR));
assertEquals(89736, frame.getAsInt(Label.BBRHPJR));
assertEquals("HPJR", frame.get(Label.PTEC));
assertEquals("----", frame.get(Label.DEMAIN));
assertEquals(3, frame.getAsInt(Label.IINST));
assertEquals(37, frame.getAsInt(Label.IMAX));
assertEquals(620, frame.getAsInt(Label.PAPP));
assertFalse(frame.getLabelToValues().containsKey(Label.ADPS));
assertNull(frame.get(Label.ADPS));
assertEquals("Y", frame.get(Label.HHPHC));
assertEquals("B", frame.getProgrammeCircuit1());
assertEquals("P2", frame.getProgrammeCircuit2());
}
}
@Test
public void testReadNextFrameCbemmEvoIccBase1() throws Exception {
try (TeleinfoInputStream in = new TeleinfoInputStream(
new FileInputStream(TestUtils.getTestFile("cbemm-evo-icc-base-option-1.raw")), TIMEOUT_US, TIMEOUT_US,
false)) {
new FileInputStream(TestUtils.getTestFile("cbemm-evo-icc-base-option-1.raw")), false)) {
Frame frame = in.readNextFrame();
assertNotNull(frame);
assertEquals(FrameCbemmEvolutionIccBaseOption.class, frame.getClass());
FrameCbemmEvolutionIccBaseOption frameCbemmEvolutionIccBaseOption = (FrameCbemmEvolutionIccBaseOption) frame;
assertEquals("031762120162", frameCbemmEvolutionIccBaseOption.getAdco());
assertEquals(30, frameCbemmEvolutionIccBaseOption.getIsousc());
assertEquals(190575, frameCbemmEvolutionIccBaseOption.getBase());
assertEquals(Ptec.TH, frameCbemmEvolutionIccBaseOption.getPtec());
assertEquals(1, frameCbemmEvolutionIccBaseOption.getIinst());
assertEquals(90, frameCbemmEvolutionIccBaseOption.getImax().intValue());
assertEquals(270, frameCbemmEvolutionIccBaseOption.getPapp());
assertNull(frameCbemmEvolutionIccBaseOption.getAdps());
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));
}
}
@Test
public void testInvalidADPSgrouplineWithAutoRepairActivated() throws Exception {
try (TeleinfoInputStream in = new TeleinfoInputStream(
new FileInputStream(TestUtils.getTestFile("invalid-adps-groupline.raw")), TIMEOUT_US, TIMEOUT_US,
true)) {
new FileInputStream(TestUtils.getTestFile("invalid-adps-groupline.raw")), true)) {
Frame frame = in.readNextFrame();
assertNotNull(frame);
assertEquals(FrameCbemmEvolutionIccBaseOption.class, frame.getClass());
FrameCbemmEvolutionIccBaseOption frameCbemmEvolutionIccBaseOption = (FrameCbemmEvolutionIccBaseOption) frame;
assertEquals(37, frameCbemmEvolutionIccBaseOption.getAdps().intValue());
assertEquals(Frame.class, frame.getClass());
assertEquals(37, frame.getAsInt(Label.ADPS));
}
}
}