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