Search in sources :

Example 11 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class ZoneTemperatureControlDiscoveryService method internalConfigChanged.

private void internalConfigChanged(TemperatureControlStatus tempControlStatus) {
    if (tempControlStatus == null) {
        return;
    }
    if (tempControlStatus.getIsConfigured()) {
        logger.debug("found configured zone TemperatureControlStatus = {}", tempControlStatus);
        ThingUID thingUID = getThingUID(tempControlStatus);
        if (thingUID != null) {
            Map<String, Object> properties = new HashMap<>();
            properties.put(DigitalSTROMBindingConstants.ZONE_ID, tempControlStatus.getZoneID());
            String zoneName = tempControlStatus.getZoneName();
            if (StringUtils.isBlank(zoneName)) {
                zoneName = tempControlStatus.getZoneID().toString();
            }
            DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties).withBridge(bridgeUID).withLabel(zoneName).build();
            thingDiscovered(discoveryResult);
        }
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 12 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class NtpDiscovery method discoverNtp.

/**
 * Add a ntp Thing for the local time in the discovery inbox
 */
private void discoverNtp() {
    Map<String, Object> properties = new HashMap<>(4);
    properties.put(PROPERTY_TIMEZONE, TimeZone.getDefault().getID());
    ThingUID uid = new ThingUID(THING_TYPE_NTP, "local");
    DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel("Local Time").build();
    thingDiscovered(result);
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 13 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class LIRCRemoteDiscoveryService method addRemote.

private void addRemote(ThingUID bridge, String remote) {
    ThingTypeUID uid = LIRCBindingConstants.THING_TYPE_REMOTE;
    ThingUID thingUID = new ThingUID(uid, bridge, remote);
    if (thingUID != null) {
        if (discoveryServiceCallback != null && discoveryServiceCallback.getExistingDiscoveryResult(thingUID) != null) {
            // Ignore this remote as we already know about it
            logger.debug("Remote {}: Already known.", remote);
            return;
        }
        logger.trace("Remote {}: Discovered new remote.", remote);
        Map<String, Object> properties = new HashMap<>(1);
        properties.put(LIRCBindingConstants.PROPERTY_REMOTE, remote);
        DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withLabel(remote).withBridge(bridge).withProperties(properties).build();
        thingDiscovered(discoveryResult);
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Example 14 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult 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 15 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult 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)

Aggregations

DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)42 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)29 HashMap (java.util.HashMap)16 Test (org.junit.Test)14 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)12 Collection (java.util.Collection)4 DiscoveryListener (org.eclipse.smarthome.config.discovery.DiscoveryListener)4 DiscoveryService (org.eclipse.smarthome.config.discovery.DiscoveryService)4 ThingStatusInfo (org.eclipse.smarthome.core.thing.ThingStatusInfo)4 DiscoveryResultFlag (org.eclipse.smarthome.config.discovery.DiscoveryResultFlag)3 InboxPredicates.forThingUID (org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID)3 Thing (org.eclipse.smarthome.core.thing.Thing)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Date (java.util.Date)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors (java.util.stream.Collectors)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 Configuration (org.eclipse.smarthome.config.core.Configuration)2