]> git.basschouten.com Git - openhab-addons.git/blob
ac77c4dcf851f10a423c9ec0567be1bd63a8dfd8
[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.grundfosalpha.internal;
14
15 import static org.openhab.binding.bluetooth.grundfosalpha.internal.GrundfosAlphaBindingConstants.*;
16
17 import javax.measure.quantity.Dimensionless;
18 import javax.measure.quantity.Length;
19 import javax.measure.quantity.Temperature;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.binding.bluetooth.BeaconBluetoothHandler;
23 import org.openhab.binding.bluetooth.BluetoothDeviceListener;
24 import org.openhab.binding.bluetooth.notification.BluetoothScanNotification;
25 import org.openhab.core.library.dimension.VolumetricFlowRate;
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 GrundfosAlphaHandler} is responsible for handling commands, which are
35  * sent to one of the channels.
36  *
37  * @author Markus Heberling - Initial contribution
38  */
39 @NonNullByDefault
40 public class GrundfosAlphaHandler extends BeaconBluetoothHandler implements BluetoothDeviceListener {
41
42     private final Logger logger = LoggerFactory.getLogger(GrundfosAlphaHandler.class);
43
44     public GrundfosAlphaHandler(Thing thing) {
45         super(thing);
46     }
47
48     @Override
49     public void onScanRecordReceived(BluetoothScanNotification scanNotification) {
50         super.onScanRecordReceived(scanNotification);
51         byte[] data = scanNotification.getManufacturerData();
52         if (data != null && data.length == 21) {
53             int batteryLevel = (data[5] & 0xFF) * 25;
54             QuantityType<Dimensionless> quantity = new QuantityType<>(batteryLevel, Units.PERCENT);
55             updateState(CHANNEL_TYPE_BATTERY_LEVEL, quantity);
56
57             float flowRate = ((data[9] & 0xFF) << 8 | (data[8] & 0xFF)) / 6553.5f;
58             QuantityType<VolumetricFlowRate> quantity2 = new QuantityType<>(flowRate, Units.CUBICMETRE_PER_HOUR);
59             updateState(CHANNEL_TYPE_FLOW_RATE, quantity2);
60
61             float pumpHead = ((data[11] & 0xFF) << 8 | (data[10] & 0xFF)) / 3276.7f;
62             QuantityType<Length> quantity3 = new QuantityType<>(pumpHead, SIUnits.METRE);
63             updateState(CHANNEL_TYPE_PUMP_HEAD, quantity3);
64
65             float pumpTemperature = data[14] & 0xFF;
66             QuantityType<Temperature> quantity4 = new QuantityType<>(pumpTemperature, SIUnits.CELSIUS);
67             updateState(CHANNEL_TYPE_PUMP_TEMPERATUR, quantity4);
68         }
69     }
70 }