From 2f4d8c33b2913079f70eebb742d2fa6576a11253 Mon Sep 17 00:00:00 2001 From: Marcel Verpaalen Date: Wed, 27 Dec 2017 21:45:39 +0100 Subject: [PATCH] [miio] replace depreciated bundle reference * Removed depreciated bundle ref * Fixed typo for vacuum v2 * Add conversion for scene Signed-off-by: Marcel Verpaalen --- .../miio/handler/MiIoBasicHandler.java | 9 ++------ .../binding/miio/internal/MiIoDevices.java | 2 +- .../miio/internal/basic/Conversions.java | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/handler/MiIoBasicHandler.java b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/handler/MiIoBasicHandler.java index aef7288897fe3..4751a9f156fad 100644 --- a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/handler/MiIoBasicHandler.java +++ b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/handler/MiIoBasicHandler.java @@ -43,6 +43,7 @@ import org.openhab.binding.miio.internal.basic.MiIoDeviceAction; import org.openhab.binding.miio.internal.transport.MiIoAsyncCommunication; import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,7 +65,6 @@ public class MiIoBasicHandler extends MiIoAbstractHandler { private static final int MAX_PROPERTIES = 5; private final Logger logger = LoggerFactory.getLogger(MiIoBasicHandler.class); private boolean hasChannelStructure; - // private BundleContext bundleContext; List refreshList = new ArrayList(); @@ -76,11 +76,6 @@ public MiIoBasicHandler(Thing thing) { super(thing); } - // @Activate - // protected void activate(BundleContext bundleContext) { - // this.bundleContext = bundleContext; - // } - @Override public void initialize() { super.initialize(); @@ -238,7 +233,7 @@ private void checkChannelStructure() { private URL findDatabaseEntry(String deviceName) { URL fn; try { - Bundle bundle = bundleContext.getBundle(); + Bundle bundle = FrameworkUtil.getBundle(getClass()); fn = bundle.getEntry(MiIoBindingConstants.DATABASE_PATH + deviceName + ".json"); if (fn != null) { logger.trace("bundle: {}, {}, {}", bundle, fn.getFile()); diff --git a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/MiIoDevices.java b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/MiIoDevices.java index 668d594899354..396a9e6eb0638 100644 --- a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/MiIoDevices.java +++ b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/MiIoDevices.java @@ -57,7 +57,7 @@ public enum MiIoDevices { POWERSTRIP2("zimi.powerstrip.v2", "Mi Power-strip v2", MiIoBindingConstants.THING_TYPE_BASIC), TOOTHBRUSH("soocare.toothbrush.x3", "Mi Toothbrush", MiIoBindingConstants.THING_TYPE_UNSUPPORTED), VACUUM("rockrobo.vacuum.v1", "Mi Robot Vacuum", MiIoBindingConstants.THING_TYPE_VACUUM), - VACUUM2("roborock-vacuum-s5", "Mi Robot Vacuum v2", MiIoBindingConstants.THING_TYPE_VACUUM), + VACUUM2("roborock.vacuum.s5", "Mi Robot Vacuum v2", MiIoBindingConstants.THING_TYPE_VACUUM), WATER_PURIFIER2("yunmi.waterpuri.v2", "Mi Water Purifier v2", MiIoBindingConstants.THING_TYPE_UNSUPPORTED), WIFI2("xiaomi.repeater.v2", "Xiaomi Wifi Extender", MiIoBindingConstants.THING_TYPE_UNSUPPORTED), WIFISPEAKER("xiaomi.wifispeaker.v1", "Mi Internet Speaker", MiIoBindingConstants.THING_TYPE_UNSUPPORTED), diff --git a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/Conversions.java b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/Conversions.java index b382967558b1a..1671834c82c4e 100644 --- a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/Conversions.java +++ b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/Conversions.java @@ -29,6 +29,25 @@ public static JsonElement secondsToHours(JsonElement seconds) { return new JsonPrimitive(hours); } + public static JsonElement yeelightSceneConversion(JsonElement intValue) { + switch (intValue.getAsInt()) { + case 1: + return new JsonPrimitive("color"); + case 2: + return new JsonPrimitive("hsv"); + case 3: + return new JsonPrimitive("ct"); + case 4: + return new JsonPrimitive("nightlight"); + case 5: // don't know the number for colorflow... + return new JsonPrimitive("cf"); + case 6: // don't know the number for auto_delay_off, or if it is even in the properties visible... + return new JsonPrimitive("auto_delay_off"); + default: + return new JsonPrimitive("unknown"); + } + } + public static JsonElement divideTen(JsonElement value10) { double value = value10.getAsDouble() / 10; return new JsonPrimitive(value); @@ -36,6 +55,8 @@ public static JsonElement divideTen(JsonElement value10) { public static JsonElement execute(String transfortmation, JsonElement value) { switch (transfortmation.toUpperCase()) { + case "YEELIGHTSCENEID": + return yeelightSceneConversion(value); case "SECONDSTOHOURS": return secondsToHours(value); case "/10":