use of org.openhab.core.thing.binding.ThingHandlerCallback in project openhab-addons by openhab.
the class DeutscheBahnTrainHandlerTest method testWithoutBridgeStateUpdatesToOffline.
@Test
public void testWithoutBridgeStateUpdatesToOffline() {
final Thing thing = mockThing(1);
final ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
final DeutscheBahnTrainHandler handler = createAndInitHandler(callback, thing);
try {
verify(callback).statusUpdated(eq(thing), argThat(arg -> arg.getStatus().equals(ThingStatus.UNKNOWN)));
verify(callback, timeout(1000)).statusUpdated(eq(thing), argThat(arg -> arg.getStatus().equals(ThingStatus.OFFLINE)));
} finally {
handler.dispose();
}
}
use of org.openhab.core.thing.binding.ThingHandlerCallback in project openhab-addons by openhab.
the class DeutscheBahnTrainHandlerTest method testUpdateChannelsWithEventNotPresent.
@Test
public void testUpdateChannelsWithEventNotPresent() {
final Thing thing = mockThing(1);
final ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
ThingUID bridgeId = new ThingUID(DeutscheBahnBindingConstants.TIMETABLE_TYPE, "timetable");
when(callback.getBridge(bridgeId)).thenReturn(new BridgeImpl(DeutscheBahnBindingConstants.TIMETABLE_TYPE, bridgeId));
final DeutscheBahnTrainHandler handler = createAndInitHandler(callback, thing);
try {
verify(callback).statusUpdated(eq(thing), argThat(arg -> arg.getStatus().equals(ThingStatus.UNKNOWN)));
verify(callback, timeout(1000)).statusUpdated(eq(thing), argThat(arg -> arg.getStatus().equals(ThingStatus.ONLINE)));
// Provide data that will update the channels
TimetableStop stop = new TimetableStop();
Event arrival = new Event();
arrival.setPt("2108161434");
arrival.setL("RE60");
stop.setAr(arrival);
handler.updateChannels(stop);
final Date arrivalTime = new GregorianCalendar(2021, 7, 16, 14, 34).getTime();
verify(callback, timeout(1000)).stateUpdated(new ChannelUID(thing.getUID(), "trip#category"), UnDefType.UNDEF);
verify(callback, timeout(1000)).stateUpdated(new ChannelUID(thing.getUID(), "arrival#planned-time"), getDateTime(arrivalTime));
verify(callback, timeout(1000)).stateUpdated(new ChannelUID(thing.getUID(), "arrival#line"), new StringType("RE60"));
verify(callback, timeout(1000)).stateUpdated(new ChannelUID(thing.getUID(), "arrival#changed-time"), UnDefType.NULL);
verify(callback, timeout(1000)).stateUpdated(new ChannelUID(thing.getUID(), "departure#planned-time"), UnDefType.UNDEF);
verify(callback, timeout(1000)).stateUpdated(new ChannelUID(thing.getUID(), "departure#planned-platform"), UnDefType.UNDEF);
verify(callback, timeout(1000)).stateUpdated(new ChannelUID(thing.getUID(), "departure#planned-final-station"), UnDefType.UNDEF);
} finally {
handler.dispose();
}
}
use of org.openhab.core.thing.binding.ThingHandlerCallback in project openhab-addons by openhab.
the class DmxBridgeHandlerTest method setUp.
@BeforeEach
public void setUp() {
bridgeProperties = new HashMap<>();
bridge = BridgeBuilder.create(THING_TYPE_TEST_BRIDGE, "testbridge").withLabel("Test Bridge").withChannel(ChannelBuilder.create(CHANNEL_UID_MUTE, "Switch").withType(MUTE_CHANNEL_TYPEUID).build()).withConfiguration(new Configuration(bridgeProperties)).build();
ThingHandlerCallback mockCallback = mock(ThingHandlerCallback.class);
doAnswer(answer -> {
((Thing) answer.getArgument(0)).setStatusInfo(answer.getArgument(1));
return null;
}).when(mockCallback).statusUpdated(any(), any());
bridgeHandler = Mockito.spy(new DmxBridgeHandlerImpl(bridge));
bridgeHandler.getThing().setHandler(bridgeHandler);
bridgeHandler.setCallback(mockCallback);
bridgeHandler.initialize();
}
use of org.openhab.core.thing.binding.ThingHandlerCallback in project openhab-addons by openhab.
the class Lib485BridgeHandlerTest method setUp.
@BeforeEach
public void setUp() {
bridgeProperties = new HashMap<>();
bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
bridge = BridgeBuilder.create(THING_TYPE_LIB485_BRIDGE, "lib485bridge").withLabel("Lib485 Bridge").withChannel(ChannelBuilder.create(CHANNEL_UID_MUTE, "Switch").withType(MUTE_CHANNEL_TYPEUID).build()).withConfiguration(new Configuration(bridgeProperties)).build();
ThingHandlerCallback mockCallback = mock(ThingHandlerCallback.class);
doAnswer(answer -> {
((Thing) answer.getArgument(0)).setStatusInfo(answer.getArgument(1));
return null;
}).when(mockCallback).statusUpdated(any(), any());
bridgeHandler = new Lib485BridgeHandler(bridge) {
@Override
protected void validateConfigurationParameters(Map<String, Object> configurationParameters) {
}
};
bridgeHandler.getThing().setHandler(bridgeHandler);
bridgeHandler.setCallback(mockCallback);
bridgeHandler.initialize();
}
use of org.openhab.core.thing.binding.ThingHandlerCallback in project openhab-addons by openhab.
the class ArtnetBridgeHandlerTest method setUp.
@BeforeEach
public void setUp() {
bridgeProperties = new HashMap<>();
bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
bridgeProperties.put(CONFIG_UNIVERSE, TEST_UNIVERSE);
bridge = BridgeBuilder.create(THING_TYPE_ARTNET_BRIDGE, "artnetbridge").withLabel("Artnet Bridge").withChannel(ChannelBuilder.create(CHANNEL_UID_MUTE, "Switch").withType(MUTE_CHANNEL_TYPEUID).build()).withConfiguration(new Configuration(bridgeProperties)).build();
ThingHandlerCallback mockCallback = mock(ThingHandlerCallback.class);
doAnswer(answer -> {
((Thing) answer.getArgument(0)).setStatusInfo(answer.getArgument(1));
return null;
}).when(mockCallback).statusUpdated(any(), any());
bridgeHandler = new ArtnetBridgeHandler(bridge) {
@Override
protected void validateConfigurationParameters(Map<String, Object> configurationParameters) {
}
};
bridgeHandler.getThing().setHandler(bridgeHandler);
bridgeHandler.setCallback(mockCallback);
bridgeHandler.initialize();
}
Aggregations