From 9fbc82f0f0730a4adf80d7a4114b73c836f38a55 Mon Sep 17 00:00:00 2001 From: Wietse van Buitenen Date: Mon, 7 Oct 2019 18:03:18 +0200 Subject: [PATCH 01/11] add time unit to constant name Signed-off-by: Wietse van Buitenen --- .../melcloud/internal/api/MelCloudConnection.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/MelCloudConnection.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/MelCloudConnection.java index cfbca7f70db23..5199c46b183d8 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/MelCloudConnection.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/MelCloudConnection.java @@ -49,7 +49,7 @@ public class MelCloudConnection { private static final String DEVICE_LIST_URL = "https://app.melcloud.com/Mitsubishi.Wifi.Client/User/ListDevices"; private static final String DEVICE_URL = "https://app.melcloud.com/Mitsubishi.Wifi.Client/Device"; - private static final int TIMEOUT = 10000; + private static final int TIMEOUT_MILLISECONDS = 10000; // Gson objects are safe to share across threads and are somewhat expensive to construct. Use a single instance. private static final Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); @@ -73,7 +73,8 @@ public void login(String username, String password, int languageId) InputStream data = new ByteArrayInputStream(jsonReq.toString().getBytes(StandardCharsets.UTF_8)); try { - String loginResponse = HttpUtil.executeUrl("POST", LOGIN_URL, null, data, "application/json", TIMEOUT); + String loginResponse = HttpUtil.executeUrl("POST", LOGIN_URL, null, data, "application/json", + TIMEOUT_MILLISECONDS); logger.debug("Login response: {}", loginResponse); LoginClientResponse resp = gson.fromJson(loginResponse, LoginClientResponse.class); if (resp.getErrorId() != null) { @@ -94,7 +95,7 @@ public List fetchDeviceList() throws MelCloudCommException { if (isConnected()) { try { String response = HttpUtil.executeUrl("GET", DEVICE_LIST_URL, getHeaderProperties(), null, null, - TIMEOUT); + TIMEOUT_MILLISECONDS); logger.debug("Device list response: {}", response); List devices = new ArrayList(); ListDevicesResponse[] buildings = gson.fromJson(response, ListDevicesResponse[].class); @@ -128,7 +129,8 @@ public DeviceStatus fetchDeviceStatus(int deviceId, int buildingId) throws MelCl if (isConnected()) { String url = DEVICE_URL + String.format("/Get?id=%d&buildingID=%d", deviceId, buildingId); try { - String response = HttpUtil.executeUrl("GET", url, getHeaderProperties(), null, null, TIMEOUT); + String response = HttpUtil.executeUrl("GET", url, getHeaderProperties(), null, null, + TIMEOUT_MILLISECONDS); logger.debug("Device status response: {}", response); DeviceStatus deviceStatus = gson.fromJson(response, DeviceStatus.class); return deviceStatus; @@ -147,7 +149,7 @@ public DeviceStatus sendDeviceStatus(DeviceStatus deviceStatus) throws MelCloudC InputStream data = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); try { String response = HttpUtil.executeUrl("POST", DEVICE_URL + "/SetAta", getHeaderProperties(), data, - "application/json", TIMEOUT); + "application/json", TIMEOUT_MILLISECONDS); logger.debug("Device status sending response: {}", response); return gson.fromJson(response, DeviceStatus.class); } catch (IOException | JsonSyntaxException e) { From 37c7f4ec37ece814b9bdf6897ef75f4cb18fb4ca Mon Sep 17 00:00:00 2001 From: Wietse van Buitenen Date: Mon, 7 Oct 2019 18:38:01 +0200 Subject: [PATCH 02/11] correctly pass exception Signed-off-by: Wietse van Buitenen --- .../binding/melcloud/internal/api/MelCloudConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/MelCloudConnection.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/MelCloudConnection.java index 5199c46b183d8..c123f8d6e6086 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/MelCloudConnection.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/MelCloudConnection.java @@ -87,7 +87,7 @@ public void login(String username, String password, int languageId) sessionKey = resp.getLoginData().getContextKey(); setConnected(true); } catch (IOException | JsonSyntaxException e) { - throw new MelCloudCommException(String.format("Login error, reason: %s", e.getMessage(), e)); + throw new MelCloudCommException(String.format("Login error, reason: %s", e.getMessage()), e); } } From 78197ca202ec623f051af543b892cf212581793c Mon Sep 17 00:00:00 2001 From: Wietse van Buitenen Date: Mon, 7 Oct 2019 18:44:09 +0200 Subject: [PATCH 03/11] correct author Signed-off-by: Wietse van Buitenen --- .../binding/melcloud/internal/MelCloudBindingConstants.java | 2 +- .../binding/melcloud/internal/MelCloudHandlerFactory.java | 2 +- .../org/openhab/binding/melcloud/internal/api/json/Device.java | 2 +- .../openhab/binding/melcloud/internal/api/json/DeviceProps.java | 2 +- .../binding/melcloud/internal/api/json/DeviceStatus.java | 2 +- .../binding/melcloud/internal/api/json/ListDevicesResponse.java | 2 +- .../binding/melcloud/internal/api/json/LoginClientResponse.java | 2 +- .../openhab/binding/melcloud/internal/api/json/LoginData.java | 2 +- .../org/openhab/binding/melcloud/internal/api/json/Preset.java | 2 +- .../melcloud/internal/api/json/QuantizedCoordinates.java | 2 +- .../openhab/binding/melcloud/internal/api/json/Structure.java | 2 +- .../binding/melcloud/internal/api/json/WeatherObservation.java | 2 +- .../melcloud/internal/handler/MelCloudDeviceHandler.java | 2 +- .../src/main/resources/ESH-INF/binding/binding.xml | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/MelCloudBindingConstants.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/MelCloudBindingConstants.java index fb03209a137c7..e5fea58c219ce 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/MelCloudBindingConstants.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/MelCloudBindingConstants.java @@ -23,7 +23,7 @@ * The {@link MelCloudBindingConstants} class defines common constants, which are * used across the whole binding. * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution */ public class MelCloudBindingConstants { diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/MelCloudHandlerFactory.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/MelCloudHandlerFactory.java index c04e885a69999..2ad39eb9a99fc 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/MelCloudHandlerFactory.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/MelCloudHandlerFactory.java @@ -37,7 +37,7 @@ * The {@link MelCloudHandlerFactory} is responsible for creating things and thing * handlers. * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution */ @Component(configurationPid = "binding.melcloud", service = ThingHandlerFactory.class) public class MelCloudHandlerFactory extends BaseThingHandlerFactory { diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/Device.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/Device.java index e76c097c3e9a7..a1f1b8d7e781f 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/Device.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/Device.java @@ -23,7 +23,7 @@ * Device Structure. * Generated with jsonschema2pojo * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution */ public class Device { diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/DeviceProps.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/DeviceProps.java index 8e45b8097a235..0f4a5d07494fb 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/DeviceProps.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/DeviceProps.java @@ -22,7 +22,7 @@ * Device Properties. * Generated with jsonschema2pojo * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution */ public class DeviceProps { diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/DeviceStatus.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/DeviceStatus.java index 37cd71f3098e0..f1c1d02172bfe 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/DeviceStatus.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/DeviceStatus.java @@ -22,7 +22,7 @@ * Device Status data * Generated with jsonschema2pojo * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution * @author Pauli Anttila - Fine tuned expose annotations */ public class DeviceStatus { diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/ListDevicesResponse.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/ListDevicesResponse.java index 3e81d8f5372d4..a82a92ff54173 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/ListDevicesResponse.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/ListDevicesResponse.java @@ -20,7 +20,7 @@ * Response of Devices List. * Generated with jsonschema2pojo * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution */ public class ListDevicesResponse { diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/LoginClientResponse.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/LoginClientResponse.java index 468e35287e103..80febf9853360 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/LoginClientResponse.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/LoginClientResponse.java @@ -22,7 +22,7 @@ * Response Data of Login. * Generated with jsonschema2pojo * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution */ public class LoginClientResponse { diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/LoginData.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/LoginData.java index 15cba023b1ef5..26357e0a2cc65 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/LoginData.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/LoginData.java @@ -20,7 +20,7 @@ * LoginData for Login Request. * Generated with jsonschema2pojo * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution */ public class LoginData { diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/Preset.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/Preset.java index b32340ef8b636..21daf13ce5be7 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/Preset.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/Preset.java @@ -20,7 +20,7 @@ * Preset data * Generated with jsonschema2pojo * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution */ public class Preset { diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/QuantizedCoordinates.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/QuantizedCoordinates.java index 375c3add42e66..7f56d4e75ca6c 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/QuantizedCoordinates.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/QuantizedCoordinates.java @@ -20,7 +20,7 @@ * QuantizedCoordinates data * Generated with jsonschema2pojo * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution */ public class QuantizedCoordinates { diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/Structure.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/Structure.java index 97b9d93cc6903..cd4b3f4f8ab72 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/Structure.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/Structure.java @@ -22,7 +22,7 @@ * Structure Data * Generated with jsonschema2pojo * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution * @author Wietse van Buitenen - Add Floor and Area */ public class Structure { diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/WeatherObservation.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/WeatherObservation.java index 5a2d34bdae615..0c01669ba0af6 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/WeatherObservation.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/api/json/WeatherObservation.java @@ -20,7 +20,7 @@ * WeatherObservation Data * Generated with jsonschema2pojo * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution */ public class WeatherObservation { diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java index fbec9cc5c55ab..be56d5d36b06e 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java @@ -54,7 +54,7 @@ * The {@link MelCloudDeviceHandler} is responsible for handling commands, which are * sent to one of the channels. * - * @author LucaCalcaterra - Initial contribution + * @author Luca Calcaterra - Initial contribution * @author Pauli Anttila - Refactoring */ diff --git a/bundles/org.openhab.binding.melcloud/src/main/resources/ESH-INF/binding/binding.xml b/bundles/org.openhab.binding.melcloud/src/main/resources/ESH-INF/binding/binding.xml index 67835fc4a1f4e..1e358ca8cf9a8 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/resources/ESH-INF/binding/binding.xml +++ b/bundles/org.openhab.binding.melcloud/src/main/resources/ESH-INF/binding/binding.xml @@ -5,6 +5,6 @@ MELCloud Binding Binding for Mitsubishi MELCloud connected A.C. devices. - LucaCalcaterra, Pauli Anttila + Luca Calcaterra, Pauli Anttila From e26c0b78ccf46e7ba686387d9ced3c52a4dc52d5 Mon Sep 17 00:00:00 2001 From: Wietse van Buitenen Date: Mon, 7 Oct 2019 20:01:33 +0200 Subject: [PATCH 04/11] remove conditional expression Signed-off-by: Wietse van Buitenen --- .../melcloud/internal/handler/MelCloudDeviceHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java index be56d5d36b06e..e70d35f9e8e70 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java @@ -157,7 +157,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { switch (channelUID.getId()) { case CHANNEL_POWER: - cmdtoSend.setPower((OnOffType) command == OnOffType.ON ? true : false); + cmdtoSend.setPower(command == OnOffType.ON); cmdtoSend.setEffectiveFlags(EFFECTIVE_FLAG_POWER); break; case CHANNEL_OPERATION_MODE: From 638251b2fa5c124b59119a2517ad6cb41a225c10 Mon Sep 17 00:00:00 2001 From: Wietse van Buitenen Date: Mon, 7 Oct 2019 20:02:39 +0200 Subject: [PATCH 05/11] remove runnable variable Signed-off-by: Wietse van Buitenen --- .../melcloud/internal/handler/MelCloudDeviceHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java index e70d35f9e8e70..1556a1ca55ead 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java @@ -232,8 +232,8 @@ private DeviceStatus getDeviceStatusCopy(DeviceStatus deviceStatus) { private void startAutomaticRefresh() { if (refreshTask == null || refreshTask.isCancelled()) { - Runnable runnable = () -> getDeviceDataAndUpdateChannels(); - refreshTask = scheduler.scheduleWithFixedDelay(runnable, 1, config.pollingInterval, TimeUnit.SECONDS); + refreshTask = scheduler.scheduleWithFixedDelay(this::getDeviceDataAndUpdateChannels, 1, + config.pollingInterval, TimeUnit.SECONDS); } } From c69680c757e5475a4547d15cb504c6796e374d91 Mon Sep 17 00:00:00 2001 From: Wietse van Buitenen Date: Mon, 7 Oct 2019 20:03:44 +0200 Subject: [PATCH 06/11] use synchronized only on method Signed-off-by: Wietse van Buitenen --- .../melcloud/internal/handler/MelCloudDeviceHandler.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java index 1556a1ca55ead..2c3ec15053426 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java @@ -254,11 +254,9 @@ private void getDeviceDataAndUpdateChannels() { } private synchronized void updateChannels(DeviceStatus newDeviceStatus) { - synchronized (this) { - deviceStatus = newDeviceStatus; - for (Channel channel : getThing().getChannels()) { - updateChannels(channel.getUID().getId(), deviceStatus); - } + deviceStatus = newDeviceStatus; + for (Channel channel : getThing().getChannels()) { + updateChannels(channel.getUID().getId(), deviceStatus); } } From 8be35bfee197b08cb9d3ce592e83e6533a68c5de Mon Sep 17 00:00:00 2001 From: Wietse van Buitenen Date: Tue, 8 Oct 2019 08:46:10 +0200 Subject: [PATCH 07/11] remove empty Third-party Signed-off-by: Wietse van Buitenen --- bundles/org.openhab.binding.melcloud/NOTICE | 2 -- 1 file changed, 2 deletions(-) diff --git a/bundles/org.openhab.binding.melcloud/NOTICE b/bundles/org.openhab.binding.melcloud/NOTICE index 987f6af80bda0..4c20ef446c1e4 100644 --- a/bundles/org.openhab.binding.melcloud/NOTICE +++ b/bundles/org.openhab.binding.melcloud/NOTICE @@ -11,5 +11,3 @@ https://www.eclipse.org/legal/epl-2.0/. == Source Code https://github.com/openhab/openhab2-addons - -== Third-party Content From 41531e1ec167bcb8c2725510e03bd947e7117e0e Mon Sep 17 00:00:00 2001 From: Wietse van Buitenen Date: Tue, 8 Oct 2019 22:14:59 +0200 Subject: [PATCH 08/11] change item-type to String Signed-off-by: Wietse van Buitenen --- .../org.openhab.binding.melcloud/README.md | 34 +++++++++---------- .../handler/MelCloudDeviceHandler.java | 17 +++++----- .../main/resources/ESH-INF/thing/acDevice.xml | 8 ++--- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/bundles/org.openhab.binding.melcloud/README.md b/bundles/org.openhab.binding.melcloud/README.md index f7dadeb243ade..56ff7da4facb6 100644 --- a/bundles/org.openhab.binding.melcloud/README.md +++ b/bundles/org.openhab.binding.melcloud/README.md @@ -82,19 +82,19 @@ A.C. device configuration: A.C. device channels -| Channel | Type | Description | Read Only | -|---------------------|--------------------|----------------------------------------------------------------------------|-----------| -| power | Switch | Power Status of Device. | False | -| operationMode | Number | Operation mode: 1 = Heat, 2 = Dry, 3 = Cool, 7 = Fan, 8 = Auto. | False | -| setTemperature | Number:Temperature | Set Temperature: Min = 10, Max = 40. | False | -| fanSpeed | Number | Fan speed: 0 = Auto, 1 = 1, 2 = 2, 3 = 3, 4 = 4, 5 = 5. | False | -| vaneHorizontal | Number | Vane Horizontal: 0 = Auto, 1 = 1, 2 = 2, 3 = 3, 4 = 4, 5 = 5, 12 = Swing. | False | -| vaneVertical | Number | Vane Vertical: 0 = Auto, 1 = 1, 2 = 2, 3 = 3, 4 = 4, 5 = 5, 7 = Swing. | False | -| roomTemperature | Number:Temperature | Room temperature. | True | -| lastCommunication | DateTime | Last Communication time when MELCloud communicated to the device. | True | -| nextCommunication | DateTime | Next communication time when MELCloud will communicate to the device. | True | -| offline | Switch | Is device in offline state. | True | -| hasPendingCommand | Switch | Device has a pending command(s). | True | +| Channel | Type | Description | Read Only | +|---------------------|--------------------|------------------------------------------------------------------------------------------|-----------| +| power | Switch | Power Status of Device. | False | +| operationMode | String | Operation mode: "1" = Heat, "2" = Dry, "3" = Cool, "7" = Fan, "8" = Auto. | False | +| setTemperature | Number:Temperature | Set Temperature: Min = 10, Max = 40. | False | +| fanSpeed | String | Fan speed: "0" = Auto, "1" = 1, "2" = 2, "3" = 3, "4" = 4, "5" = 5. | False | +| vaneHorizontal | String | Vane Horizontal: "0" = Auto, "1" = 1, "2" = 2, "3" = 3, "4" = 4, "5" = 5, "12" = Swing. | False | +| vaneVertical | String | Vane Vertical: "0" = Auto, "1" = 1, "2" = 2, "3" = 3, "4" = 4, "5" = 5, "7" = Swing. | False | +| roomTemperature | Number:Temperature | Room temperature. | True | +| lastCommunication | DateTime | Last Communication time when MELCloud communicated to the device. | True | +| nextCommunication | DateTime | Next communication time when MELCloud will communicate to the device. | True | +| offline | Switch | Is device in offline state. | True | +| hasPendingCommand | Switch | Device has a pending command(s). | True | ## Full Example for items configuration @@ -111,11 +111,11 @@ Bridge melcloud:melcloudaccount:myaccount "My MELCloud account" [ username="user ``` Switch power { channel="melcloud:acdevice:myaccount:livingroom:power" } -Number operationMode { channel="melcloud:acdevice:myaccount:livingroom:operationMode" } +String operationMode { channel="melcloud:acdevice:myaccount:livingroom:operationMode" } Number setTemperature { channel="melcloud:acdevice:myaccount:livingroom:setTemperature" } -Number fanSpeed { channel="melcloud:acdevice:myaccount:livingroom:fanSpeed" } -Number vaneHorizontal { channel="melcloud:acdevice:myaccount:livingroom:vaneHorizontal" } -Number vaneVertical { channel="melcloud:acdevice:myaccount:livingroom:vaneVertical" } +String fanSpeed { channel="melcloud:acdevice:myaccount:livingroom:fanSpeed" } +String vaneHorizontal { channel="melcloud:acdevice:myaccount:livingroom:vaneHorizontal" } +String vaneVertical { channel="melcloud:acdevice:myaccount:livingroom:vaneVertical" } Number roomTemperature { channel="melcloud:acdevice:myaccount:livingroom:roomTemperature" } DateTime lastCommunication { channel="melcloud:acdevice:myaccount:livingroom:lastCommunication" } DateTime nextCommunication { channel="melcloud:acdevice:myaccount:livingroom:nextCommunication" } diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java index 2c3ec15053426..7221cc9f1c3d5 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudDeviceHandler.java @@ -32,6 +32,7 @@ import org.eclipse.smarthome.core.library.types.DecimalType; import org.eclipse.smarthome.core.library.types.OnOffType; import org.eclipse.smarthome.core.library.types.QuantityType; +import org.eclipse.smarthome.core.library.types.StringType; import org.eclipse.smarthome.core.library.unit.SIUnits; import org.eclipse.smarthome.core.thing.Bridge; import org.eclipse.smarthome.core.thing.Channel; @@ -161,7 +162,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { cmdtoSend.setEffectiveFlags(EFFECTIVE_FLAG_POWER); break; case CHANNEL_OPERATION_MODE: - cmdtoSend.setOperationMode(((DecimalType) command).intValue()); + cmdtoSend.setOperationMode(Integer.parseInt(command.toString())); cmdtoSend.setEffectiveFlags(EFFECTIVE_FLAG_OPERATION_MODE); break; case CHANNEL_SET_TEMPERATURE: @@ -185,15 +186,15 @@ public void handleCommand(ChannelUID channelUID, Command command) { } break; case CHANNEL_FAN_SPEED: - cmdtoSend.setSetFanSpeed(((DecimalType) command).intValue()); + cmdtoSend.setSetFanSpeed(Integer.parseInt(command.toString())); cmdtoSend.setEffectiveFlags(EFFECTIVE_FLAG_FAN_SPEED); break; case CHANNEL_VANE_VERTICAL: - cmdtoSend.setVaneVertical(((DecimalType) command).intValue()); + cmdtoSend.setVaneVertical(Integer.parseInt(command.toString())); cmdtoSend.setEffectiveFlags(EFFECTIVE_FLAG_VANE_VERTICAL); break; case CHANNEL_VANE_HORIZONTAL: - cmdtoSend.setVaneHorizontal(((DecimalType) command).intValue()); + cmdtoSend.setVaneHorizontal(Integer.parseInt(command.toString())); cmdtoSend.setEffectiveFlags(EFFECTIVE_FLAG_VANE_HORIZONTAL); break; default: @@ -266,20 +267,20 @@ private void updateChannels(String channelId, DeviceStatus deviceStatus) { updateState(CHANNEL_POWER, deviceStatus.getPower() ? OnOffType.ON : OnOffType.OFF); break; case CHANNEL_OPERATION_MODE: - updateState(CHANNEL_OPERATION_MODE, new DecimalType(deviceStatus.getOperationMode())); + updateState(CHANNEL_OPERATION_MODE, new StringType(deviceStatus.getOperationMode().toString())); break; case CHANNEL_SET_TEMPERATURE: updateState(CHANNEL_SET_TEMPERATURE, new QuantityType(deviceStatus.getSetTemperature(), SIUnits.CELSIUS)); break; case CHANNEL_FAN_SPEED: - updateState(CHANNEL_FAN_SPEED, new DecimalType(deviceStatus.getSetFanSpeed())); + updateState(CHANNEL_FAN_SPEED, new StringType(deviceStatus.getSetFanSpeed().toString())); break; case CHANNEL_VANE_HORIZONTAL: - updateState(CHANNEL_VANE_HORIZONTAL, new DecimalType(deviceStatus.getVaneHorizontal())); + updateState(CHANNEL_VANE_HORIZONTAL, new StringType(deviceStatus.getVaneHorizontal().toString())); break; case CHANNEL_VANE_VERTICAL: - updateState(CHANNEL_VANE_VERTICAL, new DecimalType(deviceStatus.getVaneVertical())); + updateState(CHANNEL_VANE_VERTICAL, new StringType(deviceStatus.getVaneVertical().toString())); break; case CHANNEL_OFFLINE: updateState(CHANNEL_OFFLINE, deviceStatus.getOffline() ? OnOffType.ON : OnOffType.OFF); diff --git a/bundles/org.openhab.binding.melcloud/src/main/resources/ESH-INF/thing/acDevice.xml b/bundles/org.openhab.binding.melcloud/src/main/resources/ESH-INF/thing/acDevice.xml index 287228077470a..e70e93676d848 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/resources/ESH-INF/thing/acDevice.xml +++ b/bundles/org.openhab.binding.melcloud/src/main/resources/ESH-INF/thing/acDevice.xml @@ -51,7 +51,7 @@ Power status of device - Number + String Operation mode @@ -71,7 +71,7 @@ - Number + String Fan speed @@ -86,7 +86,7 @@ - Number + String Vane horizontal @@ -102,7 +102,7 @@ - Number + String Vane vertical From 6c632e7d749ec3834d519f5c214f02039c9821d6 Mon Sep 17 00:00:00 2001 From: Wietse van Buitenen Date: Thu, 10 Oct 2019 08:11:37 +0200 Subject: [PATCH 09/11] use ThingHandlerService Signed-off-by: Wietse van Buitenen --- .../internal/MelCloudHandlerFactory.java | 28 ------------------ .../discovery/MelCloudDiscoveryService.java | 29 ++++++++++++++++--- .../handler/MelCloudAccountHandler.java | 8 +++++ 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/MelCloudHandlerFactory.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/MelCloudHandlerFactory.java index 2ad39eb9a99fc..2c4bdf4082819 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/MelCloudHandlerFactory.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/MelCloudHandlerFactory.java @@ -14,23 +14,15 @@ import static org.openhab.binding.melcloud.internal.MelCloudBindingConstants.*; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.smarthome.config.discovery.DiscoveryService; import org.eclipse.smarthome.core.thing.Bridge; import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.thing.ThingTypeUID; -import org.eclipse.smarthome.core.thing.ThingUID; import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory; import org.eclipse.smarthome.core.thing.binding.ThingHandler; import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory; -import org.openhab.binding.melcloud.internal.discovery.MelCloudDiscoveryService; import org.openhab.binding.melcloud.internal.handler.MelCloudAccountHandler; import org.openhab.binding.melcloud.internal.handler.MelCloudDeviceHandler; -import org.osgi.framework.ServiceRegistration; import org.osgi.service.component.annotations.Component; /** @@ -41,7 +33,6 @@ */ @Component(configurationPid = "binding.melcloud", service = ThingHandlerFactory.class) public class MelCloudHandlerFactory extends BaseThingHandlerFactory { - private Map> discoveryServiceRegistrations = new HashMap<>(); @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { @@ -54,7 +45,6 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) { if (THING_TYPE_MELCLOUD_ACCOUNT.equals(thingTypeUID)) { MelCloudAccountHandler handler = new MelCloudAccountHandler((Bridge) thing); - registerDiscoveryService(handler); return handler; } else if (THING_TYPE_ACDEVICE.equals(thingTypeUID)) { MelCloudDeviceHandler handler = new MelCloudDeviceHandler(thing); @@ -64,22 +54,4 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) { return null; } - @Override - protected void removeHandler(@NonNull ThingHandler thingHandler) { - ServiceRegistration serviceRegistration = discoveryServiceRegistrations - .get(thingHandler.getThing().getUID()); - - if (serviceRegistration != null) { - serviceRegistration.unregister(); - } - } - - private void registerDiscoveryService(MelCloudAccountHandler handler) { - MelCloudDiscoveryService discoveryService = new MelCloudDiscoveryService(handler); - - ServiceRegistration serviceRegistration = this.bundleContext - .registerService(DiscoveryService.class, discoveryService, null); - - discoveryServiceRegistrations.put(handler.getThing().getUID(), serviceRegistration); - } } diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/discovery/MelCloudDiscoveryService.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/discovery/MelCloudDiscoveryService.java index 6915317c4a752..3812484b42e33 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/discovery/MelCloudDiscoveryService.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/discovery/MelCloudDiscoveryService.java @@ -20,10 +20,14 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.smarthome.config.discovery.AbstractDiscoveryService; import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder; +import org.eclipse.smarthome.config.discovery.DiscoveryService; import org.eclipse.smarthome.core.thing.ThingUID; +import org.eclipse.smarthome.core.thing.binding.ThingHandler; +import org.eclipse.smarthome.core.thing.binding.ThingHandlerService; import org.openhab.binding.melcloud.internal.MelCloudBindingConstants; import org.openhab.binding.melcloud.internal.api.json.Device; import org.openhab.binding.melcloud.internal.exceptions.MelCloudCommException; @@ -38,20 +42,20 @@ * @author Luca Calcaterra - Initial Contribution * @author Pauli Anttila - Refactoring */ -public class MelCloudDiscoveryService extends AbstractDiscoveryService { +public class MelCloudDiscoveryService extends AbstractDiscoveryService + implements DiscoveryService, ThingHandlerService { private final Logger logger = LoggerFactory.getLogger(MelCloudDiscoveryService.class); private static final int DISCOVER_TIMEOUT_SECONDS = 10; - private final MelCloudAccountHandler melCloudHandler; + private @NonNullByDefault({}) MelCloudAccountHandler melCloudHandler; private ScheduledFuture scanTask; /** * Creates a MelCloudDiscoveryService with enabled autostart. */ - public MelCloudDiscoveryService(MelCloudAccountHandler melCloudHandler) { + public MelCloudDiscoveryService() { super(MelCloudBindingConstants.DISCOVERABLE_THING_TYPE_UIDS, DISCOVER_TIMEOUT_SECONDS, true); - this.melCloudHandler = melCloudHandler; } @Override @@ -59,6 +63,11 @@ protected void activate(Map configProperties) { super.activate(configProperties); } + @Override + public void deactivate() { + super.deactivate(); + } + @Override @Modified protected void modified(Map configProperties) { @@ -135,4 +144,16 @@ private String createLabel(Device device) { sb.append(device.getDeviceName()); return sb.toString(); } + + @Override + public void setThingHandler(@Nullable ThingHandler handler) { + if (handler instanceof MelCloudAccountHandler) { + melCloudHandler = (MelCloudAccountHandler) handler; + } + } + + @Override + public @Nullable ThingHandler getThingHandler() { + return melCloudHandler; + } } diff --git a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudAccountHandler.java b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudAccountHandler.java index 8f66c425badf2..f1daba502abdf 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudAccountHandler.java +++ b/bundles/org.openhab.binding.melcloud/src/main/java/org/openhab/binding/melcloud/internal/handler/MelCloudAccountHandler.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.melcloud.internal.handler; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -24,11 +25,13 @@ import org.eclipse.smarthome.core.thing.ThingStatusDetail; import org.eclipse.smarthome.core.thing.ThingUID; import org.eclipse.smarthome.core.thing.binding.BaseBridgeHandler; +import org.eclipse.smarthome.core.thing.binding.ThingHandlerService; import org.eclipse.smarthome.core.types.Command; import org.openhab.binding.melcloud.internal.api.MelCloudConnection; import org.openhab.binding.melcloud.internal.api.json.Device; import org.openhab.binding.melcloud.internal.api.json.DeviceStatus; import org.openhab.binding.melcloud.internal.config.AccountConfig; +import org.openhab.binding.melcloud.internal.discovery.MelCloudDiscoveryService; import org.openhab.binding.melcloud.internal.exceptions.MelCloudCommException; import org.openhab.binding.melcloud.internal.exceptions.MelCloudLoginException; import org.slf4j.Logger; @@ -55,6 +58,11 @@ public MelCloudAccountHandler(Bridge bridge) { super(bridge); } + @Override + public Collection> getServices() { + return Collections.singleton(MelCloudDiscoveryService.class); + } + @Override public void initialize() { logger.debug("Initializing MELCloud account handler."); From f753d8ecfb132ba6b63d3476ff025628693949dc Mon Sep 17 00:00:00 2001 From: Wietse van Buitenen Date: Thu, 10 Oct 2019 08:21:01 +0200 Subject: [PATCH 10/11] update author Signed-off-by: Wietse van Buitenen --- .../src/main/resources/ESH-INF/binding/binding.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.melcloud/src/main/resources/ESH-INF/binding/binding.xml b/bundles/org.openhab.binding.melcloud/src/main/resources/ESH-INF/binding/binding.xml index 1e358ca8cf9a8..3a7bbcb4d73f1 100644 --- a/bundles/org.openhab.binding.melcloud/src/main/resources/ESH-INF/binding/binding.xml +++ b/bundles/org.openhab.binding.melcloud/src/main/resources/ESH-INF/binding/binding.xml @@ -5,6 +5,6 @@ MELCloud Binding Binding for Mitsubishi MELCloud connected A.C. devices. - Luca Calcaterra, Pauli Anttila + Luca Calcaterra, Pauli Anttila, Wietse van Buitenen From ec79bc8b2de0e3dad293bed01abf1c4795e2be89 Mon Sep 17 00:00:00 2001 From: Wietse van Buitenen Date: Thu, 10 Oct 2019 08:22:38 +0200 Subject: [PATCH 11/11] update CODEOWNERS Signed-off-by: Wietse van Buitenen --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index e3a990a410fa9..5fbf25743c1a8 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -88,7 +88,7 @@ /bundles/org.openhab.binding.mail/ @J-N-K /bundles/org.openhab.binding.max/ @marcelrv /bundles/org.openhab.binding.mcp23017/ @aogorek -/bundles/org.openhab.binding.melcloud/ @lucacalcaterra @paulianttila +/bundles/org.openhab.binding.melcloud/ @lucacalcaterra @paulianttila @thewiep /bundles/org.openhab.binding.meteoblue/ @9037568 /bundles/org.openhab.binding.meteostick/ @cdjackson /bundles/org.openhab.binding.miele/ @kgoderis