Skip to content

Commit

Permalink
Add things and channels for standard tic mode
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Marceau <[email protected]>
  • Loading branch information
olivierkeke committed Apr 30, 2021
1 parent 03a8c29 commit 5d1b997
Show file tree
Hide file tree
Showing 21 changed files with 1,469 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,77 @@ private TeleinfoBindingConstants() {
public static final String CHANNEL_CBETM_SHORT_ADIR1 = "adir1";
public static final String CHANNEL_CBETM_SHORT_ADIR2 = "adir2";
public static final String CHANNEL_CBETM_SHORT_ADIR3 = "adir3";
// List ofLinky standard mode channel ids
public static final String CHANNEL_LSM_NGTF = "ngtf";
public static final String CHANNEL_LSM_LTARF = "ltarf";
public static final String CHANNEL_LSM_EAST = "east";
public static final String CHANNEL_LSM_EASF01 = "easf01";
public static final String CHANNEL_LSM_EASF02 = "easf02";
public static final String CHANNEL_LSM_EASF03 = "easf03";
public static final String CHANNEL_LSM_EASF04 = "easf04";
public static final String CHANNEL_LSM_EASF05 = "easf05";
public static final String CHANNEL_LSM_EASF06 = "easf06";
public static final String CHANNEL_LSM_EASF07 = "easf07";
public static final String CHANNEL_LSM_EASF08 = "easf08";
public static final String CHANNEL_LSM_EASF09 = "easf09";
public static final String CHANNEL_LSM_EASF10 = "easf10";
public static final String CHANNEL_LSM_EASD01 = "easd01";
public static final String CHANNEL_LSM_EASD02 = "easd02";
public static final String CHANNEL_LSM_EASD03 = "easd03";
public static final String CHANNEL_LSM_EASD04 = "easd04";
public static final String CHANNEL_LSM_IRMS1 = "irms1";
public static final String CHANNEL_LSM_URMS1 = "urms1";
public static final String CHANNEL_LSM_PREF = "pref";
public static final String CHANNEL_LSM_PCOUP = "pcoup";
public static final String CHANNEL_LSM_SINSTS = "sinsts";
public static final String CHANNEL_LSM_SMAXSN = "smaxsn";
public static final String CHANNEL_LSM_SMAXSN_MINUS_1 = "smaxsnMinus1";
public static final String CHANNEL_LSM_CCASN = "ccasn";
public static final String CHANNEL_LSM_CCASN_MINUS_1 = "ccasnMinus1";
public static final String CHANNEL_LSM_UMOY1 = "umoy1";
public static final String CHANNEL_LSM_STGE = "stge";
public static final String CHANNEL_LSM_DPM1 = "dpm1";
public static final String CHANNEL_LSM_FPM1 = "fpm1";
public static final String CHANNEL_LSM_DPM2 = "dpm2";
public static final String CHANNEL_LSM_FPM2 = "fpm2";
public static final String CHANNEL_LSM_DPM3 = "dpm3";
public static final String CHANNEL_LSM_FPM3 = "fpm3";
public static final String CHANNEL_LSM_MSG1 = "msg1";
public static final String CHANNEL_LSM_MSG2 = "msg2";
public static final String CHANNEL_LSM_PRM = "prm";
public static final String CHANNEL_LSM_RELAIS = "relais";
public static final String CHANNEL_LSM_NTARF = "ntarf";
public static final String CHANNEL_LSM_NJOURF = "njourf";
public static final String CHANNEL_LSM_NJOURF_PLUS_1 = "njourfPlus1";
public static final String CHANNEL_LSM_PJOURF_PLUS_1 = "pjourfPlus1";
public static final String CHANNEL_LSM_PPOINTE = "ppointe";

public static final String CHANNEL_LSM_IRMS2 = "irms2";
public static final String CHANNEL_LSM_IRMS3 = "irms3";
public static final String CHANNEL_LSM_URMS2 = "urms2";
public static final String CHANNEL_LSM_URMS3 = "urms3";
public static final String CHANNEL_LSM_SINSTS1 = "sinsts1";
public static final String CHANNEL_LSM_SINSTS2 = "sinsts2";
public static final String CHANNEL_LSM_SINSTS3 = "sinsts3";
public static final String CHANNEL_LSM_SMAXSN1 = "smaxsn1";
public static final String CHANNEL_LSM_SMAXSN2 = "smaxsn2";
public static final String CHANNEL_LSM_SMAXSN3 = "smaxsn3";
public static final String CHANNEL_LSM_SMAXSN1_MINUS_1 = "smaxsn1Minus1";
public static final String CHANNEL_LSM_SMAXSN2_MINUS_1 = "smaxsn2Minus1";
public static final String CHANNEL_LSM_SMAXSN3_MINUS_1 = "smaxsn3Minus1";
public static final String CHANNEL_LSM_UMOY2 = "umoy2";
public static final String CHANNEL_LSM_UMOY3 = "umoy3";

public static final String CHANNEL_LSM_EAIT = "eait";
public static final String CHANNEL_LSM_ERQ1 = "erq1";
public static final String CHANNEL_LSM_ERQ2 = "erq2";
public static final String CHANNEL_LSM_ERQ3 = "erq3";
public static final String CHANNEL_LSM_ERQ4 = "erq4";
public static final String CHANNEL_LSM_SINSTI = "sinsti";
public static final String CHANNEL_LSM_SMAXIN = "smaxin";
public static final String CHANNEL_LSM_SMAXIN_MINUS_1 = "smaxinMinus1";
public static final String CHANNEL_LSM_CCAIN = "ccain";
public static final String CHANNEL_LSM_CCAIN_MINUS_1 = "ccainMinus1";

public static final String NOT_A_CHANNEL = "";

Expand Down Expand Up @@ -118,6 +189,18 @@ private TeleinfoBindingConstants() {
public static final ThingTypeUID THING_TEMPO_CBETM_ELECTRICITY_METER_TYPE_UID = new ThingTypeUID(BINDING_ID,
"cbetm_tempo_electricitymeter");

public static final ThingTypeUID THING_LSMT_PROD_ELECTRICITY_METER_TYPE_UID = new ThingTypeUID(BINDING_ID,
"lsmt_prod_electricitymeter");

public static final ThingTypeUID THING_LSMM_PROD_ELECTRICITY_METER_TYPE_UID = new ThingTypeUID(BINDING_ID,
"lsmm_prod_electricitymeter");

public static final ThingTypeUID THING_LSMT_ELECTRICITY_METER_TYPE_UID = new ThingTypeUID(BINDING_ID,
"lsmt_electricitymeter");

public static final ThingTypeUID THING_LSMM_ELECTRICITY_METER_TYPE_UID = new ThingTypeUID(BINDING_ID,
"lsmm_electricitymeter");

public static final String ERROR_OFFLINE_SERIAL_NOT_FOUND = "@text/teleinfo.thingstate.serial_notfound";
public static final String ERROR_OFFLINE_SERIAL_INUSE = "@text/teleinfo.thingstate.serial_inuse";
public static final String ERROR_OFFLINE_SERIAL_UNSUPPORTED = "@text/teleinfo.thingstate.serial_unsupported";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -47,13 +45,15 @@
public class TeleinfoDiscoveryService extends AbstractDiscoveryService
implements TeleinfoControllerHandlerListener, ThingHandlerService, DiscoveryService {

private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Stream.of(THING_HC_CBEMM_ELECTRICITY_METER_TYPE_UID,
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_HC_CBEMM_ELECTRICITY_METER_TYPE_UID,
THING_BASE_CBEMM_ELECTRICITY_METER_TYPE_UID, THING_TEMPO_CBEMM_ELECTRICITY_METER_TYPE_UID,
THING_EJP_CBEMM_ELECTRICITY_METER_TYPE_UID, THING_HC_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID,
THING_BASE_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_TEMPO_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID,
THING_EJP_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_HC_CBETM_ELECTRICITY_METER_TYPE_UID,
THING_BASE_CBETM_ELECTRICITY_METER_TYPE_UID, THING_TEMPO_CBETM_ELECTRICITY_METER_TYPE_UID,
THING_EJP_CBETM_ELECTRICITY_METER_TYPE_UID).collect(Collectors.toSet());
THING_EJP_CBETM_ELECTRICITY_METER_TYPE_UID, THING_LSMT_PROD_ELECTRICITY_METER_TYPE_UID,
THING_LSMT_ELECTRICITY_METER_TYPE_UID, THING_LSMM_PROD_ELECTRICITY_METER_TYPE_UID,
THING_LSMM_ELECTRICITY_METER_TYPE_UID);

private static final int SCAN_DURATION_IN_S = 60;

Expand Down Expand Up @@ -140,19 +140,20 @@ private void detectNewElectricityMeterFromReceivedFrame(final Frame frameSample)
TeleinfoAbstractControllerHandler controllerHandlerRef = controllerHandler;
if (controllerHandlerRef != null) {
logger.debug("New eletricity meter detection from frame {}", frameSample);
if (frameSample.get(Label.ADCO) == null) {
throw new IllegalStateException("Missing ADCO key");
if (frameSample.get(Label.ADCO) == null && frameSample.get(Label.ADSC) == null) {
throw new IllegalStateException("Missing ADCO or ADSC key");
}

String adco = frameSample.get(Label.ADCO);
String adco = frameSample.get(Label.ADCO) != null ? frameSample.get(Label.ADCO)
: frameSample.get(Label.ADSC);
if (adco != null) {
ThingUID thingUID = new ThingUID(getThingTypeUID(frameSample), adco,
controllerHandlerRef.getThing().getUID().getId());

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))
.withLabel("Teleinfo ADCO/ADSC " + adco).withThingType(getThingTypeUID(frameSample))
.withBridge(controllerHandlerRef.getThing().getUID())
.withRepresentationProperty(representationProperty).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.InvalidFrameException;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.Label;
import org.openhab.binding.teleinfo.internal.serial.TeleinfoTicMode;

/**
* The {@link Frame} class defines common attributes for any Teleinfo frames.
Expand Down Expand Up @@ -54,6 +55,18 @@ public Frame() {
}

public FrameType getType() throws InvalidFrameException {
TeleinfoTicMode ticMode = getTicMode();
switch (ticMode) {
case HISTORICAL:
return getHistoricalType();
case STANDARD:
return getStandardType();
default:
throw new InvalidFrameException();
}
}

public FrameType getHistoricalType() throws InvalidFrameException {
Phase phase = getPhase();
Pricing pricing = getPricing();
Evolution evolution = getEvolution();
Expand Down Expand Up @@ -152,6 +165,30 @@ public Pricing getPricing() throws InvalidFrameException {
}
}

public TeleinfoTicMode getTicMode() throws InvalidFrameException {
if (labelToValues.containsKey(Label.ADCO)) {
return TeleinfoTicMode.HISTORICAL;
} else if (labelToValues.containsKey(Label.ADSC)) {
return TeleinfoTicMode.STANDARD;
}
throw new InvalidFrameException();
}

public FrameType getStandardType() throws InvalidFrameException {
boolean isProd = labelToValues.containsKey(Label.EAIT);
boolean isThreePhase = labelToValues.containsKey(Label.IRMS2);
if (isProd && isThreePhase) {
return FrameType.LSMT_PROD;
}
if (isProd) {
return FrameType.LSMM_PROD;
}
if (isThreePhase) {
return FrameType.LSMT;
}
return FrameType.LSMM;
}

public void clear() {
labelToValues.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public enum FrameType {
CBEMM_ICC_EJP(THING_EJP_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID),
CBEMM_ICC_TEMPO(THING_TEMPO_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID),
CBEMM_ICC_HC(THING_HC_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID),
LSMT_PROD(THING_LSMT_PROD_ELECTRICITY_METER_TYPE_UID),
LSMM_PROD(THING_LSMM_PROD_ELECTRICITY_METER_TYPE_UID),
LSMM(THING_LSMM_ELECTRICITY_METER_TYPE_UID),
LSMT(THING_LSMT_ELECTRICITY_METER_TYPE_UID),
UNKNOWN(null);

private ThingTypeUID thingTypeUid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.openhab.binding.teleinfo.internal.reader.io.serialport.InvalidFrameException;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.Label;
import org.openhab.binding.teleinfo.internal.reader.io.serialport.ValueType;
import org.openhab.binding.teleinfo.internal.serial.TeleinfoTicMode;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
Expand Down Expand Up @@ -130,7 +131,7 @@ protected void updateStatus(ThingStatus status) {
@Override
public void onFrameReceived(Frame frame) {
String adco = configuration.getAdco();
if (adco.equalsIgnoreCase(frame.get(Label.ADCO))) {
if (adco.equalsIgnoreCase(frame.get(Label.ADCO)) || adco.equalsIgnoreCase(frame.get(Label.ADSC))) {
updateStatesForChannels(frame);
}
}
Expand All @@ -144,34 +145,42 @@ private void updateStatesForChannels(Frame frame) {
} else if (label.getType() == ValueType.STRING) {
updateState(label.getChannelName(), StringType.valueOf(entry.getValue()));
} else if (label.getType() == ValueType.INTEGER) {
updateState(label.getChannelName(),
QuantityType.valueOf(Integer.parseInt(entry.getValue()), label.getUnit()));
updateState(label.getChannelName(), QuantityType
.valueOf(label.getFactor() * Integer.parseInt(entry.getValue()), label.getUnit()));
}
}
}
try {
if (frame.getPricing() == Pricing.TEMPO) {
updateState(CHANNEL_TEMPO_FRAME_PROGRAMME_CIRCUIT_1, StringType.valueOf(frame.getProgrammeCircuit1()));
updateState(CHANNEL_TEMPO_FRAME_PROGRAMME_CIRCUIT_2, StringType.valueOf(frame.getProgrammeCircuit2()));
}
} catch (InvalidFrameException e) {
logger.warn("Can not find pricing option.");
}
if (frame.getTicMode() == TeleinfoTicMode.HISTORICAL) {
try {
if (frame.getPricing() == Pricing.TEMPO) {
updateState(CHANNEL_TEMPO_FRAME_PROGRAMME_CIRCUIT_1,
StringType.valueOf(frame.getProgrammeCircuit1()));
updateState(CHANNEL_TEMPO_FRAME_PROGRAMME_CIRCUIT_2,
StringType.valueOf(frame.getProgrammeCircuit2()));
}
} catch (InvalidFrameException e) {
logger.warn("Can not find pricing option.");
}

try {
Phase phase = frame.getPhase();
if (phase == Phase.ONE_PHASED) {
updateStateForMissingAlert(frame, Label.ADPS);
} else if (phase == Phase.THREE_PHASED) {
if (!wasLastFrameShort) {
updateStateForMissingAlert(frame, Label.ADIR1);
updateStateForMissingAlert(frame, Label.ADIR2);
updateStateForMissingAlert(frame, Label.ADIR3);
try {
Phase phase = frame.getPhase();
if (phase == Phase.ONE_PHASED) {
updateStateForMissingAlert(frame, Label.ADPS);
} else if (phase == Phase.THREE_PHASED) {
if (!wasLastFrameShort) {
updateStateForMissingAlert(frame, Label.ADIR1);
updateStateForMissingAlert(frame, Label.ADIR2);
updateStateForMissingAlert(frame, Label.ADIR3);
}
wasLastFrameShort = frame.isShortFrame();
}
} catch (InvalidFrameException e) {
logger.warn("Can not find phase.");
}
wasLastFrameShort = frame.isShortFrame();
}
} catch (InvalidFrameException e) {
logger.warn("Can not find phase.");
logger.warn("Can not find TIC mode.");
}

updateState(CHANNEL_LAST_UPDATE, new DateTimeType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public class TeleinfoThingHandlerFactory extends BaseThingHandlerFactory {
THING_HC_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_BASE_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID,
THING_TEMPO_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_EJP_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID,
THING_HC_CBETM_ELECTRICITY_METER_TYPE_UID, THING_BASE_CBETM_ELECTRICITY_METER_TYPE_UID,
THING_TEMPO_CBETM_ELECTRICITY_METER_TYPE_UID, THING_EJP_CBETM_ELECTRICITY_METER_TYPE_UID)
THING_TEMPO_CBETM_ELECTRICITY_METER_TYPE_UID, THING_EJP_CBETM_ELECTRICITY_METER_TYPE_UID,
THING_LSMM_ELECTRICITY_METER_TYPE_UID, THING_LSMM_PROD_ELECTRICITY_METER_TYPE_UID,
THING_LSMT_ELECTRICITY_METER_TYPE_UID, THING_LSMT_PROD_ELECTRICITY_METER_TYPE_UID)
.collect(Collectors.toSet());

private final SerialPortManager serialPortManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void close() throws IOException {

Label label;
try {
label = Label.valueOf(labelStr);
label = Label.getEnum(labelStr);
} catch (IllegalArgumentException e) {
if (autoRepairInvalidADPSgroupLine && labelStr.startsWith(Label.ADPS.name())) {
// in this hardware issue, label variable is composed by label name and value. E.g:
Expand Down
Loading

0 comments on commit 5d1b997

Please sign in to comment.