]> git.basschouten.com Git - openhab-addons.git/blob
99e9c6148fe5be97e7b8178bfa709739c524007b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.enocean.internal.eep.A5_14;
14
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANNEL_BATTERY_VOLTAGE;
16
17 import java.util.function.Function;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
22 import org.openhab.binding.enocean.internal.messages.ERP1Message;
23 import org.openhab.core.config.core.Configuration;
24 import org.openhab.core.library.types.QuantityType;
25 import org.openhab.core.library.unit.Units;
26 import org.openhab.core.types.State;
27 import org.openhab.core.types.UnDefType;
28
29 /**
30  *
31  * @author Dominik Krickl-Vorreiter - Initial contribution
32  */
33 @NonNullByDefault
34 public abstract class A5_14 extends _4BSMessage {
35     public A5_14(ERP1Message packet) {
36         super(packet);
37     }
38
39     private State getBatteryVoltage() {
40         int db3 = getDB3Value();
41
42         if (db3 > 250) {
43             logger.warn("EEP A5-14 error code {}", db3);
44             return UnDefType.UNDEF;
45         }
46
47         double voltage = db3 / 50.0; // 0..250 = 0.0..5.0V
48
49         return new QuantityType<>(voltage, Units.VOLT);
50     }
51
52     @Override
53     protected State convertToStateImpl(String channelId, String channelTypeId,
54             Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
55         switch (channelId) {
56             case CHANNEL_BATTERY_VOLTAGE:
57                 return getBatteryVoltage();
58         }
59
60         return UnDefType.UNDEF;
61     }
62 }