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_10;
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.Helper;
22 import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
23 import org.openhab.binding.enocean.internal.messages.ERP1Message;
24 import org.openhab.core.config.core.Configuration;
25 import org.openhab.core.library.types.DecimalType;
26 import org.openhab.core.library.types.OnOffType;
27 import org.openhab.core.library.types.OpenClosedType;
28 import org.openhab.core.library.types.QuantityType;
29 import org.openhab.core.library.unit.SIUnits;
30 import org.openhab.core.library.unit.Units;
31 import org.openhab.core.types.State;
32 import org.openhab.core.types.UnDefType;
35 * From A5_10_01 up to A5_10_0D temperature is given as a 8Bit value (range: 255..0).
36 * Therefore higher values mean lower temperatures.
37 * Temperature range 0..40.
39 * @author Daniel Weber - Initial contribution
42 public abstract class A5_10 extends _4BSMessage {
44 public A5_10(ERP1Message packet) {
48 protected int getSetPointValue() {
49 // this is the default one
53 protected double getMinTemperatureValue() {
57 protected double getMinUnscaledTemperatureValue() {
61 protected double getMaxTemperatureValue() {
65 protected double getMaxUnscaledTemperatureValue() {
69 protected double getTemperatureValue() {
73 protected State getTemperature() {
74 return new QuantityType<>(
75 Helper.scaleValue(getTemperatureValue(), getMinUnscaledTemperatureValue(),
76 getMaxUnscaledTemperatureValue(), getMinTemperatureValue(), getMaxTemperatureValue()),
80 protected State getFanSpeedStage() {
81 if (getDB3Value() > 209) {
82 return new DecimalType(-1);
83 } else if (getDB3Value() > 189) {
84 return new DecimalType(0);
85 } else if (getDB3Value() > 164) {
86 return new DecimalType(1);
87 } else if (getDB3Value() > 144) {
88 return new DecimalType(2);
90 return new DecimalType(3);
94 protected int getIlluminationValue() {
98 protected State getIllumination() {
99 return new QuantityType<>(getIlluminationValue() * 4, Units.LUX);
102 protected double getHumidityValue() {
103 return getDB2Value();
106 protected State getSupplyVoltage() {
107 double voltage = ((double) getDB3Value()) / 50.0;
108 return new QuantityType<>(voltage, Units.VOLT);
112 protected State convertToStateImpl(String channelId, String channelTypeId,
113 Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
117 case CHANNEL_BATTERY_VOLTAGE:
118 return getSupplyVoltage();
120 case CHANNEL_ILLUMINATION:
121 return getIllumination();
123 case CHANNEL_FANSPEEDSTAGE:
124 return getFanSpeedStage();
126 case CHANNEL_SETPOINT:
127 return new DecimalType(getSetPointValue());
129 case CHANNEL_HUMIDITY:
130 return new DecimalType(getHumidityValue() / 2.5);
132 case CHANNEL_TEMPERATURE:
133 return getTemperature();
135 case CHANNEL_BATTERYLOW:
136 return getBit(getDB0(), 4) ? OnOffType.ON : OnOffType.OFF;
138 case CHANNEL_OCCUPANCY:
139 return getBit(getDB0(), 0) ? OnOffType.OFF : OnOffType.ON;
141 case CHANNEL_DAYNIGHTMODESTATE:
142 return new DecimalType(getDB0Value() & 0x01);
144 case CHANNEL_CONTACT:
145 return getBit(getDB0(), 0) ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
149 return UnDefType.UNDEF;