2 * Copyright (c) 2010-2022 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.tplinksmarthome.internal;
15 import java.util.Arrays;
16 import java.util.List;
19 import java.util.function.Function;
20 import java.util.stream.Collectors;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.ColorScales;
24 import org.openhab.core.thing.ThingTypeUID;
27 * ThingType enum with all supported TP-Link Smart Home devices.
29 * @author Hilbrand Bouwkamp - Initial contribution
33 public enum TPLinkSmartHomeThingType {
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),
52 // Plug Thing Type UIDs
53 EP10("ep10", DeviceType.PLUG),
54 HS100("hs100", DeviceType.PLUG),
55 HS103("hs103", DeviceType.PLUG),
56 HS105("hs105", DeviceType.PLUG),
57 HS110("hs110", DeviceType.PLUG_WITH_ENERGY),
58 KP100("kp100", DeviceType.PLUG),
59 KP105("kp105", DeviceType.PLUG),
60 KP115("kp115", DeviceType.PLUG_WITH_ENERGY),
61 KP125("kp125", DeviceType.PLUG_WITH_ENERGY),
62 KP405("kp405", DeviceType.DIMMER),
64 // Switch Thing Type UIDs
65 HS200("hs200", DeviceType.SWITCH),
66 HS210("hs210", DeviceType.SWITCH),
68 // Dimmer Thing Type UIDs
69 ES20M("es20m", DeviceType.DIMMER),
70 HS220("hs220", DeviceType.DIMMER),
71 KS230("ks230", DeviceType.DIMMER),
73 // Power Strip Thing Type UIDs.
74 EP40("ep40", DeviceType.STRIP, 2),
75 HS107("hs107", DeviceType.STRIP, 2),
76 HS300("hs300", DeviceType.STRIP, 6),
77 KP200("kp200", DeviceType.STRIP, 2),
78 KP303("kp303", DeviceType.STRIP, 3),
79 KP400("kp400", DeviceType.STRIP, 2),
81 // Range Extender Thing Type UIDs
82 RE270K("re270", DeviceType.RANGE_EXTENDER),
83 RE370K("re370", DeviceType.RANGE_EXTENDER);
86 * All supported Smart Home devices in a list.
88 public static final List<TPLinkSmartHomeThingType> SUPPORTED_THING_TYPES_LIST = Arrays
89 .asList(TPLinkSmartHomeThingType.values());
92 * All {@link ThingTypeUID}s of all supported Smart Home devices.
94 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = SUPPORTED_THING_TYPES_LIST.stream()
95 .map(TPLinkSmartHomeThingType::thingTypeUID).collect(Collectors.toSet());
98 * A map of all {@link TPLinkSmartHomeThingType} mapped to {@link ThingTypeUID}.
100 public static final Map<ThingTypeUID, TPLinkSmartHomeThingType> THING_TYPE_MAP = SUPPORTED_THING_TYPES_LIST.stream()
101 .collect(Collectors.toMap(TPLinkSmartHomeThingType::thingTypeUID, Function.identity()));
103 private final ThingTypeUID thingTypeUID;
104 private final DeviceType type;
105 private final ColorScales colorScales;
106 private final int sockets;
108 TPLinkSmartHomeThingType(final String name, final DeviceType type) {
112 TPLinkSmartHomeThingType(final String name, final DeviceType type, final ColorScales colorScales) {
113 this(name, type, colorScales, 0);
116 TPLinkSmartHomeThingType(final String name, final DeviceType type, final int sockets) {
117 this(name, type, ColorScales.NOT_SUPPORTED, sockets);
120 TPLinkSmartHomeThingType(final String name, final DeviceType type, final ColorScales colorScales,
122 thingTypeUID = new ThingTypeUID(TPLinkSmartHomeBindingConstants.BINDING_ID, name);
124 this.colorScales = colorScales;
125 this.sockets = sockets;
129 * @return Returns the type of the device.
131 public DeviceType getDeviceType() {
136 * @return The {@link ThingTypeUID} of this device.
138 public ThingTypeUID thingTypeUID() {
143 * @return Returns the number of sockets. Only for Strip devices.
145 public int getSockets() {
150 * @return Returns the color temperature color scales if supported or else returns null
152 public ColorScales getColorScales() {
157 * Returns true if the given {@link ThingTypeUID} matches the {@link ThingTypeUID} in this enum.
159 * @param otherThingTypeUID to check
160 * @return true if matches
162 public boolean is(final ThingTypeUID otherThingTypeUID) {
163 return thingTypeUID.equals(otherThingTypeUID);
167 * Enum indicating the type of the device.
169 public enum DeviceType {
183 * Plug device with energy measurement support.
187 * Wi-Fi range extender device with plug.
191 * Power strip device.