]> git.basschouten.com Git - openhab-addons.git/blob
83f31e5c887995b019131e80a25691ffb9d0abe2
[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.enocean.internal.eep.A5_10;
14
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
16
17 import java.util.function.Function;
18
19 import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
20 import org.openhab.binding.enocean.internal.messages.ERP1Message;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.library.types.DecimalType;
23 import org.openhab.core.library.types.OnOffType;
24 import org.openhab.core.library.types.QuantityType;
25 import org.openhab.core.library.types.StringType;
26 import org.openhab.core.library.unit.SIUnits;
27 import org.openhab.core.types.State;
28 import org.openhab.core.types.UnDefType;
29
30 /**
31  *
32  * @author Daniel Weber - Initial contribution
33  */
34 public abstract class A5_10 extends _4BSMessage {
35
36     public A5_10(ERP1Message packet) {
37         super(packet);
38     }
39
40     @Override
41     protected State convertToStateImpl(String channelId, String channelTypeId,
42             Function<String, State> getCurrentStateFunc, Configuration config) {
43         if (!isValid()) {
44             return UnDefType.UNDEF;
45         }
46
47         switch (channelId) {
48             case CHANNEL_FANSPEEDSTAGE:
49                 if (getDB_3Value() > 209) {
50                     return new StringType("-1");
51                 } else if (getDB_3Value() > 189) {
52                     return new StringType("0");
53                 } else if (getDB_3Value() > 164) {
54                     return new StringType("1");
55                 } else if (getDB_3Value() > 144) {
56                     return new StringType("2");
57                 } else {
58                     return new StringType("3");
59                 }
60
61             case CHANNEL_SETPOINT:
62                 return new DecimalType(getDB_2Value());
63
64             case CHANNEL_TEMPERATURE:
65                 double temp = (getDB_1Value() - 255) / -6.375;
66                 return new QuantityType<>(temp, SIUnits.CELSIUS);
67
68             case CHANNEL_OCCUPANCY:
69                 return getBit(getDB_0(), 0) ? OnOffType.OFF : OnOffType.ON;
70         }
71
72         return UnDefType.UNDEF;
73     }
74 }