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);
}
}
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)));
}
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));
}
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)));
}
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);
}
Aggregations