]> git.basschouten.com Git - openhab-addons.git/blob
f7202fd5af3ef2a328764df8fd4d4a9288bdc186
[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.cbemm;
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.cbemm.FrameCbemm;
19 import org.openhab.binding.teleinfo.internal.handler.TeleinfoAbstractElectricityMeterHandler;
20 import org.openhab.core.library.types.DateTimeType;
21 import org.openhab.core.library.types.QuantityType;
22 import org.openhab.core.library.types.StringType;
23 import org.openhab.core.library.unit.Units;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.types.UnDefType;
26
27 /**
28  * The {@link TeleinfoAbstractCbemmElectricityMeterHandler} class defines a skeleton for CBEMM Electricity Meters
29  * handlers.
30  *
31  * @author Nicolas SIBERIL - Initial contribution
32  */
33 @NonNullByDefault
34 public abstract class TeleinfoAbstractCbemmElectricityMeterHandler extends TeleinfoAbstractElectricityMeterHandler {
35
36     public TeleinfoAbstractCbemmElectricityMeterHandler(Thing thing) {
37         super(thing);
38     }
39
40     protected void updateStatesForCommonCbemmChannels(FrameCbemm frame) {
41         // update common channels
42         updateState(CHANNEL_CBEMM_ISOUSC, QuantityType.valueOf(frame.getIsousc(), Units.AMPERE));
43         updateState(CHANNEL_CBEMM_PTEC, new StringType(frame.getPtec().name()));
44         if (frame.getImax() == null) {
45             updateState(CHANNEL_CBEMM_IMAX, UnDefType.NULL);
46         } else {
47             updateState(CHANNEL_CBEMM_IMAX, QuantityType.valueOf(frame.getImax(), Units.AMPERE));
48         }
49
50         if (frame.getAdps() == null) {
51             updateState(CHANNEL_CBEMM_ADPS, UnDefType.NULL);
52         } else {
53             updateState(CHANNEL_CBEMM_ADPS, QuantityType.valueOf(frame.getAdps(), Units.AMPERE));
54         }
55         updateState(CHANNEL_CBEMM_IINST, QuantityType.valueOf(frame.getIinst(), Units.AMPERE));
56
57         updateState(CHANNEL_LAST_UPDATE, new DateTimeType());
58     }
59 }