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.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
22 import org.openhab.binding.enocean.internal.messages.ERP1Message;
23 import org.openhab.core.config.core.Configuration;
24 import org.openhab.core.library.types.OnOffType;
25 import org.openhab.core.library.types.QuantityType;
26 import org.openhab.core.library.unit.SIUnits;
27 import org.openhab.core.library.unit.Units;
28 import org.openhab.core.types.State;
29 import org.openhab.core.types.UnDefType;
33 * @author Daniel Weber - Initial contribution
36 public abstract class A5_08 extends _4BSMessage {
38 public A5_08(ERP1Message packet) {
42 protected double getUnscaledTemperatureMin() {
46 protected double getUnscaledTemperatureMax() {
50 protected double getUnscaledIlluminationMin() {
54 protected double getUnscaledIlluminationMax() {
58 protected abstract double getScaledTemperatureMin();
60 protected abstract double getScaledTemperatureMax();
62 protected abstract double getScaledIlluminationMin();
64 protected abstract double getScaledIlluminationMax();
66 protected int getUnscaledTemperatureValue() {
70 protected int getUnscaledIlluminationValue() {
75 protected State convertToStateImpl(String channelId, String channelTypeId,
76 Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
77 if (channelId.equals(CHANNEL_TEMPERATURE)) {
78 double scaledTemp = getScaledTemperatureMin()
79 + ((getUnscaledTemperatureValue() * (getScaledTemperatureMax() - getScaledTemperatureMin()))
80 / (getUnscaledTemperatureMax() - getUnscaledTemperatureMin()));
81 return new QuantityType<>(scaledTemp, SIUnits.CELSIUS);
82 } else if (channelId.equals(CHANNEL_ILLUMINATION)) {
83 double scaledIllumination = getScaledIlluminationMin()
84 + ((getUnscaledIlluminationValue() * (getScaledIlluminationMax() - getScaledIlluminationMin()))
85 / (getUnscaledIlluminationMax() - getUnscaledIlluminationMin()));
86 return new QuantityType<>(scaledIllumination, Units.LUX);
87 } else if (channelId.equals(CHANNEL_MOTIONDETECTION)) {
88 return getBit(getDB0(), 1) ? OnOffType.OFF : OnOffType.ON;
89 } else if (channelId.equals(CHANNEL_OCCUPANCY)) {
90 return getBit(getDB0(), 0) ? OnOffType.OFF : OnOffType.ON;
93 return UnDefType.UNDEF;