]> git.basschouten.com Git - openhab-addons.git/blob
a5b36a8b0f78d508ba5438f5041af3d113b21ec3
[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.radoneye.internal;
14
15 import static org.openhab.binding.bluetooth.radoneye.internal.RadoneyeBindingConstants.*;
16
17 import java.util.Map;
18 import java.util.UUID;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.core.library.dimension.Density;
22 import org.openhab.core.library.types.QuantityType;
23 import org.openhab.core.thing.Thing;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * The {@link RadoneyeHandler} is responsible for handling commands, which are
29  * sent to one of the channels.
30  *
31  * @author Peter Obel - Initial contribution
32  */
33 @NonNullByDefault
34 public class RadoneyeHandler extends AbstractRadoneyeHandler {
35
36     private static final String SERVICE_UUID = "00001523-1212-efde-1523-785feabcd123";
37     private static final String TRIGGER_UID = "00001524-1212-efde-1523-785feabcd123";
38     private static final String DATA_UUID = "00001525-1212-efde-1523-785feabcd123";
39
40     public RadoneyeHandler(Thing thing) {
41         super(thing);
42     }
43
44     private final Logger logger = LoggerFactory.getLogger(RadoneyeHandler.class);
45
46     private final UUID dataUuid = UUID.fromString(DATA_UUID);
47     private final UUID triggerUuid = UUID.fromString(TRIGGER_UID);
48     private final byte[] triggerData = new byte[] { 0x50 };
49
50     @Override
51     protected void updateChannels(int[] is) {
52         Map<String, Number> data;
53         try {
54             data = RadoneyeDataParser.parseRd200Data(is);
55             logger.debug("Parsed data: {}", data);
56             Number radon = data.get(RadoneyeDataParser.RADON);
57             logger.debug("Parsed data radon number: {}", radon);
58             if (radon != null) {
59                 updateState(CHANNEL_ID_RADON, new QuantityType<Density>(radon, BECQUEREL_PER_CUBIC_METRE));
60             }
61         } catch (RadoneyeParserException e) {
62             logger.error("Failed to parse data received from Radoneye sensor: {}", e.getMessage());
63         }
64     }
65
66     @Override
67     protected UUID getDataUUID() {
68         return dataUuid;
69     }
70
71     @Override
72     protected UUID getTriggerUUID() {
73         return triggerUuid;
74     }
75
76     @Override
77     protected byte[] getTriggerData() {
78         return triggerData;
79     }
80 }