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.grundfosalpha.internal;
15 import static org.openhab.binding.bluetooth.grundfosalpha.internal.GrundfosAlphaBindingConstants.*;
17 import javax.measure.quantity.Dimensionless;
18 import javax.measure.quantity.Length;
19 import javax.measure.quantity.Temperature;
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;
34 * The {@link GrundfosAlphaHandler} is responsible for handling commands, which are
35 * sent to one of the channels.
37 * @author Markus Heberling - Initial contribution
40 public class GrundfosAlphaHandler extends BeaconBluetoothHandler implements BluetoothDeviceListener {
42 private final Logger logger = LoggerFactory.getLogger(GrundfosAlphaHandler.class);
44 public GrundfosAlphaHandler(Thing thing) {
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);
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);
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);
65 float pumpTemperature = data[14] & 0xFF;
66 QuantityType<Temperature> quantity4 = new QuantityType<>(pumpTemperature, SIUnits.CELSIUS);
67 updateState(CHANNEL_TYPE_PUMP_TEMPERATUR, quantity4);