2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.teleinfo.internal.handler.cbetm;
15 import static org.openhab.binding.teleinfo.internal.TeleinfoBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetm;
19 import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmLong;
20 import org.openhab.binding.teleinfo.internal.dto.cbetm.FrameCbetmShort;
21 import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractElectricityMeterHandler;
22 import org.openhab.core.library.types.DateTimeType;
23 import org.openhab.core.library.types.QuantityType;
24 import org.openhab.core.library.types.StringType;
25 import org.openhab.core.library.unit.Units;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.types.UnDefType;
30 * The {@link TeleinfoAbstractCbetmElectricityMeterHandler} class defines a skeleton for CBETM Electricity Meters
33 * @author Nicolas SIBERIL - Initial contribution
36 public abstract class TeleinfoAbstractCbetmElectricityMeterHandler extends TeleinfoAbstractElectricityMeterHandler {
38 public TeleinfoAbstractCbetmElectricityMeterHandler(Thing thing) {
42 protected void updateStatesForCommonCbetmChannels(FrameCbetm frameCbetm) {
43 updateState(CHANNEL_CBETM_IINST1, QuantityType.valueOf(frameCbetm.getIinst1(), Units.AMPERE));
44 updateState(CHANNEL_CBETM_IINST2, QuantityType.valueOf(frameCbetm.getIinst2(), Units.AMPERE));
45 updateState(CHANNEL_CBETM_IINST3, QuantityType.valueOf(frameCbetm.getIinst3(), Units.AMPERE));
47 if (frameCbetm instanceof FrameCbetmLong) {
48 FrameCbetmLong frameCbetmLong = (FrameCbetmLong) frameCbetm;
50 updateState(CHANNEL_CBETM_FRAME_TYPE, new StringType("LONG"));
52 updateState(CHANNEL_CBETM_LONG_ISOUSC, QuantityType.valueOf(frameCbetmLong.getIsousc(), Units.AMPERE));
53 updateState(CHANNEL_CBETM_LONG_PTEC, new StringType(frameCbetmLong.getPtec().name()));
54 if (frameCbetmLong.getImax1() == null) {
55 updateState(CHANNEL_CBETM_LONG_IMAX1, UnDefType.NULL);
57 updateState(CHANNEL_CBETM_LONG_IMAX1, QuantityType.valueOf(frameCbetmLong.getImax1(), Units.AMPERE));
59 if (frameCbetmLong.getImax2() == null) {
60 updateState(CHANNEL_CBETM_LONG_IMAX2, UnDefType.NULL);
62 updateState(CHANNEL_CBETM_LONG_IMAX2, QuantityType.valueOf(frameCbetmLong.getImax2(), Units.AMPERE));
64 if (frameCbetmLong.getImax3() == null) {
65 updateState(CHANNEL_CBETM_LONG_IMAX3, UnDefType.NULL);
67 updateState(CHANNEL_CBETM_LONG_IMAX3, QuantityType.valueOf(frameCbetmLong.getImax3(), Units.AMPERE));
70 updateState(CHANNEL_CBETM_LONG_PMAX, QuantityType.valueOf(frameCbetmLong.getPmax(), Units.WATT));
71 updateState(CHANNEL_CBETM_LONG_PAPP, QuantityType.valueOf(frameCbetmLong.getPapp(), Units.VOLT_AMPERE));
72 updateState(CHANNEL_CBETM_LONG_PPOT, new StringType(frameCbetmLong.getPpot()));
74 updateState(CHANNEL_CBETM_SHORT_ADIR1, UnDefType.NULL);
75 updateState(CHANNEL_CBETM_SHORT_ADIR2, UnDefType.NULL);
76 updateState(CHANNEL_CBETM_SHORT_ADIR3, UnDefType.NULL);
77 } else { // FrameCbetmShort
78 FrameCbetmShort frameCbetmShort = (FrameCbetmShort) frameCbetm;
80 updateState(CHANNEL_CBETM_FRAME_TYPE, new StringType("SHORT"));
82 if (frameCbetmShort.getAdir1() == null) {
83 updateState(CHANNEL_CBETM_SHORT_ADIR1, UnDefType.NULL);
85 updateState(CHANNEL_CBETM_SHORT_ADIR1, QuantityType.valueOf(frameCbetmShort.getAdir1(), Units.AMPERE));
88 if (frameCbetmShort.getAdir2() == null) {
89 updateState(CHANNEL_CBETM_SHORT_ADIR2, UnDefType.NULL);
91 updateState(CHANNEL_CBETM_SHORT_ADIR2, QuantityType.valueOf(frameCbetmShort.getAdir2(), Units.AMPERE));
94 if (frameCbetmShort.getAdir3() == null) {
95 updateState(CHANNEL_CBETM_SHORT_ADIR3, UnDefType.NULL);
97 updateState(CHANNEL_CBETM_SHORT_ADIR3, QuantityType.valueOf(frameCbetmShort.getAdir3(), Units.AMPERE));
100 updateState(CHANNEL_CBETM_LONG_ISOUSC, UnDefType.NULL);
101 updateState(CHANNEL_CBETM_LONG_PTEC, UnDefType.NULL);
102 updateState(CHANNEL_CBETM_LONG_IMAX1, UnDefType.NULL);
103 updateState(CHANNEL_CBETM_LONG_IMAX2, UnDefType.NULL);
104 updateState(CHANNEL_CBETM_LONG_IMAX3, UnDefType.NULL);
105 updateState(CHANNEL_CBETM_LONG_PMAX, UnDefType.NULL);
106 updateState(CHANNEL_CBETM_LONG_PAPP, UnDefType.NULL);
107 updateState(CHANNEL_CBETM_LONG_PPOT, UnDefType.NULL);
110 updateState(CHANNEL_LAST_UPDATE, new DateTimeType());