Search in sources :

Example 66 with ThingStatusInfo

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()));
}
Also used : OwserverBridgeHandler(org.smarthomej.binding.onewire.internal.handler.OwserverBridgeHandler) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) Test(org.junit.jupiter.api.Test) JavaTest(org.openhab.core.test.java.JavaTest)

Example 67 with ThingStatusInfo

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();
}
Also used : TcpUdpChannelConfig(org.smarthomej.binding.tcpudp.internal.config.TcpUdpChannelConfig) StringType(org.openhab.core.library.types.StringType) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) ClientConfiguration(org.smarthomej.binding.tcpudp.internal.config.ClientConfiguration) EchoServer(org.smarthomej.binding.tcpudp.internal.test.EchoServer)

Example 68 with ThingStatusInfo

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)));
}
Also used : DiscoveryResult(org.openhab.core.config.discovery.DiscoveryResult) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) Test(org.junit.jupiter.api.Test)

Example 69 with ThingStatusInfo

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));
}
Also used : DiscoveryResult(org.openhab.core.config.discovery.DiscoveryResult) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) Test(org.junit.jupiter.api.Test)

Example 70 with ThingStatusInfo

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());
}
Also used : ThingStatus(org.openhab.core.thing.ThingStatus) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo)

Aggregations

ThingStatusInfo (org.openhab.core.thing.ThingStatusInfo)102 Test (org.junit.jupiter.api.Test)59 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)34 Thing (org.openhab.core.thing.Thing)23 ThingHandler (org.openhab.core.thing.binding.ThingHandler)23 ThingHandlerCallback (org.openhab.core.thing.binding.ThingHandlerCallback)20 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)18 ThingHandlerFactory (org.openhab.core.thing.binding.ThingHandlerFactory)16 Nullable (org.eclipse.jdt.annotation.Nullable)14 Configuration (org.openhab.core.config.core.Configuration)13 ThingUID (org.openhab.core.thing.ThingUID)13 InvocationOnMock (org.mockito.invocation.InvocationOnMock)12 Bridge (org.openhab.core.thing.Bridge)12 JavaTest (org.openhab.core.test.java.JavaTest)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 DiscoveryResult (org.openhab.core.config.discovery.DiscoveryResult)5 BaseThingHandler (org.openhab.core.thing.binding.BaseThingHandler)5 ArrayList (java.util.ArrayList)4 ThingStatus (org.openhab.core.thing.ThingStatus)4