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.SmartHomeUnits;
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(), SmartHomeUnits.AMPERE));
44 updateState(CHANNEL_CBETM_IINST2, QuantityType.valueOf(frameCbetm.getIinst2(), SmartHomeUnits.AMPERE));
45 updateState(CHANNEL_CBETM_IINST3, QuantityType.valueOf(frameCbetm.getIinst3(), SmartHomeUnits.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,
53 QuantityType.valueOf(frameCbetmLong.getIsousc(), SmartHomeUnits.AMPERE));
54 updateState(CHANNEL_CBETM_LONG_PTEC, new StringType(frameCbetmLong.getPtec().name()));
55 if (frameCbetmLong.getImax1() == null) {
56 updateState(CHANNEL_CBETM_LONG_IMAX1, UnDefType.NULL);
58 updateState(CHANNEL_CBETM_LONG_IMAX1,
59 QuantityType.valueOf(frameCbetmLong.getImax1(), SmartHomeUnits.AMPERE));
61 if (frameCbetmLong.getImax2() == null) {
62 updateState(CHANNEL_CBETM_LONG_IMAX2, UnDefType.NULL);
64 updateState(CHANNEL_CBETM_LONG_IMAX2,
65 QuantityType.valueOf(frameCbetmLong.getImax2(), SmartHomeUnits.AMPERE));
67 if (frameCbetmLong.getImax3() == null) {
68 updateState(CHANNEL_CBETM_LONG_IMAX3, UnDefType.NULL);
70 updateState(CHANNEL_CBETM_LONG_IMAX3,
71 QuantityType.valueOf(frameCbetmLong.getImax3(), SmartHomeUnits.AMPERE));
74 updateState(CHANNEL_CBETM_LONG_PMAX, QuantityType.valueOf(frameCbetmLong.getPmax(), SmartHomeUnits.WATT));
75 updateState(CHANNEL_CBETM_LONG_PAPP, QuantityType.valueOf(frameCbetmLong.getPapp(), SmartHomeUnits.WATT));
76 updateState(CHANNEL_CBETM_LONG_PPOT, new StringType(frameCbetmLong.getPpot()));
78 updateState(CHANNEL_CBETM_SHORT_ADIR1, UnDefType.NULL);
79 updateState(CHANNEL_CBETM_SHORT_ADIR2, UnDefType.NULL);
80 updateState(CHANNEL_CBETM_SHORT_ADIR3, UnDefType.NULL);
81 } else { // FrameCbetmShort
82 FrameCbetmShort frameCbetmShort = (FrameCbetmShort) frameCbetm;
84 updateState(CHANNEL_CBETM_FRAME_TYPE, new StringType("SHORT"));
86 if (frameCbetmShort.getAdir1() == null) {
87 updateState(CHANNEL_CBETM_SHORT_ADIR1, UnDefType.NULL);
89 updateState(CHANNEL_CBETM_SHORT_ADIR1,
90 QuantityType.valueOf(frameCbetmShort.getAdir1(), SmartHomeUnits.AMPERE));
93 if (frameCbetmShort.getAdir2() == null) {
94 updateState(CHANNEL_CBETM_SHORT_ADIR2, UnDefType.NULL);
96 updateState(CHANNEL_CBETM_SHORT_ADIR2,
97 QuantityType.valueOf(frameCbetmShort.getAdir2(), SmartHomeUnits.AMPERE));
100 if (frameCbetmShort.getAdir3() == null) {
101 updateState(CHANNEL_CBETM_SHORT_ADIR3, UnDefType.NULL);
103 updateState(CHANNEL_CBETM_SHORT_ADIR3,
104 QuantityType.valueOf(frameCbetmShort.getAdir3(), SmartHomeUnits.AMPERE));
107 updateState(CHANNEL_CBETM_LONG_ISOUSC, UnDefType.NULL);
108 updateState(CHANNEL_CBETM_LONG_PTEC, UnDefType.NULL);
109 updateState(CHANNEL_CBETM_LONG_IMAX1, UnDefType.NULL);
110 updateState(CHANNEL_CBETM_LONG_IMAX2, UnDefType.NULL);
111 updateState(CHANNEL_CBETM_LONG_IMAX3, UnDefType.NULL);
112 updateState(CHANNEL_CBETM_LONG_PMAX, UnDefType.NULL);
113 updateState(CHANNEL_CBETM_LONG_PAPP, UnDefType.NULL);
114 updateState(CHANNEL_CBETM_LONG_PPOT, UnDefType.NULL);
117 updateState(CHANNEL_LAST_UPDATE, new DateTimeType());