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.bluetooth.airthings.internal;
15 import static org.openhab.binding.bluetooth.airthings.internal.AirthingsBindingConstants.*;
18 import java.util.UUID;
20 import javax.measure.quantity.Dimensionless;
21 import javax.measure.quantity.Pressure;
22 import javax.measure.quantity.Temperature;
24 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import org.openhab.core.library.dimension.Density;
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;
34 * The {@link AirthingsWavePlusHandler} is responsible for handling commands, which are
35 * sent to one of the channels.
37 * @author Pauli Anttila - Initial contribution
38 * @author Kai Kreuzer - Added Airthings Wave Mini support
41 public class AirthingsWavePlusHandler extends AbstractAirthingsHandler {
43 private static final String DATA_UUID = "b42e2a68-ade7-11e4-89d3-123b93f75cba";
45 public AirthingsWavePlusHandler(Thing thing) {
49 private final Logger logger = LoggerFactory.getLogger(AirthingsWavePlusHandler.class);
50 private final UUID uuid = UUID.fromString(DATA_UUID);
53 protected void updateChannels(int[] is) {
54 Map<String, Number> data;
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));
62 Number temperature = data.get(AirthingsDataParser.TEMPERATURE);
63 if (temperature != null) {
64 updateState(CHANNEL_ID_TEMPERATURE, new QuantityType<Temperature>(temperature, SIUnits.CELSIUS));
66 Number pressure = data.get(AirthingsDataParser.PRESSURE);
67 if (pressure != null) {
68 updateState(CHANNEL_ID_PRESSURE, new QuantityType<Pressure>(pressure, Units.MILLIBAR));
70 Number co2 = data.get(AirthingsDataParser.CO2);
72 updateState(CHANNEL_ID_CO2, new QuantityType<Dimensionless>(co2, Units.PARTS_PER_MILLION));
74 Number tvoc = data.get(AirthingsDataParser.TVOC);
76 updateState(CHANNEL_ID_TVOC, new QuantityType<Dimensionless>(tvoc, Units.PARTS_PER_BILLION));
78 Number radonShortTermAvg = data.get(AirthingsDataParser.RADON_SHORT_TERM_AVG);
79 if (radonShortTermAvg != null) {
80 updateState(CHANNEL_ID_RADON_ST_AVG,
81 new QuantityType<Density>(radonShortTermAvg, Units.BECQUEREL_PER_CUBIC_METRE));
83 Number radonLongTermAvg = data.get(AirthingsDataParser.RADON_LONG_TERM_AVG);
84 if (radonLongTermAvg != null) {
85 updateState(CHANNEL_ID_RADON_LT_AVG,
86 new QuantityType<Density>(radonLongTermAvg, Units.BECQUEREL_PER_CUBIC_METRE));
88 } catch (AirthingsParserException e) {
89 logger.error("Failed to parse data received from Airthings sensor: {}", e.getMessage());
94 protected UUID getDataUUID() {