Search in sources :

Example 11 with ThingStatusInfo

use of org.eclipse.smarthome.core.thing.ThingStatusInfo in project smarthome by eclipse.

the class LifxLightHandler method updateStatusIfChanged.

private void updateStatusIfChanged(@NonNull ThingStatus status, @NonNull ThingStatusDetail statusDetail) {
    ThingStatusInfo newStatusInfo = new ThingStatusInfo(status, statusDetail, null);
    Duration durationSinceLastUpdate = Duration.between(lastStatusInfoUpdate, LocalDateTime.now());
    boolean intervalElapsed = MIN_STATUS_INFO_UPDATE_INTERVAL.minus(durationSinceLastUpdate).isNegative();
    if (statusInfo == null || !statusInfo.equals(newStatusInfo) || intervalElapsed) {
        statusInfo = newStatusInfo;
        lastStatusInfoUpdate = LocalDateTime.now();
        updateStatus(status, statusDetail);
    }
}
Also used : ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo) Duration(java.time.Duration)

Example 12 with ThingStatusInfo

use of org.eclipse.smarthome.core.thing.ThingStatusInfo in project smarthome by eclipse.

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(thingRegistry.get(THING_UID)).thenReturn(thing);
    when(thingStatusInfoChangedEvent.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
    when(thingStatusInfoChangedEvent.getThingUID()).thenReturn(THING_UID);
    inboxAutoIgnore.receive(thingStatusInfoChangedEvent);
    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.eclipse.smarthome.config.discovery.DiscoveryResult) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo) Test(org.junit.Test)

Example 13 with ThingStatusInfo

use of org.eclipse.smarthome.core.thing.ThingStatusInfo in project smarthome by eclipse.

the class AutomaticInboxProcessorTest method testThingWithOtherBindingIDButSameRepresentationPropertyWentOnline.

/**
 * This test is just like the test testThingWentOnline in the AutomaticInboxProcessorTest, but in contrast to the
 * above test (where a thing with the same binding ID and the same representation property value went online) here a
 * thing with another binding ID and the same representation property value goes online.
 * <p/>
 * In this case, the discovery result should not be ignored, since it has a different thing type.
 */
@Test
public void testThingWithOtherBindingIDButSameRepresentationPropertyWentOnline() {
    // Add discovery result with thing type THING_TYPE_UID and representation property value DEVICE_ID
    inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(DEVICE_ID_KEY, DEVICE_ID).withRepresentationProperty(DEVICE_ID_KEY).build());
    // Then there is a discovery result which is NEW
    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)));
    // Now a thing with thing type THING_TYPE_UID3 goes online, with representation property value being also the
    // device id
    when(thingRegistry.get(THING_UID3)).thenReturn(thing3);
    when(thingStatusInfoChangedEvent.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
    when(thingStatusInfoChangedEvent.getThingUID()).thenReturn(THING_UID3);
    inboxAutoIgnore.receive(thingStatusInfoChangedEvent);
    // Then there should still be the NEW discovery result, but no IGNORED discovery result
    results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList());
    assertThat(results.size(), is(1));
    assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID)));
    results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList());
    assertThat(results.size(), is(0));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo) Test(org.junit.Test)

Example 14 with ThingStatusInfo

use of org.eclipse.smarthome.core.thing.ThingStatusInfo in project smarthome by eclipse.

the class AutomaticInboxProcessorTest method testThingWithConfigWentOnline.

@Test
public void testThingWithConfigWentOnline() {
    inbox.add(DiscoveryResultBuilder.create(THING_UID2).withProperty(OTHER_KEY, OTHER_VALUE).withRepresentationProperty(OTHER_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_UID2)));
    when(thingRegistry.get(THING_UID2)).thenReturn(thing2);
    when(thingStatusInfoChangedEvent.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
    when(thingStatusInfoChangedEvent.getThingUID()).thenReturn(THING_UID2);
    inboxAutoIgnore.receive(thingStatusInfoChangedEvent);
    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_UID2)));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo) Test(org.junit.Test)

Example 15 with ThingStatusInfo

use of org.eclipse.smarthome.core.thing.ThingStatusInfo in project smarthome by eclipse.

the class FSInternetRadioHandlerJavaTest method verifyConfigurationError.

private void verifyConfigurationError() {
    ThingStatusInfoBuilder statusBuilder = ThingStatusInfoBuilder.create(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
    ThingStatusInfo statusInfo = statusBuilder.withDescription("Configuration incomplete").build();
    verify(callback, atLeast(1)).statusUpdated(radioThing, statusInfo);
}
Also used : ThingStatusInfoBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingStatusInfoBuilder) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo)

Aggregations

ThingStatusInfo (org.eclipse.smarthome.core.thing.ThingStatusInfo)26 Test (org.junit.Test)8 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)5 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)4 Thing (org.eclipse.smarthome.core.thing.Thing)3 ThingStatusInfoBuilder (org.eclipse.smarthome.core.thing.binding.builder.ThingStatusInfoBuilder)3 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Duration (java.time.Duration)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Circuit (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit)1 Device (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Device)1 AbstractHueOSGiTest (org.eclipse.smarthome.binding.hue.test.AbstractHueOSGiTest)1 Bridge (org.eclipse.smarthome.core.thing.Bridge)1 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)1 EnrichedThingDTO (org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTO)1