]> git.basschouten.com Git - openhab-addons.git/blob
a1caa67af541ce6818e61f23cfb4d977868588b9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.teleinfo.internal.handler.cbetm;
14
15 import static org.openhab.binding.teleinfo.internal.TeleinfoBindingConstants.*;
16
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;
28
29 /**
30  * The {@link TeleinfoAbstractCbetmElectricityMeterHandler} class defines a skeleton for CBETM Electricity Meters
31  * handlers.
32  *
33  * @author Nicolas SIBERIL - Initial contribution
34  */
35 @NonNullByDefault
36 public abstract class TeleinfoAbstractCbetmElectricityMeterHandler extends TeleinfoAbstractElectricityMeterHandler {
37
38     public TeleinfoAbstractCbetmElectricityMeterHandler(Thing thing) {
39         super(thing);
40     }
41
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));
46
47         if (frameCbetm instanceof FrameCbetmLong) {
48             FrameCbetmLong frameCbetmLong = (FrameCbetmLong) frameCbetm;
49
50             updateState(CHANNEL_CBETM_FRAME_TYPE, new StringType("LONG"));
51
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);
57             } else {
58                 updateState(CHANNEL_CBETM_LONG_IMAX1,
59                         QuantityType.valueOf(frameCbetmLong.getImax1(), SmartHomeUnits.AMPERE));
60             }
61             if (frameCbetmLong.getImax2() == null) {
62                 updateState(CHANNEL_CBETM_LONG_IMAX2, UnDefType.NULL);
63             } else {
64                 updateState(CHANNEL_CBETM_LONG_IMAX2,
65                         QuantityType.valueOf(frameCbetmLong.getImax2(), SmartHomeUnits.AMPERE));
66             }
67             if (frameCbetmLong.getImax3() == null) {
68                 updateState(CHANNEL_CBETM_LONG_IMAX3, UnDefType.NULL);
69             } else {
70                 updateState(CHANNEL_CBETM_LONG_IMAX3,
71                         QuantityType.valueOf(frameCbetmLong.getImax3(), SmartHomeUnits.AMPERE));
72             }
73
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()));
77
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;
83
84             updateState(CHANNEL_CBETM_FRAME_TYPE, new StringType("SHORT"));
85
86             if (frameCbetmShort.getAdir1() == null) {
87                 updateState(CHANNEL_CBETM_SHORT_ADIR1, UnDefType.NULL);
88             } else {
89                 updateState(CHANNEL_CBETM_SHORT_ADIR1,
90                         QuantityType.valueOf(frameCbetmShort.getAdir1(), SmartHomeUnits.AMPERE));
91             }
92
93             if (frameCbetmShort.getAdir2() == null) {
94                 updateState(CHANNEL_CBETM_SHORT_ADIR2, UnDefType.NULL);
95             } else {
96                 updateState(CHANNEL_CBETM_SHORT_ADIR2,
97                         QuantityType.valueOf(frameCbetmShort.getAdir2(), SmartHomeUnits.AMPERE));
98             }
99
100             if (frameCbetmShort.getAdir3() == null) {
101                 updateState(CHANNEL_CBETM_SHORT_ADIR3, UnDefType.NULL);
102             } else {
103                 updateState(CHANNEL_CBETM_SHORT_ADIR3,
104                         QuantityType.valueOf(frameCbetmShort.getAdir3(), SmartHomeUnits.AMPERE));
105             }
106
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);
115         }
116
117         updateState(CHANNEL_LAST_UPDATE, new DateTimeType());
118     }
119 }