]> git.basschouten.com Git - openhab-addons.git/blob
bec8d436612613163fee031939dd33ebd0d17018
[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.Temperature;
22
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.openhab.core.library.types.QuantityType;
25 import org.openhab.core.library.unit.SIUnits;
26 import org.openhab.core.library.unit.Units;
27 import org.openhab.core.thing.Thing;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * The {@link AirthingsWaveMiniHandler} is responsible for handling commands, which are
33  * sent to one of the channels.
34  *
35  * @author Kai Kreuzer - Initial contribution
36  */
37 @NonNullByDefault
38 public class AirthingsWaveMiniHandler extends AbstractAirthingsHandler {
39
40     private static final String DATA_UUID = "b42e3b98-ade7-11e4-89d3-123b93f75cba";
41
42     public AirthingsWaveMiniHandler(Thing thing) {
43         super(thing);
44     }
45
46     private final Logger logger = LoggerFactory.getLogger(AirthingsWaveMiniHandler.class);
47
48     private final UUID uuid = UUID.fromString(DATA_UUID);
49
50     @Override
51     protected void updateChannels(int[] is) {
52         Map<String, Number> data;
53         try {
54             data = AirthingsDataParser.parseWaveMiniData(is);
55             logger.debug("Parsed data: {}", data);
56             Number humidity = data.get(AirthingsDataParser.HUMIDITY);
57             if (humidity != null) {
58                 updateState(CHANNEL_ID_HUMIDITY, new QuantityType<Dimensionless>(humidity, Units.PERCENT));
59             }
60             Number temperature = data.get(AirthingsDataParser.TEMPERATURE);
61             if (temperature != null) {
62                 updateState(CHANNEL_ID_TEMPERATURE, new QuantityType<Temperature>(temperature, SIUnits.CELSIUS));
63             }
64             Number tvoc = data.get(AirthingsDataParser.TVOC);
65             if (tvoc != null) {
66                 updateState(CHANNEL_ID_TVOC, new QuantityType<Dimensionless>(tvoc, Units.PARTS_PER_BILLION));
67             }
68         } catch (AirthingsParserException e) {
69             logger.error("Failed to parse data received from Airthings sensor: {}", e.getMessage());
70         }
71     }
72
73     @Override
74     protected UUID getDataUUID() {
75         return uuid;
76     }
77 }