use of org.openhab.core.thing.profiles.ProfileCallback in project openhab-addons by openhab.
the class ModbusGainOffsetProfileTest method testOnUpdateFromHandlerGeneric.
/**
* Test profile behaviour when handler updates the state
*
* @param preGainOffset profile pre-gain-offset offset
* @param gain profile gain
* @param updateFromHandlerObj state update from handler. String representing QuantityType or State/Command
* @param expectedUpdateTowardsItemObj expected state/command update towards item. String representing QuantityType
* or
* State
* @param stateUpdateFromHandler whether there is state update from handler. Otherwise command
*/
@SuppressWarnings("rawtypes")
private void testOnUpdateFromHandlerGeneric(String preGainOffset, String gain, Object updateFromHandlerObj, Object expectedUpdateTowardsItemObj, boolean stateUpdateFromHandler) {
ProfileCallback callback = mock(ProfileCallback.class);
ModbusGainOffsetProfile profile = createProfile(callback, gain, preGainOffset);
final Type actualStateUpdateTowardsItem;
if (stateUpdateFromHandler) {
final State updateFromHandler;
if (updateFromHandlerObj instanceof String) {
updateFromHandler = new QuantityType((String) updateFromHandlerObj);
} else {
assertTrue(updateFromHandlerObj instanceof State);
updateFromHandler = (State) updateFromHandlerObj;
}
profile.onStateUpdateFromHandler(updateFromHandler);
ArgumentCaptor<State> capture = ArgumentCaptor.forClass(State.class);
verify(callback, times(1)).sendUpdate(capture.capture());
actualStateUpdateTowardsItem = capture.getValue();
} else {
final Command updateFromHandler;
if (updateFromHandlerObj instanceof String) {
updateFromHandler = new QuantityType((String) updateFromHandlerObj);
} else {
assertTrue(updateFromHandlerObj instanceof State);
updateFromHandler = (Command) updateFromHandlerObj;
}
profile.onCommandFromHandler(updateFromHandler);
ArgumentCaptor<Command> capture = ArgumentCaptor.forClass(Command.class);
verify(callback, times(1)).sendCommand(capture.capture());
actualStateUpdateTowardsItem = capture.getValue();
}
Type expectedStateUpdateTowardsItem = (expectedUpdateTowardsItemObj instanceof String) ? new QuantityType((String) expectedUpdateTowardsItemObj) : (Type) expectedUpdateTowardsItemObj;
assertEquals(expectedStateUpdateTowardsItem, actualStateUpdateTowardsItem);
verifyNoMoreInteractions(callback);
}
use of org.openhab.core.thing.profiles.ProfileCallback in project openhab-addons by openhab.
the class ModbusGainOffsetProfileTest method testInvalidInit.
@Test
public void testInvalidInit() {
// preGainOffset must be dimensionless
ProfileCallback callback = mock(ProfileCallback.class);
ModbusGainOffsetProfile<?> profile = createProfile(callback, "1.0", "0.0 K");
assertFalse(profile.isValid());
}
use of org.openhab.core.thing.profiles.ProfileCallback in project openhab-addons by openhab.
the class ModbusGainOffsetProfileTest method testInitGainDefault.
@ParameterizedTest
@NullSource
@EmptySource
public void testInitGainDefault(String gain) {
ProfileCallback callback = mock(ProfileCallback.class);
ModbusGainOffsetProfile<?> p = createProfile(callback, gain, "0.0");
assertTrue(p.isValid());
assertEquals(p.getGain(), Optional.of(QuantityType.ONE));
}
use of org.openhab.core.thing.profiles.ProfileCallback in project openhab-core by openhab.
the class SystemOffsetProfileTest method testQuantityTypeOnCommandFromItem.
@Test
public void testQuantityTypeOnCommandFromItem() {
ProfileCallback callback = mock(ProfileCallback.class);
SystemOffsetProfile offsetProfile = createProfile(callback, "3°C");
Command cmd = new QuantityType<>("23°C");
offsetProfile.onCommandFromItem(cmd);
ArgumentCaptor<Command> capture = ArgumentCaptor.forClass(Command.class);
verify(callback, times(1)).handleCommand(capture.capture());
Command result = capture.getValue();
QuantityType<?> decResult = (QuantityType<?>) result;
assertEquals(20, decResult.intValue());
assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
use of org.openhab.core.thing.profiles.ProfileCallback in project openhab-core by openhab.
the class SystemOffsetProfileTest method testQuantityTypeOnCommandFromHandler.
@Test
public void testQuantityTypeOnCommandFromHandler() {
ProfileCallback callback = mock(ProfileCallback.class);
SystemOffsetProfile offsetProfile = createProfile(callback, "3°C");
Command cmd = new QuantityType<>("23°C");
offsetProfile.onCommandFromHandler(cmd);
ArgumentCaptor<Command> capture = ArgumentCaptor.forClass(Command.class);
verify(callback, times(1)).sendCommand(capture.capture());
Command result = capture.getValue();
QuantityType<?> decResult = (QuantityType<?>) result;
assertEquals(26, decResult.intValue());
assertEquals(SIUnits.CELSIUS, decResult.getUnit());
}
Aggregations