]> git.basschouten.com Git - openhab-addons.git/blob
a356442c7e5d3a9daec098afb09752d84df063f1
[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.bluetooth.airthings.internal;
14
15 import static org.openhab.binding.bluetooth.airthings.internal.AirthingsBindingConstants.*;
16
17 import java.util.Map;
18 import java.util.UUID;
19
20 import javax.measure.quantity.Dimensionless;
21 import javax.measure.quantity.Pressure;
22 import javax.measure.quantity.Temperature;
23
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.openhab.core.library.dimension.RadiationSpecificActivity;
26 import org.openhab.core.library.types.QuantityType;
27 import org.openhab.core.library.unit.SIUnits;
28 import org.openhab.core.library.unit.Units;
29 import org.openhab.core.thing.Thing;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 /**
34  * The {@link AirthingsWavePlusHandler} is responsible for handling commands, which are
35  * sent to one of the channels.
36  *
37  * @author Pauli Anttila - Initial contribution
38  * @author Kai Kreuzer - Added Airthings Wave Mini support
39  */
40 @NonNullByDefault
41 public class AirthingsWavePlusHandler extends AbstractAirthingsHandler {
42
43     private static final String DATA_UUID = "b42e2a68-ade7-11e4-89d3-123b93f75cba";
44
45     public AirthingsWavePlusHandler(Thing thing) {
46         super(thing);
47     }
48
49     private final Logger logger = LoggerFactory.getLogger(AirthingsWavePlusHandler.class);
50     private final UUID uuid = UUID.fromString(DATA_UUID);
51
52     @Override
53     protected void updateChannels(int[] is) {
54         Map<String, Number> data;
55         try {
56             data = AirthingsDataParser.parseWavePlusData(is);
57             logger.debug("Parsed data: {}", data);
58             Number humidity = data.get(AirthingsDataParser.HUMIDITY);
59             if (humidity != null) {
60                 updateState(CHANNEL_ID_HUMIDITY, new QuantityType<Dimensionless>(humidity, Units.PERCENT));
61             }
62             Number temperature = data.get(AirthingsDataParser.TEMPERATURE);
63             if (temperature != null) {
64                 updateState(CHANNEL_ID_TEMPERATURE, new QuantityType<Temperature>(temperature, SIUnits.CELSIUS));
65             }
66             Number pressure = data.get(AirthingsDataParser.PRESSURE);
67             if (pressure != null) {
68                 updateState(CHANNEL_ID_PRESSURE, new QuantityType<Pressure>(pressure, Units.MILLIBAR));
69             }
70             Number co2 = data.get(AirthingsDataParser.CO2);
71             if (co2 != null) {
72                 updateState(CHANNEL_ID_CO2, new QuantityType<Dimensionless>(co2, Units.PARTS_PER_MILLION));
73             }
74             Number tvoc = data.get(AirthingsDataParser.TVOC);
75             if (tvoc != null) {
76                 updateState(CHANNEL_ID_TVOC, new QuantityType<Dimensionless>(tvoc, Units.PARTS_PER_BILLION));
77             }
78             Number radonShortTermAvg = data.get(AirthingsDataParser.RADON_SHORT_TERM_AVG);
79             if (radonShortTermAvg != null) {
80                 updateState(CHANNEL_ID_RADON_ST_AVG, new QuantityType<RadiationSpecificActivity>(radonShortTermAvg,
81                         Units.BECQUEREL_PER_CUBIC_METRE));
82             }
83             Number radonLongTermAvg = data.get(AirthingsDataParser.RADON_LONG_TERM_AVG);
84             if (radonLongTermAvg != null) {
85                 updateState(CHANNEL_ID_RADON_LT_AVG,
86                         new QuantityType<RadiationSpecificActivity>(radonLongTermAvg, Units.BECQUEREL_PER_CUBIC_METRE));
87             }
88         } catch (AirthingsParserException e) {
89             logger.error("Failed to parse data received from Airthings sensor: {}", e.getMessage());
90         }
91     }
92
93     @Override
94     protected UUID getDataUUID() {
95         return uuid;
96     }
97 }