]> git.basschouten.com Git - openhab-addons.git/blob
dabf2d1783eff19a865fdea329be1d3ea0de0104
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.enocean.internal.eep.A5_02;
14
15 import java.util.function.Function;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
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.QuantityType;
23 import org.openhab.core.library.unit.SIUnits;
24 import org.openhab.core.types.State;
25
26 /**
27  *
28  * @author Daniel Weber - Initial contribution
29  */
30 @NonNullByDefault
31 public abstract class A5_02 extends _4BSMessage {
32
33     public A5_02(ERP1Message packet) {
34         super(packet);
35     }
36
37     protected double getUnscaledMin() {
38         return 255;
39     }
40
41     protected double getUnscaledMax() {
42         return 0;
43     }
44
45     protected abstract double getScaledMin();
46
47     protected abstract double getScaledMax();
48
49     protected int getUnscaledTemperatureValue() {
50         return getDB1Value();
51     }
52
53     @Override
54     protected State convertToStateImpl(String channelId, String channelTypeId,
55             Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
56         double scaledTemp = getScaledMin()
57                 - (((getUnscaledMin() - getUnscaledTemperatureValue()) * (getScaledMin() - getScaledMax()))
58                         / getUnscaledMin());
59         return new QuantityType<>(scaledTemp, SIUnits.CELSIUS);
60     }
61 }