-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Markus Heberling <[email protected]>
- Loading branch information
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
.../org/openhab/binding/bluetooth/grundfosalpha/internal/GrundfosAlphaReaderHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.bluetooth.grundfosalpha.internal; | ||
|
||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.openhab.binding.bluetooth.notification.BluetoothScanNotification; | ||
import org.openhab.core.library.types.QuantityType; | ||
import org.openhab.core.library.unit.SIUnits; | ||
import org.openhab.core.library.unit.Units; | ||
import org.openhab.core.thing.ChannelUID; | ||
import org.openhab.core.thing.Thing; | ||
import org.openhab.core.thing.ThingStatus; | ||
import org.openhab.core.thing.ThingStatusDetail; | ||
import org.openhab.core.thing.ThingStatusInfo; | ||
import org.openhab.core.thing.ThingUID; | ||
import org.openhab.core.thing.binding.ThingHandlerCallback; | ||
import org.openhab.core.util.HexUtils; | ||
|
||
/** | ||
* Test the {@link GrundfosAlphaReaderHandler}. | ||
* | ||
* @author Markus Heberling - Initial contribution | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
class GrundfosAlphaReaderHandlerTest { | ||
|
||
private @Mock Thing thingMock; | ||
|
||
private @Mock ThingHandlerCallback callback; | ||
|
||
@Test | ||
public void testMessageType0xf1() { | ||
byte[] data = HexUtils.hexToBytes("15f130017a5113030300994109589916613003004005"); | ||
final BluetoothScanNotification scanNotification = new BluetoothScanNotification(); | ||
scanNotification.setManufacturerData(data); | ||
final GrundfosAlphaReaderHandler handler = new GrundfosAlphaReaderHandler(thingMock); | ||
handler.setCallback(callback); | ||
handler.onScanRecordReceived(scanNotification); | ||
|
||
verify(callback).statusUpdated(thingMock, | ||
new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null)); | ||
|
||
verifyNoMoreInteractions(callback); | ||
} | ||
|
||
@Test | ||
public void testMessageType0xf2() { | ||
when(thingMock.getUID()) | ||
.thenReturn(new ThingUID(GrundfosAlphaReaderBindingConstants.THING_TYPE_MI401, "dummy")); | ||
|
||
byte[] data = HexUtils.hexToBytes("14f23001650305065419b9180f011f007c1878170d"); | ||
final BluetoothScanNotification scanNotification = new BluetoothScanNotification(); | ||
scanNotification.setManufacturerData(data); | ||
final GrundfosAlphaReaderHandler handler = new GrundfosAlphaReaderHandler(thingMock); | ||
handler.setCallback(callback); | ||
handler.onScanRecordReceived(scanNotification); | ||
|
||
verify(callback).statusUpdated(thingMock, | ||
new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null)); | ||
verify(callback).stateUpdated( | ||
new ChannelUID(thingMock.getUID(), GrundfosAlphaReaderBindingConstants.CHANNEL_TYPE_BATTERY_LEVEL), | ||
new QuantityType<>(75, Units.PERCENT)); | ||
verify(callback).stateUpdated( | ||
new ChannelUID(thingMock.getUID(), GrundfosAlphaReaderBindingConstants.CHANNEL_TYPE_FLOW_RATE), | ||
new QuantityType<>(0.98939496, Units.CUBICMETRE_PER_HOUR)); | ||
verify(callback).stateUpdated( | ||
new ChannelUID(thingMock.getUID(), GrundfosAlphaReaderBindingConstants.CHANNEL_TYPE_PUMP_HEAD), | ||
new QuantityType<>(1.9315165, SIUnits.METRE)); | ||
verify(callback).stateUpdated( | ||
new ChannelUID(thingMock.getUID(), GrundfosAlphaReaderBindingConstants.CHANNEL_TYPE_PUMP_TEMPERATUR), | ||
new QuantityType<>(31, SIUnits.CELSIUS)); | ||
|
||
verifyNoMoreInteractions(callback); | ||
} | ||
} |