]> git.basschouten.com Git - openhab-addons.git/blob
96563dfa57d151f12fd13f63a5c79c639bf8d88d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.tplinksmarthome.internal;
14
15 import java.util.Arrays;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.Set;
19 import java.util.function.Function;
20 import java.util.stream.Collectors;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.ColorScales;
24 import org.openhab.core.thing.ThingTypeUID;
25
26 /**
27  * ThingType enum with all supported TP-Link Smart Home devices.
28  *
29  * @author Hilbrand Bouwkamp - Initial contribution
30  *
31  */
32 @NonNullByDefault
33 public enum TPLinkSmartHomeThingType {
34
35     // Bulb Thing Type UIDs
36     KB100("kb100", DeviceType.BULB),
37     KB130("kb130", DeviceType.BULB, ColorScales.K_2500_9000),
38     LB100("lb100", DeviceType.BULB),
39     LB110("lb110", DeviceType.BULB),
40     LB120("lb120", DeviceType.BULB, ColorScales.K_2700_6500),
41     LB130("lb130", DeviceType.BULB, ColorScales.K_2500_9000),
42     LB200("lb200", DeviceType.BULB),
43     LB230("lb230", DeviceType.BULB, ColorScales.K_2500_9000),
44     KL50("kl50", DeviceType.BULB),
45     KL60("kl60", DeviceType.BULB),
46     KL110("kl110", DeviceType.BULB),
47     KL120("kl120", DeviceType.BULB, ColorScales.K_2700_6500),
48     KL125("kl125", DeviceType.BULB, ColorScales.K_2500_6500),
49     KL130("kl130", DeviceType.BULB, ColorScales.K_2500_9000),
50     KL135("kl135", DeviceType.BULB, ColorScales.K_2500_6500),
51
52     // Light String thing Type UIDs.
53     KL400("kl400", DeviceType.LIGHT_STRIP, ColorScales.K_2500_9000),
54     KL430("kl430", DeviceType.LIGHT_STRIP, ColorScales.K_2500_9000),
55
56     // Plug Thing Type UIDs
57     EP10("ep10", DeviceType.PLUG),
58     HS100("hs100", DeviceType.PLUG),
59     HS103("hs103", DeviceType.PLUG),
60     HS105("hs105", DeviceType.PLUG),
61     HS110("hs110", DeviceType.PLUG_WITH_ENERGY),
62     KP100("kp100", DeviceType.PLUG),
63     KP105("kp105", DeviceType.PLUG),
64     KP115("kp115", DeviceType.PLUG_WITH_ENERGY),
65     KP125("kp125", DeviceType.PLUG_WITH_ENERGY),
66     KP401("kp401", DeviceType.PLUG),
67
68     // Switch Thing Type UIDs
69     HS200("hs200", DeviceType.SWITCH),
70     HS210("hs210", DeviceType.SWITCH),
71
72     // Dimmer Thing Type UIDs
73     ES20M("es20m", DeviceType.DIMMER),
74     HS220("hs220", DeviceType.DIMMER),
75     KS230("ks230", DeviceType.DIMMER),
76     KP405("kp405", DeviceType.DIMMER),
77
78     // Power Strip Thing Type UIDs.
79     EP40("ep40", DeviceType.STRIP, 2),
80     HS107("hs107", DeviceType.STRIP, 2),
81     HS300("hs300", DeviceType.STRIP, 6),
82     KP200("kp200", DeviceType.STRIP, 2),
83     KP303("kp303", DeviceType.STRIP, 3),
84     KP400("kp400", DeviceType.STRIP, 2),
85
86     // Range Extender Thing Type UIDs
87     RE270K("re270", DeviceType.RANGE_EXTENDER),
88     RE370K("re370", DeviceType.RANGE_EXTENDER);
89
90     /**
91      * All supported Smart Home devices in a list.
92      */
93     public static final List<TPLinkSmartHomeThingType> SUPPORTED_THING_TYPES_LIST = Arrays
94             .asList(TPLinkSmartHomeThingType.values());
95
96     /**
97      * All {@link ThingTypeUID}s of all supported Smart Home devices.
98      */
99     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = SUPPORTED_THING_TYPES_LIST.stream()
100             .map(TPLinkSmartHomeThingType::thingTypeUID).collect(Collectors.toSet());
101
102     /**
103      * A map of all {@link TPLinkSmartHomeThingType} mapped to {@link ThingTypeUID}.
104      */
105     public static final Map<ThingTypeUID, TPLinkSmartHomeThingType> THING_TYPE_MAP = SUPPORTED_THING_TYPES_LIST.stream()
106             .collect(Collectors.toMap(TPLinkSmartHomeThingType::thingTypeUID, Function.identity()));
107
108     private final ThingTypeUID thingTypeUID;
109     private final DeviceType type;
110     private final ColorScales colorScales;
111     private final int sockets;
112
113     TPLinkSmartHomeThingType(final String name, final DeviceType type) {
114         this(name, type, 0);
115     }
116
117     TPLinkSmartHomeThingType(final String name, final DeviceType type, final ColorScales colorScales) {
118         this(name, type, colorScales, 0);
119     }
120
121     TPLinkSmartHomeThingType(final String name, final DeviceType type, final int sockets) {
122         this(name, type, ColorScales.NOT_SUPPORTED, sockets);
123     }
124
125     TPLinkSmartHomeThingType(final String name, final DeviceType type, final ColorScales colorScales,
126             final int sockets) {
127         thingTypeUID = new ThingTypeUID(TPLinkSmartHomeBindingConstants.BINDING_ID, name);
128         this.type = type;
129         this.colorScales = colorScales;
130         this.sockets = sockets;
131     }
132
133     /**
134      * @return Returns the type of the device.
135      */
136     public DeviceType getDeviceType() {
137         return type;
138     }
139
140     /**
141      * @return The {@link ThingTypeUID} of this device.
142      */
143     public ThingTypeUID thingTypeUID() {
144         return thingTypeUID;
145     }
146
147     /**
148      * @return Returns the number of sockets. Only for Strip devices.
149      */
150     public int getSockets() {
151         return sockets;
152     }
153
154     /**
155      * @return Returns the color temperature color scales if supported or else returns null
156      */
157     public ColorScales getColorScales() {
158         return colorScales;
159     }
160
161     /**
162      * Returns true if the given {@link ThingTypeUID} matches the {@link ThingTypeUID} in this enum.
163      *
164      * @param otherThingTypeUID to check
165      * @return true if matches
166      */
167     public boolean is(final ThingTypeUID otherThingTypeUID) {
168         return thingTypeUID.equals(otherThingTypeUID);
169     }
170
171     /**
172      * Enum indicating the type of the device.
173      */
174     public enum DeviceType {
175         /**
176          * Light Bulb device.
177          */
178         BULB,
179         /**
180          * Dimmer device.
181          */
182         DIMMER,
183         /**
184          * Light Strip device.
185          */
186         LIGHT_STRIP,
187         /**
188          * Plug device.
189          */
190         PLUG,
191         /**
192          * Plug device with energy measurement support.
193          */
194         PLUG_WITH_ENERGY,
195         /**
196          * Wi-Fi range extender device with plug.
197          */
198         RANGE_EXTENDER,
199         /**
200          * Power strip device.
201          */
202         STRIP,
203         /**
204          * Switch device.
205          */
206         SWITCH
207     }
208 }