Search in sources :

Example 1 with ThingUID

use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.

the class PersistentInbox method add.

@Override
public synchronized boolean add(DiscoveryResult result) throws IllegalStateException {
    if (result != null) {
        ThingUID thingUID = result.getThingUID();
        Thing thing = this.thingRegistry.get(thingUID);
        if (thing == null) {
            DiscoveryResult inboxResult = get(thingUID);
            if (inboxResult == null) {
                discoveryResultStorage.put(result.getThingUID().toString(), result);
                notifyListeners(result, EventType.added);
                logger.info("Added new thing '{}' to inbox.", thingUID);
                return true;
            } else {
                if (inboxResult instanceof DiscoveryResultImpl) {
                    DiscoveryResultImpl resultImpl = (DiscoveryResultImpl) inboxResult;
                    resultImpl.synchronize(result);
                    discoveryResultStorage.put(result.getThingUID().toString(), resultImpl);
                    notifyListeners(resultImpl, EventType.updated);
                    logger.debug("Updated discovery result for '{}'.", thingUID);
                    return true;
                } else {
                    logger.warn("Cannot synchronize result with implementation class '{}'.", inboxResult.getClass().getName());
                }
            }
        } else {
            logger.debug("Discovery result with thing '{}' not added as inbox entry." + " It is already present as thing in the ThingRegistry.", thingUID);
            boolean updated = synchronizeConfiguration(result.getThingTypeUID(), result.getProperties(), thing.getConfiguration());
            if (updated) {
                logger.debug("The configuration for thing '{}' is updated...", thingUID);
                this.managedThingProvider.update(thing);
            }
        }
    }
    return false;
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) InboxPredicates.forThingUID(org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 2 with ThingUID

use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.

the class PersistentInbox method addThingSafely.

private void addThingSafely(Thing thing) {
    ThingUID thingUID = thing.getUID();
    if (thingRegistry.get(thingUID) != null) {
        thingRegistry.remove(thingUID);
    }
    thingRegistry.add(thing);
}
Also used : InboxPredicates.forThingUID(org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 3 with ThingUID

use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.

the class PersistentInbox method matchFilter.

private boolean matchFilter(DiscoveryResult discoveryResult, InboxFilterCriteria criteria) {
    if (criteria != null) {
        String bindingId = criteria.getBindingId();
        if ((bindingId != null) && (!bindingId.isEmpty())) {
            if (!discoveryResult.getBindingId().equals(bindingId)) {
                return false;
            }
        }
        ThingTypeUID thingTypeUID = criteria.getThingTypeUID();
        if (thingTypeUID != null) {
            if (!discoveryResult.getThingTypeUID().equals(thingTypeUID)) {
                return false;
            }
        }
        ThingUID thingUID = criteria.getThingUID();
        if (thingUID != null) {
            if (!discoveryResult.getThingUID().equals(thingUID)) {
                return false;
            }
        }
        DiscoveryResultFlag flag = criteria.getFlag();
        if (flag != null) {
            if (discoveryResult.getFlag() != flag) {
                return false;
            }
        }
    }
    return true;
}
Also used : DiscoveryResultFlag(org.eclipse.smarthome.config.discovery.DiscoveryResultFlag) InboxPredicates.forThingUID(org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Example 4 with ThingUID

use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.

the class PersistentInbox method removeOlderResults.

@Override
public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp, Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) {
    HashSet<ThingUID> removedThings = new HashSet<>();
    for (DiscoveryResult discoveryResult : getAll()) {
        Class<?> discoverer = resultDiscovererMap.get(discoveryResult);
        if (thingTypeUIDs != null && thingTypeUIDs.contains(discoveryResult.getThingTypeUID()) && discoveryResult.getTimestamp() < timestamp && (discoverer == null || source.getClass() == discoverer)) {
            ThingUID thingUID = discoveryResult.getThingUID();
            if (bridgeUID == null || bridgeUID.equals(discoveryResult.getBridgeUID())) {
                removedThings.add(thingUID);
                remove(thingUID);
                logger.debug("Removed {} from inbox because it was older than {}", thingUID, new Date(timestamp));
            }
        }
    }
    return removedThings;
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) InboxPredicates.forThingUID(org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Date(java.util.Date) HashSet(java.util.HashSet)

Example 5 with ThingUID

use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.

the class InboxConsoleCommandExtension method clearInboxEntries.

private void clearInboxEntries(Console console, List<DiscoveryResult> discoveryResults) {
    if (discoveryResults.isEmpty()) {
        console.println("No inbox entries found.");
    }
    for (DiscoveryResult discoveryResult : discoveryResults) {
        ThingTypeUID thingTypeUID = discoveryResult.getThingTypeUID();
        ThingUID thingUID = discoveryResult.getThingUID();
        String label = discoveryResult.getLabel();
        DiscoveryResultFlag flag = discoveryResult.getFlag();
        ThingUID bridgeId = discoveryResult.getBridgeUID();
        Map<String, Object> properties = discoveryResult.getProperties();
        console.println(String.format("REMOVED [%s]: %s [label=%s, thingId=%s, bridgeId=%s, properties=%s]", flag.name(), thingTypeUID, label, thingUID, bridgeId, properties));
        inbox.remove(thingUID);
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) DiscoveryResultFlag(org.eclipse.smarthome.config.discovery.DiscoveryResultFlag) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Aggregations

ThingUID (org.eclipse.smarthome.core.thing.ThingUID)99 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)29 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)27 Thing (org.eclipse.smarthome.core.thing.Thing)26 Test (org.junit.Test)25 HashMap (java.util.HashMap)21 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)14 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Path (javax.ws.rs.Path)9 JsonObject (com.google.gson.JsonObject)8 JsonParser (com.google.gson.JsonParser)7 RolesAllowed (javax.annotation.security.RolesAllowed)7 Locale (java.util.Locale)6 Nullable (org.eclipse.jdt.annotation.Nullable)6 Consumes (javax.ws.rs.Consumes)5 Configuration (org.eclipse.smarthome.config.core.Configuration)5 Collection (java.util.Collection)4 GET (javax.ws.rs.GET)4 InboxPredicates.forThingUID (org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID)4