Search in sources :

Example 1 with Inbox

use of org.eclipse.smarthome.config.discovery.inbox.Inbox in project smarthome by eclipse.

the class AutomaticInboxProcessor method thingAdded.

@Override
public void thingAdded(Inbox inbox, DiscoveryResult result) {
    if (autoIgnore) {
        String value = getRepresentationValue(result);
        if (value != null) {
            Thing thing = thingRegistry.stream().filter(t -> Objects.equals(value, getRepresentationPropertyValueForThing(t))).filter(t -> Objects.equals(t.getThingTypeUID(), result.getThingTypeUID())).findFirst().orElse(null);
            if (thing != null) {
                logger.debug("Auto-ignoring the inbox entry for the representation value {}", value);
                inbox.setFlag(result.getThingUID(), DiscoveryResultFlag.IGNORED);
            }
        }
    }
    if (autoApprove) {
        inbox.approve(result.getThingUID(), result.getLabel());
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) InboxListener(org.eclipse.smarthome.config.discovery.inbox.InboxListener) EventSubscriber(org.eclipse.smarthome.core.events.EventSubscriber) RegistryChangeListener(org.eclipse.smarthome.core.common.registry.RegistryChangeListener) ThingStatusInfoChangedEvent(org.eclipse.smarthome.core.thing.events.ThingStatusInfoChangedEvent) Component(org.osgi.service.component.annotations.Component) Inbox(org.eclipse.smarthome.config.discovery.inbox.Inbox) Nullable(org.eclipse.jdt.annotation.Nullable) Map(java.util.Map) Thing(org.eclipse.smarthome.core.thing.Thing) Configuration(org.eclipse.smarthome.config.core.Configuration) InboxPredicates(org.eclipse.smarthome.config.discovery.inbox.InboxPredicates) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) Logger(org.slf4j.Logger) Collectors(java.util.stream.Collectors) ThingTypeRegistry(org.eclipse.smarthome.core.thing.type.ThingTypeRegistry) Objects(java.util.Objects) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) List(java.util.List) DiscoveryResultFlag(org.eclipse.smarthome.config.discovery.DiscoveryResultFlag) AbstractTypedEventSubscriber(org.eclipse.smarthome.core.events.AbstractTypedEventSubscriber) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Reference(org.osgi.service.component.annotations.Reference) DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingStatus(org.eclipse.smarthome.core.thing.ThingStatus) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 2 with Inbox

use of org.eclipse.smarthome.config.discovery.inbox.Inbox in project smarthome by eclipse.

the class DiscoveryServiceRegistryOSGiTest method cleanUp.

@After
public void cleanUp() {
    extendedDiscoveryServiceMock.abortScan();
    discoveryServiceFaultyMock.abortScan();
    discoveryServiceMockForBinding1.abortScan();
    discoveryServiceMockForBinding2.abortScan();
    discoveryServiceMockForBinding3Bridge1.abortScan();
    discoveryServiceMockForBinding3Bridge2.abortScan();
    serviceRegs.forEach(ServiceRegistration::unregister);
    Inbox inbox = getService(Inbox.class);
    List<DiscoveryResult> discoveryResults = inbox.getAll();
    discoveryResults.forEach(res -> inbox.remove(res.getThingUID()));
    discoveryServiceRegistry.removeDiscoveryListener(mockDiscoveryListener);
}
Also used : Inbox(org.eclipse.smarthome.config.discovery.inbox.Inbox) ServiceRegistration(org.osgi.framework.ServiceRegistration) After(org.junit.After)

Example 3 with Inbox

use of org.eclipse.smarthome.config.discovery.inbox.Inbox in project smarthome by eclipse.

the class DiscoveryServiceRegistryOSGiTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    registerVolatileStorageService();
    thingRegistry = getService(ThingRegistry.class);
    assertNotNull(thingRegistry);
    inbox = getService(Inbox.class);
    assertNotNull(inbox);
    discoveryServiceMockForBinding1 = new DiscoveryServiceMock(new ThingTypeUID(ANY_BINDING_ID_1, ANY_THING_TYPE_1), 1);
    discoveryServiceMockForBinding2 = new ExtendedDiscoveryServiceMock(new ThingTypeUID(ANY_BINDING_ID_2, ANY_THING_TYPE_2), 3);
    discoveryServiceMockForBinding3Bridge1 = new DiscoveryServiceMockOfBridge(new ThingTypeUID(ANY_BINDING_ID_3, ANY_THING_TYPE_3), 1, BRIDGE_UID_1);
    discoveryServiceMockForBinding3Bridge2 = new DiscoveryServiceMockOfBridge(new ThingTypeUID(ANY_BINDING_ID_3, ANY_THING_TYPE_3), 1, BRIDGE_UID_2);
    discoveryServiceFaultyMock = new DiscoveryServiceMock(new ThingTypeUID(FAULTY_BINDING_ID, FAULTY_THING_TYPE), 1, true);
    extendedDiscoveryServiceMock = new ExtendedDiscoveryServiceMock(new ThingTypeUID(EXTENDED_BINDING_ID, EXTENDED_THING_TYPE), 1, true);
    serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceMockForBinding1, null));
    serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceMockForBinding2, null));
    serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceMockForBinding3Bridge1, null));
    serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceMockForBinding3Bridge2, null));
    serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), discoveryServiceFaultyMock, null));
    serviceRegs.add(bundleContext.registerService(DiscoveryService.class.getName(), extendedDiscoveryServiceMock, null));
    discoveryServiceRegistry = getService(DiscoveryServiceRegistry.class);
}
Also used : ExtendedDiscoveryServiceMock(org.eclipse.smarthome.config.setup.test.discovery.ExtendedDiscoveryServiceMock) DiscoveryServiceMockOfBridge(org.eclipse.smarthome.config.setup.test.discovery.DiscoveryServiceMockOfBridge) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Inbox(org.eclipse.smarthome.config.discovery.inbox.Inbox) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) ExtendedDiscoveryServiceMock(org.eclipse.smarthome.config.setup.test.discovery.ExtendedDiscoveryServiceMock) DiscoveryServiceMock(org.eclipse.smarthome.config.setup.test.discovery.DiscoveryServiceMock) Before(org.junit.Before)

Aggregations

Inbox (org.eclipse.smarthome.config.discovery.inbox.Inbox)3 ThingRegistry (org.eclipse.smarthome.core.thing.ThingRegistry)2 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)2 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 Configuration (org.eclipse.smarthome.config.core.Configuration)1 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)1 DiscoveryResultFlag (org.eclipse.smarthome.config.discovery.DiscoveryResultFlag)1 InboxListener (org.eclipse.smarthome.config.discovery.inbox.InboxListener)1 InboxPredicates (org.eclipse.smarthome.config.discovery.inbox.InboxPredicates)1 DiscoveryServiceMock (org.eclipse.smarthome.config.setup.test.discovery.DiscoveryServiceMock)1 DiscoveryServiceMockOfBridge (org.eclipse.smarthome.config.setup.test.discovery.DiscoveryServiceMockOfBridge)1 ExtendedDiscoveryServiceMock (org.eclipse.smarthome.config.setup.test.discovery.ExtendedDiscoveryServiceMock)1 RegistryChangeListener (org.eclipse.smarthome.core.common.registry.RegistryChangeListener)1 AbstractTypedEventSubscriber (org.eclipse.smarthome.core.events.AbstractTypedEventSubscriber)1 EventSubscriber (org.eclipse.smarthome.core.events.EventSubscriber)1