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