use of org.eclipse.smarthome.binding.lifx.internal.protocol.Products 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();
}
use of org.eclipse.smarthome.binding.lifx.internal.protocol.Products in project smarthome by eclipse.
the class LifxLightPropertiesUpdater method handleResponsePacket.
public void handleResponsePacket(Packet packet) {
if (!updating) {
return;
}
if (packet instanceof StateVersionResponse) {
Products products = Products.getProductFromProductID(((StateVersionResponse) packet).getProduct());
long productVersion = ((StateVersionResponse) packet).getVersion();
properties.put(LifxBindingConstants.PROPERTY_PRODUCT_ID, Long.toString(products.getProduct()));
properties.put(LifxBindingConstants.PROPERTY_PRODUCT_NAME, products.getName());
properties.put(LifxBindingConstants.PROPERTY_PRODUCT_VERSION, Long.toString(productVersion));
properties.put(LifxBindingConstants.PROPERTY_VENDOR_ID, Long.toString(products.getVendor()));
properties.put(LifxBindingConstants.PROPERTY_VENDOR_NAME, products.getVendorName());
receivedPacketTypes.add(packet.getPacketType());
} else if (packet instanceof StateHostFirmwareResponse) {
String hostVersion = ((StateHostFirmwareResponse) packet).getVersion().toString();
properties.put(LifxBindingConstants.PROPERTY_HOST_VERSION, hostVersion);
receivedPacketTypes.add(packet.getPacketType());
} else if (packet instanceof StateWifiFirmwareResponse) {
String wifiVersion = ((StateWifiFirmwareResponse) packet).getVersion().toString();
properties.put(LifxBindingConstants.PROPERTY_WIFI_VERSION, wifiVersion);
receivedPacketTypes.add(packet.getPacketType());
}
if (receivedAllResponsePackets()) {
updating = false;
propertiesUpdateListeners.forEach(listener -> listener.handlePropertiesUpdate(properties));
logger.debug("{} : Finished updating light properties", logId);
}
}
Aggregations