]> git.basschouten.com Git - openhab-addons.git/blob
24962869ce30597cff8a54c847c22ca23cb7f271
[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_09;
14
15 import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
16
17 import java.util.function.Function;
18
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.unit.Units;
24 import org.openhab.core.types.State;
25
26 /**
27  *
28  * @author Zhivka Dimova - Initial contribution
29  */
30 @NonNullByDefault
31 public class A5_09_0C extends A5_09_05 {
32
33     public A5_09_0C(ERP1Message packet) {
34         super(packet);
35     }
36
37     @Override
38     protected String[] getVOCIdentifications() {
39         String[] VOCIdsSuper = super.getVOCIdentifications();
40         int elFromSuper = VOCIdsSuper.length - 2;
41         String[] VOCIdsExtension = new String[] { "Naphthalene", "4-Phenylcyclohexene", "Limonene", "Trichloroethylene",
42                 "Isovaleric acid", "Indole", "Cadaverine", "Putrescine", "Caproic acid", "Ozone" };
43         String[] VOCIdsExtended = new String[elFromSuper + VOCIdsExtension.length];
44
45         System.arraycopy(VOCIdsSuper, 0, VOCIdsExtended, 0, elFromSuper);
46         System.arraycopy(VOCIdsExtension, 0, VOCIdsExtended, elFromSuper, VOCIdsExtension.length);
47
48         return VOCIdsExtended;
49     }
50
51     @Override
52     protected State convertToStateImpl(String channelId, String channelTypeId,
53             Function<String, State> getCurrentStateFunc, Configuration config) {
54
55         if (CHANNEL_VOC.equals(channelId)) {
56             double scaledVOC = getUnscaledVOCValue() * getScalingFactor();
57             if (getBit(getDB0(), 2)) {
58                 return new QuantityType<>(scaledVOC, Units.MICROGRAM_PER_CUBICMETRE);
59             }
60             return new QuantityType<>(scaledVOC, Units.PARTS_PER_BILLION);
61         }
62
63         return super.convertToStateImpl(channelId, channelTypeId, getCurrentStateFunc, config);
64     }
65 }