2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lifx.internal.protocol;
15 import static org.openhab.binding.lifx.internal.protocol.Product.Feature.*;
16 import static org.openhab.binding.lifx.internal.protocol.Product.TemperatureRange.*;
17 import static org.openhab.binding.lifx.internal.protocol.Product.Vendor.LIFX;
19 import java.util.Arrays;
20 import java.util.EnumSet;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.lifx.internal.LifxBindingConstants;
24 import org.openhab.core.thing.ThingTypeUID;
27 * Enumerates the LIFX products, their IDs and feature set.
29 * @see https://lan.developer.lifx.com/docs/lifx-products
31 * @author Wouter Born - Support LIFX 2016 product line-up and infrared functionality
32 * @author Wouter Born - Add temperature ranges and simplify feature definitions
37 PRODUCT_1(1, "Original 1000", TR_2500_9000, COLOR),
38 PRODUCT_3(3, "Color 650", TR_2500_9000, COLOR),
39 PRODUCT_10(10, "White 800 (Low Voltage)", TR_2700_6500),
40 PRODUCT_11(11, "White 800 (High Voltage)", TR_2700_6500),
41 PRODUCT_18(18, "White 900 BR30 (Low Voltage)", TR_2700_6500),
42 PRODUCT_20(20, "Color 1000 BR30", TR_2500_9000, COLOR),
43 PRODUCT_22(22, "Color 1000", TR_2500_9000, COLOR),
44 PRODUCT_27(27, "LIFX A19", TR_2500_9000, COLOR),
45 PRODUCT_28(28, "LIFX BR30", TR_2500_9000, COLOR),
46 PRODUCT_29(29, "LIFX+ A19", TR_2500_9000, COLOR, INFRARED),
47 PRODUCT_30(30, "LIFX+ BR30", TR_2500_9000, COLOR, INFRARED),
48 PRODUCT_31(31, "LIFX Z", TR_2500_9000, COLOR, MULTIZONE),
49 PRODUCT_32(32, "LIFX Z 2", TR_2500_9000, COLOR, MULTIZONE),
50 PRODUCT_36(36, "LIFX Downlight", TR_2500_9000, COLOR),
51 PRODUCT_37(37, "LIFX Downlight", TR_2500_9000, COLOR),
52 PRODUCT_38(38, "LIFX Beam", TR_2500_9000, COLOR, MULTIZONE),
53 PRODUCT_43(43, "LIFX A19", TR_2500_9000, COLOR),
54 PRODUCT_44(44, "LIFX BR30", TR_2500_9000, COLOR),
55 PRODUCT_45(45, "LIFX+ A19", TR_2500_9000, COLOR, INFRARED),
56 PRODUCT_46(46, "LIFX+ BR30", TR_2500_9000, COLOR, INFRARED),
57 PRODUCT_49(49, "LIFX Mini", TR_2500_9000, COLOR),
58 PRODUCT_50(50, "LIFX Mini Day and Dusk", TR_1500_4000),
59 PRODUCT_51(51, "LIFX Mini White", TR_2700_2700),
60 PRODUCT_52(52, "LIFX GU10", TR_2500_9000, COLOR),
61 PRODUCT_55(55, "LIFX Tile", TR_2500_9000, CHAIN, COLOR, MATRIX, TILE_EFFECT),
62 PRODUCT_57(57, "LIFX Candle", TR_1500_9000, COLOR, MATRIX),
63 PRODUCT_59(59, "LIFX Mini Color", TR_2500_9000, COLOR),
64 PRODUCT_60(60, "LIFX Mini Day and Dusk", TR_1500_4000),
65 PRODUCT_61(61, "LIFX Mini White", TR_2700_2700),
66 PRODUCT_62(62, "LIFX A19", TR_2500_9000, COLOR),
67 PRODUCT_63(63, "LIFX BR30", TR_2500_9000, COLOR),
68 PRODUCT_64(64, "LIFX+ A19", TR_2500_9000, COLOR, INFRARED),
69 PRODUCT_65(65, "LIFX+ BR30", TR_2500_9000, COLOR, INFRARED),
70 PRODUCT_68(68, "LIFX Candle", TR_1500_9000, COLOR, MATRIX),
71 PRODUCT_81(81, "LIFX Candle Warm to White", TR_2200_6500, MATRIX),
72 PRODUCT_82(82, "LIFX Filament", TR_2000_2000);
75 * Enumerates the product features.
87 * Enumerates the product vendors.
93 private final String name;
95 Vendor(int id, String name) {
104 public String getName() {
110 * Enumerates the color temperature ranges of lights.
112 public enum TemperatureRange {
116 TR_1500_4000(1500, 4000),
121 TR_1500_9000(1500, 9000),
126 TR_2000_2000(2000, 2000),
131 TR_2200_6500(2200, 6500),
136 TR_2500_9000(2500, 9000),
141 TR_2700_2700(2700, 2700),
146 TR_2700_6500(2700, 6500);
148 private final int minimum;
149 private final int maximum;
151 TemperatureRange(int minimum, int maximum) {
152 this.minimum = minimum;
153 this.maximum = maximum;
157 * The minimum color temperature in degrees Kelvin.
159 * @return minimum color temperature (K)
161 public int getMinimum() {
166 * The maxiumum color temperature in degrees Kelvin.
168 * @return maximum color temperature (K)
170 public int getMaximum() {
175 * The color temperature range in degrees Kelvin.
177 * @return difference between maximum and minimum color temperature values
179 public int getRange() {
180 return maximum - minimum;
184 private final Vendor vendor;
185 private final long id;
186 private final String name;
187 private final TemperatureRange temperatureRange;
188 private final EnumSet<Feature> features = EnumSet.noneOf(Feature.class);
190 private Product(long id, String name, TemperatureRange temperatureRange) {
191 this(LIFX, id, name, temperatureRange);
194 private Product(long id, String name, TemperatureRange temperatureRange, Feature... features) {
195 this(LIFX, id, name, temperatureRange, features);
198 private Product(Vendor vendor, long id, String name, TemperatureRange temperatureRange) {
199 this(vendor, id, name, temperatureRange, new Feature[0]);
202 private Product(Vendor vendor, long id, String name, TemperatureRange temperatureRange, Feature... features) {
203 this.vendor = vendor;
206 this.temperatureRange = temperatureRange;
207 this.features.addAll(Arrays.asList(features));
211 public String toString() {
215 public Vendor getVendor() {
219 public long getID() {
223 public String getName() {
227 public TemperatureRange getTemperatureRange() {
228 return temperatureRange;
231 public ThingTypeUID getThingTypeUID() {
232 if (hasFeature(COLOR)) {
233 if (hasFeature(TILE_EFFECT)) {
234 return LifxBindingConstants.THING_TYPE_TILELIGHT;
235 } else if (hasFeature(INFRARED)) {
236 return LifxBindingConstants.THING_TYPE_COLORIRLIGHT;
237 } else if (hasFeature(MULTIZONE)) {
238 return LifxBindingConstants.THING_TYPE_COLORMZLIGHT;
240 return LifxBindingConstants.THING_TYPE_COLORLIGHT;
243 return LifxBindingConstants.THING_TYPE_WHITELIGHT;
247 public boolean hasFeature(Feature feature) {
248 return features.contains(feature);
252 * Returns a product that has the given thing type UID.
254 * @param uid a thing type UID
255 * @return a product that has the given thing type UID
256 * @throws IllegalArgumentException when <code>uid</code> is not a valid LIFX thing type UID
258 public static Product getLikelyProduct(ThingTypeUID uid) throws IllegalArgumentException {
259 for (Product product : Product.values()) {
260 if (product.getThingTypeUID().equals(uid)) {
265 throw new IllegalArgumentException(uid + " is not a valid product thing type UID");
269 * Returns the product that has the given product ID.
271 * @param id the product ID
272 * @return the product that has the given product ID
273 * @throws IllegalArgumentException when <code>id</code> is not a valid LIFX product ID
275 public static Product getProductFromProductID(long id) throws IllegalArgumentException {
276 for (Product product : Product.values()) {
277 if (product.id == id) {
282 throw new IllegalArgumentException(id + " is not a valid product ID");