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_09;
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.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.types.StringType;
24 import org.openhab.core.library.unit.Units;
25 import org.openhab.core.types.State;
26 import org.openhab.core.types.UnDefType;
30 * @author Zhivka Dimova - Initial contribution
33 public class A5_09_05 extends A5_09 {
35 public A5_09_05(ERP1Message packet) {
39 protected double[] ScaleMultiplier = new double[] { 0.01, 0.1, 1, 10 };
41 protected String[] getVOCIdentifications() {
42 return new String[] { "VOCT", "Formaldehyde", "Benzene", "Styrene", "Toluene", "Tetrachloroethylene", "Xylene",
43 "n-Hexane", "n-Octane", "Cyclopentane", "Methanol", "Ethanol", "1-Pentanol", "Acetone",
44 "ethylene Oxide", "Acetaldehyde ue", "Acetic Acid", "Propionine Acid", "Valeric Acid", "Butyric Acid",
45 "Ammoniac", "Hidrogen Sulfide", "Dimethylsulfide", "2-Butanol", "2-Methylpropanol", "Diethyl ether",
46 "VOC-Index", "Ozone" };
49 protected long getUnscaledVOCValue() {
50 return getDBByOffsetSizeValue(0, 16);
53 protected double getScalingFactor() {
54 int smid = Long.valueOf(getDBByOffsetSizeValue(30, 2)).intValue();
55 if (smid < 0 || smid >= ScaleMultiplier.length) {
56 logger.debug("Invalid value according to enocean specification for A5_09 Scale Multiplier {}", smid);
60 return ScaleMultiplier[smid];
63 protected String getVOCID() {
64 int vocId = getDB1Value();
65 String[] VOCIdentifications = getVOCIdentifications();
67 return VOCIdentifications[VOCIdentifications.length - 1];
68 } else if (vocId < 0 || vocId >= VOCIdentifications.length - 1) {
69 logger.debug("Invalid value according to enocean specification for A5_09 VOC Identification {}", vocId);
73 return VOCIdentifications[vocId];
77 protected State convertToStateImpl(String channelId, String channelTypeId,
78 Function<String, State> getCurrentStateFunc, Configuration config) {
79 if (CHANNEL_VOC.equals(channelId)) {
80 double scaledVOC = getUnscaledVOCValue() * getScalingFactor();
81 return new QuantityType<>(scaledVOC, Units.PARTS_PER_BILLION);
82 } else if (CHANNEL_VOC_ID.equals(channelId)) {
83 return new StringType(getVOCID());
86 return UnDefType.UNDEF;