use of org.openhab.core.thing.ThingStatusInfo in project addons by smarthomej.
the class OwserverBridgeHandlerTest method testInitializationReportsRefreshableOnSuccessfullConnection.
@Test
public void testInitializationReportsRefreshableOnSuccessfullConnection() {
final OwserverBridgeHandler bridgeHandler = this.bridgeHandler;
if (bridgeHandler == null) {
fail("bridgeHandler is null");
return;
}
Mockito.doAnswer(answer -> {
bridgeHandler.reportConnectionState(OwserverConnectionState.OPENED);
return null;
}).when(owserverConnection).start();
bridgeHandler.initialize();
ArgumentCaptor<ThingStatusInfo> statusCaptor = ArgumentCaptor.forClass(ThingStatusInfo.class);
waitForAssert(() -> {
verify(thingHandlerCallback, times(2)).statusUpdated(eq(bridge), statusCaptor.capture());
});
assertThat(statusCaptor.getAllValues().get(0).getStatus(), is(ThingStatus.UNKNOWN));
assertThat(statusCaptor.getAllValues().get(1).getStatus(), is(ThingStatus.ONLINE));
waitForAssert(() -> assertTrue(bridgeHandler.isRefreshable()));
}
use of org.openhab.core.thing.ThingStatusInfo in project addons by smarthomej.
the class ClientThingHandlerTest method sendTest.
private void sendTest(ClientConfiguration.Protocol protocol) {
EchoServer echoServer = new EchoServer(protocol);
waitForAssert(() -> assertNotEquals(0, echoServer.getPort(), "Could not start EchoServer"));
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.host = "127.0.0.1";
clientConfiguration.port = echoServer.getPort();
clientConfiguration.protocol = protocol;
TcpUdpChannelConfig tcpUdpChannelConfig = new TcpUdpChannelConfig();
tcpUdpChannelConfig.mode = ChannelMode.WRITEONLY;
ClientThingHandler clientThingHandler = getClientThingHandler(clientConfiguration, tcpUdpChannelConfig);
clientThingHandler.handleCommand(TEST_CHANNEL_UID, new StringType(TEST_STATE_CONTENT));
// check that the thing status is set to unknown
verify(thingHandlerCallback).statusUpdated(clientThingHandler.getThing(), new ThingStatusInfo(ThingStatus.UNKNOWN, ThingStatusDetail.NONE, null));
// wait until we have at least one calls and stop the thing handler
waitForAssert(() -> assertEquals(1, echoServer.getReceivedValues().size()));
clientThingHandler.dispose();
// check the contents are all what we send
List<String> receivedValues = echoServer.getReceivedValues();
assertTrue(receivedValues.stream().allMatch(TEST_STATE_CONTENT::equals));
// no state updates
verify(thingHandlerCallback, never()).stateUpdated(any(), any());
echoServer.stop();
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
the class AutomaticInboxProcessorTest method testThingWentOnline.
@Test
public void testThingWentOnline() {
inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(DEVICE_ID_KEY, DEVICE_ID).withRepresentationProperty(DEVICE_ID_KEY).build());
List<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList());
assertThat(results.size(), is(1));
assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID)));
when(thingRegistryMock.get(THING_UID)).thenReturn(thingMock);
when(thingStatusInfoChangedEventMock.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
when(thingStatusInfoChangedEventMock.getThingUID()).thenReturn(THING_UID);
automaticInboxProcessor.receive(thingStatusInfoChangedEventMock);
results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList());
assertThat(results.size(), is(0));
results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList());
assertThat(results.size(), is(1));
assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID)));
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
the class AutomaticInboxProcessorTest method testThingWhenNoRepresentationPropertySet.
@Test
public void testThingWhenNoRepresentationPropertySet() {
inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(DEVICE_ID_KEY, DEVICE_ID).build());
List<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList());
assertThat(results.size(), is(1));
assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID)));
when(thingMock.getProperties()).thenReturn(Collections.emptyMap());
when(thingStatusInfoChangedEventMock.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
when(thingStatusInfoChangedEventMock.getThingUID()).thenReturn(THING_UID);
automaticInboxProcessor.receive(thingStatusInfoChangedEventMock);
results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList());
assertThat(results.size(), is(0));
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
the class ThingStateMetric method receive.
@Override
public void receive(Event event) {
logger.trace("Received ThingStatusInfo(Changed)Event...");
String thingId = event.getTopic().substring(THINGSTATUS_TOPIC_PREFIX.length(), event.getTopic().lastIndexOf('/'));
ThingStatus status = gson.fromJson(event.getPayload(), ThingStatusInfo.class).getStatus();
createOrUpdateMetricForBundleState(thingId, status.ordinal());
}
Aggregations