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.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;
29 * Convertes EEP A5-13 messages of type 0x01 into Temperature, Illumination, Wind Speed and Temperature states
31 * @author Daniel Weber - Initial contribution
33 public class A5_13_01 extends A5_13 {
35 public A5_13_01(ERP1Message packet) {
39 protected State getIllumination() {
40 return new QuantityType<>(((getDB_3Value() * 1000.0) / 255.0), Units.LUX);
43 protected State getIllumination(double value) {
44 return new QuantityType<>(((value * 1000.0 * 150.0) / 255.0), Units.LUX);
47 protected State getIlluminationWest() {
48 return getIllumination(getDB_3Value());
51 protected State getIlluminationSouthNorth() {
52 return getIllumination(getDB_2Value());
55 protected State getIlluminationEast() {
56 return getIllumination(getDB_1Value());
59 protected State getTemperature() {
60 return new QuantityType<>(-40.0 + ((getDB_2Value() * 120.0) / 255.0), SIUnits.CELSIUS);
63 protected State getWindSpeed() {
64 return new QuantityType<>(((getDB_1Value() * 70.0) / 255.0), Units.METRE_PER_SECOND);
67 protected State getRainStatus() {
68 return getBit(getDB_0Value(), 1) ? OnOffType.ON : OnOffType.OFF;
72 protected State convertToStateImpl(String channelId, String channelTypeId,
73 Function<String, State> getCurrentStateFunc, Configuration config) {
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();
89 case CHANNEL_ILLUMINATIONWEST:
90 return getIlluminationWest();
91 case CHANNEL_ILLUMINATIONSOUTHNORTH:
92 return getIlluminationSouthNorth();
93 case CHANNEL_ILLUMINATIONEAST:
94 return getIlluminationEast();
98 return UnDefType.UNDEF;