]> git.basschouten.com Git - openhab-addons.git/blob
be14ca9d3b9f8751d80fbc54c576e5c1320ccb12
[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_13;
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.messages.ERP1Message;
22 import org.openhab.core.config.core.Configuration;
23 import org.openhab.core.library.types.OnOffType;
24 import org.openhab.core.library.types.QuantityType;
25 import org.openhab.core.library.unit.SIUnits;
26 import org.openhab.core.library.unit.Units;
27 import org.openhab.core.types.State;
28 import org.openhab.core.types.UnDefType;
29
30 /**
31  * Convertes EEP A5-13 messages of type 0x01 into Temperature, Illumination, Wind Speed and Temperature states
32  *
33  * @author Daniel Weber - Initial contribution
34  */
35 @NonNullByDefault
36 public class A5_13_01 extends A5_13 {
37
38     public A5_13_01(ERP1Message packet) {
39         super(packet);
40     }
41
42     protected State getIllumination() {
43         return new QuantityType<>(((getDB3Value() * 1000.0) / 255.0), Units.LUX);
44     }
45
46     protected State getIllumination(double value) {
47         return new QuantityType<>(((value * 1000.0 * 150.0) / 255.0), Units.LUX);
48     }
49
50     protected State getIlluminationWest() {
51         return getIllumination(getDB3Value());
52     }
53
54     protected State getIlluminationSouthNorth() {
55         return getIllumination(getDB2Value());
56     }
57
58     protected State getIlluminationEast() {
59         return getIllumination(getDB1Value());
60     }
61
62     protected State getTemperature() {
63         return new QuantityType<>(-40.0 + ((getDB2Value() * 120.0) / 255.0), SIUnits.CELSIUS);
64     }
65
66     protected State getWindSpeed() {
67         return new QuantityType<>(((getDB1Value() * 70.0) / 255.0), Units.METRE_PER_SECOND);
68     }
69
70     protected State getRainStatus() {
71         return OnOffType.from(getBit(getDB0Value(), 1));
72     }
73
74     @Override
75     protected State convertToStateImpl(String channelId, String channelTypeId,
76             Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
77         if (isPartOne()) {
78             switch (channelId) {
79                 case CHANNEL_ILLUMINATION:
80                     return getIllumination();
81                 case CHANNEL_TEMPERATURE:
82                     return getTemperature();
83                 case CHANNEL_WINDSPEED:
84                     return getWindSpeed();
85                 case CHANNEL_RAINSTATUS:
86                     return getRainStatus();
87             }
88         }
89
90         if (isPartTwo()) {
91             switch (channelId) {
92                 case CHANNEL_ILLUMINATIONWEST:
93                     return getIlluminationWest();
94                 case CHANNEL_ILLUMINATIONSOUTHNORTH:
95                     return getIlluminationSouthNorth();
96                 case CHANNEL_ILLUMINATIONEAST:
97                     return getIlluminationEast();
98             }
99         }
100
101         return UnDefType.UNDEF;
102     }
103 }