Search in sources :

Example 1 with DiscoveryResultBuilder

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

the class LifxLightDiscovery method createDiscoveryResult.

private DiscoveryResult createDiscoveryResult(DiscoveredLight light) throws IllegalArgumentException {
    Products product = light.product;
    if (product == null) {
        throw new IllegalArgumentException("Product of discovered light is null");
    }
    String macAsLabel = light.macAddress.getAsLabel();
    ThingUID thingUID = new ThingUID(product.getThingTypeUID(), macAsLabel);
    String label = light.label;
    if (StringUtils.isBlank(label)) {
        label = product.getName();
    }
    logger.trace("Discovered a LIFX light: {}", label);
    DiscoveryResultBuilder builder = DiscoveryResultBuilder.create(thingUID);
    builder.withRepresentationProperty(LifxBindingConstants.PROPERTY_MAC_ADDRESS);
    builder.withLabel(label);
    builder.withProperty(LifxBindingConstants.CONFIG_PROPERTY_DEVICE_ID, macAsLabel);
    builder.withProperty(LifxBindingConstants.PROPERTY_MAC_ADDRESS, macAsLabel);
    builder.withProperty(LifxBindingConstants.PROPERTY_PRODUCT_ID, product.getProduct());
    builder.withProperty(LifxBindingConstants.PROPERTY_PRODUCT_NAME, product.getName());
    builder.withProperty(LifxBindingConstants.PROPERTY_PRODUCT_VERSION, light.productVersion);
    builder.withProperty(LifxBindingConstants.PROPERTY_VENDOR_ID, product.getVendor());
    builder.withProperty(LifxBindingConstants.PROPERTY_VENDOR_NAME, product.getVendorName());
    return builder.build();
}
Also used : Products(org.eclipse.smarthome.binding.lifx.internal.protocol.Products) DiscoveryResultBuilder(org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Aggregations

Products (org.eclipse.smarthome.binding.lifx.internal.protocol.Products)1 DiscoveryResultBuilder (org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder)1 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)1