use of org.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
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(thingRegistryMock.get(THING_UID2)).thenReturn(thing2Mock);
when(thingStatusInfoChangedEventMock.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
when(thingStatusInfoChangedEventMock.getThingUID()).thenReturn(THING_UID2);
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_UID2)));
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
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(thingRegistryMock.get(THING_UID3)).thenReturn(thing3Mock);
when(thingStatusInfoChangedEventMock.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
when(thingStatusInfoChangedEventMock.getThingUID()).thenReturn(THING_UID3);
automaticInboxProcessor.receive(thingStatusInfoChangedEventMock);
// 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.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
the class ThingManagerImpl method registerAndInitializeHandler.
private void registerAndInitializeHandler(final Thing thing, @Nullable final ThingHandlerFactory thingHandlerFactory) {
if (isDisabledByStorage(thing.getUID())) {
logger.debug("Not registering a handler at this point. Thing is disabled.");
thing.setStatusInfo(new ThingStatusInfo(ThingStatus.UNINITIALIZED, ThingStatusDetail.DISABLED, null));
} else {
if (thingHandlerFactory != null) {
final String identifier = getBundleIdentifier(thingHandlerFactory);
if (loadedXmlThingTypes.contains(identifier)) {
registerHandler(thing, thingHandlerFactory);
initializeHandler(thing);
} else {
logger.debug("Not registering a handler at this point. The thing types of bundle '{}' are not fully loaded yet.", identifier);
}
} else {
logger.debug("Not registering a handler at this point. No handler factory for thing '{}' found.", thing.getUID());
}
}
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
the class ThingManagerImpl method setThingStatus.
private void setThingStatus(Thing thing, ThingStatusInfo thingStatusInfo) {
ThingStatusInfo oldStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, null);
thing.setStatusInfo(thingStatusInfo);
ThingStatusInfo newStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, null);
try {
eventPublisher.post(ThingEventFactory.createStatusInfoEvent(thing.getUID(), newStatusInfo));
if (!oldStatusInfo.equals(newStatusInfo)) {
eventPublisher.post(ThingEventFactory.createStatusInfoChangedEvent(thing.getUID(), newStatusInfo, oldStatusInfo));
}
} catch (Exception ex) {
logger.error("Could not post 'ThingStatusInfoEvent' event: {}", ex.getMessage(), ex);
}
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
the class ThingEventFactory method createStatusInfoChangedEvent.
private Event createStatusInfoChangedEvent(String topic, String payload) throws Exception {
String[] topicElements = getTopicElements(topic);
if (topicElements.length != 4) {
throw new IllegalArgumentException("ThingStatusInfoChangedEvent creation failed, invalid topic: " + topic);
}
ThingUID thingUID = new ThingUID(topicElements[2]);
ThingStatusInfo[] thingStatusInfo = deserializePayload(payload, ThingStatusInfo[].class);
return new ThingStatusInfoChangedEvent(topic, payload, thingUID, thingStatusInfo[0], thingStatusInfo[1]);
}
Aggregations