]> git.basschouten.com Git - openhab-addons.git/blob
cee8e8d04dd791aa24508ef5e5e644c02e573aaf
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lifx.internal.protocol;
14
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;
18
19 import java.util.Arrays;
20 import java.util.EnumSet;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.lifx.internal.LifxBindingConstants;
24 import org.openhab.core.thing.ThingTypeUID;
25
26 /**
27  * Enumerates the LIFX products, their IDs and feature set.
28  *
29  * @see https://lan.developer.lifx.com/docs/lifx-products
30  *
31  * @author Wouter Born - Support LIFX 2016 product line-up and infrared functionality
32  * @author Wouter Born - Add temperature ranges and simplify feature definitions
33  */
34 @NonNullByDefault
35 public enum Product {
36
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);
95
96     /**
97      * Enumerates the product features.
98      */
99     public enum Feature {
100         CHAIN,
101         COLOR,
102         HEV,
103         INFRARED,
104         MATRIX,
105         MULTIZONE,
106         TILE_EFFECT
107     }
108
109     /**
110      * Enumerates the product vendors.
111      */
112     public enum Vendor {
113         LIFX(1, "LIFX");
114
115         private final int id;
116         private final String name;
117
118         Vendor(int id, String name) {
119             this.id = id;
120             this.name = name;
121         }
122
123         public int getID() {
124             return id;
125         }
126
127         public String getName() {
128             return name;
129         }
130     }
131
132     /**
133      * Enumerates the color temperature ranges of lights.
134      */
135     public enum TemperatureRange {
136         /**
137          * 1500-4000K
138          */
139         TR_1500_4000(1500, 4000),
140
141         /**
142          * 1500-9000K
143          */
144         TR_1500_9000(1500, 9000),
145
146         /**
147          * 2000-2000K
148          */
149         TR_2000_2000(2000, 2000),
150
151         /**
152          * 2100-2100K
153          */
154         TR_2100_2100(2100, 2100),
155
156         /**
157          * 2200-6500K
158          */
159         TR_2200_6500(2200, 6500),
160
161         /**
162          * 2500-9000K
163          */
164         TR_2500_9000(2500, 9000),
165
166         /**
167          * 2700-2700K
168          */
169         TR_2700_2700(2700, 2700),
170
171         /**
172          * 2700-6500K
173          */
174         TR_2700_6500(2700, 6500);
175
176         private final int minimum;
177         private final int maximum;
178
179         TemperatureRange(int minimum, int maximum) {
180             this.minimum = minimum;
181             this.maximum = maximum;
182         }
183
184         /**
185          * The minimum color temperature in degrees Kelvin.
186          *
187          * @return minimum color temperature (K)
188          */
189         public int getMinimum() {
190             return minimum;
191         }
192
193         /**
194          * The maxiumum color temperature in degrees Kelvin.
195          *
196          * @return maximum color temperature (K)
197          */
198         public int getMaximum() {
199             return maximum;
200         }
201
202         /**
203          * The color temperature range in degrees Kelvin.
204          *
205          * @return difference between maximum and minimum color temperature values
206          */
207         public int getRange() {
208             return maximum - minimum;
209         }
210     }
211
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);
217
218     private Product(long id, String name, TemperatureRange temperatureRange) {
219         this(LIFX, id, name, temperatureRange);
220     }
221
222     private Product(long id, String name, TemperatureRange temperatureRange, Feature... features) {
223         this(LIFX, id, name, temperatureRange, features);
224     }
225
226     private Product(Vendor vendor, long id, String name, TemperatureRange temperatureRange) {
227         this(vendor, id, name, temperatureRange, new Feature[0]);
228     }
229
230     private Product(Vendor vendor, long id, String name, TemperatureRange temperatureRange, Feature... features) {
231         this.vendor = vendor;
232         this.id = id;
233         this.name = name;
234         this.temperatureRange = temperatureRange;
235         this.features.addAll(Arrays.asList(features));
236     }
237
238     @Override
239     public String toString() {
240         return name;
241     }
242
243     public Vendor getVendor() {
244         return vendor;
245     }
246
247     public long getID() {
248         return id;
249     }
250
251     public String getName() {
252         return name;
253     }
254
255     public TemperatureRange getTemperatureRange() {
256         return temperatureRange;
257     }
258
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;
267             } else {
268                 return LifxBindingConstants.THING_TYPE_COLORLIGHT;
269             }
270         } else {
271             return LifxBindingConstants.THING_TYPE_WHITELIGHT;
272         }
273     }
274
275     public boolean hasFeature(Feature feature) {
276         return features.contains(feature);
277     }
278
279     /**
280      * Returns a product that has the given thing type UID.
281      *
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
285      */
286     public static Product getLikelyProduct(ThingTypeUID uid) throws IllegalArgumentException {
287         for (Product product : Product.values()) {
288             if (product.getThingTypeUID().equals(uid)) {
289                 return product;
290             }
291         }
292
293         throw new IllegalArgumentException(uid + " is not a valid product thing type UID");
294     }
295
296     /**
297      * Returns the product that has the given product ID.
298      *
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
302      */
303     public static Product getProductFromProductID(long id) throws IllegalArgumentException {
304         for (Product product : Product.values()) {
305             if (product.id == id) {
306                 return product;
307             }
308         }
309
310         throw new IllegalArgumentException(id + " is not a valid product ID");
311     }
312 }