Java Code Examples for org.eclipse.smarthome.config.discovery.DiscoveryResult#getProperties()

The following examples show how to use org.eclipse.smarthome.config.discovery.DiscoveryResult#getProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InboxConsoleCommandExtension.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void printInboxEntries(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();
        String representationProperty = discoveryResult.getRepresentationProperty();
        String timestamp = new Date(discoveryResult.getTimestamp()).toString();
        String timeToLive = discoveryResult.getTimeToLive() == DiscoveryResult.TTL_UNLIMITED ? "UNLIMITED"
                : "" + discoveryResult.getTimeToLive();
        console.println(String.format(
                "%s [%s]: %s [thingId=%s, bridgeId=%s, properties=%s, representationProperty=%s, timestamp=%s, timeToLive=%s]",
                flag.name(), thingTypeUID, label, thingUID, bridgeId, properties, representationProperty, timestamp,
                timeToLive));

    }
}
 
Example 2
Source File: InboxConsoleCommandExtension.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 3
Source File: PersistentInbox.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Get the properties and configuration parameters for the thing with the given {@link DiscoveryResult}.
 *
 * @param discoveryResult the DiscoveryResult
 * @param props the location the properties should be stored to.
 * @param configParams the location the configuration parameters should be stored to.
 */
private void getPropsAndConfigParams(final DiscoveryResult discoveryResult, final Map<String, String> props,
        final Map<String, Object> configParams) {
    final List<ConfigDescriptionParameter> configDescParams = getConfigDescParams(discoveryResult);
    final Set<String> paramNames = getConfigDescParamNames(configDescParams);
    final Map<String, Object> resultProps = discoveryResult.getProperties();
    for (String resultKey : resultProps.keySet()) {
        if (paramNames.contains(resultKey)) {
            ConfigDescriptionParameter param = getConfigDescriptionParam(configDescParams, resultKey);
            Object normalizedValue = ConfigUtil.normalizeType(resultProps.get(resultKey), param);
            configParams.put(resultKey, normalizedValue);
        } else {
            props.put(resultKey, String.valueOf(resultProps.get(resultKey)));
        }
    }
}
 
Example 4
Source File: UsbSerialDiscoveryService.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private DiscoveryResult createDiscoveryResultWithUsbProperties(DiscoveryResult result,
        UsbSerialDeviceInformation usbSerialDeviceInformation) {
    Map<String, Object> resultProperties = new HashMap<>(result.getProperties());
    resultProperties.put(THING_PROPERTY_USB_VENDOR_ID, usbSerialDeviceInformation.getVendorId());
    resultProperties.put(THING_PROPERTY_USB_PRODUCT_ID, usbSerialDeviceInformation.getProductId());

    return DiscoveryResultBuilder.create(result.getThingUID())
            .withProperties(resultProperties)
            .withBridge(result.getBridgeUID())
            .withTTL(result.getTimeToLive())
            .withLabel(result.getLabel())
            .withRepresentationProperty(result.getRepresentationProperty())
            .build();

}
 
Example 5
Source File: DiscoveryResultDTOMapper.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Maps discovery result into discovery result data transfer object.
 *
 * @param discoveryResult the discovery result
 * @return the discovery result data transfer object
 */
public static DiscoveryResultDTO map(DiscoveryResult discoveryResult) {
    ThingUID thingUID = discoveryResult.getThingUID();
    ThingUID bridgeUID = discoveryResult.getBridgeUID();

    return new DiscoveryResultDTO(thingUID.toString(), bridgeUID != null ? bridgeUID.toString() : null,
            discoveryResult.getThingTypeUID().toString(), discoveryResult.getLabel(), discoveryResult.getFlag(),
            discoveryResult.getProperties(), discoveryResult.getRepresentationProperty());
}
 
Example 6
Source File: DiscoveryResultImpl.java    From smarthome with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Merges the content of the specified source {@link DiscoveryResult} into this object.
 * <p>
 * <i>Hint:</i> The {@link DiscoveryResultFlag} of this object keeps its state.
 * <p>
 * This method returns silently if the specified source {@link DiscoveryResult} is {@code null} or its {@code Thing}
 * type or ID does not fit to this object.
 *
 * @param sourceResult the discovery result which is used as source for the merge
 */
public void synchronize(DiscoveryResult sourceResult) {
    if ((sourceResult != null) && (sourceResult.getThingUID().equals(this.thingUID))) {
        this.properties = sourceResult.getProperties();
        this.representationProperty = sourceResult.getRepresentationProperty();
        this.label = sourceResult.getLabel();
        this.timestamp = new Date().getTime();
        this.timeToLive = sourceResult.getTimeToLive();
    }
}