Search in sources :

Example 31 with ThingStatusInfo

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

Example 32 with ThingStatusInfo

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

Example 33 with ThingStatusInfo

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

Example 34 with ThingStatusInfo

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

Example 35 with ThingStatusInfo

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

Aggregations

ThingStatusInfo (org.openhab.core.thing.ThingStatusInfo)101 Test (org.junit.jupiter.api.Test)58 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)33 Thing (org.openhab.core.thing.Thing)22 ThingHandler (org.openhab.core.thing.binding.ThingHandler)22 ThingHandlerCallback (org.openhab.core.thing.binding.ThingHandlerCallback)20 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)17 ThingHandlerFactory (org.openhab.core.thing.binding.ThingHandlerFactory)15 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 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)4