]> git.basschouten.com Git - openhab-addons.git/blob
7c9a62a8de97e63a49363d1f04851aa2a751c98d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.Units;
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(), Units.AMPERE));
44         updateState(CHANNEL_CBETM_IINST2, QuantityType.valueOf(frameCbetm.getIinst2(), Units.AMPERE));
45         updateState(CHANNEL_CBETM_IINST3, QuantityType.valueOf(frameCbetm.getIinst3(), Units.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, 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);
56             } else {
57                 updateState(CHANNEL_CBETM_LONG_IMAX1, QuantityType.valueOf(frameCbetmLong.getImax1(), Units.AMPERE));
58             }
59             if (frameCbetmLong.getImax2() == null) {
60                 updateState(CHANNEL_CBETM_LONG_IMAX2, UnDefType.NULL);
61             } else {
62                 updateState(CHANNEL_CBETM_LONG_IMAX2, QuantityType.valueOf(frameCbetmLong.getImax2(), Units.AMPERE));
63             }
64             if (frameCbetmLong.getImax3() == null) {
65                 updateState(CHANNEL_CBETM_LONG_IMAX3, UnDefType.NULL);
66             } else {
67                 updateState(CHANNEL_CBETM_LONG_IMAX3, QuantityType.valueOf(frameCbetmLong.getImax3(), Units.AMPERE));
68             }
69
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()));
73
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;
79
80             updateState(CHANNEL_CBETM_FRAME_TYPE, new StringType("SHORT"));
81
82             if (frameCbetmShort.getAdir1() == null) {
83                 updateState(CHANNEL_CBETM_SHORT_ADIR1, UnDefType.NULL);
84             } else {
85                 updateState(CHANNEL_CBETM_SHORT_ADIR1, QuantityType.valueOf(frameCbetmShort.getAdir1(), Units.AMPERE));
86             }
87
88             if (frameCbetmShort.getAdir2() == null) {
89                 updateState(CHANNEL_CBETM_SHORT_ADIR2, UnDefType.NULL);
90             } else {
91                 updateState(CHANNEL_CBETM_SHORT_ADIR2, QuantityType.valueOf(frameCbetmShort.getAdir2(), Units.AMPERE));
92             }
93
94             if (frameCbetmShort.getAdir3() == null) {
95                 updateState(CHANNEL_CBETM_SHORT_ADIR3, UnDefType.NULL);
96             } else {
97                 updateState(CHANNEL_CBETM_SHORT_ADIR3, QuantityType.valueOf(frameCbetmShort.getAdir3(), Units.AMPERE));
98             }
99
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);
108         }
109
110         updateState(CHANNEL_LAST_UPDATE, new DateTimeType());
111     }
112 }