]> git.basschouten.com Git - openhab-addons.git/commitdiff
[tplinksmarthome] Added new devices EP10, EP40, KL125, and KL135 (#11282)
authorHilbrand Bouwkamp <hilbrand@h72.nl>
Tue, 28 Sep 2021 16:28:15 +0000 (18:28 +0200)
committerGitHub <noreply@github.com>
Tue, 28 Sep 2021 16:28:15 +0000 (18:28 +0200)
Closes #11156

Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
bundles/org.openhab.binding.tplinksmarthome/README.md
bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/TPLinkSmartHomeBindingConstants.java
bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/TPLinkSmartHomeHandlerFactory.java
bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/TPLinkSmartHomeThingType.java
bundles/org.openhab.binding.tplinksmarthome/src/main/java/org/openhab/binding/tplinksmarthome/internal/device/BulbDevice.java
bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/EP10.xml [new file with mode: 0644]
bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/EP40.xml [new file with mode: 0644]
bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/KL125.xml [new file with mode: 0644]
bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/KL135.xml [new file with mode: 0644]
bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/channels.xml
bundles/org.openhab.binding.tplinksmarthome/src/test/java/org/openhab/binding/tplinksmarthome/internal/device/BulbDeviceTest.java

index 6dfe23271cceb2e9696bab48c004e7f5c063b249..e1df96e22350f85988ed98a0b8c4bfe0a6957d9d 100644 (file)
@@ -6,6 +6,19 @@ This binding adds support to control TP-Link Smart Home Devices from your local
 
 The following TP-Link Smart Devices are supported:
 
+### EP10 Kasa Smart Wi-Fi Plug Mini
+
+* Power On/Off
+* LED On/Off
+* Wi-Fi signal strength (RSSI)
+
+### EP40 Kasa Smart Wi-Fi Outdoor Plug
+
+* Power On/Off Group
+* Power On/Off 2 Outlets
+* LED On/Off
+* Wi-Fi signal strength (RSSI)
+
 ### HS100 Smart Wi-Fi Plug
 
 * Power On/Off
@@ -27,7 +40,7 @@ The following TP-Link Smart Devices are supported:
 ### HS107 Smart Wi-Fi Plug, 2-Outlets
 
 * Power On/Off Group
-* Power On/Off Outlets
+* Power On/Off Outlets
 * LED On/Off
 * Wi-Fi signal strength (RSSI)
 
@@ -68,12 +81,12 @@ Switching via openHAB activates the switch directly.
 ### HS300 Smart Wi-Fi Power Strip
 
 * Power On/Off Group
-* Power On/Off Outlets
-* Energy readings Outlets
+* Power On/Off Outlets
+* Energy readings Outlets
 * LED On/Off
 * Wi-Fi signal strength (RSSI)
 
-### KB100 Kasa Smart Light Bulb
+### LB100 Smart Wi-Fi LED Bulb with Dimmable Light
 
 * Power On/Off
 * Adjust the brightness
@@ -82,86 +95,46 @@ Switching via openHAB activates the switch directly.
 
 Switching and Brightness is done using the `brightness` channel.
 
-### KB130 Kasa Multi-color Smart Light Bulb
+### LB110 Smart Wi-Fi LED Bulb with Dimmable Light
 
 * Power On/Off
-* Fine-tune colors
-* Adjust light appearance from soft white (2500k) to daylight (9000k)
 * Adjust the brightness
 * Actual power usage
 * Wi-Fi signal strength (RSSI)
 
-Switching, Brightness and Color is done using the `color` channel.
-
-### KP100 Kasa Wi-Fi Smart Plug - Slim Edition
-
-* Power On/Off
-* LED On/Off
-* Wi-Fi signal strength (RSSI)
-
-### KP105 Kasa Wi-Fi Smart Plug - Slim Edition
-
-* Power On/Off
-* LED On/Off
-* Wi-Fi signal strength (RSSI)
-
-### KP115 Kasa Wi-Fi Smart Plug with Energy Monitoring - Slim Edition
-
-* Power On/Off
-* Energy readings
-* LED On/Off
-* Wi-Fi signal strength (RSSI)
-
-### KP200 Smart Wi-Fi Power Outlet, 2-Sockets
-
-* Power On/Off Group
-* Power On/Off Outlets
-* LED On/Off
-* Wi-Fi signal strength (RSSI)
-
-### KP303 Smart Wi-Fi Power Outlet, 3-Sockets
-
-* Power On/Off Group
-* Power On/Off Outlets
-* LED On/Off
-* Wi-Fi signal strength (RSSI)
-
-### KP400 Smart Outdoor Plug
-
-* Power On/Off Group
-* Power On/Off Outlets
-* LED On/Off
-* Wi-Fi signal strength (RSSI)
+Switching and Brightness is done using the `brightness` channel.
 
-### LB100 Smart Wi-Fi LED Bulb with Dimmable Light
+### LB120 Smart Wi-Fi LED Bulb with Tunable White Light
 
 * Power On/Off
+* Adjust light appearance from soft white (2700k) to daylight (6500k)
 * Adjust the brightness
 * Actual power usage
 * Wi-Fi signal strength (RSSI)
 
 Switching and Brightness is done using the `brightness` channel.
 
-### LB110 Smart Wi-Fi LED Bulb with Dimmable Light
+### LB130 Smart Wi-Fi LED Bulb with Color Changing Hue
 
 * Power On/Off
+* Fine-tune colors
+* Adjust light appearance from soft white (2500k) to daylight (9000k)
 * Adjust the brightness
 * Actual power usage
 * Wi-Fi signal strength (RSSI)
 
-Switching and Brightness is done using the `brightness` channel.
+Switching, Brightness and Color is done using the `color` channel.
 
-### LB120 Smart Wi-Fi LED Bulb with Tunable White Light
+### LB200 Smart Wi-Fi LED Bulb with Dimmable Light
 
 * Power On/Off
-* Adjust light appearance from soft white (2700k) to daylight (6500k)
 * Adjust the brightness
 * Actual power usage
 * Wi-Fi signal strength (RSSI)
 
 Switching and Brightness is done using the `brightness` channel.
 
-### LB130 Smart Wi-Fi LED Bulb with Color Changing Hue
+### LB230 Smart Wi-Fi LED Bulb with Color Changing Hue
 
 * Power On/Off
 * Fine-tune colors
@@ -172,7 +145,7 @@ Switching and Brightness is done using the `brightness` channel.
 
 Switching, Brightness and Color is done using the `color` channel.
 
-### LB200 Smart Wi-Fi LED Bulb with Dimmable Light
+### KB100 Kasa Smart Light Bulb
 
 * Power On/Off
 * Adjust the brightness
@@ -181,7 +154,7 @@ Switching, Brightness and Color is done using the `color` channel.
 
 Switching and Brightness is done using the `brightness` channel.
 
-### LB230 Smart Wi-Fi LED Bulb with Color Changing Hue
+### KB130 Kasa Multi-color Smart Light Bulb
 
 * Power On/Off
 * Fine-tune colors
@@ -229,6 +202,17 @@ Switching and Brightness is done using the `brightness` channel.
 
 Switching and Brightness is done using the `brightness` channel.
 
+### KL125 Kasa Smart Wi-Fi Bulb Multicolor
+
+* Power On/Off
+* Fine-tune colors
+* Adjust light appearance from soft white (2500k) to daylight (6500k)
+* Adjust the brightness
+* Actual power usage
+* Wi-Fi signal strength (RSSI)
+
+Switching, Brightness and Color is done using the `color` channel.
+
 ### KL130 Smart Wi-Fi LED Bulb with Color Changing Hue
 
 * Power On/Off
@@ -240,6 +224,57 @@ Switching and Brightness is done using the `brightness` channel.
 
 Switching, Brightness and Color is done using the `color` channel.
 
+### KL135 Kasa Smart Wi-Fi Bulb Multicolor
+
+* Power On/Off
+* Fine-tune colors
+* Adjust light appearance from soft white (2500k) to daylight (6500k)
+* Adjust the brightness
+* Actual power usage
+* Wi-Fi signal strength (RSSI)
+
+Switching, Brightness and Color is done using the `color` channel.
+
+### KP100 Kasa Wi-Fi Smart Plug - Slim Edition
+
+* Power On/Off
+* LED On/Off
+* Wi-Fi signal strength (RSSI)
+
+### KP105 Kasa Wi-Fi Smart Plug - Slim Edition
+
+* Power On/Off
+* LED On/Off
+* Wi-Fi signal strength (RSSI)
+
+### KP115 Kasa Wi-Fi Smart Plug with Energy Monitoring - Slim Edition
+
+* Power On/Off
+* Energy readings
+* LED On/Off
+* Wi-Fi signal strength (RSSI)
+
+### KP200 Smart Wi-Fi Power Outlet, 2-Sockets
+
+* Power On/Off Group
+* Power On/Off 2 Outlets
+* LED On/Off
+* Wi-Fi signal strength (RSSI)
+
+### KP303 Smart Wi-Fi Power Outlet, 3-Sockets
+
+* Power On/Off Group
+* Power On/Off 3 Outlets
+* LED On/Off
+* Wi-Fi signal strength (RSSI)
+
+### KP400 Smart Outdoor Plug
+
+* Power On/Off Group
+* Power On/Off 2 Outlets
+* LED On/Off
+* Wi-Fi signal strength (RSSI)
+
 ### RE270K AC750 Wi-Fi Range Extender with Smart Plug
 
 * Power On/Off (readonly)
@@ -296,21 +331,21 @@ Either `deviceId` or `ipAddress` must be set.
 
 All devices support some of the following channels:
 
-| Channel Type ID     | Item Type                | Description                                    | Thing types supporting this channel                                                                |
-|---------------------|--------------------------|------------------------------------------------|----------------------------------------------------------------------------------------------------|
-| switch              | Switch                   | Power the device on or off.                    | HS100, HS103, HS105, HS107, HS110, HS200, HS210, HS300, KP100, KP105, KP115, KP200, KP303, KP400, RE270K, RE370K |
-| brightness          | Dimmer                   | Set the brightness of device or dimmer.        | HS220, KB100, KL50, KL60, KL110, KL120, LB100, LB110, LB120, LB200                                 |
-| colorTemperature    | Dimmer                   | Set the color temperature in percentage.       | KB130, KL120, KL130, LB120, LB130, LB230                                                           |
-| colorTemperatureAbs | Number                   | Set the color temperature in Kelvin.           | KB130, KL120, KL130, LB120, LB130, LB230                                                           |
-| color               | Color                    | Set the color of the light.                    | KB130, KL130, LB130, LB230                                                                         |
-| power               | Number:Power             | Actual energy usage in Watt.                   | HS110, HS300, KLxxx, KP115, LBxxx,                                                                 |
-| eneryUsage          | Number:Energy            | Energy Usage in kWh.                           | HS110, HS300, KP115                                                                                |
-| current             | Number:ElectricCurrent   | Actual current usage in Ampere.                | HS110, HS300, KP115                                                                                |
-| voltage             | Number:ElectricPotential | Actual voltage usage in Volt.                  | HS110, HS300, KP115                                                                                |
-| led                 | Switch                   | Switch the status LED on the device on or off. | HS100, HS103, HS105, HS107, HS110, HS200, HS210, HS220, HS300, KP100, KP105, KP115, KP303, KP200, KP400 |
-| rssi                | Number:Power             | Wi-Fi signal strength indicator in dBm.        | All                                                                                                |
-
-The outlet devices (HS107, HS300, KP200, KP400) have group channels.
+| Channel Type ID     | Item Type                | Description                                    | Thing types supporting this channel                                                                                          |
+|---------------------|--------------------------|------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
+| switch              | Switch                   | Power the device on or off.                    | EP10, EP40, HS100, HS103, HS105, HS107, HS110, HS200, HS210, HS300, KP100, KP105, KP115, KP200, KP303, KP400, RE270K, RE370K |
+| brightness          | Dimmer                   | Set the brightness of device or dimmer.        | HS220, KB100, KL50, KL60, KL110, KL120, LB100, LB110, LB120, LB200                                                           |
+| colorTemperature    | Dimmer                   | Set the color temperature in percentage.       | KB130, KL120, KL125, KL130, KL135, LB120, LB130, LB230                                                                       |
+| colorTemperatureAbs | Number                   | Set the color temperature in Kelvin.           | KB130, KL120, KL125, KL130, KL135, LB120, LB130, LB230                                                                       |
+| color               | Color                    | Set the color of the light.                    | KB130, KL125, KL130, KL135, LB130, LB230                                                                                     |
+| power               | Number:Power             | Actual energy usage in Watt.                   | HS110, HS300, KLxxx, KP115, LBxxx,                                                                                           |
+| eneryUsage          | Number:Energy            | Energy Usage in kWh.                           | HS110, HS300, KP115                                                                                                          |
+| current             | Number:ElectricCurrent   | Actual current usage in Ampere.                | HS110, HS300, KP115                                                                                                          |
+| voltage             | Number:ElectricPotential | Actual voltage usage in Volt.                  | HS110, HS300, KP115                                                                                                          |
+| led                 | Switch                   | Switch the status LED on the device on or off. | EP10, EP40, HS100, HS103, HS105, HS107, HS110, HS200, HS210, HS220, HS300, KP100, KP105, KP115, KP303, KP200, KP400          |
+| rssi                | Number:Power             | Wi-Fi signal strength indicator in dBm.        | All                                                                                                                          |
+
+The outlet devices (EP40, HS107, HS300, KP200, KP400) have group channels.
 This means the channel is prefixed with the group id.
 The following group ids are available:
 
index b8e243a5a5778eb3dbd0b692dc255d8535500921..ba0126afccb68a69c37212f5f64f7508d81be828 100644 (file)
@@ -27,6 +27,29 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 @NonNullByDefault
 public final class TPLinkSmartHomeBindingConstants {
 
+    public enum ColorScales {
+        NOT_SUPPORTED(0, 0),
+        K_2500_6500(2500, 6500),
+        K_2700_6500(2700, 6500),
+        K_2500_9000(2500, 9000);
+
+        private final int warm;
+        private final int cool;
+
+        ColorScales(final int warm, final int cool) {
+            this.warm = warm;
+            this.cool = cool;
+        }
+
+        public int getWarm() {
+            return warm;
+        }
+
+        public int getCool() {
+            return cool;
+        }
+    }
+
     public static final String BINDING_ID = "tplinksmarthome";
 
     // List of all switch channel ids
@@ -40,10 +63,6 @@ public final class TPLinkSmartHomeBindingConstants {
     public static final String CHANNEL_COLOR = "color";
     public static final String CHANNEL_COLOR_TEMPERATURE = "colorTemperature";
     public static final String CHANNEL_COLOR_TEMPERATURE_ABS = "colorTemperatureAbs";
-    public static final int COLOR_TEMPERATURE_1_MIN = 2700;
-    public static final int COLOR_TEMPERATURE_1_MAX = 6500;
-    public static final int COLOR_TEMPERATURE_2_MIN = 2500;
-    public static final int COLOR_TEMPERATURE_2_MAX = 9000;
 
     public static final Set<String> CHANNELS_BULB_SWITCH = Stream.of(CHANNEL_BRIGHTNESS, CHANNEL_COLOR,
             CHANNEL_COLOR_TEMPERATURE, CHANNEL_COLOR_TEMPERATURE_ABS, CHANNEL_SWITCH).collect(Collectors.toSet());
index f55409173dea8a35cc625fd117d110bca2596e1e..3e71a709b7f3621c3147ebc848a042c88104616e 100644 (file)
@@ -12,8 +12,7 @@
  */
 package org.openhab.binding.tplinksmarthome.internal;
 
-import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.*;
-import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeThingType.*;
+import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeThingType.SUPPORTED_THING_TYPES;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -46,13 +45,13 @@ public class TPLinkSmartHomeHandlerFactory extends BaseThingHandlerFactory {
     private @NonNullByDefault({}) TPLinkIpAddressService ipAddressService;
 
     @Override
-    public boolean supportsThingType(ThingTypeUID thingTypeUID) {
+    public boolean supportsThingType(final ThingTypeUID thingTypeUID) {
         return SUPPORTED_THING_TYPES.contains(thingTypeUID);
     }
 
     @Nullable
     @Override
-    protected ThingHandler createHandler(Thing thing) {
+    protected ThingHandler createHandler(final Thing thing) {
         final ThingTypeUID thingTypeUID = thing.getThingTypeUID();
         final TPLinkSmartHomeThingType type = TPLinkSmartHomeThingType.THING_TYPE_MAP.get(thingTypeUID);
 
@@ -63,23 +62,19 @@ public class TPLinkSmartHomeHandlerFactory extends BaseThingHandlerFactory {
 
         switch (type.getDeviceType()) {
             case BULB:
-                if (TPLinkSmartHomeThingType.isBulbDeviceWithTemperatureColor1(thingTypeUID)) {
-                    device = new BulbDevice(thingTypeUID, COLOR_TEMPERATURE_1_MIN, COLOR_TEMPERATURE_1_MAX);
-                } else if (TPLinkSmartHomeThingType.isBulbDeviceWithTemperatureColor2(thingTypeUID)) {
-                    device = new BulbDevice(thingTypeUID, COLOR_TEMPERATURE_2_MIN, COLOR_TEMPERATURE_2_MAX);
-                } else {
-                    device = new BulbDevice(thingTypeUID);
-                }
+                device = new BulbDevice(type);
                 break;
             case DIMMER:
                 device = new DimmerDevice();
                 break;
             case PLUG:
-                if (HS110.is(thingTypeUID) || KP115.is(thingTypeUID)) {
-                    device = new EnergySwitchDevice();
-                } else {
-                    device = new SwitchDevice();
-                }
+                device = new SwitchDevice();
+                break;
+            case PLUG_WITH_ENERGY:
+                device = new EnergySwitchDevice();
+                break;
+            case STRIP:
+                device = new PowerStripDevice(type);
                 break;
             case SWITCH:
                 device = new SwitchDevice();
@@ -87,9 +82,6 @@ public class TPLinkSmartHomeHandlerFactory extends BaseThingHandlerFactory {
             case RANGE_EXTENDER:
                 device = new RangeExtenderDevice();
                 break;
-            case STRIP:
-                device = new PowerStripDevice(type);
-                break;
             default:
                 return null;
         }
@@ -97,11 +89,11 @@ public class TPLinkSmartHomeHandlerFactory extends BaseThingHandlerFactory {
     }
 
     @Reference
-    protected void setTPLinkIpAddressCache(TPLinkIpAddressService ipAddressCache) {
+    protected void setTPLinkIpAddressCache(final TPLinkIpAddressService ipAddressCache) {
         this.ipAddressService = ipAddressCache;
     }
 
-    protected void unsetTPLinkIpAddressCache(TPLinkIpAddressService ipAddressCache) {
+    protected void unsetTPLinkIpAddressCache(final TPLinkIpAddressService ipAddressCache) {
         this.ipAddressService = null;
     }
 }
index 93a09cb0c210e3185cf1f6db6077a131b6d95d4e..35411f75ddcfe8e44bbf7a0ced449c02bf4595e3 100644 (file)
@@ -18,9 +18,9 @@ import java.util.Map;
 import java.util.Set;
 import java.util.function.Function;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.ColorScales;
 import org.openhab.core.thing.ThingTypeUID;
 
 /**
@@ -34,27 +34,30 @@ public enum TPLinkSmartHomeThingType {
 
     // Bulb Thing Type UIDs
     KB100("kb100", DeviceType.BULB),
-    KB130("kb130", DeviceType.BULB),
+    KB130("kb130", DeviceType.BULB, ColorScales.K_2500_9000),
     LB100("lb100", DeviceType.BULB),
     LB110("lb110", DeviceType.BULB),
-    LB120("lb120", DeviceType.BULB),
-    LB130("lb130", DeviceType.BULB),
+    LB120("lb120", DeviceType.BULB, ColorScales.K_2700_6500),
+    LB130("lb130", DeviceType.BULB, ColorScales.K_2500_9000),
     LB200("lb200", DeviceType.BULB),
-    LB230("lb230", DeviceType.BULB),
+    LB230("lb230", DeviceType.BULB, ColorScales.K_2500_9000),
     KL50("kl50", DeviceType.BULB),
     KL60("kl60", DeviceType.BULB),
     KL110("kl110", DeviceType.BULB),
-    KL120("kl120", DeviceType.BULB),
-    KL130("kl130", DeviceType.BULB),
+    KL120("kl120", DeviceType.BULB, ColorScales.K_2700_6500),
+    KL125("kl125", DeviceType.BULB, ColorScales.K_2500_6500),
+    KL130("kl130", DeviceType.BULB, ColorScales.K_2500_9000),
+    KL135("kl135", DeviceType.BULB, ColorScales.K_2500_6500),
 
     // Plug Thing Type UIDs
+    EP10("ep10", DeviceType.PLUG),
     HS100("hs100", DeviceType.PLUG),
     HS103("hs103", DeviceType.PLUG),
     HS105("hs105", DeviceType.PLUG),
-    HS110("hs110", DeviceType.PLUG),
+    HS110("hs110", DeviceType.PLUG_WITH_ENERGY),
     KP100("kp100", DeviceType.PLUG),
     KP105("kp105", DeviceType.PLUG),
-    KP115("kp115", DeviceType.PLUG),
+    KP115("kp115", DeviceType.PLUG_WITH_ENERGY),
 
     // Switch Thing Type UIDs
     HS200("hs200", DeviceType.SWITCH),
@@ -64,6 +67,7 @@ public enum TPLinkSmartHomeThingType {
     HS220("hs220", DeviceType.DIMMER),
 
     // Power Strip Thing Type UIDs.
+    EP40("ep40", DeviceType.STRIP, 2),
     HS107("hs107", DeviceType.STRIP, 2),
     HS300("hs300", DeviceType.STRIP, 6),
     KP200("kp200", DeviceType.STRIP, 2),
@@ -91,22 +95,29 @@ public enum TPLinkSmartHomeThingType {
      */
     public static final Map<ThingTypeUID, TPLinkSmartHomeThingType> THING_TYPE_MAP = SUPPORTED_THING_TYPES_LIST.stream()
             .collect(Collectors.toMap(TPLinkSmartHomeThingType::thingTypeUID, Function.identity()));
-    private static final List<TPLinkSmartHomeThingType> BULB_WITH_TEMPERATURE_COLOR_1 = Stream.of(LB120, KL120)
-            .collect(Collectors.toList());
-    private static final List<TPLinkSmartHomeThingType> BULB_WITH_TEMPERATURE_COLOR_2 = Stream
-            .of(KB130, KL130, LB130, LB230).collect(Collectors.toList());
 
     private final ThingTypeUID thingTypeUID;
     private final DeviceType type;
+    private final ColorScales colorScales;
     private final int sockets;
 
     TPLinkSmartHomeThingType(final String name, final DeviceType type) {
         this(name, type, 0);
     }
 
-    TPLinkSmartHomeThingType(final String name, final DeviceType type, int sockets) {
+    TPLinkSmartHomeThingType(final String name, final DeviceType type, final ColorScales colorScales) {
+        this(name, type, colorScales, 0);
+    }
+
+    TPLinkSmartHomeThingType(final String name, final DeviceType type, final int sockets) {
+        this(name, type, ColorScales.NOT_SUPPORTED, sockets);
+    }
+
+    TPLinkSmartHomeThingType(final String name, final DeviceType type, final ColorScales colorScales,
+            final int sockets) {
         thingTypeUID = new ThingTypeUID(TPLinkSmartHomeBindingConstants.BINDING_ID, name);
         this.type = type;
+        this.colorScales = colorScales;
         this.sockets = sockets;
     }
 
@@ -132,29 +143,10 @@ public enum TPLinkSmartHomeThingType {
     }
 
     /**
-     * Returns true if the given {@link ThingTypeUID} matches a device that is a bulb with color temperature ranges 1
-     * (2700 to 6500k).
-     *
-     * @param thingTypeUID if the check
-     * @return true if it's a bulb device with color temperature range 1
-     */
-    public static boolean isBulbDeviceWithTemperatureColor1(ThingTypeUID thingTypeUID) {
-        return isDevice(thingTypeUID, BULB_WITH_TEMPERATURE_COLOR_1);
-    }
-
-    /**
-     * Returns true if the given {@link ThingTypeUID} matches a device that is a bulb with color temperature ranges 2
-     * (2500 to 9000k).
-     *
-     * @param thingTypeUID if the check
-     * @return true if it's a bulb device with color temperature range 2
+     * @return Returns the color temperature color scales if supported or else returns null
      */
-    public static boolean isBulbDeviceWithTemperatureColor2(ThingTypeUID thingTypeUID) {
-        return isDevice(thingTypeUID, BULB_WITH_TEMPERATURE_COLOR_2);
-    }
-
-    private static boolean isDevice(ThingTypeUID thingTypeUID, List<TPLinkSmartHomeThingType> thingTypes) {
-        return thingTypes.stream().anyMatch(t -> t.is(thingTypeUID));
+    public ColorScales getColorScales() {
+        return colorScales;
     }
 
     /**
@@ -163,7 +155,7 @@ public enum TPLinkSmartHomeThingType {
      * @param otherThingTypeUID to check
      * @return true if matches
      */
-    public boolean is(ThingTypeUID otherThingTypeUID) {
+    public boolean is(final ThingTypeUID otherThingTypeUID) {
         return thingTypeUID.equals(otherThingTypeUID);
     }
 
@@ -183,6 +175,10 @@ public enum TPLinkSmartHomeThingType {
          * Plug device.
          */
         PLUG,
+        /**
+         * Plug device with energy measurement support.
+         */
+        PLUG_WITH_ENERGY,
         /**
          * Wi-Fi range extender device with plug.
          */
index d4ca5490aab630088fe1324da64478a59192f71b..ab638a835ee7783267fd0353ea3355a17bdef8aa 100644 (file)
  */
 package org.openhab.binding.tplinksmarthome.internal.device;
 
-import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.*;
+import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.CHANNELS_BULB_SWITCH;
+import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.CHANNEL_BRIGHTNESS;
+import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.CHANNEL_COLOR;
+import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.CHANNEL_COLOR_TEMPERATURE;
+import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.CHANNEL_COLOR_TEMPERATURE_ABS;
+import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.CHANNEL_ENERGY_POWER;
+import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.CHANNEL_SWITCH;
 
 import java.io.IOException;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.tplinksmarthome.internal.Commands;
+import org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeThingType;
 import org.openhab.binding.tplinksmarthome.internal.model.HasErrorResponse;
 import org.openhab.binding.tplinksmarthome.internal.model.LightState;
 import org.openhab.binding.tplinksmarthome.internal.model.TransitionLightStateResponse;
@@ -27,7 +34,6 @@ import org.openhab.core.library.types.HSBType;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.PercentType;
 import org.openhab.core.thing.ChannelUID;
-import org.openhab.core.thing.ThingTypeUID;
 import org.openhab.core.types.Command;
 import org.openhab.core.types.State;
 import org.openhab.core.types.UnDefType;
@@ -46,13 +52,9 @@ public class BulbDevice extends SmartHomeDevice {
     private final int colorTempMax;
     private final int colorTempRangeFactor;
 
-    public BulbDevice(ThingTypeUID thingTypeUID) {
-        this(thingTypeUID, 0, 0);
-    }
-
-    public BulbDevice(ThingTypeUID thingTypeUID, int colorTempMin, int colorTempMax) {
-        this.colorTempMin = colorTempMin;
-        this.colorTempMax = colorTempMax;
+    public BulbDevice(final TPLinkSmartHomeThingType type) {
+        this.colorTempMin = type.getColorScales().getWarm();
+        this.colorTempMax = type.getColorScales().getCool();
         colorTempRangeFactor = (colorTempMax - colorTempMin) / 100;
     }
 
@@ -62,7 +64,7 @@ public class BulbDevice extends SmartHomeDevice {
     }
 
     @Override
-    public boolean handleCommand(ChannelUID channelUid, Command command) throws IOException {
+    public boolean handleCommand(final ChannelUID channelUid, final Command command) throws IOException {
         final String channelId = channelUid.getId();
         final int transitionPeriod = configuration.transitionPeriod;
         final HasErrorResponse response;
@@ -80,8 +82,8 @@ public class BulbDevice extends SmartHomeDevice {
         return response != null;
     }
 
-    private @Nullable HasErrorResponse handleOnOffType(String channelID, OnOffType onOff, int transitionPeriod)
-            throws IOException {
+    private @Nullable HasErrorResponse handleOnOffType(final String channelID, final OnOffType onOff,
+            final int transitionPeriod) throws IOException {
         if (CHANNELS_BULB_SWITCH.contains(channelID)) {
             return commands.setTransitionLightStateResponse(
                     connection.sendCommand(commands.setLightState(onOff, transitionPeriod)));
@@ -89,8 +91,8 @@ public class BulbDevice extends SmartHomeDevice {
         return null;
     }
 
-    private @Nullable HasErrorResponse handleDecimalType(String channelID, DecimalType command, int transitionPeriod)
-            throws IOException {
+    private @Nullable HasErrorResponse handleDecimalType(final String channelID, final DecimalType command,
+            final int transitionPeriod) throws IOException {
         if (CHANNEL_COLOR.equals(channelID) || CHANNEL_BRIGHTNESS.equals(channelID)) {
             return commands.setTransitionLightStateResponse(
                     connection.sendCommand(commands.setBrightness(command.intValue(), transitionPeriod)));
@@ -102,14 +104,15 @@ public class BulbDevice extends SmartHomeDevice {
         return null;
     }
 
-    private @Nullable TransitionLightStateResponse handleColorTemperature(int colorTemperature, int transitionPeriod)
-            throws IOException {
+    private @Nullable TransitionLightStateResponse handleColorTemperature(final int colorTemperature,
+            final int transitionPeriod) throws IOException {
         return commands.setTransitionLightStateResponse(
                 connection.sendCommand(commands.setColorTemperature(colorTemperature, transitionPeriod)));
     }
 
     @Nullable
-    private HasErrorResponse handleHSBType(String channelID, HSBType command, int transitionPeriod) throws IOException {
+    private HasErrorResponse handleHSBType(final String channelID, final HSBType command, final int transitionPeriod)
+            throws IOException {
         if (CHANNEL_COLOR.equals(channelID)) {
             return commands.setTransitionLightStateResponse(
                     connection.sendCommand(commands.setColor(command, transitionPeriod)));
@@ -118,7 +121,7 @@ public class BulbDevice extends SmartHomeDevice {
     }
 
     @Override
-    public State updateChannel(ChannelUID channelUid, DeviceState deviceState) {
+    public State updateChannel(final ChannelUID channelUid, final DeviceState deviceState) {
         final LightState lightState = deviceState.getSysinfo().getLightState();
         final State state;
 
@@ -148,15 +151,15 @@ public class BulbDevice extends SmartHomeDevice {
         return state;
     }
 
-    private int convertPercentageToKelvin(int percentage) {
+    private int convertPercentageToKelvin(final int percentage) {
         return guardColorTemperature(colorTempMin + colorTempRangeFactor * percentage);
     }
 
-    private int convertKelvinToPercentage(int colorTemperature) {
+    private int convertKelvinToPercentage(final int colorTemperature) {
         return (guardColorTemperature(colorTemperature) - colorTempMin) / colorTempRangeFactor;
     }
 
-    private int guardColorTemperature(int colorTemperature) {
+    private int guardColorTemperature(final int colorTemperature) {
         return Math.max(colorTempMin, Math.min(colorTempMax, colorTemperature));
     }
 }
diff --git a/bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/EP10.xml b/bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/EP10.xml
new file mode 100644 (file)
index 0000000..4f1484c
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<thing:thing-descriptions bindingId="tplinksmarthome"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
+       xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
+
+       <thing-type id="ep10">
+               <label>EP10</label>
+               <description>TP-Link EP10 Kasa Smart Wi-Fi Plug Mini</description>
+               <category>PowerOutlet</category>
+
+               <channels>
+                       <channel id="switch" typeId="system.power"/>
+                       <channel id="led" typeId="led"/>
+                       <channel id="rssi" typeId="rssi"/>
+               </channels>
+
+               <representation-property>deviceId</representation-property>
+
+               <config-description-ref uri="thing-type:tplinksmarthome:device-plug"/>
+       </thing-type>
+</thing:thing-descriptions>
diff --git a/bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/EP40.xml b/bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/EP40.xml
new file mode 100644 (file)
index 0000000..bb5f1fc
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<thing:thing-descriptions bindingId="tplinksmarthome"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
+       xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
+
+       <thing-type id="ep40">
+               <label>EP40</label>
+               <description>TP-Link EP40 Kasa Smart Wi-Fi Outdoor Plug</description>
+               <category>PowerOutlet</category>
+
+               <channel-groups>
+                       <channel-group id="groupSwitch" typeId="switch-group"/>
+                       <channel-group id="outlet1" typeId="switch-outlet">
+                               <label>Outlet 1</label>
+                       </channel-group>
+                       <channel-group id="outlet2" typeId="switch-outlet">
+                               <label>Outlet 2</label>
+                       </channel-group>
+               </channel-groups>
+
+               <representation-property>deviceId</representation-property>
+
+               <config-description-ref uri="thing-type:tplinksmarthome:device-plug"/>
+       </thing-type>
+</thing:thing-descriptions>
diff --git a/bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/KL125.xml b/bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/KL125.xml
new file mode 100644 (file)
index 0000000..3583b60
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<thing:thing-descriptions bindingId="tplinksmarthome"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
+       xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
+
+       <thing-type id="kl125">
+               <label>KL125</label>
+               <description>TP-Link KL125 Kasa Smart Wi-Fi Bulb Multicolor</description>
+               <category>Lightbulb</category>
+
+               <channels>
+                       <channel id="brightness" typeId="system.brightness"/>
+                       <channel id="colorTemperature" typeId="system.color-temperature"/>
+                       <channel id="colorTemperatureAbs" typeId="colorTemperatureAbs3"/>
+                       <channel id="power" typeId="power"/>
+                       <channel id="rssi" typeId="rssi"/>
+               </channels>
+
+               <representation-property>deviceId</representation-property>
+
+               <config-description-ref uri="thing-type:tplinksmarthome:device-bulb"/>
+       </thing-type>
+</thing:thing-descriptions>
diff --git a/bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/KL135.xml b/bundles/org.openhab.binding.tplinksmarthome/src/main/resources/OH-INF/thing/KL135.xml
new file mode 100644 (file)
index 0000000..2970144
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<thing:thing-descriptions bindingId="tplinksmarthome"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
+       xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
+
+       <thing-type id="kl135">
+               <label>KL135</label>
+               <description>TP-Link KL135 Kasa Smart Wi-Fi Bulb Multicolor</description>
+               <category>Lightbulb</category>
+
+               <channels>
+                       <channel id="brightness" typeId="system.brightness"/>
+                       <channel id="colorTemperature" typeId="system.color-temperature"/>
+                       <channel id="colorTemperatureAbs" typeId="colorTemperatureAbs3"/>
+                       <channel id="power" typeId="power"/>
+                       <channel id="rssi" typeId="rssi"/>
+               </channels>
+
+               <representation-property>deviceId</representation-property>
+
+               <config-description-ref uri="thing-type:tplinksmarthome:device-bulb"/>
+       </thing-type>
+</thing:thing-descriptions>
index ba74f5f3bc72442896234365d303879acc5ad746..e02a37e043559676fc598fb22866cdd53f378007 100644 (file)
                <state min="2500" max="9000" pattern="%d K"/>
        </channel-type>
 
+       <channel-type id="colorTemperatureAbs3" advanced="true">
+               <item-type>Number</item-type>
+               <label>Color Temperature</label>
+               <description>This channel supports adjusting the color temperature from 2500K to 6500K.</description>
+               <category>ColorLight</category>
+               <state min="2500" max="6500" pattern="%d K"/>
+       </channel-type>
+
        <!-- Energy Channel types -->
        <channel-type id="power">
                <item-type>Number:Power</item-type>
index dee98eaab7d63ee44fafabbdb45e07ef5e80c54b..35d6bba45b27a3f52820d135c6b311457c48881c 100644 (file)
  */
 package org.openhab.binding.tplinksmarthome.internal.device;
 
-import static org.junit.jupiter.api.Assertions.*;
-import static org.openhab.binding.tplinksmarthome.internal.ChannelUIDConstants.*;
-import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.openhab.binding.tplinksmarthome.internal.ChannelUIDConstants.CHANNEL_UID_BRIGHTNESS;
+import static org.openhab.binding.tplinksmarthome.internal.ChannelUIDConstants.CHANNEL_UID_COLOR;
+import static org.openhab.binding.tplinksmarthome.internal.ChannelUIDConstants.CHANNEL_UID_COLOR_TEMPERATURE;
+import static org.openhab.binding.tplinksmarthome.internal.ChannelUIDConstants.CHANNEL_UID_COLOR_TEMPERATURE_ABS;
+import static org.openhab.binding.tplinksmarthome.internal.ChannelUIDConstants.CHANNEL_UID_ENERGY_POWER;
+import static org.openhab.binding.tplinksmarthome.internal.ChannelUIDConstants.CHANNEL_UID_OTHER;
+import static org.openhab.binding.tplinksmarthome.internal.ChannelUIDConstants.CHANNEL_UID_SWITCH;
 import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeThingType.LB130;
 
 import java.io.IOException;
@@ -40,8 +47,7 @@ public class BulbDeviceTest extends DeviceTestBase<BulbDevice> {
     private static final String DEVICE_OFF = "bulb_get_sysinfo_response_off";
 
     public BulbDeviceTest() throws IOException {
-        super(new BulbDevice(LB130.thingTypeUID(), COLOR_TEMPERATURE_2_MIN, COLOR_TEMPERATURE_2_MAX),
-                "bulb_get_sysinfo_response_on");
+        super(new BulbDevice(LB130), "bulb_get_sysinfo_response_on");
     }
 
     @BeforeEach