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.mockito.Mockito.verify;
16 import static org.mockito.Mockito.verifyNoMoreInteractions;
17 import static org.mockito.Mockito.when;
19 import org.junit.jupiter.api.Test;
20 import org.junit.jupiter.api.extension.ExtendWith;
21 import org.mockito.Mock;
22 import org.mockito.junit.jupiter.MockitoExtension;
23 import org.openhab.binding.bluetooth.notification.BluetoothScanNotification;
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.ChannelUID;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingStatus;
30 import org.openhab.core.thing.ThingStatusDetail;
31 import org.openhab.core.thing.ThingStatusInfo;
32 import org.openhab.core.thing.ThingUID;
33 import org.openhab.core.thing.binding.ThingHandlerCallback;
34 import org.openhab.core.util.HexUtils;
37 * Test the {@link GrundfosAlphaHandler}.
39 * @author Markus Heberling - Initial contribution
41 @ExtendWith(MockitoExtension.class)
42 class GrundfosAlphaHandlerTest {
44 private @Mock Thing thingMock;
46 private @Mock ThingHandlerCallback callback;
49 public void testMessageType0xf1() {
50 byte[] data = HexUtils.hexToBytes("15f130017a5113030300994109589916613003004005");
51 final BluetoothScanNotification scanNotification = new BluetoothScanNotification();
52 scanNotification.setManufacturerData(data);
53 final GrundfosAlphaHandler handler = new GrundfosAlphaHandler(thingMock);
54 handler.setCallback(callback);
55 handler.onScanRecordReceived(scanNotification);
57 verify(callback).statusUpdated(thingMock,
58 new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
60 verifyNoMoreInteractions(callback);
64 public void testMessageType0xf2() {
65 when(thingMock.getUID()).thenReturn(new ThingUID(GrundfosAlphaBindingConstants.THING_TYPE_MI401, "dummy"));
67 byte[] data = HexUtils.hexToBytes("14f23001650305065419b9180f011f007c1878170d");
68 final BluetoothScanNotification scanNotification = new BluetoothScanNotification();
69 scanNotification.setManufacturerData(data);
70 final GrundfosAlphaHandler handler = new GrundfosAlphaHandler(thingMock);
71 handler.setCallback(callback);
72 handler.onScanRecordReceived(scanNotification);
74 verify(callback).statusUpdated(thingMock,
75 new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
76 verify(callback).stateUpdated(
77 new ChannelUID(thingMock.getUID(), GrundfosAlphaBindingConstants.CHANNEL_TYPE_BATTERY_LEVEL),
78 new QuantityType<>(75, Units.PERCENT));
79 verify(callback).stateUpdated(
80 new ChannelUID(thingMock.getUID(), GrundfosAlphaBindingConstants.CHANNEL_TYPE_FLOW_RATE),
81 new QuantityType<>(0.98939496, Units.CUBICMETRE_PER_HOUR));
82 verify(callback).stateUpdated(
83 new ChannelUID(thingMock.getUID(), GrundfosAlphaBindingConstants.CHANNEL_TYPE_PUMP_HEAD),
84 new QuantityType<>(1.9315165, SIUnits.METRE));
85 verify(callback).stateUpdated(
86 new ChannelUID(thingMock.getUID(), GrundfosAlphaBindingConstants.CHANNEL_TYPE_PUMP_TEMPERATUR),
87 new QuantityType<>(31, SIUnits.CELSIUS));
89 verifyNoMoreInteractions(callback);