Search in sources :

Example 1 with ThingTypeUID

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

the class DiscoveryServiceRegistryImpl method abortScans.

private boolean abortScans(Set<DiscoveryService> discoveryServices) {
    boolean allServicesAborted = true;
    for (DiscoveryService discoveryService : discoveryServices) {
        Collection<ThingTypeUID> supportedThingTypes = discoveryService.getSupportedThingTypes();
        try {
            logger.debug("Abort scan for thing types '{}' on '{}'...", supportedThingTypes, discoveryService.getClass().getName());
            discoveryService.abortScan();
            logger.debug("Scan for thing types '{}' aborted on '{}'.", supportedThingTypes, discoveryService.getClass().getName());
        } catch (Exception ex) {
            logger.error("Cannot abort scan for thing types '{}' on '{}'!", supportedThingTypes, discoveryService.getClass().getName(), ex);
            allServicesAborted = false;
        }
    }
    return allServicesAborted;
}
Also used : ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ExtendedDiscoveryService(org.eclipse.smarthome.config.discovery.ExtendedDiscoveryService) DiscoveryService(org.eclipse.smarthome.config.discovery.DiscoveryService) CancellationException(java.util.concurrent.CancellationException)

Example 2 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID 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 3 with ThingTypeUID

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

the class PersistentInbox method approve.

@Override
public Thing approve(ThingUID thingUID, String label) {
    if (thingUID == null) {
        throw new IllegalArgumentException("Thing UID must not be null");
    }
    List<DiscoveryResult> results = stream().filter(forThingUID(thingUID)).collect(Collectors.toList());
    if (results.isEmpty()) {
        throw new IllegalArgumentException("No Thing with UID " + thingUID.getAsString() + " in inbox");
    }
    DiscoveryResult result = results.get(0);
    final Map<String, String> properties = new HashMap<>();
    final Map<String, Object> configParams = new HashMap<>();
    getPropsAndConfigParams(result, properties, configParams);
    final Configuration config = new Configuration(configParams);
    ThingTypeUID thingTypeUID = result.getThingTypeUID();
    Thing newThing = ThingFactory.createThing(thingUID, config, properties, result.getBridgeUID(), thingTypeUID, this.thingHandlerFactories);
    if (newThing == null) {
        logger.warn("Cannot create thing. No binding found that supports creating a thing" + " of type {}.", thingTypeUID);
        return null;
    }
    if (label != null && !label.isEmpty()) {
        newThing.setLabel(label);
    } else {
        newThing.setLabel(result.getLabel());
    }
    addThingSafely(newThing);
    return newThing;
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) Configuration(org.eclipse.smarthome.config.core.Configuration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 4 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID 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)

Example 5 with ThingTypeUID

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

the class DiscoveryResultDTOMapper method map.

/**
 * Maps discovery result data transfer object into discovery result.
 *
 * @param discoveryResultDTO the discovery result data transfer object
 * @return the discovery result
 */
public static DiscoveryResult map(DiscoveryResultDTO discoveryResultDTO) {
    final ThingUID thingUID = new ThingUID(discoveryResultDTO.thingUID);
    final String dtoThingTypeUID = discoveryResultDTO.thingTypeUID;
    final ThingTypeUID thingTypeUID = dtoThingTypeUID != null ? new ThingTypeUID(dtoThingTypeUID) : null;
    final String dtoBridgeUID = discoveryResultDTO.bridgeUID;
    final ThingUID bridgeUID = dtoBridgeUID != null ? new ThingUID(dtoBridgeUID) : null;
    return DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID).withBridge(bridgeUID).withLabel(discoveryResultDTO.label).withRepresentationProperty(discoveryResultDTO.representationProperty).withProperties(discoveryResultDTO.properties).build();
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Aggregations

ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)63 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)27 Test (org.junit.Test)27 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)25 Thing (org.eclipse.smarthome.core.thing.Thing)12 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)11 Locale (java.util.Locale)10 HashMap (java.util.HashMap)9 Collection (java.util.Collection)5 DiscoveryService (org.eclipse.smarthome.config.discovery.DiscoveryService)5 Before (org.junit.Before)5 Configuration (org.eclipse.smarthome.config.core.Configuration)4 DiscoveryListener (org.eclipse.smarthome.config.discovery.DiscoveryListener)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Nullable (org.eclipse.jdt.annotation.Nullable)3 ThingRegistry (org.eclipse.smarthome.core.thing.ThingRegistry)3 BaseThingHandlerFactory (org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory)3 Firmware (org.eclipse.smarthome.core.thing.binding.firmware.Firmware)3 ArrayList (java.util.ArrayList)2