2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.enocean.internal.eep.A5_13;
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
17 import java.util.function.Function;
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;
31 * Convertes EEP A5-13 messages of type 0x01 into Temperature, Illumination, Wind Speed and Temperature states
33 * @author Daniel Weber - Initial contribution
36 public class A5_13_01 extends A5_13 {
38 public A5_13_01(ERP1Message packet) {
42 protected State getIllumination() {
43 return new QuantityType<>(((getDB3Value() * 1000.0) / 255.0), Units.LUX);
46 protected State getIllumination(double value) {
47 return new QuantityType<>(((value * 1000.0 * 150.0) / 255.0), Units.LUX);
50 protected State getIlluminationWest() {
51 return getIllumination(getDB3Value());
54 protected State getIlluminationSouthNorth() {
55 return getIllumination(getDB2Value());
58 protected State getIlluminationEast() {
59 return getIllumination(getDB1Value());
62 protected State getTemperature() {
63 return new QuantityType<>(-40.0 + ((getDB2Value() * 120.0) / 255.0), SIUnits.CELSIUS);
66 protected State getWindSpeed() {
67 return new QuantityType<>(((getDB1Value() * 70.0) / 255.0), Units.METRE_PER_SECOND);
70 protected State getRainStatus() {
71 return OnOffType.from(getBit(getDB0Value(), 1));
75 protected State convertToStateImpl(String channelId, String channelTypeId,
76 Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
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();
92 case CHANNEL_ILLUMINATIONWEST:
93 return getIlluminationWest();
94 case CHANNEL_ILLUMINATIONSOUTHNORTH:
95 return getIlluminationSouthNorth();
96 case CHANNEL_ILLUMINATIONEAST:
97 return getIlluminationEast();
101 return UnDefType.UNDEF;