2 * Copyright (c) 2010-2021 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, "LIFX Original 1000", TR_2500_9000, COLOR),
38 PRODUCT_3(3, "LIFX Color 650", TR_2500_9000, COLOR),
39 PRODUCT_10(10, "LIFX White 800 (Low Voltage)", TR_2700_6500),
40 PRODUCT_11(11, "LIFX White 800 (High Voltage)", TR_2700_6500),
41 PRODUCT_15(15, "LIFX Color 1000", TR_2500_9000, COLOR),
42 PRODUCT_18(18, "LIFX White 900 BR30 (Low Voltage)", TR_2700_6500),
43 PRODUCT_19(19, "LIFX White 900 BR30 (High Voltage)", TR_2700_6500),
44 PRODUCT_20(20, "LIFX Color 1000 BR30", TR_2500_9000, COLOR),
45 PRODUCT_22(22, "LIFX Color 1000", TR_2500_9000, COLOR),
46 PRODUCT_27(27, "LIFX A19", TR_2500_9000, COLOR),
47 PRODUCT_28(28, "LIFX BR30", TR_2500_9000, COLOR),
48 PRODUCT_29(29, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED),
49 PRODUCT_30(30, "LIFX BR30 Night Vision", TR_2500_9000, COLOR, INFRARED),
50 PRODUCT_31(31, "LIFX Z", TR_2500_9000, COLOR, MULTIZONE),
51 PRODUCT_32(32, "LIFX Z", TR_2500_9000, COLOR, MULTIZONE),
52 PRODUCT_36(36, "LIFX Downlight", TR_2500_9000, COLOR),
53 PRODUCT_37(37, "LIFX Downlight", TR_2500_9000, COLOR),
54 PRODUCT_38(38, "LIFX Beam", TR_2500_9000, COLOR, MULTIZONE),
55 PRODUCT_39(39, "LIFX Downlight White to Warm", TR_1500_9000),
56 PRODUCT_40(40, "LIFX Downlight", TR_2500_9000, COLOR),
57 PRODUCT_43(43, "LIFX A19", TR_2500_9000, COLOR),
58 PRODUCT_44(44, "LIFX BR30", TR_2500_9000, COLOR),
59 PRODUCT_45(45, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED),
60 PRODUCT_46(46, "LIFX BR30 Night Vision", TR_2500_9000, COLOR, INFRARED),
61 PRODUCT_49(49, "LIFX Mini Color", TR_2500_9000, COLOR),
62 PRODUCT_50(50, "LIFX Mini White to Warm", TR_1500_4000),
63 PRODUCT_51(51, "LIFX Mini White", TR_2700_2700),
64 PRODUCT_52(52, "LIFX GU10", TR_2500_9000, COLOR),
65 PRODUCT_53(53, "LIFX GU10", TR_2500_9000, COLOR),
66 PRODUCT_55(55, "LIFX Tile", TR_2500_9000, CHAIN, COLOR, MATRIX, TILE_EFFECT),
67 PRODUCT_57(57, "LIFX Candle", TR_1500_9000, COLOR, MATRIX),
68 PRODUCT_59(59, "LIFX Mini Color", TR_2500_9000, COLOR),
69 PRODUCT_60(60, "LIFX Mini White to Warm", TR_1500_4000),
70 PRODUCT_61(61, "LIFX Mini White", TR_2700_2700),
71 PRODUCT_62(62, "LIFX A19", TR_2500_9000, COLOR),
72 PRODUCT_63(63, "LIFX BR30", TR_2500_9000, COLOR),
73 PRODUCT_64(64, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED),
74 PRODUCT_65(65, "LIFX BR30 Night Vision", TR_2500_9000, COLOR, INFRARED),
75 PRODUCT_66(66, "LIFX Mini White", TR_2700_2700),
76 PRODUCT_68(68, "LIFX Candle", TR_1500_9000, MATRIX),
77 PRODUCT_81(81, "LIFX Candle White to Warm", TR_2200_6500),
78 PRODUCT_82(82, "LIFX Filament Clear", TR_2100_2100),
79 PRODUCT_85(85, "LIFX Filament Amber", TR_2000_2000),
80 PRODUCT_87(87, "LIFX Mini White", TR_2700_2700),
81 PRODUCT_88(88, "LIFX Mini White", TR_2700_2700),
82 PRODUCT_90(90, "LIFX Clean", TR_2500_9000, HEV),
83 PRODUCT_91(91, "LIFX Color", TR_2500_9000, COLOR),
84 PRODUCT_92(92, "LIFX Color", TR_2500_9000, COLOR),
85 PRODUCT_94(94, "LIFX BR30", TR_2500_9000, COLOR),
86 PRODUCT_96(96, "LIFX Candle White to Warm", TR_2200_6500),
87 PRODUCT_97(97, "LIFX A19", TR_2500_9000, COLOR),
88 PRODUCT_98(98, "LIFX BR30", TR_2500_9000, COLOR),
89 PRODUCT_99(99, "LIFX Clean", TR_2500_9000, HEV),
90 PRODUCT_100(100, "LIFX Filament Clear", TR_2100_2100),
91 PRODUCT_101(101, "LIFX Filament Amber", TR_2000_2000),
92 PRODUCT_109(109, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED),
93 PRODUCT_110(110, "LIFX BR30 Night Vision", TR_2500_9000, COLOR, INFRARED),
94 PRODUCT_111(111, "LIFX A19 Night Vision", TR_2500_9000, COLOR, INFRARED);
97 * Enumerates the product features.
110 * Enumerates the product vendors.
115 private final int id;
116 private final String name;
118 Vendor(int id, String name) {
127 public String getName() {
133 * Enumerates the color temperature ranges of lights.
135 public enum TemperatureRange {
139 TR_1500_4000(1500, 4000),
144 TR_1500_9000(1500, 9000),
149 TR_2000_2000(2000, 2000),
154 TR_2100_2100(2100, 2100),
159 TR_2200_6500(2200, 6500),
164 TR_2500_9000(2500, 9000),
169 TR_2700_2700(2700, 2700),
174 TR_2700_6500(2700, 6500);
176 private final int minimum;
177 private final int maximum;
179 TemperatureRange(int minimum, int maximum) {
180 this.minimum = minimum;
181 this.maximum = maximum;
185 * The minimum color temperature in degrees Kelvin.
187 * @return minimum color temperature (K)
189 public int getMinimum() {
194 * The maxiumum color temperature in degrees Kelvin.
196 * @return maximum color temperature (K)
198 public int getMaximum() {
203 * The color temperature range in degrees Kelvin.
205 * @return difference between maximum and minimum color temperature values
207 public int getRange() {
208 return maximum - minimum;
212 private final Vendor vendor;
213 private final long id;
214 private final String name;
215 private final TemperatureRange temperatureRange;
216 private final EnumSet<Feature> features = EnumSet.noneOf(Feature.class);
218 private Product(long id, String name, TemperatureRange temperatureRange) {
219 this(LIFX, id, name, temperatureRange);
222 private Product(long id, String name, TemperatureRange temperatureRange, Feature... features) {
223 this(LIFX, id, name, temperatureRange, features);
226 private Product(Vendor vendor, long id, String name, TemperatureRange temperatureRange) {
227 this(vendor, id, name, temperatureRange, new Feature[0]);
230 private Product(Vendor vendor, long id, String name, TemperatureRange temperatureRange, Feature... features) {
231 this.vendor = vendor;
234 this.temperatureRange = temperatureRange;
235 this.features.addAll(Arrays.asList(features));
239 public String toString() {
243 public Vendor getVendor() {
247 public long getID() {
251 public String getName() {
255 public TemperatureRange getTemperatureRange() {
256 return temperatureRange;
259 public ThingTypeUID getThingTypeUID() {
260 if (hasFeature(COLOR)) {
261 if (hasFeature(TILE_EFFECT)) {
262 return LifxBindingConstants.THING_TYPE_TILELIGHT;
263 } else if (hasFeature(INFRARED)) {
264 return LifxBindingConstants.THING_TYPE_COLORIRLIGHT;
265 } else if (hasFeature(MULTIZONE)) {
266 return LifxBindingConstants.THING_TYPE_COLORMZLIGHT;
268 return LifxBindingConstants.THING_TYPE_COLORLIGHT;
271 return LifxBindingConstants.THING_TYPE_WHITELIGHT;
275 public boolean hasFeature(Feature feature) {
276 return features.contains(feature);
280 * Returns a product that has the given thing type UID.
282 * @param uid a thing type UID
283 * @return a product that has the given thing type UID
284 * @throws IllegalArgumentException when <code>uid</code> is not a valid LIFX thing type UID
286 public static Product getLikelyProduct(ThingTypeUID uid) throws IllegalArgumentException {
287 for (Product product : Product.values()) {
288 if (product.getThingTypeUID().equals(uid)) {
293 throw new IllegalArgumentException(uid + " is not a valid product thing type UID");
297 * Returns the product that has the given product ID.
299 * @param id the product ID
300 * @return the product that has the given product ID
301 * @throws IllegalArgumentException when <code>id</code> is not a valid LIFX product ID
303 public static Product getProductFromProductID(long id) throws IllegalArgumentException {
304 for (Product product : Product.values()) {
305 if (product.id == id) {
310 throw new IllegalArgumentException(id + " is not a valid product ID");