From b1c45aebcd6b7da5f9a33457628983fb6c247129 Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 30 Jan 2019 11:40:15 +0100 Subject: [PATCH] [miio] Fix issue battery channel (#4752) * Fix issue battery channel - Fix error for devices with battery channel - Add chungmi plug m3 - minor edits Signed-off-by: Marcel Verpaalen --- .../org.openhab.binding.miio/database/chuangmi.plug.m1.json | 1 + .../database/zhimi.airmonitor.v1.json | 2 +- .../org.openhab.binding.miio/database/zhimi.fan.v3.json | 2 +- .../java/org/openhab/binding/miio/internal/MiIoDevices.java | 1 + .../binding/miio/internal/basic/MiIoBasicChannel.java | 5 ++++- .../binding/miio/internal/handler/MiIoBasicHandler.java | 2 +- .../org/openhab/binding/miio/internal/robot/StatusType.java | 1 + .../miio/internal/transport/MiIoAsyncCommunication.java | 2 +- 8 files changed, 11 insertions(+), 5 deletions(-) diff --git a/addons/binding/org.openhab.binding.miio/database/chuangmi.plug.m1.json b/addons/binding/org.openhab.binding.miio/database/chuangmi.plug.m1.json index f3aa31fd56238..e16c7e0af9034 100644 --- a/addons/binding/org.openhab.binding.miio/database/chuangmi.plug.m1.json +++ b/addons/binding/org.openhab.binding.miio/database/chuangmi.plug.m1.json @@ -2,6 +2,7 @@ "deviceMapping": { "id": [ "chuangmi.plug.m1", + "chuangmi.plug.m3", "chuangmi.plug.hmi205" ], "channels": [ diff --git a/addons/binding/org.openhab.binding.miio/database/zhimi.airmonitor.v1.json b/addons/binding/org.openhab.binding.miio/database/zhimi.airmonitor.v1.json index 1cf563897b3c5..3bce8c6bfdf12 100644 --- a/addons/binding/org.openhab.binding.miio/database/zhimi.airmonitor.v1.json +++ b/addons/binding/org.openhab.binding.miio/database/zhimi.airmonitor.v1.json @@ -32,7 +32,7 @@ "property": "battery", "friendlyName": "Battery", "channel": "battery", - "channelType":"system.battery-level", + "channelType":"system:battery-level", "type": "Number", "refresh": true, "ChannelGroup": "Status", diff --git a/addons/binding/org.openhab.binding.miio/database/zhimi.fan.v3.json b/addons/binding/org.openhab.binding.miio/database/zhimi.fan.v3.json index c937e1ac09a06..48666439500bd 100644 --- a/addons/binding/org.openhab.binding.miio/database/zhimi.fan.v3.json +++ b/addons/binding/org.openhab.binding.miio/database/zhimi.fan.v3.json @@ -197,7 +197,7 @@ "property": "battery", "friendlyName": "Battery", "channel": "battery", - "channelType": "system.battery-level", + "channelType": "system:battery-level", "type": "Number", "refresh": true, "ChannelGroup": "Status", 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 f0d1ffab516bf..ed363d54312a4 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 @@ -82,6 +82,7 @@ public enum MiIoDevices { POWERPLUG1("chuangmi.plug.v1", "Mi Power-plug v1", THING_TYPE_BASIC), POWERPLUG2("chuangmi.plug.v2", "Mi Power-plug v2", THING_TYPE_BASIC), POWERPLUG3("chuangmi.plug.v3", "Mi Power-plug v3", THING_TYPE_BASIC), + POWERPLUGM3("chuangmi.plug.m3", "Mi Power-plug", THING_TYPE_BASIC), POWERPLUG_HMI205("chuangmi.plug.hmi205", "Mi Smart Plug", THING_TYPE_BASIC), POWERSTRIP("qmi.powerstrip.v1", "Qing Mi Smart Power Strip v1", THING_TYPE_BASIC), POWERSTRIP2("zimi.powerstrip.v2", "Mi Power-strip v2", THING_TYPE_BASIC), diff --git a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/MiIoBasicChannel.java b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/MiIoBasicChannel.java index 9c72c0ac81842..ae08a12c60dee 100644 --- a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/MiIoBasicChannel.java +++ b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/basic/MiIoBasicChannel.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.miio.internal.basic; +import static org.openhab.binding.miio.internal.MiIoBindingConstants.BINDING_ID; + import java.util.ArrayList; import java.util.List; @@ -78,7 +80,8 @@ public void setChannel(String channel) { } public String getChannelType() { - return channelType == null || channelType.isEmpty() ? channel : channelType; + return channelType == null || channelType.isEmpty() ? BINDING_ID + ":" + channel + : (channelType.startsWith("system") ? channelType : BINDING_ID + ":" + channelType); } public void setChannelType(String channelType) { diff --git a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java index a795d80f9d142..1f9a83b984d90 100644 --- a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java +++ b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java @@ -360,7 +360,7 @@ private boolean addChannel(ThingBuilder thingBuilder, String channel, String cha return false; } ChannelUID channelUID = new ChannelUID(getThing().getUID(), channel); - ChannelTypeUID channelTypeUID = new ChannelTypeUID(MiIoBindingConstants.BINDING_ID, channelType); + ChannelTypeUID channelTypeUID = new ChannelTypeUID(channelType); // TODO: Need to understand if this harms anything. If yes, channel only to be added when not there already. // current way allows to have no issues when channels are changing. diff --git a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/StatusType.java b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/StatusType.java index cbf3aed6498e1..df12af708e921 100644 --- a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/StatusType.java +++ b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/StatusType.java @@ -35,6 +35,7 @@ public enum StatusType { SHUTTING_DOWN(13, "Shutting Down"), UPDATING(14, "Updating"), DOCKING(15, "Docking"), + GOTO(16, "Go To"), ZONE(17, "Zone Clean"), FULL(100, "Full"); diff --git a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/transport/MiIoAsyncCommunication.java b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/transport/MiIoAsyncCommunication.java index 35bb74df47715..708e943f14d5a 100644 --- a/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/transport/MiIoAsyncCommunication.java +++ b/addons/binding/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/transport/MiIoAsyncCommunication.java @@ -74,7 +74,7 @@ public class MiIoAsyncCommunication { private int timeout; private boolean needPing = true; private static final int MAX_ERRORS = 3; - private static final int MAX_ID = 1000; + private static final int MAX_ID = 15000; private ConcurrentLinkedQueue concurrentLinkedQueue = new ConcurrentLinkedQueue();