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_08;
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
17 import java.util.function.Function;
19 import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
20 import org.openhab.binding.enocean.internal.messages.ERP1Message;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.library.types.OnOffType;
23 import org.openhab.core.library.types.QuantityType;
24 import org.openhab.core.library.unit.SIUnits;
25 import org.openhab.core.library.unit.Units;
26 import org.openhab.core.types.State;
27 import org.openhab.core.types.UnDefType;
31 * @author Daniel Weber - Initial contribution
33 public abstract class A5_08 extends _4BSMessage {
35 public A5_08(ERP1Message packet) {
39 protected double getUnscaledTemperatureMin() {
43 protected double getUnscaledTemperatureMax() {
47 protected double getUnscaledIlluminationMin() {
51 protected double getUnscaledIlluminationMax() {
55 protected abstract double getScaledTemperatureMin();
57 protected abstract double getScaledTemperatureMax();
59 protected abstract double getScaledIlluminationMin();
61 protected abstract double getScaledIlluminationMax();
63 protected int getUnscaledTemperatureValue() {
64 return getDB_1Value();
67 protected int getUnscaledIlluminationValue() {
68 return getDB_2Value();
72 protected State convertToStateImpl(String channelId, String channelTypeId,
73 Function<String, State> getCurrentStateFunc, Configuration config) {
75 if (channelId.equals(CHANNEL_TEMPERATURE)) {
76 double scaledTemp = getScaledTemperatureMin()
77 + ((getUnscaledTemperatureValue() * (getScaledTemperatureMax() - getScaledTemperatureMin()))
78 / (getUnscaledTemperatureMax() - getUnscaledTemperatureMin()));
79 return new QuantityType<>(scaledTemp, SIUnits.CELSIUS);
80 } else if (channelId.equals(CHANNEL_ILLUMINATION)) {
81 double scaledIllumination = getScaledIlluminationMin()
82 + ((getUnscaledIlluminationValue() * (getScaledIlluminationMax() - getScaledIlluminationMin()))
83 / (getUnscaledIlluminationMax() - getUnscaledIlluminationMin()));
84 return new QuantityType<>(scaledIllumination, Units.LUX);
85 } else if (channelId.equals(CHANNEL_MOTIONDETECTION)) {
86 return getBit(getDB_0(), 1) ? OnOffType.OFF : OnOffType.ON;
87 } else if (channelId.equals(CHANNEL_OCCUPANCY)) {
88 return getBit(getDB_0(), 0) ? OnOffType.OFF : OnOffType.ON;
91 return UnDefType.UNDEF;