]> git.basschouten.com Git - openhab-addons.git/blob
c1de0b517b51dab8da0eb95d8e9764d40e9041f2
[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 UUID SERVICE_UUID_V1 = UUID.fromString("00001523-1212-efde-1523-785feabcd123");
37     private static final UUID SERVICE_UUID_V2 = UUID.fromString("00001524-0000-1000-8000-00805f9b34fb");
38     private static final UUID TRIGGER_UID_V1 = UUID.fromString("00001524-1212-efde-1523-785feabcd123");
39     private static final UUID TRIGGER_UID_V2 = UUID.fromString("00001524-0000-1000-8000-00805f9b34fb");
40     private static final UUID DATA_UUID_V1 = UUID.fromString("00001525-1212-efde-1523-785feabcd123");
41     private static final UUID DATA_UUID_V2 = UUID.fromString("00001525-0000-1000-8000-00805f9b34fb");
42     private static final byte[] DATA_TRIGGER_V1 = new byte[] { 0x50 };
43     private static final byte[] DATA_TRIGGER_V2 = new byte[] { 0x50 };
44
45     public RadoneyeHandler(Thing thing) {
46         super(thing);
47     }
48
49     private final Logger logger = LoggerFactory.getLogger(RadoneyeHandler.class);
50
51     @Override
52     protected void updateChannels(int[] is) {
53         Map<String, Number> data;
54         try {
55             data = RadoneyeDataParser.parseRd200Data(getFwVersion(), is);
56             logger.debug("Parsed data: {}", data);
57             Number radon = data.get(RadoneyeDataParser.RADON);
58             logger.debug("Parsed data radon number: {}", radon);
59             if (radon != null) {
60                 updateState(CHANNEL_ID_RADON, new QuantityType<Density>(radon, BECQUEREL_PER_CUBIC_METRE));
61             }
62         } catch (RadoneyeParserException e) {
63             logger.error("Failed to parse data received from Radoneye sensor: {}", e.getMessage());
64         }
65     }
66
67     @Override
68     protected UUID getDataUUID() {
69         int fwVersion = getFwVersion();
70         switch (fwVersion) {
71             case 1:
72                 return DATA_UUID_V1;
73             case 2:
74                 return DATA_UUID_V2;
75             default:
76                 throw new UnsupportedOperationException("fwVersion: " + fwVersion + " is not implemented");
77         }
78     }
79
80     @Override
81     protected UUID getTriggerUUID() {
82         int fwVersion = getFwVersion();
83         switch (fwVersion) {
84             case 1:
85                 return TRIGGER_UID_V1;
86             case 2:
87                 return TRIGGER_UID_V2;
88             default:
89                 throw new UnsupportedOperationException("fwVersion: " + fwVersion + " is not implemented");
90         }
91     }
92
93     @Override
94     protected byte[] getTriggerData() {
95         int fwVersion = getFwVersion();
96         switch (fwVersion) {
97             case 1:
98                 return DATA_TRIGGER_V1;
99             case 2:
100                 return DATA_TRIGGER_V2;
101             default:
102                 throw new UnsupportedOperationException("fwVersion: " + fwVersion + " is not implemented");
103         }
104     }
105 }