From 8a18317f9b5e08b780468921a61707f3d62636e4 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 19 Nov 2020 17:13:50 +0100 Subject: [PATCH 01/40] Add support for ESP32 devices Signed-off-by: Christian Schlipp --- .../internal/WlanThermoBindingConstants.java | 22 +- ...tion.java => WlanThermoConfiguration.java} | 4 +- .../WlanThermoExtendedConfiguration.java | 54 ++ .../internal/WlanThermoHandlerFactory.java | 14 +- .../internal/WlanThermoNanoConfiguration.java | 101 ---- .../internal/api/esp32/UtilEsp32.java | 82 ++++ .../esp32/WlanThermoEsp32CommandHandler.java | 272 ++++++++++ .../api/esp32/WlanThermoEsp32Handler.java | 222 +++++++++ .../internal/api/esp32/data/Channel.java | 125 +++++ .../internal/api/esp32/data/Data.java | 50 ++ .../internal/api/esp32/data/Pitmaster.java | 39 ++ .../internal/api/esp32/data/Pm.java | 103 ++++ .../internal/api/esp32/data/System.java | 81 +++ .../internal/api/esp32/settings/Api.java | 26 + .../internal/api/esp32/settings/Device.java | 103 ++++ .../internal/api/esp32/settings/Display.java | 37 ++ .../internal/api/esp32/settings/Ext.java | 83 ++++ .../internal/api/esp32/settings/Features.java | 37 ++ .../internal/api/esp32/settings/Iot.java | 136 +++++ .../internal/api/esp32/settings/Notes.java | 39 ++ .../internal/api/esp32/settings/Pid.java | 169 +++++++ .../internal/api/esp32/settings/Sensor.java | 48 ++ .../internal/api/esp32/settings/Settings.java | 138 ++++++ .../internal/api/esp32/settings/System.java | 125 +++++ .../{ => api/mini}/WlanThermoMiniHandler.java | 11 +- .../internal/api/nano/UtilNano.java | 2 +- ...va => WlanThermoNanoV1CommandHandler.java} | 4 +- .../nano/WlanThermoNanoV1Handler.java} | 32 +- .../thing/channel-group-types-esp32.xml | 51 ++ .../OH-INF/thing/channel-group-types-mini.xml | 47 ++ .../OH-INF/thing/channel-group-types-nano.xml | 52 ++ .../resources/OH-INF/thing/channel-types.xml | 261 ++++++++++ .../OH-INF/thing/thing-types-esp32.xml | 151 ++++++ .../OH-INF/thing/thing-types-mini.xml | 79 +++ .../OH-INF/thing/thing-types-nano.xml | 74 +++ .../resources/OH-INF/thing/thing-types.xml | 463 ------------------ 36 files changed, 2732 insertions(+), 605 deletions(-) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/{WlanThermoMiniConfiguration.java => WlanThermoConfiguration.java} (91%) create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoExtendedConfiguration.java delete mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoNanoConfiguration.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Channel.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Data.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pitmaster.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pm.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/System.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Api.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Device.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Display.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Ext.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Features.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Iot.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Notes.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Pid.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Sensor.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Settings.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/System.java rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/{ => api/mini}/WlanThermoMiniHandler.java (93%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{WlanThermoNanoCommandHandler.java => WlanThermoNanoV1CommandHandler.java} (98%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/{WlanThermoNanoHandler.java => api/nano/WlanThermoNanoV1Handler.java} (86%) create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-esp32.xml create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-mini.xml create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-nano.xml create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-esp32.xml create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-mini.xml create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-nano.xml delete mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types.xml diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java index 92c6a00fdd59f..6b06338ae4248 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java @@ -27,12 +27,21 @@ public class WlanThermoBindingConstants { private static final String BINDING_ID = "wlanthermo"; // List of all Thing Type UIDs - public static final ThingTypeUID THING_TYPE_WLANTHERMO_NANO = new ThingTypeUID(BINDING_ID, "nano"); + public static final ThingTypeUID THING_TYPE_WLANTHERMO_NANO_V1 = new ThingTypeUID(BINDING_ID, "nano"); public static final ThingTypeUID THING_TYPE_WLANTHERMO_MINI = new ThingTypeUID(BINDING_ID, "mini"); + public static final ThingTypeUID THING_TYPE_WLANTHERMO_ESP32 = new ThingTypeUID(BINDING_ID, "esp32"); // ThreadPool public static final String WLANTHERMO_THREAD_POOL = "wlanthermo"; + // Properties + public static final String PROPERTY_MODEL = "model"; + public static final String PROPERTY_SERIAL = "serial"; + public static final String PROPERTY_ESP32_BT_ENABLED = "esp32_bt_enabled"; + public static final String PROPERTY_ESP32_PM_ENABLED = "esp32_pm_enabled"; + public static final String PROPERTY_ESP32_TEMP_CHANNELS = "esp32_temp_channels"; + public static final String PROPERTY_ESP32_PM_CHANNELS = "esp32_pm_channels"; + // List of all Channel ids // System Channels public static final String SYSTEM = "system"; @@ -43,16 +52,7 @@ public class WlanThermoBindingConstants { public static final String SYSTEM_CPU_LOAD = "cpu_load"; public static final String SYSTEM_CPU_TEMP = "cpu_temp"; - public static final String CHANNEL0 = "channel0"; - public static final String CHANNEL1 = "channel1"; - public static final String CHANNEL2 = "channel2"; - public static final String CHANNEL3 = "channel3"; - public static final String CHANNEL4 = "channel4"; - public static final String CHANNEL5 = "channel5"; - public static final String CHANNEL6 = "channel6"; - public static final String CHANNEL7 = "channel7"; - public static final String CHANNEL8 = "channel8"; - public static final String CHANNEL9 = "channel9"; + public static final String CHANNEL_PREFIX = "channel"; public static final String CHANNEL_NAME = "name"; public static final String CHANNEL_TYP = "typ"; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoMiniConfiguration.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoConfiguration.java similarity index 91% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoMiniConfiguration.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoConfiguration.java index f62571d43ed9e..41508eb543ad3 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoMiniConfiguration.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoConfiguration.java @@ -18,12 +18,12 @@ import org.eclipse.jdt.annotation.NonNullByDefault; /** - * The {@link WlanThermoMiniConfiguration} class contains fields mapping thing configuration parameters. + * The {@link WlanThermoConfiguration} class contains fields mapping thing configuration parameters. * * @author Christian Schlipp - Initial contribution */ @NonNullByDefault -public class WlanThermoMiniConfiguration { +public class WlanThermoConfiguration { /** * IP Address of WlanThermo. diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoExtendedConfiguration.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoExtendedConfiguration.java new file mode 100644 index 0000000000000..b8bf679961e55 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoExtendedConfiguration.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wlanthermo.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +/** + * The {@link WlanThermoExtendedConfiguration} class contains fields mapping thing configuration parameters. + * + * @author Christian Schlipp - Initial contribution + */ +@NonNullByDefault +public class WlanThermoExtendedConfiguration extends WlanThermoConfiguration { + + /** + * Username of WlanThermo user. + */ + private @Nullable String username; + + /** + * Password of WlanThermo user. + */ + + private @Nullable String password; + + @Nullable + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + @Nullable + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoHandlerFactory.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoHandlerFactory.java index c84195ddb162b..da0d991a39a8e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoHandlerFactory.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoHandlerFactory.java @@ -19,6 +19,9 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; +import org.openhab.binding.wlanthermo.internal.api.esp32.WlanThermoEsp32Handler; +import org.openhab.binding.wlanthermo.internal.api.mini.WlanThermoMiniHandler; +import org.openhab.binding.wlanthermo.internal.api.nano.WlanThermoNanoV1Handler; import org.openhab.core.io.net.http.HttpClientFactory; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingTypeUID; @@ -40,8 +43,9 @@ public class WlanThermoHandlerFactory extends BaseThingHandlerFactory { private static final Set SUPPORTED_THING_TYPES_UIDS = new HashSet( - Arrays.asList(WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_NANO, - WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_MINI)); + Arrays.asList(WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_NANO_V1, + WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_MINI, + WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_ESP32)); private final HttpClient httpClient; @Activate @@ -58,10 +62,12 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) { protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); - if (WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_NANO.equals(thingTypeUID)) { - return new WlanThermoNanoHandler(thing, httpClient); + if (WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_NANO_V1.equals(thingTypeUID)) { + return new WlanThermoNanoV1Handler(thing, httpClient); } else if (WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_MINI.equals(thingTypeUID)) { return new WlanThermoMiniHandler(thing, httpClient); + } else if (WlanThermoBindingConstants.THING_TYPE_WLANTHERMO_ESP32.equals(thingTypeUID)) { + return new WlanThermoEsp32Handler(thing, httpClient); } return null; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoNanoConfiguration.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoNanoConfiguration.java deleted file mode 100644 index 378b5b6d47230..0000000000000 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoNanoConfiguration.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright (c) 2010-2021 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.wlanthermo.internal; - -import java.net.URI; -import java.net.URISyntaxException; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; - -/** - * The {@link WlanThermoNanoConfiguration} class contains fields mapping thing configuration parameters. - * - * @author Christian Schlipp - Initial contribution - */ -@NonNullByDefault -public class WlanThermoNanoConfiguration { - - /** - * IP Address of WlanThermo. - */ - private String ipAddress = ""; - - /** - * Username of WlanThermo user. - */ - private @Nullable String username; - - /** - * Password of WlanThermo user. - */ - - private @Nullable String password; - - /** - * Polling interval - */ - private int pollingInterval = 10; - - public String getIpAddress() { - return ipAddress; - } - - public URI getUri(String path) throws URISyntaxException { - String uri = ipAddress; - if (!uri.startsWith("http://")) { - uri = "http://" + uri; - } - - if (!path.startsWith("/") && !uri.endsWith("/")) { - uri = uri + "/"; - } - uri = uri + path; - - return new URI(uri); - } - - public URI getUri() throws URISyntaxException { - return getUri(""); - } - - public void setIpAddress(String ipAddress) { - this.ipAddress = ipAddress; - } - - @Nullable - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - @Nullable - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public int getPollingInterval() { - return pollingInterval; - } - - public void setPollingInterval(int pollingInterval) { - this.pollingInterval = pollingInterval; - } -} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java new file mode 100644 index 0000000000000..0f1f7ae6132fe --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wlanthermo.internal.api.esp32; + +import java.util.HashMap; +import java.util.Map; + +/** + * The {@link UtilEsp32} class provides conversion functions for the WlanThermo Nano V3 + * + * @author Christian Schlipp - Initial contribution + */ +public class UtilEsp32 { + + private static final Map COLOR_MAPPINGS = createColorMap(); + private static final String DEFAULT_HEX = "#ffffff"; + private static final String DEFAULT_COLORNAME = "niagara"; + + private UtilEsp32() { + // hidden + } + + private static Map createColorMap() { + HashMap map = new HashMap<>(); + map.put("yellow", "#FFFF00"); + map.put("dark yellow", "#FFC002"); + map.put("green", "#00FF00"); + map.put("white", "#FFFFFF"); + map.put("pink", "#FF1DC4"); + map.put("orange", "#E46C0A"); + map.put("olive", "#C3D69B"); + map.put("light blue", "#0FE6F1"); + map.put("blue", "#0000FF"); + map.put("dark green", "#03A923"); + map.put("brown", "#C84B32"); + map.put("light brown", "#FF9B69"); + map.put("dark blue", "#5082BE"); + map.put("light pink", "#FFB1D0"); + map.put("light green", "#A6EF03"); + map.put("dark pink", "#D42A6B"); + map.put("beige", "#FFDA8F"); + map.put("azure", "#00B0F0"); + map.put("dark olive", "#948A54"); + return map; + } + + /** + * Convert WlanThermo Color Name to Hex + * + * @param colorName the WlanThermo color name + * @return The color as Hex String + */ + public static String toHex(String colorName) { + return COLOR_MAPPINGS.getOrDefault(colorName, DEFAULT_HEX); + } + + public static String toColorName(String colorHex) { + String colorName = null; + if (!colorHex.startsWith("#")) { + colorHex = "#" + colorHex; + } + for (Map.Entry entry : COLOR_MAPPINGS.entrySet()) { + if (entry.getValue().equalsIgnoreCase(colorHex)) { + colorName = entry.getKey(); + } + } + if (colorName == null) { + colorName = DEFAULT_COLORNAME; + } + return colorName; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java new file mode 100644 index 0000000000000..4946957886171 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -0,0 +1,272 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wlanthermo.internal.api.esp32; + +import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.*; + +import java.awt.*; +import java.math.BigInteger; +import java.util.List; + +import org.openhab.binding.wlanthermo.internal.api.esp32.data.Channel; +import org.openhab.binding.wlanthermo.internal.api.esp32.data.Data; +import org.openhab.binding.wlanthermo.internal.api.esp32.data.Pm; +import org.openhab.binding.wlanthermo.internal.api.esp32.data.System; +import org.openhab.binding.wlanthermo.internal.api.esp32.settings.Settings; +import org.openhab.core.library.types.*; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; +import org.openhab.core.types.UnDefType; + +/** + * The {@link WlanThermoEsp32CommandHandler} is responsible for mapping the Commands to the respective data fields + * of the API. + * + * @author Christian Schlipp - Initial contribution + */ +public class WlanThermoEsp32CommandHandler { + + public State getState(ChannelUID channelUID, Data data, Settings settings) { + State state = null; + if (data == null || settings == null) { + return null; + } + System system = data.getSystem(); + List channel = data.getChannel(); + if ("system".equals(channelUID.getGroupId()) && system != null) { + switch (channelUID.getIdWithoutGroup()) { + case SYSTEM_SOC: + if (system.getSoc() != null) { + state = new DecimalType(system.getSoc()); + } else { + state = UnDefType.UNDEF; + } + break; + case SYSTEM_CHARGE: + if (system.getCharge() != null) { + state = OnOffType.from(system.getCharge()); + } else { + state = UnDefType.UNDEF; + } + break; + case SYSTEM_RSSI_SIGNALSTRENGTH: + int dbm = system.getRssi(); + if (dbm >= -80) { + state = new DecimalType(4); + } else if (dbm >= -95) { + state = new DecimalType(3); + } else if (dbm >= -105) { + state = new DecimalType(2); + } else { + state = new DecimalType(1); + } + break; + case SYSTEM_RSSI: + state = new DecimalType(system.getRssi()); + break; + } + } else if (channelUID.getId().startsWith("channel")) { + int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1; + if (channel != null && channel.size() > 0 && channelId < channel.size()) { + switch (channelUID.getIdWithoutGroup()) { + case CHANNEL_NAME: + state = new StringType(channel.get(channelId).getName()); + break; + case CHANNEL_TYP: + state = new StringType(settings.getSensors().get(channel.get(channelId).getTyp()).getName()); + break; + case CHANNEL_TEMP: + if (channel.get(channelId).getTemp() == 999.0) { + state = UnDefType.UNDEF; + } else { + state = new DecimalType(channel.get(channelId).getTemp()); + } + break; + case CHANNEL_MIN: + state = new DecimalType(channel.get(channelId).getMin()); + break; + case CHANNEL_MAX: + state = new DecimalType(channel.get(channelId).getMax()); + break; + case CHANNEL_ALARM_DEVICE: + state = OnOffType.from(BigInteger.valueOf(channel.get(channelId).getAlarm()).testBit(1)); + break; + case CHANNEL_ALARM_PUSH: + state = OnOffType.from(BigInteger.valueOf(channel.get(channelId).getAlarm()).testBit(0)); + break; + case CHANNEL_ALARM_OPENHAB_HIGH: + if (channel.get(channelId).getTemp() != 999 + && channel.get(channelId).getTemp() > channel.get(channelId).getMax()) { + state = OnOffType.ON; + } else { + state = OnOffType.OFF; + } + break; + case CHANNEL_ALARM_OPENHAB_LOW: + if (channel.get(channelId).getTemp() != 999 + && channel.get(channelId).getTemp() < channel.get(channelId).getMin()) { + state = OnOffType.ON; + } else { + state = OnOffType.OFF; + } + break; + case CHANNEL_COLOR: + String color = channel.get(channelId).getColor(); + if (color != null && !color.isEmpty()) { + Color c = Color.decode(color); + state = HSBType.fromRGB(c.getRed(), c.getGreen(), c.getBlue()); + } + break; + case CHANNEL_COLOR_NAME: + String colorHex = channel.get(channelId).getColor(); + if (colorHex != null && !colorHex.isEmpty()) { + state = new StringType(UtilEsp32.toColorName(colorHex)); + } + break; + } + } + } else if (channelUID.getId().startsWith("pit1")) { + if (data.getPitmaster() != null && data.getPitmaster().getPm() != null + && data.getPitmaster().getPm().size() > 0) { + Pm pm = data.getPitmaster().getPm().get(0); + switch (channelUID.getIdWithoutGroup()) { + case CHANNEL_PITMASTER_CHANNEL_ID: + state = new DecimalType(pm.getChannel()); + break; + case CHANNEL_PITMASTER_PIDPROFILE: + state = new DecimalType(pm.getPid()); + break; + case CHANNEL_PITMASTER_DUTY_CYCLE: + state = new DecimalType(pm.getValue()); + break; + case CHANNEL_PITMASTER_SETPOINT: + state = new DecimalType(pm.getSet()); + break; + case CHANNEL_PITMASTER_STATE: + state = new StringType(pm.getTyp()); + } + } else { + return UnDefType.UNDEF; + } + } + return state; + } + + public boolean setState(ChannelUID channelUID, Command command, Data data) { + boolean success = false; + List channel = data.getChannel(); + if (channelUID.getId().startsWith("channel")) { + int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1; + if (channel.size() > 0 && channelId < channel.size()) { + switch (channelUID.getIdWithoutGroup()) { + case CHANNEL_NAME: + if (command instanceof StringType) { + channel.get(channelId).setName(command.toFullString()); + success = true; + } + break; + case CHANNEL_MIN: + if (command instanceof QuantityType) { + channel.get(channelId).setMin(((QuantityType) command).doubleValue()); + success = true; + } + break; + case CHANNEL_MAX: + if (command instanceof QuantityType) { + channel.get(channelId).setMax(((QuantityType) command).doubleValue()); + success = true; + } + break; + case CHANNEL_ALARM_DEVICE: + if (command instanceof OnOffType) { + BigInteger value; + if (command == OnOffType.ON) { + value = BigInteger.valueOf(channel.get(channelId).getAlarm()).setBit(1); + } else { + value = BigInteger.valueOf(channel.get(channelId).getAlarm()).clearBit(1); + } + channel.get(channelId).setAlarm(value.intValue()); + success = true; + } + break; + case CHANNEL_ALARM_PUSH: + if (command instanceof OnOffType) { + BigInteger value; + if (command == OnOffType.ON) { + value = BigInteger.valueOf(channel.get(channelId).getAlarm()).setBit(0); + } else { + value = BigInteger.valueOf(channel.get(channelId).getAlarm()).clearBit(0); + } + channel.get(channelId).setAlarm(value.intValue()); + success = true; + } + break; + case CHANNEL_COLOR_NAME: + if (command instanceof StringType) { + channel.get(channelId).setColor(UtilEsp32.toHex(((StringType) command).toString())); + success = true; + } + break; + } + } + } else if (channelUID.getId().equals("pit1")) { + if (data.getPitmaster() != null && data.getPitmaster().getPm() != null + && data.getPitmaster().getPm().size() > 0) { + Pm pm = data.getPitmaster().getPm().get(0); + switch (channelUID.getIdWithoutGroup()) { + case CHANNEL_PITMASTER_CHANNEL_ID: + pm.setChannel(((QuantityType) command).intValue()); + success = true; + break; + case CHANNEL_PITMASTER_PIDPROFILE: + pm.setPid(((QuantityType) command).intValue()); + success = true; + break; + case CHANNEL_PITMASTER_SETPOINT: + pm.setSet(((QuantityType) command).doubleValue()); + success = true; + break; + case CHANNEL_PITMASTER_STATE: + String state = ((StringType) command).toString(); + if (state.equalsIgnoreCase("off") || state.equalsIgnoreCase("manual") + || state.equalsIgnoreCase("auto")) { + pm.setTyp(state); + success = true; + } + } + } + } + return success; + } + + public String getTrigger(ChannelUID channelUID, Data data) { + String trigger = null; + List channel = data.getChannel(); + if (channelUID.getId().startsWith("channel")) { + int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1; + if (channel.size() > 0 && channelId < channel.size()) { + if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { + if (channel.get(channelId).getTemp() != 999) { + if (channel.get(channelId).getTemp() > channel.get(channelId).getMax()) { + trigger = TRIGGER_ALARM_MAX; + } else if (channel.get(channelId).getTemp() < channel.get(channelId).getMin()) { + trigger = TRIGGER_ALARM_MIN; + } + } + } + } + } + return trigger; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java new file mode 100644 index 0000000000000..1e123e4031a44 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -0,0 +1,222 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wlanthermo.internal.api.esp32; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Map; +import java.util.concurrent.*; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.client.api.Authentication; +import org.eclipse.jetty.client.api.AuthenticationStore; +import org.eclipse.jetty.client.util.DigestAuthentication; +import org.eclipse.jetty.client.util.StringContentProvider; +import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; +import org.openhab.binding.wlanthermo.internal.WlanThermoExtendedConfiguration; +import org.openhab.binding.wlanthermo.internal.api.esp32.data.Data; +import org.openhab.binding.wlanthermo.internal.api.esp32.settings.Settings; +import org.openhab.core.common.ThreadPoolManager; +import org.openhab.core.thing.*; +import org.openhab.core.thing.binding.BaseThingHandler; +import org.openhab.core.types.Command; +import org.openhab.core.types.RefreshType; +import org.openhab.core.types.State; +import org.openhab.core.types.UnDefType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.Gson; + +/** + * The {@link WlanThermoEsp32Handler} is responsible for handling commands, which are + * sent to one of the channels. + * + * @author Christian Schlipp - Initial contribution + */ +@NonNullByDefault +public class WlanThermoEsp32Handler extends BaseThingHandler { + + private final Logger logger = LoggerFactory.getLogger(WlanThermoEsp32Handler.class); + + private WlanThermoExtendedConfiguration config = new WlanThermoExtendedConfiguration(); + private WlanThermoEsp32CommandHandler wlanThermoEsp32CommandHandler = new WlanThermoEsp32CommandHandler(); + private final HttpClient httpClient; + private @Nullable ScheduledFuture pollingScheduler; + private final ScheduledExecutorService scheduler = ThreadPoolManager + .getScheduledPool(WlanThermoBindingConstants.WLANTHERMO_THREAD_POOL); + private final Gson gson = new Gson(); + private @Nullable Data data = new Data(); + private @Nullable Settings settings = new Settings(); + + public WlanThermoEsp32Handler(Thing thing, HttpClient httpClient) { + super(thing); + this.httpClient = httpClient; + } + + @Override + public void initialize() { + logger.debug("Start initializing WlanThermo Nano!"); + config = getConfigAs(WlanThermoExtendedConfiguration.class); + + updateStatus(ThingStatus.UNKNOWN); + try { + if (config.getUsername() != null && !config.getUsername().isEmpty() && config.getPassword() != null + && !config.getPassword().isEmpty()) { + AuthenticationStore authStore = httpClient.getAuthenticationStore(); + authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM, + config.getUsername(), config.getPassword())); + } + scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); + + logger.debug("Finished initializing WlanThermo Nano!"); + } catch (URISyntaxException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + "Failed to initialize WlanThermo Nano!"); + logger.debug("Failed to initialize WlanThermo Nano!", e); + } + } + + private void checkConnection() { + try { + if (httpClient.GET(config.getUri()).getStatus() == 200) { + updateStatus(ThingStatus.ONLINE); + ScheduledFuture oldScheduler = pollingScheduler; + if (oldScheduler != null) { + oldScheduler.cancel(false); + } + pollingScheduler = scheduler.scheduleWithFixedDelay(this::update, 0, config.getPollingInterval(), + TimeUnit.SECONDS); + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + "WlanThermo not found under given address."); + } + } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { + logger.debug("Failed to connect.", e); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Could not connect to WlanThermo at " + config.getIpAddress()); + ScheduledFuture oldScheduler = pollingScheduler; + if (oldScheduler != null) { + oldScheduler.cancel(false); + } + pollingScheduler = scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); + } + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + if (command instanceof RefreshType) { + State s = wlanThermoEsp32CommandHandler.getState(channelUID, data, settings); + if (s != null) + updateState(channelUID, s); + } else { + if (wlanThermoEsp32CommandHandler.setState(channelUID, command, data)) { + logger.debug("Data updated, pushing changes"); + push(); + } else { + logger.debug("Could not handle command of type {} for channel {}!", + command.getClass().toGenericString(), channelUID.getId()); + } + } + } + + private void update() { + try { + // Update objects with data from device + String json = httpClient.GET(config.getUri("/data")).getContentAsString(); + data = gson.fromJson(json, Data.class); + logger.debug("Received at /data: {}", json); + json = httpClient.GET(config.getUri("/settings")).getContentAsString(); + settings = gson.fromJson(json, Settings.class); + logger.debug("Received at /settings: {}", json); + + // Update Channels if required + Map properties = editProperties(); + Boolean pmEnabled = settings.getFeatures().getBluetooth(); + int pmChannels = pmEnabled ? data.getPitmaster().getPm().size() : 0; + int tempChannels = data.getChannel().size(); + + // Update properties + properties.put(WlanThermoBindingConstants.PROPERTY_MODEL, settings.getDevice().getDevice()); + properties.put(WlanThermoBindingConstants.PROPERTY_SERIAL, settings.getDevice().getSerial()); + properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_BT_ENABLED, + settings.getFeatures().getBluetooth().toString()); + properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_PM_ENABLED, pmEnabled.toString()); + properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_TEMP_CHANNELS, String.valueOf(tempChannels)); + properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_PM_CHANNELS, String.valueOf(pmChannels)); + updateProperties(properties); + + // Update channel state + for (Channel channel : thing.getChannels()) { + State state = wlanThermoEsp32CommandHandler.getState(channel.getUID(), data, settings); + if (state != null) { + updateState(channel.getUID(), state); + } else { + // if we could not obtain a state, try trigger instead + String trigger = wlanThermoEsp32CommandHandler.getTrigger(channel.getUID(), data); + if (trigger != null) { + triggerChannel(channel.getUID(), trigger); + } + } + } + } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { + logger.debug("Update failed, checking connection", e); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed, reconnecting..."); + ScheduledFuture oldScheduler = pollingScheduler; + if (oldScheduler != null) { + oldScheduler.cancel(false); + } + for (Channel channel : thing.getChannels()) { + updateState(channel.getUID(), UnDefType.UNDEF); + } + checkConnection(); + } + } + + private void push() { + data.getChannel().forEach(c -> { + try { + String json = gson.toJson(c); + logger.debug("Pushing: {}", json); + URI uri = config.getUri("/setchannels"); + int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") + .timeout(5, TimeUnit.SECONDS).send().getStatus(); + if (status == 401) { + updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); + } else if (status != 200) { + updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + + c.getName() + " on device, Statuscode " + status + " on URI " + uri.toString()); + } else { + updateStatus(ThingStatus.ONLINE); + } + } catch (InterruptedException | TimeoutException | ExecutionException | URISyntaxException e) { + updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to update channel " + c.getName() + " on device!"); + logger.debug("Failed to update channel {} on device", c.getName(), e); + } + }); + } + + @Override + public void dispose() { + ScheduledFuture oldScheduler = pollingScheduler; + if (oldScheduler != null) { + boolean stopped = oldScheduler.cancel(true); + logger.debug("Stopped polling: {}", stopped); + } + pollingScheduler = null; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Channel.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Channel.java new file mode 100644 index 0000000000000..12537d0272c22 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Channel.java @@ -0,0 +1,125 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.data; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Channel { + + @SerializedName("number") + @Expose + private Integer number; + @SerializedName("name") + @Expose + private String name; + @SerializedName("typ") + @Expose + private Integer typ; + @SerializedName("temp") + @Expose + private Double temp; + @SerializedName("min") + @Expose + private Double min; + @SerializedName("max") + @Expose + private Double max; + @SerializedName("alarm") + @Expose + private Integer alarm; + @SerializedName("color") + @Expose + private String color; + @SerializedName("fixed") + @Expose + private Boolean fixed; + @SerializedName("connected") + @Expose + private Boolean connected; + + public Integer getNumber() { + return number; + } + + public void setNumber(Integer number) { + this.number = number; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getTyp() { + return typ; + } + + public void setTyp(Integer typ) { + this.typ = typ; + } + + public Double getTemp() { + return temp; + } + + public void setTemp(Double temp) { + this.temp = temp; + } + + public Double getMin() { + return min; + } + + public void setMin(Double min) { + this.min = min; + } + + public Double getMax() { + return max; + } + + public void setMax(Double max) { + this.max = max; + } + + public Integer getAlarm() { + return alarm; + } + + public void setAlarm(Integer alarm) { + this.alarm = alarm; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + public Boolean getFixed() { + return fixed; + } + + public void setFixed(Boolean fixed) { + this.fixed = fixed; + } + + public Boolean getConnected() { + return connected; + } + + public void setConnected(Boolean connected) { + this.connected = connected; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Data.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Data.java new file mode 100644 index 0000000000000..cd6d0e3424236 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Data.java @@ -0,0 +1,50 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.data; + +import java.util.List; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Data { + + @SerializedName("system") + @Expose + private System system; + @SerializedName("channel") + @Expose + private List channel = null; + @SerializedName("pitmaster") + @Expose + private Pitmaster pitmaster; + + public System getSystem() { + return system; + } + + public void setSystem(System system) { + this.system = system; + } + + public List getChannel() { + return channel; + } + + public void setChannel(List channel) { + this.channel = channel; + } + + public Pitmaster getPitmaster() { + return pitmaster; + } + + public void setPitmaster(Pitmaster pitmaster) { + this.pitmaster = pitmaster; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pitmaster.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pitmaster.java new file mode 100644 index 0000000000000..0021602638915 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pitmaster.java @@ -0,0 +1,39 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.data; + +import java.util.List; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Pitmaster { + + @SerializedName("type") + @Expose + private List type = null; + @SerializedName("pm") + @Expose + private List pm = null; + + public List getType() { + return type; + } + + public void setType(List type) { + this.type = type; + } + + public List getPm() { + return pm; + } + + public void setPm(List pm) { + this.pm = pm; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pm.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pm.java new file mode 100644 index 0000000000000..c48a453e9d607 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pm.java @@ -0,0 +1,103 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.data; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Pm { + + @SerializedName("id") + @Expose + private Integer id; + @SerializedName("channel") + @Expose + private Integer channel; + @SerializedName("pid") + @Expose + private Integer pid; + @SerializedName("value") + @Expose + private Integer value; + @SerializedName("set") + @Expose + private Double set; + @SerializedName("typ") + @Expose + private String typ; + @SerializedName("set_color") + @Expose + private String setColor; + @SerializedName("value_color") + @Expose + private String valueColor; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getChannel() { + return channel; + } + + public void setChannel(Integer channel) { + this.channel = channel; + } + + public Integer getPid() { + return pid; + } + + public void setPid(Integer pid) { + this.pid = pid; + } + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } + + public Double getSet() { + return set; + } + + public void setSet(Double set) { + this.set = set; + } + + public String getTyp() { + return typ; + } + + public void setTyp(String typ) { + this.typ = typ; + } + + public String getSetColor() { + return setColor; + } + + public void setSetColor(String setColor) { + this.setColor = setColor; + } + + public String getValueColor() { + return valueColor; + } + + public void setValueColor(String valueColor) { + this.valueColor = valueColor; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/System.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/System.java new file mode 100644 index 0000000000000..cf111862dc50a --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/System.java @@ -0,0 +1,81 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.data; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class System { + + @SerializedName("time") + @Expose + private String time; + @SerializedName("unit") + @Expose + private String unit; + @SerializedName("soc") + @Expose + private Integer soc; + @SerializedName("charge") + @Expose + private Boolean charge; + @SerializedName("rssi") + @Expose + private Integer rssi; + @SerializedName("online") + @Expose + private Integer online; + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + public Integer getSoc() { + return soc; + } + + public void setSoc(Integer soc) { + this.soc = soc; + } + + public Boolean getCharge() { + return charge; + } + + public void setCharge(Boolean charge) { + this.charge = charge; + } + + public Integer getRssi() { + return rssi; + } + + public void setRssi(Integer rssi) { + this.rssi = rssi; + } + + public Integer getOnline() { + return online; + } + + public void setOnline(Integer online) { + this.online = online; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Api.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Api.java new file mode 100644 index 0000000000000..cae63b06a63e7 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Api.java @@ -0,0 +1,26 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.settings; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Api { + + @SerializedName("version") + @Expose + private String version; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Device.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Device.java new file mode 100644 index 0000000000000..61e41f6170882 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Device.java @@ -0,0 +1,103 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.settings; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Device { + + @SerializedName("device") + @Expose + private String device; + @SerializedName("serial") + @Expose + private String serial; + @SerializedName("cpu") + @Expose + private String cpu; + @SerializedName("flash_size") + @Expose + private Integer flashSize; + @SerializedName("hw_version") + @Expose + private String hwVersion; + @SerializedName("sw_version") + @Expose + private String swVersion; + @SerializedName("api_version") + @Expose + private String apiVersion; + @SerializedName("language") + @Expose + private String language; + + public String getDevice() { + return device; + } + + public void setDevice(String device) { + this.device = device; + } + + public String getSerial() { + return serial; + } + + public void setSerial(String serial) { + this.serial = serial; + } + + public String getCpu() { + return cpu; + } + + public void setCpu(String cpu) { + this.cpu = cpu; + } + + public Integer getFlashSize() { + return flashSize; + } + + public void setFlashSize(Integer flashSize) { + this.flashSize = flashSize; + } + + public String getHwVersion() { + return hwVersion; + } + + public void setHwVersion(String hwVersion) { + this.hwVersion = hwVersion; + } + + public String getSwVersion() { + return swVersion; + } + + public void setSwVersion(String swVersion) { + this.swVersion = swVersion; + } + + public String getApiVersion() { + return apiVersion; + } + + public void setApiVersion(String apiVersion) { + this.apiVersion = apiVersion; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Display.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Display.java new file mode 100644 index 0000000000000..9b494ee36ddc5 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Display.java @@ -0,0 +1,37 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.settings; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Display { + + @SerializedName("updname") + @Expose + private String updname; + @SerializedName("orientation") + @Expose + private Integer orientation; + + public String getUpdname() { + return updname; + } + + public void setUpdname(String updname) { + this.updname = updname; + } + + public Integer getOrientation() { + return orientation; + } + + public void setOrientation(Integer orientation) { + this.orientation = orientation; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Ext.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Ext.java new file mode 100644 index 0000000000000..8dffd3372761c --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Ext.java @@ -0,0 +1,83 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.settings; + +import java.util.List; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Ext { + + @SerializedName("on") + @Expose + private Integer on; + @SerializedName("token") + @Expose + private String token; + @SerializedName("id") + @Expose + private String id; + @SerializedName("repeat") + @Expose + private Integer repeat; + @SerializedName("service") + @Expose + private Integer service; + @SerializedName("services") + @Expose + private List services = null; + + public Integer getOn() { + return on; + } + + public void setOn(Integer on) { + this.on = on; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Integer getRepeat() { + return repeat; + } + + public void setRepeat(Integer repeat) { + this.repeat = repeat; + } + + public Integer getService() { + return service; + } + + public void setService(Integer service) { + this.service = service; + } + + public List getServices() { + return services; + } + + public void setServices(List services) { + this.services = services; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Features.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Features.java new file mode 100644 index 0000000000000..b9cd15da421c6 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Features.java @@ -0,0 +1,37 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.settings; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Features { + + @SerializedName("bluetooth") + @Expose + private Boolean bluetooth; + @SerializedName("pitmaster") + @Expose + private Boolean pitmaster; + + public Boolean getBluetooth() { + return bluetooth; + } + + public void setBluetooth(Boolean bluetooth) { + this.bluetooth = bluetooth; + } + + public Boolean getPitmaster() { + return pitmaster; + } + + public void setPitmaster(Boolean pitmaster) { + this.pitmaster = pitmaster; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Iot.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Iot.java new file mode 100644 index 0000000000000..8a05ef17aa5e6 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Iot.java @@ -0,0 +1,136 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.settings; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Iot { + + @SerializedName("PMQhost") + @Expose + private String pMQhost; + @SerializedName("PMQport") + @Expose + private Integer pMQport; + @SerializedName("PMQuser") + @Expose + private String pMQuser; + @SerializedName("PMQpass") + @Expose + private String pMQpass; + @SerializedName("PMQqos") + @Expose + private Integer pMQqos; + @SerializedName("PMQon") + @Expose + private Boolean pMQon; + @SerializedName("PMQint") + @Expose + private Integer pMQint; + @SerializedName("CLon") + @Expose + private Boolean cLon; + @SerializedName("CLtoken") + @Expose + private String cLtoken; + @SerializedName("CLint") + @Expose + private Integer cLint; + @SerializedName("CLurl") + @Expose + private String cLurl; + + public String getPMQhost() { + return pMQhost; + } + + public void setPMQhost(String pMQhost) { + this.pMQhost = pMQhost; + } + + public Integer getPMQport() { + return pMQport; + } + + public void setPMQport(Integer pMQport) { + this.pMQport = pMQport; + } + + public String getPMQuser() { + return pMQuser; + } + + public void setPMQuser(String pMQuser) { + this.pMQuser = pMQuser; + } + + public String getPMQpass() { + return pMQpass; + } + + public void setPMQpass(String pMQpass) { + this.pMQpass = pMQpass; + } + + public Integer getPMQqos() { + return pMQqos; + } + + public void setPMQqos(Integer pMQqos) { + this.pMQqos = pMQqos; + } + + public Boolean getPMQon() { + return pMQon; + } + + public void setPMQon(Boolean pMQon) { + this.pMQon = pMQon; + } + + public Integer getPMQint() { + return pMQint; + } + + public void setPMQint(Integer pMQint) { + this.pMQint = pMQint; + } + + public Boolean getCLon() { + return cLon; + } + + public void setCLon(Boolean cLon) { + this.cLon = cLon; + } + + public String getCLtoken() { + return cLtoken; + } + + public void setCLtoken(String cLtoken) { + this.cLtoken = cLtoken; + } + + public Integer getCLint() { + return cLint; + } + + public void setCLint(Integer cLint) { + this.cLint = cLint; + } + + public String getCLurl() { + return cLurl; + } + + public void setCLurl(String cLurl) { + this.cLurl = cLurl; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Notes.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Notes.java new file mode 100644 index 0000000000000..8761408506295 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Notes.java @@ -0,0 +1,39 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.settings; + +import java.util.List; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Notes { + + @SerializedName("fcm") + @Expose + private List fcm = null; + @SerializedName("ext") + @Expose + private Ext ext; + + public List getFcm() { + return fcm; + } + + public void setFcm(List fcm) { + this.fcm = fcm; + } + + public Ext getExt() { + return ext; + } + + public void setExt(Ext ext) { + this.ext = ext; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Pid.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Pid.java new file mode 100644 index 0000000000000..d6f231ea8a294 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Pid.java @@ -0,0 +1,169 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.settings; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Pid { + + @SerializedName("name") + @Expose + private String name; + @SerializedName("id") + @Expose + private Integer id; + @SerializedName("aktor") + @Expose + private Integer aktor; + @SerializedName("Kp") + @Expose + private Double kp; + @SerializedName("Ki") + @Expose + private Double ki; + @SerializedName("Kd") + @Expose + private Double kd; + @SerializedName("DCmmin") + @Expose + private Double dCmmin; + @SerializedName("DCmmax") + @Expose + private Double dCmmax; + @SerializedName("opl") + @Expose + private Integer opl; + @SerializedName("SPmin") + @Expose + private Double sPmin; + @SerializedName("SPmax") + @Expose + private Double sPmax; + @SerializedName("link") + @Expose + private Integer link; + @SerializedName("tune") + @Expose + private Integer tune; + @SerializedName("jp") + @Expose + private Integer jp; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getAktor() { + return aktor; + } + + public void setAktor(Integer aktor) { + this.aktor = aktor; + } + + public Double getKp() { + return kp; + } + + public void setKp(Double kp) { + this.kp = kp; + } + + public Double getKi() { + return ki; + } + + public void setKi(Double ki) { + this.ki = ki; + } + + public Double getKd() { + return kd; + } + + public void setKd(Double kd) { + this.kd = kd; + } + + public Double getDCmmin() { + return dCmmin; + } + + public void setDCmmin(Double dCmmin) { + this.dCmmin = dCmmin; + } + + public Double getDCmmax() { + return dCmmax; + } + + public void setDCmmax(Double dCmmax) { + this.dCmmax = dCmmax; + } + + public Integer getOpl() { + return opl; + } + + public void setOpl(Integer opl) { + this.opl = opl; + } + + public Double getSPmin() { + return sPmin; + } + + public void setSPmin(Double sPmin) { + this.sPmin = sPmin; + } + + public Double getSPmax() { + return sPmax; + } + + public void setSPmax(Double sPmax) { + this.sPmax = sPmax; + } + + public Integer getLink() { + return link; + } + + public void setLink(Integer link) { + this.link = link; + } + + public Integer getTune() { + return tune; + } + + public void setTune(Integer tune) { + this.tune = tune; + } + + public Integer getJp() { + return jp; + } + + public void setJp(Integer jp) { + this.jp = jp; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Sensor.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Sensor.java new file mode 100644 index 0000000000000..74f9025f1a940 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Sensor.java @@ -0,0 +1,48 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.settings; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Sensor { + + @SerializedName("type") + @Expose + private Integer type; + @SerializedName("name") + @Expose + private String name; + @SerializedName("fixed") + @Expose + private Boolean fixed; + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Boolean getFixed() { + return fixed; + } + + public void setFixed(Boolean fixed) { + this.fixed = fixed; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Settings.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Settings.java new file mode 100644 index 0000000000000..10a52c8addfdd --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Settings.java @@ -0,0 +1,138 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.settings; + +import java.util.List; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class Settings { + + @SerializedName("device") + @Expose + private Device device; + @SerializedName("system") + @Expose + private System system; + @SerializedName("hardware") + @Expose + private List hardware = null; + @SerializedName("api") + @Expose + private Api api; + @SerializedName("sensors") + @Expose + private List sensors = null; + @SerializedName("features") + @Expose + private Features features; + @SerializedName("pid") + @Expose + private List pid = null; + @SerializedName("aktor") + @Expose + private List aktor = null; + @SerializedName("display") + @Expose + private Display display; + @SerializedName("iot") + @Expose + private Iot iot; + @SerializedName("notes") + @Expose + private Notes notes; + + public Device getDevice() { + return device; + } + + public void setDevice(Device device) { + this.device = device; + } + + public System getSystem() { + return system; + } + + public void setSystem(System system) { + this.system = system; + } + + public List getHardware() { + return hardware; + } + + public void setHardware(List hardware) { + this.hardware = hardware; + } + + public Api getApi() { + return api; + } + + public void setApi(Api api) { + this.api = api; + } + + public List getSensors() { + return sensors; + } + + public void setSensors(List sensors) { + this.sensors = sensors; + } + + public Features getFeatures() { + return features; + } + + public void setFeatures(Features features) { + this.features = features; + } + + public List getPid() { + return pid; + } + + public void setPid(List pid) { + this.pid = pid; + } + + public List getAktor() { + return aktor; + } + + public void setAktor(List aktor) { + this.aktor = aktor; + } + + public Display getDisplay() { + return display; + } + + public void setDisplay(Display display) { + this.display = display; + } + + public Iot getIot() { + return iot; + } + + public void setIot(Iot iot) { + this.iot = iot; + } + + public Notes getNotes() { + return notes; + } + + public void setNotes(Notes notes) { + this.notes = notes; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/System.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/System.java new file mode 100644 index 0000000000000..fe59ddf2907b3 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/System.java @@ -0,0 +1,125 @@ + +package org.openhab.binding.wlanthermo.internal.api.esp32.settings; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * This DTO is used to parse the JSON + * Class is auto-generated from JSON using http://www.jsonschema2pojo.org/ + * + * @author Christian Schlipp - Initial contribution + */ +public class System { + + @SerializedName("time") + @Expose + private String time; + @SerializedName("unit") + @Expose + private String unit; + @SerializedName("ap") + @Expose + private String ap; + @SerializedName("host") + @Expose + private String host; + @SerializedName("language") + @Expose + private String language; + @SerializedName("version") + @Expose + private String version; + @SerializedName("getupdate") + @Expose + private String getupdate; + @SerializedName("autoupd") + @Expose + private Boolean autoupd; + @SerializedName("prerelease") + @Expose + private Boolean prerelease; + @SerializedName("hwversion") + @Expose + private String hwversion; + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + public String getAp() { + return ap; + } + + public void setAp(String ap) { + this.ap = ap; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getGetupdate() { + return getupdate; + } + + public void setGetupdate(String getupdate) { + this.getupdate = getupdate; + } + + public Boolean getAutoupd() { + return autoupd; + } + + public void setAutoupd(Boolean autoupd) { + this.autoupd = autoupd; + } + + public Boolean getPrerelease() { + return prerelease; + } + + public void setPrerelease(Boolean prerelease) { + this.prerelease = prerelease; + } + + public String getHwversion() { + return hwversion; + } + + public void setHwversion(String hwversion) { + this.hwversion = hwversion; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java similarity index 93% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoMiniHandler.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index eb0c3893e3acb..1115f39ee8008 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -10,15 +10,16 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal; +package org.openhab.binding.wlanthermo.internal.api.mini; import java.net.URISyntaxException; -import java.util.Objects; import java.util.concurrent.*; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; +import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; +import org.openhab.binding.wlanthermo.internal.WlanThermoConfiguration; import org.openhab.binding.wlanthermo.internal.api.mini.builtin.App; import org.openhab.binding.wlanthermo.internal.api.mini.builtin.WlanThermoMiniCommandHandler; import org.openhab.core.common.ThreadPoolManager; @@ -45,7 +46,7 @@ public class WlanThermoMiniHandler extends BaseThingHandler { private final Logger logger = LoggerFactory.getLogger(WlanThermoMiniHandler.class); private final WlanThermoMiniCommandHandler wlanThermoMiniCommandHandler = new WlanThermoMiniCommandHandler(); - private WlanThermoMiniConfiguration config = new WlanThermoMiniConfiguration(); + private WlanThermoConfiguration config = new WlanThermoConfiguration(); private final HttpClient httpClient; private @Nullable ScheduledFuture pollingScheduler; private final ScheduledExecutorService scheduler = ThreadPoolManager @@ -61,7 +62,7 @@ public WlanThermoMiniHandler(Thing thing, HttpClient httpClient) { @Override public void initialize() { logger.debug("Start initializing WlanThermo Mini!"); - config = getConfigAs(WlanThermoMiniConfiguration.class); + config = getConfigAs(WlanThermoConfiguration.class); updateStatus(ThingStatus.UNKNOWN); scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); @@ -109,7 +110,7 @@ private void update() { try { // Update objects with data from device String json = httpClient.GET(config.getUri("/app.php")).getContentAsString(); - app = Objects.requireNonNull(gson.fromJson(json, App.class)); + app = gson.fromJson(json, App.class); logger.debug("Received at /app.php: {}", json); // Update channels diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java index c488248c14b26..a6084651cc450 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java @@ -16,7 +16,7 @@ import java.util.Map; /** - * The {@link UtilNano} class provides conversion functions for the WlanThermo Nano + * The {@link UtilNano} class provides conversion functions for the WlanThermo Nano V1+ * * @author Christian Schlipp - Initial contribution */ diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoCommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java similarity index 98% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoCommandHandler.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index f6d9dfa67af55..9c4f940f7890a 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoCommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -30,12 +30,12 @@ import org.openhab.core.types.UnDefType; /** - * The {@link WlanThermoNanoCommandHandler} is responsible for mapping the Commands to the respective data fields + * The {@link WlanThermoNanoV1CommandHandler} is responsible for mapping the Commands to the respective data fields * of the API. * * @author Christian Schlipp - Initial contribution */ -public class WlanThermoNanoCommandHandler { +public class WlanThermoNanoV1CommandHandler { public State getState(ChannelUID channelUID, Data data, Settings settings) { State state = null; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoNanoHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java similarity index 86% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoNanoHandler.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 0b44d3e6e7604..e0c0d83d07c24 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoNanoHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -10,11 +10,10 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal; +package org.openhab.binding.wlanthermo.internal.api.nano; import java.net.URI; import java.net.URISyntaxException; -import java.util.Objects; import java.util.concurrent.*; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -24,7 +23,8 @@ import org.eclipse.jetty.client.api.AuthenticationStore; import org.eclipse.jetty.client.util.DigestAuthentication; import org.eclipse.jetty.client.util.StringContentProvider; -import org.openhab.binding.wlanthermo.internal.api.nano.WlanThermoNanoCommandHandler; +import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; +import org.openhab.binding.wlanthermo.internal.WlanThermoExtendedConfiguration; import org.openhab.binding.wlanthermo.internal.api.nano.data.Data; import org.openhab.binding.wlanthermo.internal.api.nano.settings.Settings; import org.openhab.core.common.ThreadPoolManager; @@ -40,18 +40,18 @@ import com.google.gson.Gson; /** - * The {@link WlanThermoNanoHandler} is responsible for handling commands, which are + * The {@link WlanThermoNanoV1Handler} is responsible for handling commands, which are * sent to one of the channels. * * @author Christian Schlipp - Initial contribution */ @NonNullByDefault -public class WlanThermoNanoHandler extends BaseThingHandler { +public class WlanThermoNanoV1Handler extends BaseThingHandler { - private final Logger logger = LoggerFactory.getLogger(WlanThermoNanoHandler.class); + private final Logger logger = LoggerFactory.getLogger(WlanThermoNanoV1Handler.class); - private WlanThermoNanoConfiguration config = new WlanThermoNanoConfiguration(); - private WlanThermoNanoCommandHandler wlanThermoNanoCommandHandler = new WlanThermoNanoCommandHandler(); + private WlanThermoExtendedConfiguration config = new WlanThermoExtendedConfiguration(); + private WlanThermoNanoV1CommandHandler wlanThermoNanoV1CommandHandler = new WlanThermoNanoV1CommandHandler(); private final HttpClient httpClient; private @Nullable ScheduledFuture pollingScheduler; private final ScheduledExecutorService scheduler = ThreadPoolManager @@ -60,7 +60,7 @@ public class WlanThermoNanoHandler extends BaseThingHandler { private Data data = new Data(); private Settings settings = new Settings(); - public WlanThermoNanoHandler(Thing thing, HttpClient httpClient) { + public WlanThermoNanoV1Handler(Thing thing, HttpClient httpClient) { super(thing); this.httpClient = httpClient; } @@ -68,7 +68,7 @@ public WlanThermoNanoHandler(Thing thing, HttpClient httpClient) { @Override public void initialize() { logger.debug("Start initializing WlanThermo Nano!"); - config = getConfigAs(WlanThermoNanoConfiguration.class); + config = getConfigAs(WlanThermoExtendedConfiguration.class); updateStatus(ThingStatus.UNKNOWN); try { @@ -117,11 +117,11 @@ private void checkConnection() { @Override public void handleCommand(ChannelUID channelUID, Command command) { if (command instanceof RefreshType) { - State s = wlanThermoNanoCommandHandler.getState(channelUID, data, settings); + State s = wlanThermoNanoV1CommandHandler.getState(channelUID, data, settings); if (s != null) updateState(channelUID, s); } else { - if (wlanThermoNanoCommandHandler.setState(channelUID, command, data)) { + if (wlanThermoNanoV1CommandHandler.setState(channelUID, command, data)) { logger.debug("Data updated, pushing changes"); push(); } else { @@ -135,20 +135,20 @@ private void update() { try { // Update objects with data from device String json = httpClient.GET(config.getUri("/data")).getContentAsString(); - data = Objects.requireNonNull(gson.fromJson(json, Data.class)); + data = gson.fromJson(json, Data.class); logger.debug("Received at /data: {}", json); json = httpClient.GET(config.getUri("/settings")).getContentAsString(); - settings = Objects.requireNonNull(gson.fromJson(json, Settings.class)); + settings = gson.fromJson(json, Settings.class); logger.debug("Received at /settings: {}", json); // Update channels for (Channel channel : thing.getChannels()) { - State state = wlanThermoNanoCommandHandler.getState(channel.getUID(), data, settings); + State state = wlanThermoNanoV1CommandHandler.getState(channel.getUID(), data, settings); if (state != null) { updateState(channel.getUID(), state); } else { // if we could not obtain a state, try trigger instead - String trigger = wlanThermoNanoCommandHandler.getTrigger(channel.getUID(), data); + String trigger = wlanThermoNanoV1CommandHandler.getTrigger(channel.getUID(), data); if (trigger != null) { triggerChannel(channel.getUID(), trigger); } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-esp32.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-esp32.xml new file mode 100644 index 0000000000000..eaa05855f4eba --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-esp32.xml @@ -0,0 +1,51 @@ + + + + + + This group contains all system channels + + + + + + + + + + + + Sensor + + + + + + + + + + + + + + + + + + + + Sensor + + + + + + + + + + diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-mini.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-mini.xml new file mode 100644 index 0000000000000..0b73407cd243b --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-mini.xml @@ -0,0 +1,47 @@ + + + + + + This group contains all system channels + + + + + + + + + + Sensor + + + + + + + + + + + + + + + + + + Sensor + + + + + + + + + + diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-nano.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-nano.xml new file mode 100644 index 0000000000000..320d55b5ff047 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-nano.xml @@ -0,0 +1,52 @@ + + + + + + This group contains all system channels + + + + + + + + + + + + Sensor + + + + + + + + + + + + + + + + + + + + Sensor + + + + + + + + + + + diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml new file mode 100644 index 0000000000000..c2da897df073f --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml @@ -0,0 +1,261 @@ + + + + Number + + + + + + String + + Text + + + + String + + Text + + + + + String + + Text + + + + + Number:Temperature + + Temperature + + + + + Number:Temperature + + Temperature + + + + + Number:Temperature + + Temperature + + + + + Number:Temperature + + Temperature + + + + + Number:Temperature + + Temperature + + + + + Switch + + Switch + + + + Switch + + Switch + + + + + Switch + + Switch + + + + trigger + + + + + + + + + + + Switch + + + + + + Switch + + + + + + Color + + Colorpicker + + + + + String + + Colorpicker + + + + + + + + + + + + + + + + + + String + + Colorpicker + + + + + + + + + + + + + + + + + + + + + + + + + + + Color + + Colorpicker + + + + + String + + Text + + + + + Switch + + + + + + Number:Temperature + + Temperature + + + + + Number + + + + + + Switch + + + + + + Number + + + + + + String + + + + + + + + + + + + + Number + + + + + + Number + + + + + + Number:Temperature + + Temperature + + + + + Number + + + + + + Switch + + Energy + + + + + Number + + Text + + + diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-esp32.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-esp32.xml new file mode 100644 index 0000000000000..e0718f6ed5ff7 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-esp32.xml @@ -0,0 +1,151 @@ + + + + + WlanThermo device with ESP32 processor, such as Mini V2 (ESP32), Nano V3, Link V1 + + + + + + This group contains all channels for temperature probe 1 + + + + This group contains all channels for temperature probe 2 + + + + This group contains all channels for temperature probe 3 + + + + This group contains all channels for temperature probe 4 + + + + This group contains all channels for temperature probe 5 + + + + This group contains all channels for temperature probe 6 + + + + This group contains all channels for temperature probe 7 + + + + This group contains all channels for temperature probe 8 + + + + This group contains all channels for temperature probe 9 + + + + This group contains all channels for temperature probe 10 + + + + This group contains all channels for temperature probe 11 + + + + This group contains all channels for temperature probe 12 + + + + This group contains all channels for temperature probe 13 + + + + This group contains all channels for temperature probe 14 + + + + This group contains all channels for temperature probe 15 + + + + This group contains all channels for temperature probe 16 + + + + This group contains all channels for temperature probe 17 + + + + This group contains all channels for temperature probe 18 + + + + This group contains all channels for temperature probe 19 + + + + This group contains all channels for temperature probe 20 + + + + This group contains all channels for temperature probe 21 + + + + This group contains all channels for temperature probe 22 + + + + This group contains all channels for temperature probe 23 + + + + This group contains all channels for temperature probe 24 + + + + This group contains all channels for pitmaster channel 1 + + + + This group contains all channels for pitmaster channel 2 + + + + + Model + Serial Number + Bluetooth available + Pitmaster available + Temperature channels + Pitmaster channels + + + + + network-address + + Network address of the WlanThermo Nano. + + + + Optional, only required for write access. Default: 'admin' + admin + + + password + + Optional, only required for write access. Default: 'admin' + admin + + + + Seconds between fetching values from the WlanThermo Nano. + 10 + + + + diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-mini.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-mini.xml new file mode 100644 index 0000000000000..9e2c260d2fa4e --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-mini.xml @@ -0,0 +1,79 @@ + + + + + + + WlanThermo Mini with Raspberry Pi processor, such as Mini V1/V2 + + + + + + This group contains all channels for temperature probe 1 + + + + This group contains all channels for temperature probe 2 + + + + This group contains all channels for temperature probe 3 + + + + This group contains all channels for temperature probe 4 + + + + This group contains all channels for temperature probe 5 + + + + This group contains all channels for temperature probe 6 + + + + This group contains all channels for temperature probe 7 + + + + This group contains all channels for temperature probe 8 + + + + This group contains all channels for temperature probe 9 + + + + This group contains all channels for temperature probe 10 + + + + This group contains all channels for pitmaster channel 1 + + + + This group contains all channels for pitmaster channel 2 + + + + + + network-address + + Network address of the WlanThermo Mini. + + + + Seconds between fetching values from the WlanThermo Mini. + 10 + + + + + + diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-nano.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-nano.xml new file mode 100644 index 0000000000000..e6955e8e33d12 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-nano.xml @@ -0,0 +1,74 @@ + + + + + WlanThermo Nano V1/V1+ + + + + + + This group contains all channels for temperature probe 1 + + + + This group contains all channels for temperature probe 2 + + + + This group contains all channels for temperature probe 3 + + + + This group contains all channels for temperature probe 4 + + + + This group contains all channels for temperature probe 5 + + + + This group contains all channels for temperature probe 6 + + + + This group contains all channels for temperature probe 7 + + + + This group contains all channels for temperature probe 8 + + + + This group contains all channels for pitmaster channel 1 + + + + + + network-address + + Network address of the WlanThermo Nano. + + + + Optional, only required for write access. Default: 'admin' + admin + + + password + + Optional, only required for write access. Default: 'admin' + admin + + + + Seconds between fetching values from the WlanThermo Nano. + 10 + + + + diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types.xml deleted file mode 100644 index 13171663f773f..0000000000000 --- a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types.xml +++ /dev/null @@ -1,463 +0,0 @@ - - - - - - WlanThermo Nano V1/V1+ - - - - - - This group contains all channels for temperature probe 1 - - - - This group contains all channels for temperature probe 2 - - - - This group contains all channels for temperature probe 3 - - - - This group contains all channels for temperature probe 4 - - - - This group contains all channels for temperature probe 5 - - - - This group contains all channels for temperature probe 6 - - - - This group contains all channels for temperature probe 7 - - - - This group contains all channels for temperature probe 8 - - - - This group contains all channels for pitmaster channel 1 - - - - - - network-address - - Network address of the WlanThermo Nano. - - - - Optional, only required for write access. Default: 'admin' - admin - - - password - - Optional, only required for write access. Default: 'admin' - admin - - - - Seconds between fetching values from the WlanThermo Nano. - 10 - - - - - - - - WlanThermo Mini - - - - - - This group contains all channels for temperature probe 1 - - - - This group contains all channels for temperature probe 2 - - - - This group contains all channels for temperature probe 3 - - - - This group contains all channels for temperature probe 4 - - - - This group contains all channels for temperature probe 5 - - - - This group contains all channels for temperature probe 6 - - - - This group contains all channels for temperature probe 7 - - - - This group contains all channels for temperature probe 8 - - - - This group contains all channels for temperature probe 9 - - - - This group contains all channels for temperature probe 10 - - - - This group contains all channels for pitmaster channel 1 - - - - This group contains all channels for pitmaster channel 2 - - - - - - network-address - - Network address of the WlanThermo Mini. - - - - Seconds between fetching values from the WlanThermo Mini. - 10 - - - - - - - - - This group contains all system channels - - - - - - - - - - Switch - - Energy - - - - - Number - - Text - - - - - - - This group contains all system channels - - - - - - - - Number - - - - - - - - Sensor - - - - - - - - - - - - - - - - - - - - Sensor - - - - - - - - - - - - - - - - - String - - Text - - - - String - - Text - - - - - String - - Text - - - - - Number:Temperature - - Temperature - - - - - Number:Temperature - - Temperature - - - - - Number:Temperature - - Temperature - - - - - Number:Temperature - - Temperature - - - - - Number:Temperature - - Temperature - - - - - Switch - - Switch - - - - Switch - - Switch - - - - - Switch - - Switch - - - - trigger - - - - - - - - - - - Switch - - - - - - Switch - - - - - - Color - - Colorpicker - - - - - String - - Colorpicker - - - - - - - - - - - - - - - - - - Color - - Colorpicker - - - - - String - - Text - - - - - - - Sensor - - - - - - - - - - - - Switch - - - - - - Number:Temperature - - Temperature - - - - - Number - - - - - - Switch - - - - - - Number - - - - - - - - Sensor - - - - - - - - - - - String - - - - - - - - - - - - - Number - - - - - - Number - - - - - - Number:Temperature - - Temperature - - - - - Number - - - - - From 31a5d04ddc3a6b5c5530363b73518b70b46303e5 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Tue, 29 Dec 2020 13:45:35 +0100 Subject: [PATCH 02/40] Fix Compiler warnings in V3 branch Signed-off-by: Christian Schlipp --- .../wlanthermo/internal/api/mini/WlanThermoMiniHandler.java | 2 +- .../wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index 1115f39ee8008..51c6a6d6d5776 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -52,7 +52,7 @@ public class WlanThermoMiniHandler extends BaseThingHandler { private final ScheduledExecutorService scheduler = ThreadPoolManager .getScheduledPool(WlanThermoBindingConstants.WLANTHERMO_THREAD_POOL); private final Gson gson = new Gson(); - private App app = new App(); + private @Nullable App app = new App(); public WlanThermoMiniHandler(Thing thing, HttpClient httpClient) { super(thing); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index e0c0d83d07c24..d7868902eb606 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -57,8 +57,8 @@ public class WlanThermoNanoV1Handler extends BaseThingHandler { private final ScheduledExecutorService scheduler = ThreadPoolManager .getScheduledPool(WlanThermoBindingConstants.WLANTHERMO_THREAD_POOL); private final Gson gson = new Gson(); - private Data data = new Data(); - private Settings settings = new Settings(); + private @Nullable Data data = new Data(); + private @Nullable Settings settings = new Settings(); public WlanThermoNanoV1Handler(Thing thing, HttpClient httpClient) { super(thing); From 24680ba232d62a1bb28892e9632f216121a82d56 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 31 Dec 2020 14:56:28 +0100 Subject: [PATCH 03/40] moved auto-generated classed to dto package Signed-off-by: Christian Schlipp --- .../api/esp32/WlanThermoEsp32CommandHandler.java | 10 +++++----- .../internal/api/esp32/WlanThermoEsp32Handler.java | 4 ++-- .../internal/api/esp32/{ => dto}/data/Channel.java | 2 +- .../internal/api/esp32/{ => dto}/data/Data.java | 2 +- .../internal/api/esp32/{ => dto}/data/Pitmaster.java | 2 +- .../internal/api/esp32/{ => dto}/data/Pm.java | 2 +- .../internal/api/esp32/{ => dto}/data/System.java | 2 +- .../internal/api/esp32/{ => dto}/settings/Api.java | 2 +- .../internal/api/esp32/{ => dto}/settings/Device.java | 2 +- .../internal/api/esp32/{ => dto}/settings/Display.java | 2 +- .../internal/api/esp32/{ => dto}/settings/Ext.java | 2 +- .../api/esp32/{ => dto}/settings/Features.java | 2 +- .../internal/api/esp32/{ => dto}/settings/Iot.java | 2 +- .../internal/api/esp32/{ => dto}/settings/Notes.java | 2 +- .../internal/api/esp32/{ => dto}/settings/Pid.java | 2 +- .../internal/api/esp32/{ => dto}/settings/Sensor.java | 2 +- .../api/esp32/{ => dto}/settings/Settings.java | 2 +- .../internal/api/esp32/{ => dto}/settings/System.java | 2 +- .../{builtin => }/WlanThermoMiniCommandHandler.java | 3 ++- .../internal/api/mini/WlanThermoMiniHandler.java | 3 +-- .../internal/api/mini/{ => dto}/builtin/App.java | 2 +- .../internal/api/mini/{ => dto}/builtin/Channel.java | 2 +- .../internal/api/mini/{ => dto}/builtin/Data.java | 2 +- .../internal/api/mini/{ => dto}/builtin/Pit.java | 2 +- .../internal/api/mini/{ => dto}/builtin/UtilMini.java | 2 +- .../api/nano/WlanThermoNanoV1CommandHandler.java | 10 +++++----- .../internal/api/nano/WlanThermoNanoV1Handler.java | 4 ++-- .../internal/api/nano/{ => dto}/data/Channel.java | 2 +- .../internal/api/nano/{ => dto}/data/Data.java | 2 +- .../internal/api/nano/{ => dto}/data/Pitmaster.java | 2 +- .../internal/api/nano/{ => dto}/data/Pm.java | 2 +- .../internal/api/nano/{ => dto}/data/System.java | 2 +- .../internal/api/nano/{ => dto}/settings/Api.java | 2 +- .../internal/api/nano/{ => dto}/settings/Device.java | 2 +- .../internal/api/nano/{ => dto}/settings/Ext.java | 2 +- .../internal/api/nano/{ => dto}/settings/Iot.java | 2 +- .../internal/api/nano/{ => dto}/settings/Notes.java | 2 +- .../internal/api/nano/{ => dto}/settings/Pid.java | 2 +- .../internal/api/nano/{ => dto}/settings/Settings.java | 2 +- .../internal/api/nano/{ => dto}/settings/System.java | 2 +- 40 files changed, 51 insertions(+), 51 deletions(-) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/data/Channel.java (97%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/data/Data.java (93%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/data/Pitmaster.java (91%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/data/Pm.java (96%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/data/System.java (95%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/settings/Api.java (87%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/settings/Device.java (96%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/settings/Display.java (91%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/settings/Ext.java (95%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/settings/Features.java (91%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/settings/Iot.java (97%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/settings/Notes.java (90%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/settings/Pid.java (97%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/settings/Sensor.java (92%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/settings/Settings.java (97%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{ => dto}/settings/System.java (97%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/{builtin => }/WlanThermoMiniCommandHandler.java (98%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/{ => dto}/builtin/App.java (98%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/{ => dto}/builtin/Channel.java (98%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/{ => dto}/builtin/Data.java (98%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/{ => dto}/builtin/Pit.java (98%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/{ => dto}/builtin/UtilMini.java (97%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/data/Channel.java (98%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/data/Data.java (97%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/data/Pitmaster.java (96%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/data/Pm.java (98%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/data/System.java (97%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/settings/Api.java (91%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/settings/Device.java (94%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/settings/Ext.java (94%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/settings/Iot.java (95%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/settings/Notes.java (92%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/settings/Pid.java (95%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/settings/Settings.java (95%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{ => dto}/settings/System.java (95%) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index 4946957886171..bbb042149a584 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -18,11 +18,11 @@ import java.math.BigInteger; import java.util.List; -import org.openhab.binding.wlanthermo.internal.api.esp32.data.Channel; -import org.openhab.binding.wlanthermo.internal.api.esp32.data.Data; -import org.openhab.binding.wlanthermo.internal.api.esp32.data.Pm; -import org.openhab.binding.wlanthermo.internal.api.esp32.data.System; -import org.openhab.binding.wlanthermo.internal.api.esp32.settings.Settings; +import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Channel; +import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Data; +import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Pm; +import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.System; +import org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings.Settings; import org.openhab.core.library.types.*; import org.openhab.core.thing.ChannelUID; import org.openhab.core.types.Command; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 1e123e4031a44..16a94923c31c3 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -26,8 +26,8 @@ import org.eclipse.jetty.client.util.StringContentProvider; import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; import org.openhab.binding.wlanthermo.internal.WlanThermoExtendedConfiguration; -import org.openhab.binding.wlanthermo.internal.api.esp32.data.Data; -import org.openhab.binding.wlanthermo.internal.api.esp32.settings.Settings; +import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Data; +import org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings.Settings; import org.openhab.core.common.ThreadPoolManager; import org.openhab.core.thing.*; import org.openhab.core.thing.binding.BaseThingHandler; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Channel.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Channel.java similarity index 97% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Channel.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Channel.java index 12537d0272c22..794803db4890e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Channel.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Channel.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.data; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Data.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Data.java similarity index 93% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Data.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Data.java index cd6d0e3424236..be4bab815c866 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Data.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Data.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.data; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pitmaster.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pitmaster.java similarity index 91% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pitmaster.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pitmaster.java index 0021602638915..22c3450c1283d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pitmaster.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pitmaster.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.data; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pm.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pm.java similarity index 96% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pm.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pm.java index c48a453e9d607..b6487fdb4b4d0 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/Pm.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pm.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.data; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/System.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/System.java similarity index 95% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/System.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/System.java index cf111862dc50a..6398f6bc29c60 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/data/System.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/System.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.data; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Api.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Api.java similarity index 87% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Api.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Api.java index cae63b06a63e7..edd4a2f622e20 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Api.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Api.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.settings; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Device.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Device.java similarity index 96% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Device.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Device.java index 61e41f6170882..262d16897a60e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Device.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Device.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.settings; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Display.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Display.java similarity index 91% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Display.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Display.java index 9b494ee36ddc5..bec07f4acceed 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Display.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Display.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.settings; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Ext.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Ext.java similarity index 95% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Ext.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Ext.java index 8dffd3372761c..06f022cd01906 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Ext.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Ext.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.settings; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Features.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Features.java similarity index 91% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Features.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Features.java index b9cd15da421c6..1b884c6b3bba7 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Features.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Features.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.settings; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Iot.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Iot.java similarity index 97% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Iot.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Iot.java index 8a05ef17aa5e6..f16e47c23ff38 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Iot.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Iot.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.settings; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Notes.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Notes.java similarity index 90% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Notes.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Notes.java index 8761408506295..e743328fb18c7 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Notes.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Notes.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.settings; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Pid.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Pid.java similarity index 97% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Pid.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Pid.java index d6f231ea8a294..d0a54b33c3bc5 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Pid.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Pid.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.settings; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Sensor.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Sensor.java similarity index 92% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Sensor.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Sensor.java index 74f9025f1a940..d660576f35d74 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Sensor.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Sensor.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.settings; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Settings.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Settings.java similarity index 97% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Settings.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Settings.java index 10a52c8addfdd..165a527eb4906 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/Settings.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Settings.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.settings; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/System.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/System.java similarity index 97% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/System.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/System.java index fe59ddf2907b3..0a755783af285 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/settings/System.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/System.java @@ -1,5 +1,5 @@ -package org.openhab.binding.wlanthermo.internal.api.esp32.settings; +package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/WlanThermoMiniCommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java similarity index 98% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/WlanThermoMiniCommandHandler.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java index 4ebda782612af..6aae5c89d1466 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/WlanThermoMiniCommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java @@ -10,11 +10,12 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.mini.builtin; +package org.openhab.binding.wlanthermo.internal.api.mini; import java.awt.*; import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; +import org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin.*; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.HSBType; import org.openhab.core.library.types.OnOffType; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index 51c6a6d6d5776..3a439dd0b2c61 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -20,8 +20,7 @@ import org.eclipse.jetty.client.HttpClient; import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; import org.openhab.binding.wlanthermo.internal.WlanThermoConfiguration; -import org.openhab.binding.wlanthermo.internal.api.mini.builtin.App; -import org.openhab.binding.wlanthermo.internal.api.mini.builtin.WlanThermoMiniCommandHandler; +import org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin.App; import org.openhab.core.common.ThreadPoolManager; import org.openhab.core.thing.*; import org.openhab.core.thing.binding.BaseThingHandler; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/App.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/App.java similarity index 98% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/App.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/App.java index f45c16becb7e2..2b3cd6fb8ba13 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/App.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/App.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.mini.builtin; +package org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/Channel.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/Channel.java similarity index 98% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/Channel.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/Channel.java index 5329d3378d3c8..0dec13cf4c154 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/Channel.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/Channel.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.mini.builtin; +package org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/Data.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/Data.java similarity index 98% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/Data.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/Data.java index 3dc0ee6b70001..ef8c015a3ff0a 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/Data.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/Data.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.mini.builtin; +package org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/Pit.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/Pit.java similarity index 98% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/Pit.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/Pit.java index cabe125238fc2..396a7a9f2229b 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/Pit.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/Pit.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.mini.builtin; +package org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/UtilMini.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/UtilMini.java similarity index 97% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/UtilMini.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/UtilMini.java index e1513cd3eaeac..f538d86f6e11c 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/builtin/UtilMini.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/UtilMini.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.mini.builtin; +package org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin; import java.util.HashMap; import java.util.Map; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index 9c4f940f7890a..f7dec06182c13 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -18,11 +18,11 @@ import java.math.BigInteger; import java.util.List; -import org.openhab.binding.wlanthermo.internal.api.nano.data.Channel; -import org.openhab.binding.wlanthermo.internal.api.nano.data.Data; -import org.openhab.binding.wlanthermo.internal.api.nano.data.Pm; -import org.openhab.binding.wlanthermo.internal.api.nano.data.System; -import org.openhab.binding.wlanthermo.internal.api.nano.settings.Settings; +import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Channel; +import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Data; +import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Pm; +import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.System; +import org.openhab.binding.wlanthermo.internal.api.nano.dto.settings.Settings; import org.openhab.core.library.types.*; import org.openhab.core.thing.ChannelUID; import org.openhab.core.types.Command; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index d7868902eb606..35663012f262e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -25,8 +25,8 @@ import org.eclipse.jetty.client.util.StringContentProvider; import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; import org.openhab.binding.wlanthermo.internal.WlanThermoExtendedConfiguration; -import org.openhab.binding.wlanthermo.internal.api.nano.data.Data; -import org.openhab.binding.wlanthermo.internal.api.nano.settings.Settings; +import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Data; +import org.openhab.binding.wlanthermo.internal.api.nano.dto.settings.Settings; import org.openhab.core.common.ThreadPoolManager; import org.openhab.core.thing.*; import org.openhab.core.thing.binding.BaseThingHandler; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/Channel.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/Channel.java similarity index 98% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/Channel.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/Channel.java index 429bb33d891f0..9d1672cf595aa 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/Channel.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/Channel.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.data; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.data; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/Data.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/Data.java similarity index 97% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/Data.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/Data.java index 0ca7bc0dcf17d..b1225216d9f5a 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/Data.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/Data.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.data; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.data; import java.util.ArrayList; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/Pitmaster.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/Pitmaster.java similarity index 96% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/Pitmaster.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/Pitmaster.java index 50234024d821e..7205aa3fdc5c1 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/Pitmaster.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/Pitmaster.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.data; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.data; import java.util.ArrayList; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/Pm.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/Pm.java similarity index 98% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/Pm.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/Pm.java index 3f1162a540d6c..43c96511e24ca 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/Pm.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/Pm.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.data; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.data; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/System.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/System.java similarity index 97% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/System.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/System.java index e441af34126af..c50c1a894c34a 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/data/System.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/data/System.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.data; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.data; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Api.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Api.java similarity index 91% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Api.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Api.java index ba2429a3fd169..7e0fbc7cd33c4 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Api.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Api.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.settings; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Device.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Device.java similarity index 94% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Device.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Device.java index 2c921a4e57046..e3663a5d9415d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Device.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Device.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.settings; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Ext.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Ext.java similarity index 94% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Ext.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Ext.java index 093a12cdfdcea..6cb19d8b3f4ea 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Ext.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Ext.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.settings; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.settings; import java.util.ArrayList; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Iot.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Iot.java similarity index 95% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Iot.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Iot.java index a5ee2976cb218..18b331af04784 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Iot.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Iot.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.settings; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Notes.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Notes.java similarity index 92% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Notes.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Notes.java index 4c04e0160434a..15710ff4872ba 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Notes.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Notes.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.settings; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.settings; import java.util.ArrayList; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Pid.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Pid.java similarity index 95% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Pid.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Pid.java index ea5b7d306b383..a3d099da58601 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Pid.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Pid.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.settings; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Settings.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Settings.java similarity index 95% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Settings.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Settings.java index 20dd854f85802..f2c960ba26c8c 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/Settings.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/Settings.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.settings; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.settings; import java.util.ArrayList; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/System.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/System.java similarity index 95% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/System.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/System.java index 4a762bdf922fc..8c988d9f3fdb3 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/settings/System.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/dto/settings/System.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.nano.settings; +package org.openhab.binding.wlanthermo.internal.api.nano.dto.settings; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; From 7f85970721a73f875c0e7f888444f4bd599b88be Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 31 Dec 2020 16:14:34 +0100 Subject: [PATCH 04/40] fix typo Signed-off-by: Christian Schlipp --- .../src/main/resources/OH-INF/thing/channel-types.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml index c2da897df073f..60fcad0c3987d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml @@ -85,7 +85,7 @@ trigger - + From 56623060fc6c0346948b5ecc97627300ef287e35 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 31 Dec 2020 16:15:32 +0100 Subject: [PATCH 05/40] fix imports Signed-off-by: Christian Schlipp --- .../internal/api/esp32/WlanThermoEsp32CommandHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index bbb042149a584..6e881d18fb35f 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -14,7 +14,7 @@ import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.*; -import java.awt.*; +import java.awt.Color; import java.math.BigInteger; import java.util.List; From dd494b93fa407635a654b993dd849c6a03a02db2 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 31 Dec 2020 16:17:11 +0100 Subject: [PATCH 06/40] reduce logs Signed-off-by: Christian Schlipp --- .../internal/api/esp32/WlanThermoEsp32Handler.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 16a94923c31c3..8caa041b62134 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -68,7 +68,6 @@ public WlanThermoEsp32Handler(Thing thing, HttpClient httpClient) { @Override public void initialize() { - logger.debug("Start initializing WlanThermo Nano!"); config = getConfigAs(WlanThermoExtendedConfiguration.class); updateStatus(ThingStatus.UNKNOWN); @@ -84,8 +83,7 @@ public void initialize() { logger.debug("Finished initializing WlanThermo Nano!"); } catch (URISyntaxException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Failed to initialize WlanThermo Nano!"); - logger.debug("Failed to initialize WlanThermo Nano!", e); + "Failed to initialize WlanThermo Nano: " + e.getMessage()); } } @@ -106,7 +104,7 @@ private void checkConnection() { } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { logger.debug("Failed to connect.", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Could not connect to WlanThermo at " + config.getIpAddress()); + "Could not connect to WlanThermo at " + config.getIpAddress() + ": "+ e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; if (oldScheduler != null) { oldScheduler.cancel(false); @@ -172,8 +170,7 @@ private void update() { } } } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { - logger.debug("Update failed, checking connection", e); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed, reconnecting..."); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed: " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; if (oldScheduler != null) { oldScheduler.cancel(false); @@ -204,8 +201,7 @@ private void push() { } } catch (InterruptedException | TimeoutException | ExecutionException | URISyntaxException e) { updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to update channel " + c.getName() + " on device!"); - logger.debug("Failed to update channel {} on device", c.getName(), e); + "Failed to update channel " + c.getName() + " on device: " + e.getMessage()); } }); } From 3021e06e7f6c899842f084c0c2cc5c8eea463b6b Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 31 Dec 2020 16:31:09 +0100 Subject: [PATCH 07/40] fix formatting Signed-off-by: Christian Schlipp --- .../wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 8caa041b62134..45aac812964d0 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -117,8 +117,9 @@ private void checkConnection() { public void handleCommand(ChannelUID channelUID, Command command) { if (command instanceof RefreshType) { State s = wlanThermoEsp32CommandHandler.getState(channelUID, data, settings); - if (s != null) + if (s != null) { updateState(channelUID, s); + } } else { if (wlanThermoEsp32CommandHandler.setState(channelUID, command, data)) { logger.debug("Data updated, pushing changes"); From 6356ac26707482ce6a377110fd5e793d92ba2f2d Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 31 Dec 2020 16:40:07 +0100 Subject: [PATCH 08/40] removed nullable config further improved logging Signed-off-by: Christian Schlipp --- .../WlanThermoExtendedConfiguration.java | 7 ++----- .../api/esp32/WlanThermoEsp32Handler.java | 11 ++++------- .../api/mini/WlanThermoMiniHandler.java | 10 +++------- .../api/nano/WlanThermoNanoV1Handler.java | 19 ++++++------------- 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoExtendedConfiguration.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoExtendedConfiguration.java index b8bf679961e55..8a11b3641e6e2 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoExtendedConfiguration.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoExtendedConfiguration.java @@ -13,7 +13,6 @@ package org.openhab.binding.wlanthermo.internal; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; /** * The {@link WlanThermoExtendedConfiguration} class contains fields mapping thing configuration parameters. @@ -26,15 +25,14 @@ public class WlanThermoExtendedConfiguration extends WlanThermoConfiguration { /** * Username of WlanThermo user. */ - private @Nullable String username; + private String username = ""; /** * Password of WlanThermo user. */ - private @Nullable String password; + private String password = ""; - @Nullable public String getUsername() { return username; } @@ -43,7 +41,6 @@ public void setUsername(String username) { this.username = username; } - @Nullable public String getPassword() { return password; } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 45aac812964d0..6d6b77ea4f65e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -72,15 +72,12 @@ public void initialize() { updateStatus(ThingStatus.UNKNOWN); try { - if (config.getUsername() != null && !config.getUsername().isEmpty() && config.getPassword() != null - && !config.getPassword().isEmpty()) { + if (!config.getUsername().isEmpty() && !config.getPassword().isEmpty()) { AuthenticationStore authStore = httpClient.getAuthenticationStore(); authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM, config.getUsername(), config.getPassword())); } scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); - - logger.debug("Finished initializing WlanThermo Nano!"); } catch (URISyntaxException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Failed to initialize WlanThermo Nano: " + e.getMessage()); @@ -102,9 +99,8 @@ private void checkConnection() { "WlanThermo not found under given address."); } } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { - logger.debug("Failed to connect.", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Could not connect to WlanThermo at " + config.getIpAddress() + ": "+ e.getMessage()); + "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; if (oldScheduler != null) { oldScheduler.cancel(false); @@ -171,7 +167,8 @@ private void update() { } } } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed: " + e.getMessage()); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Update failed: " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; if (oldScheduler != null) { oldScheduler.cancel(false); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index 3a439dd0b2c61..d074ff0c4c298 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -60,13 +60,10 @@ public WlanThermoMiniHandler(Thing thing, HttpClient httpClient) { @Override public void initialize() { - logger.debug("Start initializing WlanThermo Mini!"); config = getConfigAs(WlanThermoConfiguration.class); updateStatus(ThingStatus.UNKNOWN); scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); - - logger.debug("Finished initializing WlanThermo Mini!"); } private void checkConnection() { @@ -84,9 +81,8 @@ private void checkConnection() { "WlanThermo not found under given address."); } } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { - logger.debug("Failed to connect.", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Could not connect to WlanThermo at " + config.getIpAddress()); + "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; if (oldScheduler != null) { oldScheduler.cancel(false); @@ -127,8 +123,8 @@ private void update() { } } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { - logger.debug("Update failed, checking connection", e); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed, reconnecting..."); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Update failed: " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; if (oldScheduler != null) { oldScheduler.cancel(false); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 35663012f262e..5e3f52a73571a 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -67,24 +67,19 @@ public WlanThermoNanoV1Handler(Thing thing, HttpClient httpClient) { @Override public void initialize() { - logger.debug("Start initializing WlanThermo Nano!"); config = getConfigAs(WlanThermoExtendedConfiguration.class); updateStatus(ThingStatus.UNKNOWN); try { - if (config.getUsername() != null && !config.getUsername().isEmpty() && config.getPassword() != null - && !config.getPassword().isEmpty()) { + if (!config.getUsername().isEmpty() && !config.getPassword().isEmpty()) { AuthenticationStore authStore = httpClient.getAuthenticationStore(); authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM, config.getUsername(), config.getPassword())); } scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); - - logger.debug("Finished initializing WlanThermo Nano!"); } catch (URISyntaxException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Failed to initialize WlanThermo Nano!"); - logger.debug("Failed to initialize WlanThermo Nano!", e); + "Failed to initialize WlanThermo Nano: " + e.getMessage()); } } @@ -103,9 +98,8 @@ private void checkConnection() { "WlanThermo not found under given address."); } } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { - logger.debug("Failed to connect.", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Could not connect to WlanThermo at " + config.getIpAddress()); + "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; if (oldScheduler != null) { oldScheduler.cancel(false); @@ -155,8 +149,8 @@ private void update() { } } } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { - logger.debug("Update failed, checking connection", e); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed, reconnecting..."); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Update failed: " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; if (oldScheduler != null) { oldScheduler.cancel(false); @@ -187,8 +181,7 @@ private void push() { } } catch (InterruptedException | TimeoutException | ExecutionException | URISyntaxException e) { updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to update channel " + c.getName() + " on device!"); - logger.debug("Failed to update channel {} on device", c.getName(), e); + "Failed to update channel " + c.getName() + " on device: " + e.getMessage()); } }); } From 5855a565f6fb3de2edff5ba030b60a3fbb7ce64c Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Fri, 1 Jan 2021 11:11:04 +0100 Subject: [PATCH 09/40] Only log payload if response code != 200 Signed-off-by: Christian Schlipp --- .../wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java | 2 +- .../wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 6d6b77ea4f65e..9823abaccbaa8 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -184,7 +184,6 @@ private void push() { data.getChannel().forEach(c -> { try { String json = gson.toJson(c); - logger.debug("Pushing: {}", json); URI uri = config.getUri("/setchannels"); int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") .timeout(5, TimeUnit.SECONDS).send().getStatus(); @@ -194,6 +193,7 @@ private void push() { } else if (status != 200) { updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + c.getName() + " on device, Statuscode " + status + " on URI " + uri.toString()); + logger.debug("Payload sent: {}", json); } else { updateStatus(ThingStatus.ONLINE); } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 5e3f52a73571a..71cbbf98151b1 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -166,7 +166,6 @@ private void push() { data.getChannel().forEach(c -> { try { String json = gson.toJson(c); - logger.debug("Pushing: {}", json); URI uri = config.getUri("/setchannels"); int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") .timeout(5, TimeUnit.SECONDS).send().getStatus(); @@ -176,6 +175,7 @@ private void push() { } else if (status != 200) { updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + c.getName() + " on device, Statuscode " + status + " on URI " + uri.toString()); + logger.debug("Payload sent: {}", json); } else { updateStatus(ThingStatus.ONLINE); } From c76ecfa4f6bcf829e1f5ab85934b3b899e5f19d5 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Fri, 1 Jan 2021 14:04:48 +0100 Subject: [PATCH 10/40] fix compiler warnings Signed-off-by: Christian Schlipp --- .../esp32/WlanThermoEsp32CommandHandler.java | 29 +++++++++++------- .../api/esp32/WlanThermoEsp32Handler.java | 9 ++++++ .../mini/WlanThermoMiniCommandHandler.java | 18 +++++++---- .../nano/WlanThermoNanoV1CommandHandler.java | 30 +++++++++++++------ .../api/nano/WlanThermoNanoV1Handler.java | 3 ++ 5 files changed, 65 insertions(+), 24 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index 6e881d18fb35f..5f83359c27375 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -39,12 +39,13 @@ public class WlanThermoEsp32CommandHandler { public State getState(ChannelUID channelUID, Data data, Settings settings) { State state = null; - if (data == null || settings == null) { + String groupId = channelUID.getGroupId(); + if (groupId == null || data == null || settings == null) { return null; } System system = data.getSystem(); List channel = data.getChannel(); - if ("system".equals(channelUID.getGroupId()) && system != null) { + if ("system".equals(groupId) && system != null) { switch (channelUID.getIdWithoutGroup()) { case SYSTEM_SOC: if (system.getSoc() != null) { @@ -77,7 +78,7 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { break; } } else if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1; + int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; if (channel != null && channel.size() > 0 && channelId < channel.size()) { switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -165,9 +166,13 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { public boolean setState(ChannelUID channelUID, Command command, Data data) { boolean success = false; + String groupId = channelUID.getGroupId(); + if (groupId == null || data == null) { + return false; + } List channel = data.getChannel(); if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1; + int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; if (channel.size() > 0 && channelId < channel.size()) { switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -178,13 +183,13 @@ public boolean setState(ChannelUID channelUID, Command command, Data data) { break; case CHANNEL_MIN: if (command instanceof QuantityType) { - channel.get(channelId).setMin(((QuantityType) command).doubleValue()); + channel.get(channelId).setMin(((QuantityType) command).doubleValue()); success = true; } break; case CHANNEL_MAX: if (command instanceof QuantityType) { - channel.get(channelId).setMax(((QuantityType) command).doubleValue()); + channel.get(channelId).setMax(((QuantityType) command).doubleValue()); success = true; } break; @@ -226,15 +231,15 @@ public boolean setState(ChannelUID channelUID, Command command, Data data) { Pm pm = data.getPitmaster().getPm().get(0); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_PITMASTER_CHANNEL_ID: - pm.setChannel(((QuantityType) command).intValue()); + pm.setChannel(((QuantityType) command).intValue()); success = true; break; case CHANNEL_PITMASTER_PIDPROFILE: - pm.setPid(((QuantityType) command).intValue()); + pm.setPid(((QuantityType) command).intValue()); success = true; break; case CHANNEL_PITMASTER_SETPOINT: - pm.setSet(((QuantityType) command).doubleValue()); + pm.setSet(((QuantityType) command).doubleValue()); success = true; break; case CHANNEL_PITMASTER_STATE: @@ -252,9 +257,13 @@ public boolean setState(ChannelUID channelUID, Command command, Data data) { public String getTrigger(ChannelUID channelUID, Data data) { String trigger = null; + String groupId = channelUID.getGroupId(); + if (groupId == null || data == null) { + return null; + } List channel = data.getChannel(); if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1; + int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; if (channel.size() > 0 && channelId < channel.size()) { if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { if (channel.get(channelId).getTemp() != 999) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 9823abaccbaa8..c0e61f03cb983 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -137,6 +137,12 @@ private void update() { settings = gson.fromJson(json, Settings.class); logger.debug("Received at /settings: {}", json); + if (data == null || settings == null) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to parse Data and/or Settings values!"); + return; + } + // Update Channels if required Map properties = editProperties(); Boolean pmEnabled = settings.getFeatures().getBluetooth(); @@ -181,6 +187,9 @@ private void update() { } private void push() { + if (data == null) { + return; + } data.getChannel().forEach(c -> { try { String json = gson.toJson(c); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java index 6aae5c89d1466..0db8958ce1f27 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java @@ -34,7 +34,11 @@ public class WlanThermoMiniCommandHandler { public State getState(ChannelUID channelUID, App app) { State state = null; - if ("system".equals(channelUID.getGroupId())) { + String groupId = channelUID.getGroupId(); + if (groupId == null || app == null) { + return null; + } + if ("system".equals(groupId)) { switch (channelUID.getIdWithoutGroup()) { case WlanThermoBindingConstants.SYSTEM_CPU_TEMP: if (app.getCpuTemp() == null) { @@ -52,7 +56,7 @@ public State getState(ChannelUID channelUID, App app) { break; } } else if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())); + int channelId = Integer.parseInt(groupId.substring("channel".length())); if (channelId >= 0 && channelId <= 9) { Channel channel = app.getChannel(); if (channel == null) { @@ -104,9 +108,9 @@ public State getState(ChannelUID channelUID, App app) { } } else if (channelUID.getId().startsWith("pit")) { Pit pit; - if (channelUID.getGroupId().equals("pit1")) { + if (groupId.equals("pit1")) { pit = app.getPit(); - } else if (channelUID.getGroupId().equals("pit2")) { + } else if (groupId.equals("pit2")) { pit = app.getPit2(); } else { return UnDefType.UNDEF; @@ -140,8 +144,12 @@ public State getState(ChannelUID channelUID, App app) { public String getTrigger(ChannelUID channelUID, App app) { String trigger = null; + String groupId = channelUID.getGroupId(); + if (groupId == null || app == null) { + return null; + } if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1; + int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; if (channelId >= 0 && channelId <= 9) { Channel channel = app.getChannel(); if (channel == null) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index f7dec06182c13..2a9f667e4c216 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -39,9 +39,13 @@ public class WlanThermoNanoV1CommandHandler { public State getState(ChannelUID channelUID, Data data, Settings settings) { State state = null; + String groupId = channelUID.getGroupId(); + if (groupId == null || data == null || settings == null) { + return null; + } System system = data.getSystem(); List channel = data.getChannel(); - if ("system".equals(channelUID.getGroupId()) && system != null) { + if ("system".equals(groupId) && system != null) { switch (channelUID.getIdWithoutGroup()) { case SYSTEM_SOC: state = new DecimalType(system.getSoc()); @@ -66,7 +70,7 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { break; } } else if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1; + int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; if (channel.size() > 0 && channelId <= channel.size()) { switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -154,9 +158,13 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { public boolean setState(ChannelUID channelUID, Command command, Data data) { boolean success = false; + String groupId = channelUID.getGroupId(); + if (groupId == null || data == null) { + return false; + } List channel = data.getChannel(); if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1; + int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; if (channel.size() > 0 && channelId <= channel.size()) { switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -167,13 +175,13 @@ public boolean setState(ChannelUID channelUID, Command command, Data data) { break; case CHANNEL_MIN: if (command instanceof QuantityType) { - channel.get(channelId).setMin(((QuantityType) command).doubleValue()); + channel.get(channelId).setMin(((QuantityType) command).doubleValue()); success = true; } break; case CHANNEL_MAX: if (command instanceof QuantityType) { - channel.get(channelId).setMax(((QuantityType) command).doubleValue()); + channel.get(channelId).setMax(((QuantityType) command).doubleValue()); success = true; } break; @@ -215,15 +223,15 @@ public boolean setState(ChannelUID channelUID, Command command, Data data) { Pm pm = data.getPitmaster().getPm().get(0); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_PITMASTER_CHANNEL_ID: - pm.setChannel(((QuantityType) command).intValue()); + pm.setChannel(((QuantityType) command).intValue()); success = true; break; case CHANNEL_PITMASTER_PIDPROFILE: - pm.setPid(((QuantityType) command).intValue()); + pm.setPid(((QuantityType) command).intValue()); success = true; break; case CHANNEL_PITMASTER_SETPOINT: - pm.setSet(((QuantityType) command).doubleValue()); + pm.setSet(((QuantityType) command).doubleValue()); success = true; break; case CHANNEL_PITMASTER_STATE: @@ -241,9 +249,13 @@ public boolean setState(ChannelUID channelUID, Command command, Data data) { public String getTrigger(ChannelUID channelUID, Data data) { String trigger = null; + String groupId = channelUID.getGroupId(); + if (groupId == null || data == null) { + return null; + } List channel = data.getChannel(); if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(channelUID.getGroupId().substring("channel".length())) - 1; + int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; if (channel.size() > 0 && channelId <= channel.size()) { if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { if (channel.get(channelId).getTemp() != 999) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 71cbbf98151b1..962090d9aa815 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -163,6 +163,9 @@ private void update() { } private void push() { + if (data == null) { + return; + } data.getChannel().forEach(c -> { try { String json = gson.toJson(c); From db1da51cd9206457e0698940eb1a011df6b810b7 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Fri, 1 Jan 2021 15:00:02 +0100 Subject: [PATCH 11/40] fix channel naming Specify Quantity Type for Temperature and Power Channels Signed-off-by: Christian Schlipp --- .../esp32/WlanThermoEsp32CommandHandler.java | 29 ++++++++++++--- .../mini/WlanThermoMiniCommandHandler.java | 28 ++++++++++---- .../nano/WlanThermoNanoV1CommandHandler.java | 29 ++++++++++++--- .../thing/channel-group-types-esp32.xml | 6 +-- .../resources/OH-INF/thing/channel-types.xml | 37 +++++++++---------- .../OH-INF/thing/thing-types-esp32.xml | 4 +- .../OH-INF/thing/thing-types-mini.xml | 4 +- 7 files changed, 91 insertions(+), 46 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index 5f83359c27375..a53f9736ad926 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -18,12 +18,18 @@ import java.math.BigInteger; import java.util.List; +import javax.measure.Unit; +import javax.measure.quantity.Temperature; + import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Channel; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Data; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Pm; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.System; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings.Settings; import org.openhab.core.library.types.*; +import org.openhab.core.library.unit.ImperialUnits; +import org.openhab.core.library.unit.SIUnits; +import org.openhab.core.library.unit.Units; import org.openhab.core.thing.ChannelUID; import org.openhab.core.types.Command; import org.openhab.core.types.State; @@ -39,13 +45,24 @@ public class WlanThermoEsp32CommandHandler { public State getState(ChannelUID channelUID, Data data, Settings settings) { State state = null; + String groupId = channelUID.getGroupId(); if (groupId == null || data == null || settings == null) { return null; } + System system = data.getSystem(); + + Unit unit; + if (system.getUnit().equals("F")) { + unit = ImperialUnits.FAHRENHEIT; + } else { + // Default to Celsius + unit = SIUnits.CELSIUS; + } + List channel = data.getChannel(); - if ("system".equals(groupId) && system != null) { + if ("system".equals(groupId)) { switch (channelUID.getIdWithoutGroup()) { case SYSTEM_SOC: if (system.getSoc() != null) { @@ -74,7 +91,7 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { } break; case SYSTEM_RSSI: - state = new DecimalType(system.getRssi()); + state = new QuantityType<>(system.getRssi(), Units.DECIBEL_MILLIWATTS); break; } } else if (channelUID.getId().startsWith("channel")) { @@ -91,14 +108,14 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { if (channel.get(channelId).getTemp() == 999.0) { state = UnDefType.UNDEF; } else { - state = new DecimalType(channel.get(channelId).getTemp()); + state = new QuantityType<>(channel.get(channelId).getTemp(), unit); } break; case CHANNEL_MIN: - state = new DecimalType(channel.get(channelId).getMin()); + state = new QuantityType<>(channel.get(channelId).getMin(), unit); break; case CHANNEL_MAX: - state = new DecimalType(channel.get(channelId).getMax()); + state = new QuantityType<>(channel.get(channelId).getMax(), unit); break; case CHANNEL_ALARM_DEVICE: state = OnOffType.from(BigInteger.valueOf(channel.get(channelId).getAlarm()).testBit(1)); @@ -152,7 +169,7 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { state = new DecimalType(pm.getValue()); break; case CHANNEL_PITMASTER_SETPOINT: - state = new DecimalType(pm.getSet()); + state = new QuantityType<>(pm.getSet(), unit); break; case CHANNEL_PITMASTER_STATE: state = new StringType(pm.getTyp()); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java index 0db8958ce1f27..b4f72889e8044 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java @@ -14,12 +14,14 @@ import java.awt.*; +import javax.measure.Unit; +import javax.measure.quantity.Temperature; + import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; import org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin.*; -import org.openhab.core.library.types.DecimalType; -import org.openhab.core.library.types.HSBType; -import org.openhab.core.library.types.OnOffType; -import org.openhab.core.library.types.StringType; +import org.openhab.core.library.types.*; +import org.openhab.core.library.unit.ImperialUnits; +import org.openhab.core.library.unit.SIUnits; import org.openhab.core.thing.ChannelUID; import org.openhab.core.types.State; import org.openhab.core.types.UnDefType; @@ -34,10 +36,20 @@ public class WlanThermoMiniCommandHandler { public State getState(ChannelUID channelUID, App app) { State state = null; + String groupId = channelUID.getGroupId(); if (groupId == null || app == null) { return null; } + + Unit unit; + if (app.getTempUnit().equals("fahrenheit")) { + unit = ImperialUnits.FAHRENHEIT; + } else { + // Default to Celsius + unit = SIUnits.CELSIUS; + } + if ("system".equals(groupId)) { switch (channelUID.getIdWithoutGroup()) { case WlanThermoBindingConstants.SYSTEM_CPU_TEMP: @@ -71,14 +83,14 @@ public State getState(ChannelUID channelUID, App app) { if (data.getState().equals("er")) { state = UnDefType.UNDEF; } else { - state = new DecimalType(data.getTemp()); + state = new QuantityType<>(data.getTemp(), unit); } break; case WlanThermoBindingConstants.CHANNEL_MIN: - state = new DecimalType(data.getTempMin()); + state = new QuantityType<>(data.getTempMin(), unit); break; case WlanThermoBindingConstants.CHANNEL_MAX: - state = new DecimalType(data.getTempMax()); + state = new QuantityType<>(data.getTempMax(), unit); break; case WlanThermoBindingConstants.CHANNEL_ALARM_DEVICE: state = OnOffType.from(data.getAlert()); @@ -126,7 +138,7 @@ public State getState(ChannelUID channelUID, App app) { state = new DecimalType(pit.getCurrent()); break; case WlanThermoBindingConstants.CHANNEL_PITMASTER_SETPOINT: - state = new DecimalType(pit.getSetpoint()); + state = new QuantityType<>(pit.getSetpoint(), unit); break; case WlanThermoBindingConstants.CHANNEL_PITMASTER_DUTY_CYCLE: state = new DecimalType(pit.getControlOut()); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index 2a9f667e4c216..93d3c8cded6f5 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -18,12 +18,18 @@ import java.math.BigInteger; import java.util.List; +import javax.measure.Unit; +import javax.measure.quantity.Temperature; + import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Channel; import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Data; import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Pm; import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.System; import org.openhab.binding.wlanthermo.internal.api.nano.dto.settings.Settings; import org.openhab.core.library.types.*; +import org.openhab.core.library.unit.ImperialUnits; +import org.openhab.core.library.unit.SIUnits; +import org.openhab.core.library.unit.Units; import org.openhab.core.thing.ChannelUID; import org.openhab.core.types.Command; import org.openhab.core.types.State; @@ -39,13 +45,24 @@ public class WlanThermoNanoV1CommandHandler { public State getState(ChannelUID channelUID, Data data, Settings settings) { State state = null; + String groupId = channelUID.getGroupId(); if (groupId == null || data == null || settings == null) { return null; } + System system = data.getSystem(); + + Unit unit; + if (system.getUnit().equals("F")) { + unit = ImperialUnits.FAHRENHEIT; + } else { + // Default to Celsius + unit = SIUnits.CELSIUS; + } + List channel = data.getChannel(); - if ("system".equals(groupId) && system != null) { + if ("system".equals(groupId)) { switch (channelUID.getIdWithoutGroup()) { case SYSTEM_SOC: state = new DecimalType(system.getSoc()); @@ -66,7 +83,7 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { } break; case SYSTEM_RSSI: - state = new DecimalType(system.getRssi()); + state = new QuantityType<>(system.getRssi(), Units.DECIBEL_MILLIWATTS); break; } } else if (channelUID.getId().startsWith("channel")) { @@ -83,14 +100,14 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { if (channel.get(channelId).getTemp() == 999.0) { state = UnDefType.UNDEF; } else { - state = new DecimalType(channel.get(channelId).getTemp()); + state = new QuantityType<>(channel.get(channelId).getTemp(), unit); } break; case CHANNEL_MIN: - state = new DecimalType(channel.get(channelId).getMin()); + state = new QuantityType<>(channel.get(channelId).getMin(), unit); break; case CHANNEL_MAX: - state = new DecimalType(channel.get(channelId).getMax()); + state = new QuantityType<>(channel.get(channelId).getMax(), unit); break; case CHANNEL_ALARM_DEVICE: state = OnOffType.from(BigInteger.valueOf(channel.get(channelId).getAlarm()).testBit(1)); @@ -144,7 +161,7 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { state = new DecimalType(pm.getValue()); break; case CHANNEL_PITMASTER_SETPOINT: - state = new DecimalType(pm.getSet()); + state = new QuantityType<>(pm.getSet(), unit); break; case CHANNEL_PITMASTER_STATE: state = new StringType(pm.getTyp()); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-esp32.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-esp32.xml index eaa05855f4eba..f9b207c5206fb 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-esp32.xml +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-esp32.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd"> - + This group contains all system channels @@ -17,7 +17,7 @@ - + Sensor @@ -37,7 +37,7 @@ - + Sensor diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml index 60fcad0c3987d..75e8e8d1a11bf 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml @@ -11,20 +11,20 @@ String - + Text String - + Text String - + Text @@ -115,7 +115,7 @@ String - + Colorpicker @@ -135,7 +135,7 @@ String - + Colorpicker @@ -164,65 +164,64 @@ Color - + Colorpicker String - + Text Switch - + Number:Temperature - + Temperature Number - + Switch - + Number - + String - + - Number - + @@ -234,15 +233,15 @@ Number:Temperature - + Temperature Number - - + + @@ -253,7 +252,7 @@ - Number + Number:Power Text diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-esp32.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-esp32.xml index e0718f6ed5ff7..fbb08037c8ef0 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-esp32.xml +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-esp32.xml @@ -4,8 +4,8 @@ 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"> - - WlanThermo device with ESP32 processor, such as Mini V2 (ESP32), Nano V3, Link V1 + + ESP32 processor, such as Mini V2 (ESP32), Nano V3, Link V1 ]]> diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-mini.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-mini.xml index 9e2c260d2fa4e..c0946abfd61f9 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-mini.xml +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/thing-types-mini.xml @@ -6,8 +6,8 @@ - - WlanThermo Mini with Raspberry Pi processor, such as Mini V1/V2 + + Raspberry Pi processor, such as Mini V1/V2 ]]> From ebe40119d018ca06ae6ae62abd3bd4ceb904b10f Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Fri, 1 Jan 2021 16:44:29 +0100 Subject: [PATCH 12/40] fixed checkstyle error Signed-off-by: Christian Schlipp --- .../wlanthermo/internal/api/mini/WlanThermoMiniHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index d074ff0c4c298..920c1db14b00d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -119,7 +119,6 @@ private void update() { triggerChannel(channel.getUID(), trigger); } } - } } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { From c675da78571adef398e029f3b19d71bd371539e5 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Fri, 1 Jan 2021 18:14:23 +0100 Subject: [PATCH 13/40] Add license headers Signed-off-by: Christian Schlipp --- .../internal/api/esp32/dto/data/Channel.java | 12 ++++++++++++ .../wlanthermo/internal/api/esp32/dto/data/Data.java | 12 ++++++++++++ .../internal/api/esp32/dto/data/Pitmaster.java | 12 ++++++++++++ .../wlanthermo/internal/api/esp32/dto/data/Pm.java | 12 ++++++++++++ .../internal/api/esp32/dto/data/System.java | 12 ++++++++++++ .../internal/api/esp32/dto/settings/Api.java | 12 ++++++++++++ .../internal/api/esp32/dto/settings/Device.java | 12 ++++++++++++ .../internal/api/esp32/dto/settings/Display.java | 12 ++++++++++++ .../internal/api/esp32/dto/settings/Ext.java | 12 ++++++++++++ .../internal/api/esp32/dto/settings/Features.java | 12 ++++++++++++ .../internal/api/esp32/dto/settings/Iot.java | 12 ++++++++++++ .../internal/api/esp32/dto/settings/Notes.java | 12 ++++++++++++ .../internal/api/esp32/dto/settings/Pid.java | 12 ++++++++++++ .../internal/api/esp32/dto/settings/Sensor.java | 12 ++++++++++++ .../internal/api/esp32/dto/settings/Settings.java | 12 ++++++++++++ .../internal/api/esp32/dto/settings/System.java | 12 ++++++++++++ 16 files changed, 192 insertions(+) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Channel.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Channel.java index 794803db4890e..0697ac430fc0d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Channel.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Channel.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Data.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Data.java index be4bab815c866..44d9fa82b6568 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Data.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Data.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pitmaster.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pitmaster.java index 22c3450c1283d..c218aaf3c2874 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pitmaster.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pitmaster.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pm.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pm.java index b6487fdb4b4d0..0ac5ac604fefa 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pm.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pm.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/System.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/System.java index 6398f6bc29c60..8d5724697c27e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/System.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/System.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Api.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Api.java index edd4a2f622e20..f351fff54a42c 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Api.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Api.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Device.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Device.java index 262d16897a60e..e1f10dc7a58b4 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Device.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Device.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Display.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Display.java index bec07f4acceed..a49e3671b1023 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Display.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Display.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Ext.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Ext.java index 06f022cd01906..100a2e28e3325 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Ext.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Ext.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Features.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Features.java index 1b884c6b3bba7..7b0a332cb4987 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Features.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Features.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Iot.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Iot.java index f16e47c23ff38..c52e051753d6f 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Iot.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Iot.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Notes.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Notes.java index e743328fb18c7..1586e5ff928a7 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Notes.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Notes.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Pid.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Pid.java index d0a54b33c3bc5..3e193c31ed79c 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Pid.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Pid.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Sensor.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Sensor.java index d660576f35d74..3c488bae227a3 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Sensor.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Sensor.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Settings.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Settings.java index 165a527eb4906..1bcfa2365fa9e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Settings.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Settings.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/System.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/System.java index 0a755783af285..156723dacc8dd 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/System.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/System.java @@ -1,3 +1,15 @@ +/** + * Copyright (c) 2010-2020 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; From 65628c952508831cf4eedea0f2250001f60b2c24 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sun, 3 Jan 2021 16:00:21 +0100 Subject: [PATCH 14/40] Rebase & Update License Headers Signed-off-by: Christian Schlipp --- .../wlanthermo/internal/WlanThermoExtendedConfiguration.java | 2 +- .../binding/wlanthermo/internal/api/esp32/UtilEsp32.java | 2 +- .../internal/api/esp32/WlanThermoEsp32CommandHandler.java | 2 +- .../wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java | 2 +- .../wlanthermo/internal/api/esp32/dto/data/Channel.java | 3 +-- .../binding/wlanthermo/internal/api/esp32/dto/data/Data.java | 3 +-- .../wlanthermo/internal/api/esp32/dto/data/Pitmaster.java | 3 +-- .../binding/wlanthermo/internal/api/esp32/dto/data/Pm.java | 3 +-- .../binding/wlanthermo/internal/api/esp32/dto/data/System.java | 3 +-- .../wlanthermo/internal/api/esp32/dto/settings/Api.java | 3 +-- .../wlanthermo/internal/api/esp32/dto/settings/Device.java | 3 +-- .../wlanthermo/internal/api/esp32/dto/settings/Display.java | 3 +-- .../wlanthermo/internal/api/esp32/dto/settings/Ext.java | 3 +-- .../wlanthermo/internal/api/esp32/dto/settings/Features.java | 3 +-- .../wlanthermo/internal/api/esp32/dto/settings/Iot.java | 3 +-- .../wlanthermo/internal/api/esp32/dto/settings/Notes.java | 3 +-- .../wlanthermo/internal/api/esp32/dto/settings/Pid.java | 3 +-- .../wlanthermo/internal/api/esp32/dto/settings/Sensor.java | 3 +-- .../wlanthermo/internal/api/esp32/dto/settings/Settings.java | 3 +-- .../wlanthermo/internal/api/esp32/dto/settings/System.java | 3 +-- 20 files changed, 20 insertions(+), 36 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoExtendedConfiguration.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoExtendedConfiguration.java index 8a11b3641e6e2..c78d341881b00 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoExtendedConfiguration.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoExtendedConfiguration.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java index 0f1f7ae6132fe..16d292021a8db 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index a53f9736ad926..a9cc28770f465 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index c0e61f03cb983..4d3fffbf6fe0d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Channel.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Channel.java index 0697ac430fc0d..3301918454dcf 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Channel.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Channel.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; import com.google.gson.annotations.Expose; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Data.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Data.java index 44d9fa82b6568..470d8801a0f2a 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Data.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Data.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pitmaster.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pitmaster.java index c218aaf3c2874..3d6f542006676 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pitmaster.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pitmaster.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pm.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pm.java index 0ac5ac604fefa..27bca17fa7cc0 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pm.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/Pm.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; import com.google.gson.annotations.Expose; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/System.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/System.java index 8d5724697c27e..6a1286008ad7c 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/System.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/data/System.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.data; import com.google.gson.annotations.Expose; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Api.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Api.java index f351fff54a42c..64fffdaac38c0 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Api.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Api.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Device.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Device.java index e1f10dc7a58b4..95552be395aef 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Device.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Device.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Display.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Display.java index a49e3671b1023..205977cf78cb2 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Display.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Display.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Ext.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Ext.java index 100a2e28e3325..985ec0a7a76b3 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Ext.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Ext.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Features.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Features.java index 7b0a332cb4987..bd4b2d39d1c3b 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Features.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Features.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Iot.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Iot.java index c52e051753d6f..e3033a497080e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Iot.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Iot.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Notes.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Notes.java index 1586e5ff928a7..f4d5cc54b1555 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Notes.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Notes.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Pid.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Pid.java index 3e193c31ed79c..512545110a86e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Pid.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Pid.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Sensor.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Sensor.java index 3c488bae227a3..e2dc02279ca1e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Sensor.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Sensor.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Settings.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Settings.java index 1bcfa2365fa9e..dc125086165b4 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Settings.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/Settings.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import java.util.List; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/System.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/System.java index 156723dacc8dd..e10af5d64ed13 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/System.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/dto/settings/System.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010-2020 Contributors to the openHAB project + * Copyright (c) 2010-2021 Contributors to the openHAB project * * See the NOTICE file(s) distributed with this work for additional * information. @@ -10,7 +10,6 @@ * * SPDX-License-Identifier: EPL-2.0 */ - package org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings; import com.google.gson.annotations.Expose; From d365c2394c4bdbb05a5b2df3823137f1b15a6ab4 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sun, 3 Jan 2021 16:39:05 +0100 Subject: [PATCH 15/40] Fix scheduled task not cancelled on dispose Revert to default scheduler Signed-off-by: Christian Schlipp --- .../internal/api/esp32/WlanThermoEsp32Handler.java | 5 +---- .../internal/api/mini/{dto/builtin => }/UtilMini.java | 2 +- .../wlanthermo/internal/api/mini/WlanThermoMiniHandler.java | 6 +----- .../internal/api/nano/WlanThermoNanoV1Handler.java | 6 +----- 4 files changed, 4 insertions(+), 15 deletions(-) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/{dto/builtin => }/UtilMini.java (97%) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 4d3fffbf6fe0d..6969f57444dec 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -28,7 +28,6 @@ import org.openhab.binding.wlanthermo.internal.WlanThermoExtendedConfiguration; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Data; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings.Settings; -import org.openhab.core.common.ThreadPoolManager; import org.openhab.core.thing.*; import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.types.Command; @@ -55,8 +54,6 @@ public class WlanThermoEsp32Handler extends BaseThingHandler { private WlanThermoEsp32CommandHandler wlanThermoEsp32CommandHandler = new WlanThermoEsp32CommandHandler(); private final HttpClient httpClient; private @Nullable ScheduledFuture pollingScheduler; - private final ScheduledExecutorService scheduler = ThreadPoolManager - .getScheduledPool(WlanThermoBindingConstants.WLANTHERMO_THREAD_POOL); private final Gson gson = new Gson(); private @Nullable Data data = new Data(); private @Nullable Settings settings = new Settings(); @@ -77,7 +74,7 @@ public void initialize() { authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM, config.getUsername(), config.getPassword())); } - scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); + pollingScheduler = scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); } catch (URISyntaxException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Failed to initialize WlanThermo Nano: " + e.getMessage()); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/UtilMini.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/UtilMini.java similarity index 97% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/UtilMini.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/UtilMini.java index f538d86f6e11c..7e47883e1c2ec 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/dto/builtin/UtilMini.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/UtilMini.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin; +package org.openhab.binding.wlanthermo.internal.api.mini; import java.util.HashMap; import java.util.Map; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index 920c1db14b00d..03ee80d516003 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -18,10 +18,8 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; -import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; import org.openhab.binding.wlanthermo.internal.WlanThermoConfiguration; import org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin.App; -import org.openhab.core.common.ThreadPoolManager; import org.openhab.core.thing.*; import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.types.Command; @@ -48,8 +46,6 @@ public class WlanThermoMiniHandler extends BaseThingHandler { private WlanThermoConfiguration config = new WlanThermoConfiguration(); private final HttpClient httpClient; private @Nullable ScheduledFuture pollingScheduler; - private final ScheduledExecutorService scheduler = ThreadPoolManager - .getScheduledPool(WlanThermoBindingConstants.WLANTHERMO_THREAD_POOL); private final Gson gson = new Gson(); private @Nullable App app = new App(); @@ -63,7 +59,7 @@ public void initialize() { config = getConfigAs(WlanThermoConfiguration.class); updateStatus(ThingStatus.UNKNOWN); - scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); + pollingScheduler = scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); } private void checkConnection() { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 962090d9aa815..5491cd9dd5a7b 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -23,11 +23,9 @@ import org.eclipse.jetty.client.api.AuthenticationStore; import org.eclipse.jetty.client.util.DigestAuthentication; import org.eclipse.jetty.client.util.StringContentProvider; -import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; import org.openhab.binding.wlanthermo.internal.WlanThermoExtendedConfiguration; import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Data; import org.openhab.binding.wlanthermo.internal.api.nano.dto.settings.Settings; -import org.openhab.core.common.ThreadPoolManager; import org.openhab.core.thing.*; import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.types.Command; @@ -54,8 +52,6 @@ public class WlanThermoNanoV1Handler extends BaseThingHandler { private WlanThermoNanoV1CommandHandler wlanThermoNanoV1CommandHandler = new WlanThermoNanoV1CommandHandler(); private final HttpClient httpClient; private @Nullable ScheduledFuture pollingScheduler; - private final ScheduledExecutorService scheduler = ThreadPoolManager - .getScheduledPool(WlanThermoBindingConstants.WLANTHERMO_THREAD_POOL); private final Gson gson = new Gson(); private @Nullable Data data = new Data(); private @Nullable Settings settings = new Settings(); @@ -76,7 +72,7 @@ public void initialize() { authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM, config.getUsername(), config.getPassword())); } - scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); + pollingScheduler = scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); } catch (URISyntaxException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Failed to initialize WlanThermo Nano: " + e.getMessage()); From aff5cb5d1d4586abbf71161d45993b63d09ab438 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Mon, 4 Jan 2021 22:22:08 +0100 Subject: [PATCH 16/40] Retrigger Jenkins build Signed-off-by: Christian Schlipp --- .../wlanthermo/internal/api/mini/WlanThermoMiniHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index 03ee80d516003..90619c528a152 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -89,12 +89,12 @@ private void checkConnection() { @Override public void handleCommand(ChannelUID channelUID, Command command) { + // Mini is read only! if (command instanceof RefreshType) { State s = wlanThermoMiniCommandHandler.getState(channelUID, app); if (s != null) updateState(channelUID, s); } - // Mini is read only! } private void update() { From 609d21312e7597805de74b705a7ffd9d94615c2b Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sat, 9 Jan 2021 12:26:46 +0100 Subject: [PATCH 17/40] fix constants Signed-off-by: Christian Schlipp --- .../internal/WlanThermoBindingConstants.java | 9 +++++ .../esp32/WlanThermoEsp32CommandHandler.java | 34 +++++++---------- .../mini/WlanThermoMiniCommandHandler.java | 38 +++++++++---------- .../nano/WlanThermoNanoV1CommandHandler.java | 34 +++++++---------- 4 files changed, 55 insertions(+), 60 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java index 6b06338ae4248..42632649c6112 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java @@ -13,6 +13,7 @@ package org.openhab.binding.wlanthermo.internal; import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.core.library.types.DecimalType; import org.openhab.core.thing.ThingTypeUID; /** @@ -67,6 +68,9 @@ public class WlanThermoBindingConstants { public static final String CHANNEL_COLOR = "color"; public static final String CHANNEL_COLOR_NAME = "color_name"; + public static final String CHANNEL_PITMASTER_PREFIX = "pit"; + public static final String CHANNEL_PITMASTER_1 = "pit1"; + public static final String CHANNEL_PITMASTER_2 = "pit2"; public static final String CHANNEL_PITMASTER_ENABLED = "enabled"; // Mini public static final String CHANNEL_PITMASTER_CURRENT = "current"; // Mini public static final String CHANNEL_PITMASTER_SETPOINT = "setpoint"; // Mini+Nano @@ -79,4 +83,9 @@ public class WlanThermoBindingConstants { public static final String TRIGGER_ALARM_OFF = "OFF"; public static final String TRIGGER_ALARM_MIN = "MIN"; public static final String TRIGGER_ALARM_MAX = "MAX"; + + public static final DecimalType SIGNAL_STRENGTH_4 = new DecimalType(4); + public static final DecimalType SIGNAL_STRENGTH_3 = new DecimalType(3); + public static final DecimalType SIGNAL_STRENGTH_2 = new DecimalType(2); + public static final DecimalType SIGNAL_STRENGTH_1 = new DecimalType(1); } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index a9cc28770f465..23110b2a73109 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -53,16 +53,10 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { System system = data.getSystem(); - Unit unit; - if (system.getUnit().equals("F")) { - unit = ImperialUnits.FAHRENHEIT; - } else { - // Default to Celsius - unit = SIUnits.CELSIUS; - } + Unit unit = "F".equals(system.getUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; List channel = data.getChannel(); - if ("system".equals(groupId)) { + if (SYSTEM.equals(groupId)) { switch (channelUID.getIdWithoutGroup()) { case SYSTEM_SOC: if (system.getSoc() != null) { @@ -81,21 +75,21 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { case SYSTEM_RSSI_SIGNALSTRENGTH: int dbm = system.getRssi(); if (dbm >= -80) { - state = new DecimalType(4); + state = SIGNAL_STRENGTH_4; } else if (dbm >= -95) { - state = new DecimalType(3); + state = SIGNAL_STRENGTH_3; } else if (dbm >= -105) { - state = new DecimalType(2); + state = SIGNAL_STRENGTH_2; } else { - state = new DecimalType(1); + state = SIGNAL_STRENGTH_1; } break; case SYSTEM_RSSI: state = new QuantityType<>(system.getRssi(), Units.DECIBEL_MILLIWATTS); break; } - } else if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; + } else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { + int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; if (channel != null && channel.size() > 0 && channelId < channel.size()) { switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -154,7 +148,7 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { break; } } - } else if (channelUID.getId().startsWith("pit1")) { + } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_1)) { if (data.getPitmaster() != null && data.getPitmaster().getPm() != null && data.getPitmaster().getPm().size() > 0) { Pm pm = data.getPitmaster().getPm().get(0); @@ -188,8 +182,8 @@ public boolean setState(ChannelUID channelUID, Command command, Data data) { return false; } List channel = data.getChannel(); - if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; + if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { + int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; if (channel.size() > 0 && channelId < channel.size()) { switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -242,7 +236,7 @@ public boolean setState(ChannelUID channelUID, Command command, Data data) { break; } } - } else if (channelUID.getId().equals("pit1")) { + } else if (channelUID.getId().equals(CHANNEL_PITMASTER_1)) { if (data.getPitmaster() != null && data.getPitmaster().getPm() != null && data.getPitmaster().getPm().size() > 0) { Pm pm = data.getPitmaster().getPm().get(0); @@ -279,8 +273,8 @@ public String getTrigger(ChannelUID channelUID, Data data) { return null; } List channel = data.getChannel(); - if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; + if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { + int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; if (channel.size() > 0 && channelId < channel.size()) { if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { if (channel.get(channelId).getTemp() != 999) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java index b4f72889e8044..5dd3be3d4cc14 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.wlanthermo.internal.api.mini; +import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.*; + import java.awt.*; import javax.measure.Unit; @@ -34,6 +36,8 @@ */ public class WlanThermoMiniCommandHandler { + public static final String ERROR = "er"; + public State getState(ChannelUID channelUID, App app) { State state = null; @@ -42,15 +46,9 @@ public State getState(ChannelUID channelUID, App app) { return null; } - Unit unit; - if (app.getTempUnit().equals("fahrenheit")) { - unit = ImperialUnits.FAHRENHEIT; - } else { - // Default to Celsius - unit = SIUnits.CELSIUS; - } + Unit unit = "fahrenheit".equals(app.getTempUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; - if ("system".equals(groupId)) { + if (SYSTEM.equals(groupId)) { switch (channelUID.getIdWithoutGroup()) { case WlanThermoBindingConstants.SYSTEM_CPU_TEMP: if (app.getCpuTemp() == null) { @@ -67,8 +65,8 @@ public State getState(ChannelUID channelUID, App app) { } break; } - } else if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(groupId.substring("channel".length())); + } else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { + int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())); if (channelId >= 0 && channelId <= 9) { Channel channel = app.getChannel(); if (channel == null) { @@ -80,7 +78,7 @@ public State getState(ChannelUID channelUID, App app) { state = new StringType(data.getName()); break; case WlanThermoBindingConstants.CHANNEL_TEMP: - if (data.getState().equals("er")) { + if (data.getState().equals(ERROR)) { state = UnDefType.UNDEF; } else { state = new QuantityType<>(data.getTemp(), unit); @@ -96,14 +94,14 @@ public State getState(ChannelUID channelUID, App app) { state = OnOffType.from(data.getAlert()); break; case WlanThermoBindingConstants.CHANNEL_ALARM_OPENHAB_HIGH: - if (!data.getState().equals("er") && data.getTemp() > data.getTempMax()) { + if (!data.getState().equals(ERROR) && data.getTemp() > data.getTempMax()) { state = OnOffType.ON; } else { state = OnOffType.OFF; } break; case WlanThermoBindingConstants.CHANNEL_ALARM_OPENHAB_LOW: - if (!data.getState().equals("er") && data.getTemp() < data.getTempMin()) { + if (!data.getState().equals(ERROR) && data.getTemp() < data.getTempMin()) { state = OnOffType.ON; } else { state = OnOffType.OFF; @@ -118,11 +116,11 @@ public State getState(ChannelUID channelUID, App app) { break; } } - } else if (channelUID.getId().startsWith("pit")) { + } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_PREFIX)) { Pit pit; - if (groupId.equals("pit1")) { + if (groupId.equals(CHANNEL_PITMASTER_1)) { pit = app.getPit(); - } else if (groupId.equals("pit2")) { + } else if (groupId.equals(CHANNEL_PITMASTER_2)) { pit = app.getPit2(); } else { return UnDefType.UNDEF; @@ -160,8 +158,8 @@ public String getTrigger(ChannelUID channelUID, App app) { if (groupId == null || app == null) { return null; } - if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; + if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { + int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; if (channelId >= 0 && channelId <= 9) { Channel channel = app.getChannel(); if (channel == null) { @@ -169,8 +167,8 @@ public String getTrigger(ChannelUID channelUID, App app) { } Data data = channel.getData(channelId); switch (channelUID.getIdWithoutGroup()) { - case "alarm_openhab": - if (!data.getState().equals("er")) { + case CHANNEL_ALARM_OPENHAB: + if (!data.getState().equals(ERROR)) { if (data.getTemp() > data.getTempMax()) { trigger = WlanThermoBindingConstants.TRIGGER_ALARM_MAX; } else if (data.getTemp() < data.getTempMin()) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index 93d3c8cded6f5..253fde8038792 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -53,16 +53,10 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { System system = data.getSystem(); - Unit unit; - if (system.getUnit().equals("F")) { - unit = ImperialUnits.FAHRENHEIT; - } else { - // Default to Celsius - unit = SIUnits.CELSIUS; - } + Unit unit = "F".equals(system.getUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; List channel = data.getChannel(); - if ("system".equals(groupId)) { + if (SYSTEM.equals(groupId)) { switch (channelUID.getIdWithoutGroup()) { case SYSTEM_SOC: state = new DecimalType(system.getSoc()); @@ -73,21 +67,21 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { case SYSTEM_RSSI_SIGNALSTRENGTH: int dbm = system.getRssi(); if (dbm >= -80) { - state = new DecimalType(4); + state = SIGNAL_STRENGTH_4; } else if (dbm >= -95) { - state = new DecimalType(3); + state = SIGNAL_STRENGTH_3; } else if (dbm >= -105) { - state = new DecimalType(2); + state = SIGNAL_STRENGTH_2; } else { - state = new DecimalType(1); + state = SIGNAL_STRENGTH_1; } break; case SYSTEM_RSSI: state = new QuantityType<>(system.getRssi(), Units.DECIBEL_MILLIWATTS); break; } - } else if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; + } else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { + int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; if (channel.size() > 0 && channelId <= channel.size()) { switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -146,7 +140,7 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { break; } } - } else if (channelUID.getId().startsWith("pit1")) { + } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_1)) { if (data.getPitmaster() != null && data.getPitmaster().getPm() != null && data.getPitmaster().getPm().size() > 0) { Pm pm = data.getPitmaster().getPm().get(0); @@ -180,8 +174,8 @@ public boolean setState(ChannelUID channelUID, Command command, Data data) { return false; } List channel = data.getChannel(); - if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; + if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { + int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; if (channel.size() > 0 && channelId <= channel.size()) { switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -234,7 +228,7 @@ public boolean setState(ChannelUID channelUID, Command command, Data data) { break; } } - } else if (channelUID.getId().equals("pit1")) { + } else if (channelUID.getId().equals(CHANNEL_PITMASTER_1)) { if (data.getPitmaster() != null && data.getPitmaster().getPm() != null && data.getPitmaster().getPm().size() > 0) { Pm pm = data.getPitmaster().getPm().get(0); @@ -271,8 +265,8 @@ public String getTrigger(ChannelUID channelUID, Data data) { return null; } List channel = data.getChannel(); - if (channelUID.getId().startsWith("channel")) { - int channelId = Integer.parseInt(groupId.substring("channel".length())) - 1; + if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { + int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; if (channel.size() > 0 && channelId <= channel.size()) { if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { if (channel.get(channelId).getTemp() != 999) { From 6f1f5e95b09eb675b431d87e333149fcf9a0a72f Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sat, 9 Jan 2021 12:50:39 +0100 Subject: [PATCH 18/40] make Util classes NonNullByDefault Make CommandHandlers static Signed-off-by: Christian Schlipp --- .../binding/wlanthermo/internal/api/esp32/UtilEsp32.java | 3 +++ .../api/esp32/WlanThermoEsp32CommandHandler.java | 6 +++--- .../internal/api/esp32/WlanThermoEsp32Handler.java | 9 ++++----- .../binding/wlanthermo/internal/api/mini/UtilMini.java | 3 +++ .../internal/api/mini/WlanThermoMiniCommandHandler.java | 4 ++-- .../internal/api/mini/WlanThermoMiniHandler.java | 7 +++---- .../binding/wlanthermo/internal/api/nano/UtilNano.java | 3 +++ .../api/nano/WlanThermoNanoV1CommandHandler.java | 6 +++--- .../internal/api/nano/WlanThermoNanoV1Handler.java | 9 ++++----- 9 files changed, 28 insertions(+), 22 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java index 16d292021a8db..9af2faf529d3b 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java @@ -15,11 +15,14 @@ import java.util.HashMap; import java.util.Map; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * The {@link UtilEsp32} class provides conversion functions for the WlanThermo Nano V3 * * @author Christian Schlipp - Initial contribution */ +@NonNullByDefault public class UtilEsp32 { private static final Map COLOR_MAPPINGS = createColorMap(); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index 23110b2a73109..2071f3b025538 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -43,7 +43,7 @@ */ public class WlanThermoEsp32CommandHandler { - public State getState(ChannelUID channelUID, Data data, Settings settings) { + public static State getState(ChannelUID channelUID, Data data, Settings settings) { State state = null; String groupId = channelUID.getGroupId(); @@ -175,7 +175,7 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { return state; } - public boolean setState(ChannelUID channelUID, Command command, Data data) { + public static boolean setState(ChannelUID channelUID, Command command, Data data) { boolean success = false; String groupId = channelUID.getGroupId(); if (groupId == null || data == null) { @@ -266,7 +266,7 @@ public boolean setState(ChannelUID channelUID, Command command, Data data) { return success; } - public String getTrigger(ChannelUID channelUID, Data data) { + public static String getTrigger(ChannelUID channelUID, Data data) { String trigger = null; String groupId = channelUID.getGroupId(); if (groupId == null || data == null) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 6969f57444dec..bf17a5d08134e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -51,7 +51,6 @@ public class WlanThermoEsp32Handler extends BaseThingHandler { private final Logger logger = LoggerFactory.getLogger(WlanThermoEsp32Handler.class); private WlanThermoExtendedConfiguration config = new WlanThermoExtendedConfiguration(); - private WlanThermoEsp32CommandHandler wlanThermoEsp32CommandHandler = new WlanThermoEsp32CommandHandler(); private final HttpClient httpClient; private @Nullable ScheduledFuture pollingScheduler; private final Gson gson = new Gson(); @@ -109,12 +108,12 @@ private void checkConnection() { @Override public void handleCommand(ChannelUID channelUID, Command command) { if (command instanceof RefreshType) { - State s = wlanThermoEsp32CommandHandler.getState(channelUID, data, settings); + State s = WlanThermoEsp32CommandHandler.getState(channelUID, data, settings); if (s != null) { updateState(channelUID, s); } } else { - if (wlanThermoEsp32CommandHandler.setState(channelUID, command, data)) { + if (WlanThermoEsp32CommandHandler.setState(channelUID, command, data)) { logger.debug("Data updated, pushing changes"); push(); } else { @@ -158,12 +157,12 @@ private void update() { // Update channel state for (Channel channel : thing.getChannels()) { - State state = wlanThermoEsp32CommandHandler.getState(channel.getUID(), data, settings); + State state = WlanThermoEsp32CommandHandler.getState(channel.getUID(), data, settings); if (state != null) { updateState(channel.getUID(), state); } else { // if we could not obtain a state, try trigger instead - String trigger = wlanThermoEsp32CommandHandler.getTrigger(channel.getUID(), data); + String trigger = WlanThermoEsp32CommandHandler.getTrigger(channel.getUID(), data); if (trigger != null) { triggerChannel(channel.getUID(), trigger); } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/UtilMini.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/UtilMini.java index 7e47883e1c2ec..f4075dbd10c93 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/UtilMini.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/UtilMini.java @@ -15,11 +15,14 @@ import java.util.HashMap; import java.util.Map; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * The {@link UtilMini} class provides conversion functions for the WlanThermo Mini * * @author Christian Schlipp - Initial contribution */ +@NonNullByDefault public class UtilMini { private static final Map COLOR_MAPPINGS = createColorMap(); private static final String DEFAULT_HEX = "#ffffff"; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java index 5dd3be3d4cc14..bbb049aa82b75 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java @@ -38,7 +38,7 @@ public class WlanThermoMiniCommandHandler { public static final String ERROR = "er"; - public State getState(ChannelUID channelUID, App app) { + public static State getState(ChannelUID channelUID, App app) { State state = null; String groupId = channelUID.getGroupId(); @@ -152,7 +152,7 @@ public State getState(ChannelUID channelUID, App app) { return state; } - public String getTrigger(ChannelUID channelUID, App app) { + public static String getTrigger(ChannelUID channelUID, App app) { String trigger = null; String groupId = channelUID.getGroupId(); if (groupId == null || app == null) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index 90619c528a152..fa407c6c644da 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -41,7 +41,6 @@ public class WlanThermoMiniHandler extends BaseThingHandler { private final Logger logger = LoggerFactory.getLogger(WlanThermoMiniHandler.class); - private final WlanThermoMiniCommandHandler wlanThermoMiniCommandHandler = new WlanThermoMiniCommandHandler(); private WlanThermoConfiguration config = new WlanThermoConfiguration(); private final HttpClient httpClient; @@ -91,7 +90,7 @@ private void checkConnection() { public void handleCommand(ChannelUID channelUID, Command command) { // Mini is read only! if (command instanceof RefreshType) { - State s = wlanThermoMiniCommandHandler.getState(channelUID, app); + State s = WlanThermoMiniCommandHandler.getState(channelUID, app); if (s != null) updateState(channelUID, s); } @@ -106,11 +105,11 @@ private void update() { // Update channels for (Channel channel : thing.getChannels()) { - State state = wlanThermoMiniCommandHandler.getState(channel.getUID(), app); + State state = WlanThermoMiniCommandHandler.getState(channel.getUID(), app); if (state != null) { updateState(channel.getUID(), state); } else { - String trigger = wlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app); + String trigger = WlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app); if (trigger != null) { triggerChannel(channel.getUID(), trigger); } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java index a6084651cc450..38e34f9d4133d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java @@ -15,11 +15,14 @@ import java.util.HashMap; import java.util.Map; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * The {@link UtilNano} class provides conversion functions for the WlanThermo Nano V1+ * * @author Christian Schlipp - Initial contribution */ +@NonNullByDefault public class UtilNano { private static final Map COLOR_MAPPINGS = createColorMap(); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index 253fde8038792..8c739563511c5 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -43,7 +43,7 @@ */ public class WlanThermoNanoV1CommandHandler { - public State getState(ChannelUID channelUID, Data data, Settings settings) { + public static State getState(ChannelUID channelUID, Data data, Settings settings) { State state = null; String groupId = channelUID.getGroupId(); @@ -167,7 +167,7 @@ public State getState(ChannelUID channelUID, Data data, Settings settings) { return state; } - public boolean setState(ChannelUID channelUID, Command command, Data data) { + public static boolean setState(ChannelUID channelUID, Command command, Data data) { boolean success = false; String groupId = channelUID.getGroupId(); if (groupId == null || data == null) { @@ -258,7 +258,7 @@ public boolean setState(ChannelUID channelUID, Command command, Data data) { return success; } - public String getTrigger(ChannelUID channelUID, Data data) { + public static String getTrigger(ChannelUID channelUID, Data data) { String trigger = null; String groupId = channelUID.getGroupId(); if (groupId == null || data == null) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 5491cd9dd5a7b..13b0612495a7d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -49,7 +49,6 @@ public class WlanThermoNanoV1Handler extends BaseThingHandler { private final Logger logger = LoggerFactory.getLogger(WlanThermoNanoV1Handler.class); private WlanThermoExtendedConfiguration config = new WlanThermoExtendedConfiguration(); - private WlanThermoNanoV1CommandHandler wlanThermoNanoV1CommandHandler = new WlanThermoNanoV1CommandHandler(); private final HttpClient httpClient; private @Nullable ScheduledFuture pollingScheduler; private final Gson gson = new Gson(); @@ -107,11 +106,11 @@ private void checkConnection() { @Override public void handleCommand(ChannelUID channelUID, Command command) { if (command instanceof RefreshType) { - State s = wlanThermoNanoV1CommandHandler.getState(channelUID, data, settings); + State s = WlanThermoNanoV1CommandHandler.getState(channelUID, data, settings); if (s != null) updateState(channelUID, s); } else { - if (wlanThermoNanoV1CommandHandler.setState(channelUID, command, data)) { + if (WlanThermoNanoV1CommandHandler.setState(channelUID, command, data)) { logger.debug("Data updated, pushing changes"); push(); } else { @@ -133,12 +132,12 @@ private void update() { // Update channels for (Channel channel : thing.getChannels()) { - State state = wlanThermoNanoV1CommandHandler.getState(channel.getUID(), data, settings); + State state = WlanThermoNanoV1CommandHandler.getState(channel.getUID(), data, settings); if (state != null) { updateState(channel.getUID(), state); } else { // if we could not obtain a state, try trigger instead - String trigger = wlanThermoNanoV1CommandHandler.getTrigger(channel.getUID(), data); + String trigger = WlanThermoNanoV1CommandHandler.getTrigger(channel.getUID(), data); if (trigger != null) { triggerChannel(channel.getUID(), trigger); } From 81fc86a2883a8d99f91c6534ce57b680692bfb24 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sat, 9 Jan 2021 17:46:16 +0100 Subject: [PATCH 19/40] Rework CommandHandler Returns Signed-off-by: Christian Schlipp --- .../internal/WlanThermoBindingConstants.java | 3 + .../internal/WlanThermoException.java | 30 +++ .../WlanThermoUnknownChannelException.java | 30 +++ .../esp32/WlanThermoEsp32CommandHandler.java | 213 ++++++++---------- .../api/esp32/WlanThermoEsp32Handler.java | 22 +- .../mini/WlanThermoMiniCommandHandler.java | 108 ++++----- .../api/mini/WlanThermoMiniHandler.java | 25 +- .../nano/WlanThermoNanoV1CommandHandler.java | 209 ++++++++--------- .../api/nano/WlanThermoNanoV1Handler.java | 23 +- 9 files changed, 345 insertions(+), 318 deletions(-) create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoException.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUnknownChannelException.java diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java index 42632649c6112..64e986627579b 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java @@ -88,4 +88,7 @@ public class WlanThermoBindingConstants { public static final DecimalType SIGNAL_STRENGTH_3 = new DecimalType(3); public static final DecimalType SIGNAL_STRENGTH_2 = new DecimalType(2); public static final DecimalType SIGNAL_STRENGTH_1 = new DecimalType(1); + + public static final String INVALID_INPUT_EXCEPTION = "Input Data is invalid!"; + public static final String UNKNOWN_CHANNEL_EXCEPTION = "Channel or Trigger unknown!"; } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoException.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoException.java new file mode 100644 index 0000000000000..6bb692093258f --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoException.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wlanthermo.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * The {@link WlanThermoException} is thrown if an exception in WlanThermoBinding occurs. + * + * @author Christian Schlipp - Initial contribution + */ +@NonNullByDefault +public class WlanThermoException extends Exception { + + static final long serialVersionUID = 1l; + + public WlanThermoException(String reason) { + super(reason, null); + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUnknownChannelException.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUnknownChannelException.java new file mode 100644 index 0000000000000..e5ef7023e0dcc --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUnknownChannelException.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wlanthermo.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * The {@link WlanThermoUnknownChannelException} is thrown if a channel or trigger is unknown + * + * @author Christian Schlipp - Initial contribution + */ +@NonNullByDefault +public class WlanThermoUnknownChannelException extends WlanThermoException { + + static final long serialVersionUID = 1l; + + public WlanThermoUnknownChannelException() { + super(WlanThermoBindingConstants.UNKNOWN_CHANNEL_EXCEPTION); + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index 2071f3b025538..add7e20495be5 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -21,6 +21,10 @@ import javax.measure.Unit; import javax.measure.quantity.Temperature; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.binding.wlanthermo.internal.WlanThermoException; +import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Channel; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Data; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Pm; @@ -41,111 +45,95 @@ * * @author Christian Schlipp - Initial contribution */ +@NonNullByDefault public class WlanThermoEsp32CommandHandler { - public static State getState(ChannelUID channelUID, Data data, Settings settings) { - State state = null; - - String groupId = channelUID.getGroupId(); - if (groupId == null || data == null || settings == null) { - return null; + public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullable Settings settings) + throws WlanThermoException { + if (channelUID.getGroupId() == null || data == null || settings == null) { + throw new WlanThermoException(INVALID_INPUT_EXCEPTION); } + String groupId = channelUID.getGroupId(); System system = data.getSystem(); - Unit unit = "F".equals(system.getUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; - List channel = data.getChannel(); + List channelList = data.getChannel(); if (SYSTEM.equals(groupId)) { switch (channelUID.getIdWithoutGroup()) { case SYSTEM_SOC: if (system.getSoc() != null) { - state = new DecimalType(system.getSoc()); + return new DecimalType(system.getSoc()); } else { - state = UnDefType.UNDEF; + return UnDefType.UNDEF; } - break; case SYSTEM_CHARGE: if (system.getCharge() != null) { - state = OnOffType.from(system.getCharge()); + return OnOffType.from(system.getCharge()); } else { - state = UnDefType.UNDEF; + return UnDefType.UNDEF; } - break; case SYSTEM_RSSI_SIGNALSTRENGTH: int dbm = system.getRssi(); if (dbm >= -80) { - state = SIGNAL_STRENGTH_4; + return SIGNAL_STRENGTH_4; } else if (dbm >= -95) { - state = SIGNAL_STRENGTH_3; + return SIGNAL_STRENGTH_3; } else if (dbm >= -105) { - state = SIGNAL_STRENGTH_2; + return SIGNAL_STRENGTH_2; } else { - state = SIGNAL_STRENGTH_1; + return SIGNAL_STRENGTH_1; } - break; case SYSTEM_RSSI: - state = new QuantityType<>(system.getRssi(), Units.DECIBEL_MILLIWATTS); - break; + return new QuantityType<>(system.getRssi(), Units.DECIBEL_MILLIWATTS); } } else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channel != null && channel.size() > 0 && channelId < channel.size()) { + if (channelList != null && channelList.size() > 0 && channelId < channelList.size()) { + Channel channel = channelList.get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: - state = new StringType(channel.get(channelId).getName()); - break; + return new StringType(channel.getName()); case CHANNEL_TYP: - state = new StringType(settings.getSensors().get(channel.get(channelId).getTyp()).getName()); - break; + return new StringType(settings.getSensors().get(channel.getTyp()).getName()); case CHANNEL_TEMP: - if (channel.get(channelId).getTemp() == 999.0) { - state = UnDefType.UNDEF; - } else { - state = new QuantityType<>(channel.get(channelId).getTemp(), unit); - } - break; + return channel.getTemp() == 999.0 ? UnDefType.UNDEF + : new QuantityType<>(channel.getTemp(), unit); case CHANNEL_MIN: - state = new QuantityType<>(channel.get(channelId).getMin(), unit); - break; + return new QuantityType<>(channel.getMin(), unit); case CHANNEL_MAX: - state = new QuantityType<>(channel.get(channelId).getMax(), unit); - break; + return new QuantityType<>(channel.getMax(), unit); case CHANNEL_ALARM_DEVICE: - state = OnOffType.from(BigInteger.valueOf(channel.get(channelId).getAlarm()).testBit(1)); - break; + return OnOffType.from(BigInteger.valueOf(channel.getAlarm()).testBit(1)); case CHANNEL_ALARM_PUSH: - state = OnOffType.from(BigInteger.valueOf(channel.get(channelId).getAlarm()).testBit(0)); - break; + return OnOffType.from(BigInteger.valueOf(channel.getAlarm()).testBit(0)); case CHANNEL_ALARM_OPENHAB_HIGH: - if (channel.get(channelId).getTemp() != 999 - && channel.get(channelId).getTemp() > channel.get(channelId).getMax()) { - state = OnOffType.ON; + if (channel.getTemp() != 999 && channel.getTemp() > channel.getMax()) { + return OnOffType.ON; } else { - state = OnOffType.OFF; + return OnOffType.OFF; } - break; case CHANNEL_ALARM_OPENHAB_LOW: - if (channel.get(channelId).getTemp() != 999 - && channel.get(channelId).getTemp() < channel.get(channelId).getMin()) { - state = OnOffType.ON; + if (channel.getTemp() != 999 && channel.getTemp() < channel.getMin()) { + return OnOffType.ON; } else { - state = OnOffType.OFF; + return OnOffType.OFF; } - break; case CHANNEL_COLOR: - String color = channel.get(channelId).getColor(); + String color = channel.getColor(); if (color != null && !color.isEmpty()) { Color c = Color.decode(color); - state = HSBType.fromRGB(c.getRed(), c.getGreen(), c.getBlue()); + return HSBType.fromRGB(c.getRed(), c.getGreen(), c.getBlue()); + } else { + return UnDefType.UNDEF; } - break; case CHANNEL_COLOR_NAME: - String colorHex = channel.get(channelId).getColor(); + String colorHex = channel.getColor(); if (colorHex != null && !colorHex.isEmpty()) { - state = new StringType(UtilEsp32.toColorName(colorHex)); + return new StringType(UtilEsp32.toColorName(colorHex)); + } else { + return UnDefType.UNDEF; } - break; } } } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_1)) { @@ -154,86 +142,80 @@ public static State getState(ChannelUID channelUID, Data data, Settings settings Pm pm = data.getPitmaster().getPm().get(0); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_PITMASTER_CHANNEL_ID: - state = new DecimalType(pm.getChannel()); - break; + return new DecimalType(pm.getChannel()); case CHANNEL_PITMASTER_PIDPROFILE: - state = new DecimalType(pm.getPid()); - break; + return new DecimalType(pm.getPid()); case CHANNEL_PITMASTER_DUTY_CYCLE: - state = new DecimalType(pm.getValue()); - break; + return new DecimalType(pm.getValue()); case CHANNEL_PITMASTER_SETPOINT: - state = new QuantityType<>(pm.getSet(), unit); - break; + return new QuantityType<>(pm.getSet(), unit); case CHANNEL_PITMASTER_STATE: - state = new StringType(pm.getTyp()); + return new StringType(pm.getTyp()); } } else { return UnDefType.UNDEF; } } - return state; + throw new WlanThermoUnknownChannelException(); } - public static boolean setState(ChannelUID channelUID, Command command, Data data) { - boolean success = false; - String groupId = channelUID.getGroupId(); - if (groupId == null || data == null) { + public static boolean setState(ChannelUID channelUID, Command command, @Nullable Data data) { + if (channelUID.getGroupId() == null || data == null) { return false; } - List channel = data.getChannel(); + + String groupId = channelUID.getGroupId(); + List channelList = data.getChannel(); + System system = data.getSystem(); + Unit unit = "F".equals(system.getUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; + if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channel.size() > 0 && channelId < channel.size()) { + if (channelList.size() > 0 && channelId < channelList.size()) { + Channel channel = channelList.get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: if (command instanceof StringType) { - channel.get(channelId).setName(command.toFullString()); - success = true; + channel.setName(command.toFullString()); + return true; } - break; case CHANNEL_MIN: if (command instanceof QuantityType) { - channel.get(channelId).setMin(((QuantityType) command).doubleValue()); - success = true; + channel.setMin(((QuantityType) command).toUnit(unit).doubleValue()); + return true; } - break; case CHANNEL_MAX: if (command instanceof QuantityType) { - channel.get(channelId).setMax(((QuantityType) command).doubleValue()); - success = true; + channel.setMax(((QuantityType) command).toUnit(unit).doubleValue()); + return true; } - break; case CHANNEL_ALARM_DEVICE: if (command instanceof OnOffType) { BigInteger value; if (command == OnOffType.ON) { - value = BigInteger.valueOf(channel.get(channelId).getAlarm()).setBit(1); + value = BigInteger.valueOf(channel.getAlarm()).setBit(1); } else { - value = BigInteger.valueOf(channel.get(channelId).getAlarm()).clearBit(1); + value = BigInteger.valueOf(channel.getAlarm()).clearBit(1); } - channel.get(channelId).setAlarm(value.intValue()); - success = true; + channel.setAlarm(value.intValue()); + return true; } - break; case CHANNEL_ALARM_PUSH: if (command instanceof OnOffType) { BigInteger value; if (command == OnOffType.ON) { - value = BigInteger.valueOf(channel.get(channelId).getAlarm()).setBit(0); + value = BigInteger.valueOf(channel.getAlarm()).setBit(0); } else { - value = BigInteger.valueOf(channel.get(channelId).getAlarm()).clearBit(0); + value = BigInteger.valueOf(channel.getAlarm()).clearBit(0); } - channel.get(channelId).setAlarm(value.intValue()); - success = true; + channel.setAlarm(value.intValue()); + return true; } - break; case CHANNEL_COLOR_NAME: if (command instanceof StringType) { - channel.get(channelId).setColor(UtilEsp32.toHex(((StringType) command).toString())); - success = true; + channel.setColor(UtilEsp32.toHex(((StringType) command).toString())); + return true; } - break; } } } else if (channelUID.getId().equals(CHANNEL_PITMASTER_1)) { @@ -243,50 +225,49 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data switch (channelUID.getIdWithoutGroup()) { case CHANNEL_PITMASTER_CHANNEL_ID: pm.setChannel(((QuantityType) command).intValue()); - success = true; - break; + return true; case CHANNEL_PITMASTER_PIDPROFILE: pm.setPid(((QuantityType) command).intValue()); - success = true; - break; + return true; case CHANNEL_PITMASTER_SETPOINT: - pm.setSet(((QuantityType) command).doubleValue()); - success = true; - break; + pm.setSet(((QuantityType) command).toUnit(unit).doubleValue()); + return true; case CHANNEL_PITMASTER_STATE: String state = ((StringType) command).toString(); if (state.equalsIgnoreCase("off") || state.equalsIgnoreCase("manual") || state.equalsIgnoreCase("auto")) { pm.setTyp(state); - success = true; + return true; } } } } - return success; + return false; } - public static String getTrigger(ChannelUID channelUID, Data data) { - String trigger = null; - String groupId = channelUID.getGroupId(); - if (groupId == null || data == null) { - return null; + public static String getTrigger(ChannelUID channelUID, @Nullable Data data) throws WlanThermoException { + if (channelUID.getGroupId() == null || data == null) { + throw new WlanThermoException(INVALID_INPUT_EXCEPTION); } - List channel = data.getChannel(); + + String groupId = channelUID.getGroupId(); + List channelList = data.getChannel(); + if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channel.size() > 0 && channelId < channel.size()) { + if (channelList.size() > 0 && channelId < channelList.size()) { + Channel channel = channelList.get(channelId); if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { - if (channel.get(channelId).getTemp() != 999) { - if (channel.get(channelId).getTemp() > channel.get(channelId).getMax()) { - trigger = TRIGGER_ALARM_MAX; - } else if (channel.get(channelId).getTemp() < channel.get(channelId).getMin()) { - trigger = TRIGGER_ALARM_MIN; + if (channel.getTemp() != 999) { + if (channel.getTemp() > channel.getMax()) { + return TRIGGER_ALARM_MAX; + } else if (channel.getTemp() < channel.getMin()) { + return TRIGGER_ALARM_MIN; } } } } } - return trigger; + throw new WlanThermoUnknownChannelException(); } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index bf17a5d08134e..b9b089cd96158 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -25,7 +25,9 @@ import org.eclipse.jetty.client.util.DigestAuthentication; import org.eclipse.jetty.client.util.StringContentProvider; import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; +import org.openhab.binding.wlanthermo.internal.WlanThermoException; import org.openhab.binding.wlanthermo.internal.WlanThermoExtendedConfiguration; +import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Data; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings.Settings; import org.openhab.core.thing.*; @@ -108,9 +110,12 @@ private void checkConnection() { @Override public void handleCommand(ChannelUID channelUID, Command command) { if (command instanceof RefreshType) { - State s = WlanThermoEsp32CommandHandler.getState(channelUID, data, settings); - if (s != null) { + try { + State s = WlanThermoEsp32CommandHandler.getState(channelUID, data, settings); updateState(channelUID, s); + } catch (WlanThermoException e) { + logger.debug("Could not handle command of type {} for channel {}!", + command.getClass().toGenericString(), channelUID.getId()); } } else { if (WlanThermoEsp32CommandHandler.setState(channelUID, command, data)) { @@ -157,18 +162,17 @@ private void update() { // Update channel state for (Channel channel : thing.getChannels()) { - State state = WlanThermoEsp32CommandHandler.getState(channel.getUID(), data, settings); - if (state != null) { + try { + State state = WlanThermoEsp32CommandHandler.getState(channel.getUID(), data, settings); updateState(channel.getUID(), state); - } else { + } catch (WlanThermoUnknownChannelException e) { // if we could not obtain a state, try trigger instead String trigger = WlanThermoEsp32CommandHandler.getTrigger(channel.getUID(), data); - if (trigger != null) { - triggerChannel(channel.getUID(), trigger); - } + triggerChannel(channel.getUID(), trigger); } } - } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { + } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException + | WlanThermoException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed: " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java index bbb049aa82b75..f43fb1682b665 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java @@ -19,7 +19,11 @@ import javax.measure.Unit; import javax.measure.quantity.Temperature; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; +import org.openhab.binding.wlanthermo.internal.WlanThermoException; +import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; import org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin.*; import org.openhab.core.library.types.*; import org.openhab.core.library.unit.ImperialUnits; @@ -34,36 +38,33 @@ * * @author Christian Schlipp - Initial contribution */ +@NonNullByDefault public class WlanThermoMiniCommandHandler { public static final String ERROR = "er"; - public static State getState(ChannelUID channelUID, App app) { - State state = null; - - String groupId = channelUID.getGroupId(); - if (groupId == null || app == null) { - return null; + public static State getState(ChannelUID channelUID, @Nullable App app) throws WlanThermoException { + if (channelUID.getGroupId() == null || app == null) { + throw new WlanThermoException(INVALID_INPUT_EXCEPTION); } + String groupId = channelUID.getGroupId(); Unit unit = "fahrenheit".equals(app.getTempUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; if (SYSTEM.equals(groupId)) { switch (channelUID.getIdWithoutGroup()) { case WlanThermoBindingConstants.SYSTEM_CPU_TEMP: if (app.getCpuTemp() == null) { - state = UnDefType.UNDEF; + return UnDefType.UNDEF; } else { - state = new DecimalType(app.getCpuTemp()); + return new DecimalType(app.getCpuTemp()); } - break; case WlanThermoBindingConstants.SYSTEM_CPU_LOAD: if (app.getCpuLoad() == null) { - state = UnDefType.UNDEF; + return UnDefType.UNDEF; } else { - state = new DecimalType(app.getCpuLoad()); + return new DecimalType(app.getCpuLoad()); } - break; } } else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())); @@ -75,45 +76,36 @@ public static State getState(ChannelUID channelUID, App app) { Data data = channel.getData(channelId); switch (channelUID.getIdWithoutGroup()) { case WlanThermoBindingConstants.CHANNEL_NAME: - state = new StringType(data.getName()); - break; + return new StringType(data.getName()); case WlanThermoBindingConstants.CHANNEL_TEMP: if (data.getState().equals(ERROR)) { - state = UnDefType.UNDEF; + return UnDefType.UNDEF; } else { - state = new QuantityType<>(data.getTemp(), unit); + return new QuantityType<>(data.getTemp(), unit); } - break; case WlanThermoBindingConstants.CHANNEL_MIN: - state = new QuantityType<>(data.getTempMin(), unit); - break; + return new QuantityType<>(data.getTempMin(), unit); case WlanThermoBindingConstants.CHANNEL_MAX: - state = new QuantityType<>(data.getTempMax(), unit); - break; + return new QuantityType<>(data.getTempMax(), unit); case WlanThermoBindingConstants.CHANNEL_ALARM_DEVICE: - state = OnOffType.from(data.getAlert()); - break; + return OnOffType.from(data.getAlert()); case WlanThermoBindingConstants.CHANNEL_ALARM_OPENHAB_HIGH: if (!data.getState().equals(ERROR) && data.getTemp() > data.getTempMax()) { - state = OnOffType.ON; + return OnOffType.ON; } else { - state = OnOffType.OFF; + return OnOffType.OFF; } - break; case WlanThermoBindingConstants.CHANNEL_ALARM_OPENHAB_LOW: if (!data.getState().equals(ERROR) && data.getTemp() < data.getTempMin()) { - state = OnOffType.ON; + return OnOffType.ON; } else { - state = OnOffType.OFF; + return OnOffType.OFF; } - break; case WlanThermoBindingConstants.CHANNEL_COLOR: Color c = Color.decode(UtilMini.toHex(data.getColor())); - state = HSBType.fromRGB(c.getRed(), c.getGreen(), c.getBlue()); - break; + return HSBType.fromRGB(c.getRed(), c.getGreen(), c.getBlue()); case WlanThermoBindingConstants.CHANNEL_COLOR_NAME: - state = new StringType(data.getColor()); - break; + return new StringType(data.getColor()); } } } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_PREFIX)) { @@ -130,54 +122,48 @@ public static State getState(ChannelUID channelUID, App app) { } switch (channelUID.getIdWithoutGroup()) { case WlanThermoBindingConstants.CHANNEL_PITMASTER_ENABLED: - state = OnOffType.from(pit.getEnabled()); - break; + return OnOffType.from(pit.getEnabled()); case WlanThermoBindingConstants.CHANNEL_PITMASTER_CURRENT: - state = new DecimalType(pit.getCurrent()); - break; + return new DecimalType(pit.getCurrent()); case WlanThermoBindingConstants.CHANNEL_PITMASTER_SETPOINT: - state = new QuantityType<>(pit.getSetpoint(), unit); - break; + return new QuantityType<>(pit.getSetpoint(), unit); case WlanThermoBindingConstants.CHANNEL_PITMASTER_DUTY_CYCLE: - state = new DecimalType(pit.getControlOut()); - break; + return new DecimalType(pit.getControlOut()); case WlanThermoBindingConstants.CHANNEL_PITMASTER_LID_OPEN: - state = OnOffType.from(pit.getOpenLid().equals("True")); - break; + return OnOffType.from(pit.getOpenLid().equals("True")); case WlanThermoBindingConstants.CHANNEL_PITMASTER_CHANNEL_ID: - state = new DecimalType(pit.getCh()); - break; + return new DecimalType(pit.getCh()); } } - return state; + throw new WlanThermoUnknownChannelException(); } - public static String getTrigger(ChannelUID channelUID, App app) { - String trigger = null; - String groupId = channelUID.getGroupId(); - if (groupId == null || app == null) { - return null; + public static String getTrigger(ChannelUID channelUID, @Nullable App app) throws WlanThermoException { + if (channelUID.getGroupId() == null || app == null) { + throw new WlanThermoException(INVALID_INPUT_EXCEPTION); } + + String groupId = channelUID.getGroupId(); + if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; if (channelId >= 0 && channelId <= 9) { Channel channel = app.getChannel(); if (channel == null) { - return ""; + throw new WlanThermoException("Channel ID is unavailable!"); } Data data = channel.getData(channelId); - switch (channelUID.getIdWithoutGroup()) { - case CHANNEL_ALARM_OPENHAB: - if (!data.getState().equals(ERROR)) { - if (data.getTemp() > data.getTempMax()) { - trigger = WlanThermoBindingConstants.TRIGGER_ALARM_MAX; - } else if (data.getTemp() < data.getTempMin()) { - trigger = WlanThermoBindingConstants.TRIGGER_ALARM_MIN; - } + if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { + if (!data.getState().equals(ERROR)) { + if (data.getTemp() > data.getTempMax()) { + return TRIGGER_ALARM_MAX; + } else if (data.getTemp() < data.getTempMin()) { + return TRIGGER_ALARM_MIN; } + } } } } - return trigger; + throw new WlanThermoUnknownChannelException(); } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index fa407c6c644da..5905531484cb1 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -19,6 +19,8 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; import org.openhab.binding.wlanthermo.internal.WlanThermoConfiguration; +import org.openhab.binding.wlanthermo.internal.WlanThermoException; +import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; import org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin.App; import org.openhab.core.thing.*; import org.openhab.core.thing.binding.BaseThingHandler; @@ -90,9 +92,14 @@ private void checkConnection() { public void handleCommand(ChannelUID channelUID, Command command) { // Mini is read only! if (command instanceof RefreshType) { - State s = WlanThermoMiniCommandHandler.getState(channelUID, app); - if (s != null) + try { + assert app != null; + State s = WlanThermoMiniCommandHandler.getState(channelUID, app); updateState(channelUID, s); + } catch (WlanThermoException e) { + logger.debug("Could not handle command of type {} for channel {}!", + command.getClass().toGenericString(), channelUID.getId()); + } } } @@ -105,18 +112,18 @@ private void update() { // Update channels for (Channel channel : thing.getChannels()) { - State state = WlanThermoMiniCommandHandler.getState(channel.getUID(), app); - if (state != null) { + try { + State state = WlanThermoMiniCommandHandler.getState(channel.getUID(), app); updateState(channel.getUID(), state); - } else { + } catch (WlanThermoUnknownChannelException e) { + // if we could not obtain a state, try trigger instead String trigger = WlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app); - if (trigger != null) { - triggerChannel(channel.getUID(), trigger); - } + triggerChannel(channel.getUID(), trigger); } } - } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { + } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException + | WlanThermoException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed: " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index 8c739563511c5..6d2a27d0cf7a4 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -21,6 +21,10 @@ import javax.measure.Unit; import javax.measure.quantity.Temperature; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.binding.wlanthermo.internal.WlanThermoException; +import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Channel; import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Data; import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Pm; @@ -41,103 +45,87 @@ * * @author Christian Schlipp - Initial contribution */ +@NonNullByDefault public class WlanThermoNanoV1CommandHandler { - public static State getState(ChannelUID channelUID, Data data, Settings settings) { - State state = null; - - String groupId = channelUID.getGroupId(); - if (groupId == null || data == null || settings == null) { - return null; + public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullable Settings settings) + throws WlanThermoException { + if (channelUID.getGroupId() == null || data == null || settings == null) { + throw new WlanThermoException(INVALID_INPUT_EXCEPTION); } + String groupId = channelUID.getGroupId(); System system = data.getSystem(); - Unit unit = "F".equals(system.getUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; + List channelList = data.getChannel(); - List channel = data.getChannel(); if (SYSTEM.equals(groupId)) { switch (channelUID.getIdWithoutGroup()) { case SYSTEM_SOC: - state = new DecimalType(system.getSoc()); - break; + return new DecimalType(system.getSoc()); case SYSTEM_CHARGE: - state = OnOffType.from(system.getCharge()); - break; + return OnOffType.from(system.getCharge()); case SYSTEM_RSSI_SIGNALSTRENGTH: int dbm = system.getRssi(); if (dbm >= -80) { - state = SIGNAL_STRENGTH_4; + return SIGNAL_STRENGTH_4; } else if (dbm >= -95) { - state = SIGNAL_STRENGTH_3; + return SIGNAL_STRENGTH_3; } else if (dbm >= -105) { - state = SIGNAL_STRENGTH_2; + return SIGNAL_STRENGTH_2; } else { - state = SIGNAL_STRENGTH_1; + return SIGNAL_STRENGTH_1; } - break; case SYSTEM_RSSI: - state = new QuantityType<>(system.getRssi(), Units.DECIBEL_MILLIWATTS); - break; + return new QuantityType<>(system.getRssi(), Units.DECIBEL_MILLIWATTS); } } else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channel.size() > 0 && channelId <= channel.size()) { + if (channelList.size() > 0 && channelId <= channelList.size()) { + Channel channel = channelList.get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: - state = new StringType(channel.get(channelId).getName()); - break; + return new StringType(channel.getName()); case CHANNEL_TYP: - state = new StringType(settings.sensors.get(channel.get(channelId).getTyp())); - break; + return new StringType(settings.sensors.get(channel.getTyp())); case CHANNEL_TEMP: - if (channel.get(channelId).getTemp() == 999.0) { - state = UnDefType.UNDEF; - } else { - state = new QuantityType<>(channel.get(channelId).getTemp(), unit); - } - break; + return channel.getTemp() == 999.0 ? UnDefType.UNDEF + : new QuantityType<>(channel.getTemp(), unit); case CHANNEL_MIN: - state = new QuantityType<>(channel.get(channelId).getMin(), unit); - break; + return new QuantityType<>(channel.getMin(), unit); case CHANNEL_MAX: - state = new QuantityType<>(channel.get(channelId).getMax(), unit); - break; + return new QuantityType<>(channel.getMax(), unit); case CHANNEL_ALARM_DEVICE: - state = OnOffType.from(BigInteger.valueOf(channel.get(channelId).getAlarm()).testBit(1)); - break; + return OnOffType.from(BigInteger.valueOf(channel.getAlarm()).testBit(1)); case CHANNEL_ALARM_PUSH: - state = OnOffType.from(BigInteger.valueOf(channel.get(channelId).getAlarm()).testBit(0)); - break; + return OnOffType.from(BigInteger.valueOf(channel.getAlarm()).testBit(0)); case CHANNEL_ALARM_OPENHAB_HIGH: - if (channel.get(channelId).getTemp() != 999 - && channel.get(channelId).getTemp() > channel.get(channelId).getMax()) { - state = OnOffType.ON; + if (channel.getTemp() != 999 && channel.getTemp() > channel.getMax()) { + return OnOffType.ON; } else { - state = OnOffType.OFF; + return OnOffType.OFF; } - break; case CHANNEL_ALARM_OPENHAB_LOW: - if (channel.get(channelId).getTemp() != 999 - && channel.get(channelId).getTemp() < channel.get(channelId).getMin()) { - state = OnOffType.ON; + if (channel.getTemp() != 999 && channel.getTemp() < channel.getMin()) { + return OnOffType.ON; } else { - state = OnOffType.OFF; + return OnOffType.OFF; } - break; case CHANNEL_COLOR: - String color = channel.get(channelId).getColor(); + String color = channel.getColor(); if (color != null && !color.isEmpty()) { Color c = Color.decode(color); - state = HSBType.fromRGB(c.getRed(), c.getGreen(), c.getBlue()); + return HSBType.fromRGB(c.getRed(), c.getGreen(), c.getBlue()); + } else { + return UnDefType.UNDEF; } - break; case CHANNEL_COLOR_NAME: - String colorHex = channel.get(channelId).getColor(); + String colorHex = channel.getColor(); if (colorHex != null && !colorHex.isEmpty()) { - state = new StringType(UtilNano.toColorName(colorHex)); + return new StringType(UtilNano.toColorName(colorHex)); + } else { + return UnDefType.UNDEF; } - break; } } } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_1)) { @@ -146,86 +134,80 @@ public static State getState(ChannelUID channelUID, Data data, Settings settings Pm pm = data.getPitmaster().getPm().get(0); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_PITMASTER_CHANNEL_ID: - state = new DecimalType(pm.getChannel()); - break; + return new DecimalType(pm.getChannel()); case CHANNEL_PITMASTER_PIDPROFILE: - state = new DecimalType(pm.getPid()); - break; + return new DecimalType(pm.getPid()); case CHANNEL_PITMASTER_DUTY_CYCLE: - state = new DecimalType(pm.getValue()); - break; + return new DecimalType(pm.getValue()); case CHANNEL_PITMASTER_SETPOINT: - state = new QuantityType<>(pm.getSet(), unit); - break; + return new QuantityType<>(pm.getSet(), unit); case CHANNEL_PITMASTER_STATE: - state = new StringType(pm.getTyp()); + return new StringType(pm.getTyp()); } } else { return UnDefType.UNDEF; } } - return state; + throw new WlanThermoUnknownChannelException(); } - public static boolean setState(ChannelUID channelUID, Command command, Data data) { - boolean success = false; - String groupId = channelUID.getGroupId(); - if (groupId == null || data == null) { + public static boolean setState(ChannelUID channelUID, Command command, @Nullable Data data) { + if (channelUID.getGroupId() == null || data == null) { return false; } - List channel = data.getChannel(); + + String groupId = channelUID.getGroupId(); + List channelList = data.getChannel(); + System system = data.getSystem(); + Unit unit = "F".equals(system.getUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; + if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channel.size() > 0 && channelId <= channel.size()) { + if (channelList.size() > 0 && channelId <= channelList.size()) { + Channel channel = channelList.get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: if (command instanceof StringType) { - channel.get(channelId).setName(command.toFullString()); - success = true; + channel.setName(command.toFullString()); + return true; } - break; case CHANNEL_MIN: if (command instanceof QuantityType) { - channel.get(channelId).setMin(((QuantityType) command).doubleValue()); - success = true; + channel.setMin(((QuantityType) command).toUnit(unit).doubleValue()); + return true; } - break; case CHANNEL_MAX: if (command instanceof QuantityType) { - channel.get(channelId).setMax(((QuantityType) command).doubleValue()); - success = true; + channel.setMax(((QuantityType) command).toUnit(unit).doubleValue()); + return true; } - break; case CHANNEL_ALARM_DEVICE: if (command instanceof OnOffType) { BigInteger value; if (command == OnOffType.ON) { - value = BigInteger.valueOf(channel.get(channelId).getAlarm()).setBit(1); + value = BigInteger.valueOf(channel.getAlarm()).setBit(1); } else { - value = BigInteger.valueOf(channel.get(channelId).getAlarm()).clearBit(1); + value = BigInteger.valueOf(channel.getAlarm()).clearBit(1); } - channel.get(channelId).setAlarm(value.intValue()); - success = true; + channel.setAlarm(value.intValue()); + return true; } - break; case CHANNEL_ALARM_PUSH: if (command instanceof OnOffType) { BigInteger value; if (command == OnOffType.ON) { - value = BigInteger.valueOf(channel.get(channelId).getAlarm()).setBit(0); + value = BigInteger.valueOf(channel.getAlarm()).setBit(0); } else { - value = BigInteger.valueOf(channel.get(channelId).getAlarm()).clearBit(0); + value = BigInteger.valueOf(channel.getAlarm()).clearBit(0); } - channel.get(channelId).setAlarm(value.intValue()); - success = true; + channel.setAlarm(value.intValue()); + return true; } - break; case CHANNEL_COLOR_NAME: if (command instanceof StringType) { - channel.get(channelId).setColor(UtilNano.toHex(((StringType) command).toString())); - success = true; + channel.setColor(UtilNano.toHex(((StringType) command).toString())); + return true; } - break; } } } else if (channelUID.getId().equals(CHANNEL_PITMASTER_1)) { @@ -235,50 +217,49 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data switch (channelUID.getIdWithoutGroup()) { case CHANNEL_PITMASTER_CHANNEL_ID: pm.setChannel(((QuantityType) command).intValue()); - success = true; - break; + return true; case CHANNEL_PITMASTER_PIDPROFILE: pm.setPid(((QuantityType) command).intValue()); - success = true; - break; + return true; case CHANNEL_PITMASTER_SETPOINT: - pm.setSet(((QuantityType) command).doubleValue()); - success = true; - break; + pm.setSet(((QuantityType) command).toUnit(unit).doubleValue()); + return true; case CHANNEL_PITMASTER_STATE: String state = ((StringType) command).toString(); if (state.equalsIgnoreCase("off") || state.equalsIgnoreCase("manual") || state.equalsIgnoreCase("auto")) { pm.setTyp(state); - success = true; + return true; } } } } - return success; + return false; } - public static String getTrigger(ChannelUID channelUID, Data data) { - String trigger = null; - String groupId = channelUID.getGroupId(); - if (groupId == null || data == null) { - return null; + public static String getTrigger(ChannelUID channelUID, @Nullable Data data) throws WlanThermoException { + if (channelUID.getGroupId() == null || data == null) { + throw new WlanThermoException(INVALID_INPUT_EXCEPTION); } - List channel = data.getChannel(); + + String groupId = channelUID.getGroupId(); + List channelList = data.getChannel(); + if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channel.size() > 0 && channelId <= channel.size()) { + if (channelList.size() > 0 && channelId <= channelList.size()) { + Channel channel = channelList.get(channelId); if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { - if (channel.get(channelId).getTemp() != 999) { - if (channel.get(channelId).getTemp() > channel.get(channelId).getMax()) { - trigger = TRIGGER_ALARM_MAX; - } else if (channel.get(channelId).getTemp() < channel.get(channelId).getMin()) { - trigger = TRIGGER_ALARM_MIN; + if (channel.getTemp() != 999) { + if (channel.getTemp() > channel.getMax()) { + return TRIGGER_ALARM_MAX; + } else if (channel.getTemp() < channel.getMin()) { + return TRIGGER_ALARM_MIN; } } } } } - return trigger; + throw new WlanThermoUnknownChannelException(); } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 13b0612495a7d..b4ef31a1eb314 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -23,7 +23,9 @@ import org.eclipse.jetty.client.api.AuthenticationStore; import org.eclipse.jetty.client.util.DigestAuthentication; import org.eclipse.jetty.client.util.StringContentProvider; +import org.openhab.binding.wlanthermo.internal.WlanThermoException; import org.openhab.binding.wlanthermo.internal.WlanThermoExtendedConfiguration; +import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Data; import org.openhab.binding.wlanthermo.internal.api.nano.dto.settings.Settings; import org.openhab.core.thing.*; @@ -106,9 +108,13 @@ private void checkConnection() { @Override public void handleCommand(ChannelUID channelUID, Command command) { if (command instanceof RefreshType) { - State s = WlanThermoNanoV1CommandHandler.getState(channelUID, data, settings); - if (s != null) + try { + State s = WlanThermoNanoV1CommandHandler.getState(channelUID, data, settings); updateState(channelUID, s); + } catch (WlanThermoException e) { + logger.debug("Could not handle command of type {} for channel {}!", + command.getClass().toGenericString(), channelUID.getId()); + } } else { if (WlanThermoNanoV1CommandHandler.setState(channelUID, command, data)) { logger.debug("Data updated, pushing changes"); @@ -132,18 +138,17 @@ private void update() { // Update channels for (Channel channel : thing.getChannels()) { - State state = WlanThermoNanoV1CommandHandler.getState(channel.getUID(), data, settings); - if (state != null) { + try { + State state = WlanThermoNanoV1CommandHandler.getState(channel.getUID(), data, settings); updateState(channel.getUID(), state); - } else { + } catch (WlanThermoUnknownChannelException e) { // if we could not obtain a state, try trigger instead String trigger = WlanThermoNanoV1CommandHandler.getTrigger(channel.getUID(), data); - if (trigger != null) { - triggerChannel(channel.getUID(), trigger); - } + triggerChannel(channel.getUID(), trigger); } } - } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { + } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException + | WlanThermoException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed: " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; From 182345803d527b479c19f1b80125cc15ca25ad6a Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sat, 9 Jan 2021 17:50:06 +0100 Subject: [PATCH 20/40] Set Thing status to OFFLINE on Communication Error Signed-off-by: Christian Schlipp --- .../internal/api/esp32/WlanThermoEsp32Handler.java | 6 +++--- .../internal/api/nano/WlanThermoNanoV1Handler.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index b9b089cd96158..d1d1e121f0a59 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -197,17 +197,17 @@ private void push() { int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") .timeout(5, TimeUnit.SECONDS).send().getStatus(); if (status == 401) { - updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); } else if (status != 200) { - updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + c.getName() + " on device, Statuscode " + status + " on URI " + uri.toString()); logger.debug("Payload sent: {}", json); } else { updateStatus(ThingStatus.ONLINE); } } catch (InterruptedException | TimeoutException | ExecutionException | URISyntaxException e) { - updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + c.getName() + " on device: " + e.getMessage()); } }); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index b4ef31a1eb314..20e2306bd3d54 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -173,17 +173,17 @@ private void push() { int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") .timeout(5, TimeUnit.SECONDS).send().getStatus(); if (status == 401) { - updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); } else if (status != 200) { - updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + c.getName() + " on device, Statuscode " + status + " on URI " + uri.toString()); logger.debug("Payload sent: {}", json); } else { updateStatus(ThingStatus.ONLINE); } } catch (InterruptedException | TimeoutException | ExecutionException | URISyntaxException e) { - updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + c.getName() + " on device: " + e.getMessage()); } }); From 00908e75982933f14f4783c274490db04a32c59d Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sat, 9 Jan 2021 17:55:26 +0100 Subject: [PATCH 21/40] Don't try to update other channels if one fails due to wrong credentials Signed-off-by: Christian Schlipp --- .../internal/api/esp32/WlanThermoEsp32Handler.java | 5 +++-- .../internal/api/nano/WlanThermoNanoV1Handler.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index d1d1e121f0a59..1196feff569b8 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -190,7 +190,7 @@ private void push() { if (data == null) { return; } - data.getChannel().forEach(c -> { + for (org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Channel c : data.getChannel()) { try { String json = gson.toJson(c); URI uri = config.getUri("/setchannels"); @@ -199,6 +199,7 @@ private void push() { if (status == 401) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); + break; } else if (status != 200) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + c.getName() + " on device, Statuscode " + status + " on URI " + uri.toString()); @@ -210,7 +211,7 @@ private void push() { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + c.getName() + " on device: " + e.getMessage()); } - }); + } } @Override diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 20e2306bd3d54..0dc4365758dc4 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -166,7 +166,7 @@ private void push() { if (data == null) { return; } - data.getChannel().forEach(c -> { + for (org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Channel c : data.getChannel()) { try { String json = gson.toJson(c); URI uri = config.getUri("/setchannels"); @@ -175,6 +175,7 @@ private void push() { if (status == 401) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); + break; } else if (status != 200) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + c.getName() + " on device, Statuscode " + status + " on URI " + uri.toString()); @@ -186,7 +187,7 @@ private void push() { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + c.getName() + " on device: " + e.getMessage()); } - }); + } } @Override From d1089575be5b391b0194bfaf615a0dfca9d6c012 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sat, 9 Jan 2021 18:05:34 +0100 Subject: [PATCH 22/40] Exit immediately if interrupted Signed-off-by: Christian Schlipp --- .../internal/api/esp32/WlanThermoEsp32Handler.java | 9 ++++++--- .../internal/api/mini/WlanThermoMiniHandler.java | 5 +++-- .../internal/api/nano/WlanThermoNanoV1Handler.java | 9 ++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 1196feff569b8..fbd8bb3caa6ea 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -171,8 +171,7 @@ private void update() { triggerChannel(channel.getUID(), trigger); } } - } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException - | WlanThermoException e) { + } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed: " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; @@ -183,6 +182,8 @@ private void update() { updateState(channel.getUID(), UnDefType.UNDEF); } checkConnection(); + } catch (InterruptedException e) { + logger.debug("Update interrupted. {}", e.getMessage()); } } @@ -207,9 +208,11 @@ private void push() { } else { updateStatus(ThingStatus.ONLINE); } - } catch (InterruptedException | TimeoutException | ExecutionException | URISyntaxException e) { + } catch (TimeoutException | ExecutionException | URISyntaxException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + c.getName() + " on device: " + e.getMessage()); + } catch (InterruptedException e) { + logger.debug("Push interrupted. {}", e.getMessage()); } } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index 5905531484cb1..73215e78a5b18 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -122,8 +122,7 @@ private void update() { } } - } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException - | WlanThermoException e) { + } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed: " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; @@ -134,6 +133,8 @@ private void update() { updateState(channel.getUID(), UnDefType.UNDEF); } checkConnection(); + } catch (InterruptedException e) { + logger.debug("Update interrupted. {}", e.getMessage()); } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 0dc4365758dc4..456c895db032d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -147,8 +147,7 @@ private void update() { triggerChannel(channel.getUID(), trigger); } } - } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException - | WlanThermoException e) { + } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Update failed: " + e.getMessage()); ScheduledFuture oldScheduler = pollingScheduler; @@ -159,6 +158,8 @@ private void update() { updateState(channel.getUID(), UnDefType.UNDEF); } checkConnection(); + } catch (InterruptedException e) { + logger.debug("Update interrupted. {}", e.getMessage()); } } @@ -183,9 +184,11 @@ private void push() { } else { updateStatus(ThingStatus.ONLINE); } - } catch (InterruptedException | TimeoutException | ExecutionException | URISyntaxException e) { + } catch (TimeoutException | ExecutionException | URISyntaxException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " + c.getName() + " on device: " + e.getMessage()); + } catch (InterruptedException e) { + logger.debug("Push interrupted. {}", e.getMessage()); } } } From 7a32b382d5e39365e3a1cdc89f26bae61546ef58 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sat, 9 Jan 2021 18:23:00 +0100 Subject: [PATCH 23/40] merge checkConnection and update method execute push method with scheduler Signed-off-by: Christian Schlipp --- .../api/esp32/WlanThermoEsp32Handler.java | 147 ++++++++---------- .../api/mini/WlanThermoMiniHandler.java | 91 +++++------ .../api/nano/WlanThermoNanoV1Handler.java | 103 ++++++------ 3 files changed, 150 insertions(+), 191 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index fbd8bb3caa6ea..0a980cd6c909d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -75,35 +75,81 @@ public void initialize() { authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM, config.getUsername(), config.getPassword())); } - pollingScheduler = scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); + pollingScheduler = scheduler.schedule(this::checkConnectionAndUpdate, config.getPollingInterval(), + TimeUnit.SECONDS); } catch (URISyntaxException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Failed to initialize WlanThermo Nano: " + e.getMessage()); } } - private void checkConnection() { - try { - if (httpClient.GET(config.getUri()).getStatus() == 200) { - updateStatus(ThingStatus.ONLINE); - ScheduledFuture oldScheduler = pollingScheduler; - if (oldScheduler != null) { - oldScheduler.cancel(false); + private void checkConnectionAndUpdate() { + if (this.thing.getStatus() == ThingStatus.OFFLINE) { + try { + if (httpClient.GET(config.getUri()).getStatus() == 200) { + updateStatus(ThingStatus.ONLINE); + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + "WlanThermo not found under given address."); } - pollingScheduler = scheduler.scheduleWithFixedDelay(this::update, 0, config.getPollingInterval(), - TimeUnit.SECONDS); - } else { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "WlanThermo not found under given address."); + } catch (URISyntaxException | ExecutionException | TimeoutException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); + } catch (InterruptedException e) { + logger.debug("Connection check interrupted. {}", e.getMessage()); } - } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); - ScheduledFuture oldScheduler = pollingScheduler; - if (oldScheduler != null) { - oldScheduler.cancel(false); + } else { + try { + // Update objects with data from device + String json = httpClient.GET(config.getUri("/data")).getContentAsString(); + data = gson.fromJson(json, Data.class); + logger.debug("Received at /data: {}", json); + json = httpClient.GET(config.getUri("/settings")).getContentAsString(); + settings = gson.fromJson(json, Settings.class); + logger.debug("Received at /settings: {}", json); + + if (data == null || settings == null) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to parse Data and/or Settings values!"); + return; + } + + // Update Channels if required + Map properties = editProperties(); + Boolean pmEnabled = settings.getFeatures().getBluetooth(); + int pmChannels = pmEnabled ? data.getPitmaster().getPm().size() : 0; + int tempChannels = data.getChannel().size(); + + // Update properties + properties.put(WlanThermoBindingConstants.PROPERTY_MODEL, settings.getDevice().getDevice()); + properties.put(WlanThermoBindingConstants.PROPERTY_SERIAL, settings.getDevice().getSerial()); + properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_BT_ENABLED, + settings.getFeatures().getBluetooth().toString()); + properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_PM_ENABLED, pmEnabled.toString()); + properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_TEMP_CHANNELS, String.valueOf(tempChannels)); + properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_PM_CHANNELS, String.valueOf(pmChannels)); + updateProperties(properties); + + // Update channel state + for (Channel channel : thing.getChannels()) { + try { + State state = WlanThermoEsp32CommandHandler.getState(channel.getUID(), data, settings); + updateState(channel.getUID(), state); + } catch (WlanThermoUnknownChannelException e) { + // if we could not obtain a state, try trigger instead + String trigger = WlanThermoEsp32CommandHandler.getTrigger(channel.getUID(), data); + triggerChannel(channel.getUID(), trigger); + } + } + } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Update failed: " + e.getMessage()); + for (Channel channel : thing.getChannels()) { + updateState(channel.getUID(), UnDefType.UNDEF); + } + } catch (InterruptedException e) { + logger.debug("Update interrupted. {}", e.getMessage()); } - pollingScheduler = scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); } } @@ -120,7 +166,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { } else { if (WlanThermoEsp32CommandHandler.setState(channelUID, command, data)) { logger.debug("Data updated, pushing changes"); - push(); + scheduler.execute(this::push); } else { logger.debug("Could not handle command of type {} for channel {}!", command.getClass().toGenericString(), channelUID.getId()); @@ -128,65 +174,6 @@ public void handleCommand(ChannelUID channelUID, Command command) { } } - private void update() { - try { - // Update objects with data from device - String json = httpClient.GET(config.getUri("/data")).getContentAsString(); - data = gson.fromJson(json, Data.class); - logger.debug("Received at /data: {}", json); - json = httpClient.GET(config.getUri("/settings")).getContentAsString(); - settings = gson.fromJson(json, Settings.class); - logger.debug("Received at /settings: {}", json); - - if (data == null || settings == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to parse Data and/or Settings values!"); - return; - } - - // Update Channels if required - Map properties = editProperties(); - Boolean pmEnabled = settings.getFeatures().getBluetooth(); - int pmChannels = pmEnabled ? data.getPitmaster().getPm().size() : 0; - int tempChannels = data.getChannel().size(); - - // Update properties - properties.put(WlanThermoBindingConstants.PROPERTY_MODEL, settings.getDevice().getDevice()); - properties.put(WlanThermoBindingConstants.PROPERTY_SERIAL, settings.getDevice().getSerial()); - properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_BT_ENABLED, - settings.getFeatures().getBluetooth().toString()); - properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_PM_ENABLED, pmEnabled.toString()); - properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_TEMP_CHANNELS, String.valueOf(tempChannels)); - properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_PM_CHANNELS, String.valueOf(pmChannels)); - updateProperties(properties); - - // Update channel state - for (Channel channel : thing.getChannels()) { - try { - State state = WlanThermoEsp32CommandHandler.getState(channel.getUID(), data, settings); - updateState(channel.getUID(), state); - } catch (WlanThermoUnknownChannelException e) { - // if we could not obtain a state, try trigger instead - String trigger = WlanThermoEsp32CommandHandler.getTrigger(channel.getUID(), data); - triggerChannel(channel.getUID(), trigger); - } - } - } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Update failed: " + e.getMessage()); - ScheduledFuture oldScheduler = pollingScheduler; - if (oldScheduler != null) { - oldScheduler.cancel(false); - } - for (Channel channel : thing.getChannels()) { - updateState(channel.getUID(), UnDefType.UNDEF); - } - checkConnection(); - } catch (InterruptedException e) { - logger.debug("Update interrupted. {}", e.getMessage()); - } - } - private void push() { if (data == null) { return; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index 73215e78a5b18..12833b53c9afc 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -64,27 +64,47 @@ public void initialize() { } private void checkConnection() { - try { - if (httpClient.GET(config.getUri("/app.php")).getStatus() == 200) { - updateStatus(ThingStatus.ONLINE); - ScheduledFuture oldScheduler = pollingScheduler; - if (oldScheduler != null) { - oldScheduler.cancel(false); + if (this.thing.getStatus() == ThingStatus.OFFLINE) { + try { + if (httpClient.GET(config.getUri("/app.php")).getStatus() == 200) { + updateStatus(ThingStatus.ONLINE); + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + "WlanThermo not found under given address."); } - pollingScheduler = scheduler.scheduleWithFixedDelay(this::update, 0, config.getPollingInterval(), - TimeUnit.SECONDS); - } else { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "WlanThermo not found under given address."); + } catch (URISyntaxException | ExecutionException | TimeoutException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); + } catch (InterruptedException e) { + logger.debug("Connection check interrupted. {}", e.getMessage()); } - } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); - ScheduledFuture oldScheduler = pollingScheduler; - if (oldScheduler != null) { - oldScheduler.cancel(false); + } else { + try { + // Update objects with data from device + String json = httpClient.GET(config.getUri("/app.php")).getContentAsString(); + app = gson.fromJson(json, App.class); + logger.debug("Received at /app.php: {}", json); + + // Update channels + for (Channel channel : thing.getChannels()) { + try { + State state = WlanThermoMiniCommandHandler.getState(channel.getUID(), app); + updateState(channel.getUID(), state); + } catch (WlanThermoUnknownChannelException e) { + // if we could not obtain a state, try trigger instead + String trigger = WlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app); + triggerChannel(channel.getUID(), trigger); + } + } + } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Update failed: " + e.getMessage()); + for (Channel channel : thing.getChannels()) { + updateState(channel.getUID(), UnDefType.UNDEF); + } + } catch (InterruptedException e) { + logger.debug("Update interrupted. {}", e.getMessage()); } - pollingScheduler = scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); } } @@ -103,41 +123,6 @@ public void handleCommand(ChannelUID channelUID, Command command) { } } - private void update() { - try { - // Update objects with data from device - String json = httpClient.GET(config.getUri("/app.php")).getContentAsString(); - app = gson.fromJson(json, App.class); - logger.debug("Received at /app.php: {}", json); - - // Update channels - for (Channel channel : thing.getChannels()) { - try { - State state = WlanThermoMiniCommandHandler.getState(channel.getUID(), app); - updateState(channel.getUID(), state); - } catch (WlanThermoUnknownChannelException e) { - // if we could not obtain a state, try trigger instead - String trigger = WlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app); - triggerChannel(channel.getUID(), trigger); - } - } - - } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Update failed: " + e.getMessage()); - ScheduledFuture oldScheduler = pollingScheduler; - if (oldScheduler != null) { - oldScheduler.cancel(false); - } - for (Channel channel : thing.getChannels()) { - updateState(channel.getUID(), UnDefType.UNDEF); - } - checkConnection(); - } catch (InterruptedException e) { - logger.debug("Update interrupted. {}", e.getMessage()); - } - } - @Override public void dispose() { ScheduledFuture oldScheduler = pollingScheduler; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 456c895db032d..c4a26693ddbd5 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -73,35 +73,59 @@ public void initialize() { authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM, config.getUsername(), config.getPassword())); } - pollingScheduler = scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); + pollingScheduler = scheduler.schedule(this::checkConnectionAndUpdate, config.getPollingInterval(), + TimeUnit.SECONDS); } catch (URISyntaxException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Failed to initialize WlanThermo Nano: " + e.getMessage()); } } - private void checkConnection() { - try { - if (httpClient.GET(config.getUri()).getStatus() == 200) { - updateStatus(ThingStatus.ONLINE); - ScheduledFuture oldScheduler = pollingScheduler; - if (oldScheduler != null) { - oldScheduler.cancel(false); + private void checkConnectionAndUpdate() { + if (this.thing.getStatus() == ThingStatus.OFFLINE) { + try { + if (httpClient.GET(config.getUri()).getStatus() == 200) { + updateStatus(ThingStatus.ONLINE); + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + "WlanThermo not found under given address."); } - pollingScheduler = scheduler.scheduleWithFixedDelay(this::update, 0, config.getPollingInterval(), - TimeUnit.SECONDS); - } else { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "WlanThermo not found under given address."); + } catch (URISyntaxException | ExecutionException | TimeoutException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); + } catch (InterruptedException e) { + logger.debug("Connection check interrupted. {}", e.getMessage()); } - } catch (URISyntaxException | InterruptedException | ExecutionException | TimeoutException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); - ScheduledFuture oldScheduler = pollingScheduler; - if (oldScheduler != null) { - oldScheduler.cancel(false); + } else { + try { + // Update objects with data from device + String json = httpClient.GET(config.getUri("/data")).getContentAsString(); + data = gson.fromJson(json, Data.class); + logger.debug("Received at /data: {}", json); + json = httpClient.GET(config.getUri("/settings")).getContentAsString(); + settings = gson.fromJson(json, Settings.class); + logger.debug("Received at /settings: {}", json); + + // Update channels + for (Channel channel : thing.getChannels()) { + try { + State state = WlanThermoNanoV1CommandHandler.getState(channel.getUID(), data, settings); + updateState(channel.getUID(), state); + } catch (WlanThermoUnknownChannelException e) { + // if we could not obtain a state, try trigger instead + String trigger = WlanThermoNanoV1CommandHandler.getTrigger(channel.getUID(), data); + triggerChannel(channel.getUID(), trigger); + } + } + } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Update failed: " + e.getMessage()); + for (Channel channel : thing.getChannels()) { + updateState(channel.getUID(), UnDefType.UNDEF); + } + } catch (InterruptedException e) { + logger.debug("Update interrupted. {}", e.getMessage()); } - pollingScheduler = scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); } } @@ -118,7 +142,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { } else { if (WlanThermoNanoV1CommandHandler.setState(channelUID, command, data)) { logger.debug("Data updated, pushing changes"); - push(); + scheduler.execute(this::push); } else { logger.debug("Could not handle command of type {} for channel {}!", command.getClass().toGenericString(), channelUID.getId()); @@ -126,43 +150,6 @@ public void handleCommand(ChannelUID channelUID, Command command) { } } - private void update() { - try { - // Update objects with data from device - String json = httpClient.GET(config.getUri("/data")).getContentAsString(); - data = gson.fromJson(json, Data.class); - logger.debug("Received at /data: {}", json); - json = httpClient.GET(config.getUri("/settings")).getContentAsString(); - settings = gson.fromJson(json, Settings.class); - logger.debug("Received at /settings: {}", json); - - // Update channels - for (Channel channel : thing.getChannels()) { - try { - State state = WlanThermoNanoV1CommandHandler.getState(channel.getUID(), data, settings); - updateState(channel.getUID(), state); - } catch (WlanThermoUnknownChannelException e) { - // if we could not obtain a state, try trigger instead - String trigger = WlanThermoNanoV1CommandHandler.getTrigger(channel.getUID(), data); - triggerChannel(channel.getUID(), trigger); - } - } - } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Update failed: " + e.getMessage()); - ScheduledFuture oldScheduler = pollingScheduler; - if (oldScheduler != null) { - oldScheduler.cancel(false); - } - for (Channel channel : thing.getChannels()) { - updateState(channel.getUID(), UnDefType.UNDEF); - } - checkConnection(); - } catch (InterruptedException e) { - logger.debug("Update interrupted. {}", e.getMessage()); - } - } - private void push() { if (data == null) { return; From b2f971b82b6db4f4accb916f8eb8bc86fd7c31c5 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sat, 9 Jan 2021 18:25:23 +0100 Subject: [PATCH 24/40] change rssi channel to category Number Signed-off-by: Christian Schlipp --- .../src/main/resources/OH-INF/thing/channel-types.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml index 75e8e8d1a11bf..f27c758d098e0 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml @@ -254,7 +254,7 @@ Number:Power - Text + Number From a7de6f611d3430ed1fc232d321e98cfe9be1ccef Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sun, 10 Jan 2021 22:30:51 +0100 Subject: [PATCH 25/40] Improve Exception handling Fix Triggers not working anymore after code modifications Signed-off-by: Christian Schlipp --- .../internal/WlanThermoBindingConstants.java | 3 -- .../internal/WlanThermoException.java | 4 +-- .../internal/WlanThermoInputException.java | 31 +++++++++++++++++++ .../WlanThermoUnknownChannelException.java | 10 ++++-- .../esp32/WlanThermoEsp32CommandHandler.java | 15 ++++----- .../api/esp32/WlanThermoEsp32Handler.java | 12 ++++--- .../mini/WlanThermoMiniCommandHandler.java | 18 ++++++----- .../api/mini/WlanThermoMiniHandler.java | 11 +++++-- .../nano/WlanThermoNanoV1CommandHandler.java | 15 ++++----- .../api/nano/WlanThermoNanoV1Handler.java | 12 ++++--- 10 files changed, 91 insertions(+), 40 deletions(-) create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoInputException.java diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java index 64e986627579b..42632649c6112 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java @@ -88,7 +88,4 @@ public class WlanThermoBindingConstants { public static final DecimalType SIGNAL_STRENGTH_3 = new DecimalType(3); public static final DecimalType SIGNAL_STRENGTH_2 = new DecimalType(2); public static final DecimalType SIGNAL_STRENGTH_1 = new DecimalType(1); - - public static final String INVALID_INPUT_EXCEPTION = "Input Data is invalid!"; - public static final String UNKNOWN_CHANNEL_EXCEPTION = "Channel or Trigger unknown!"; } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoException.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoException.java index 6bb692093258f..28f7dbcb690b2 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoException.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoException.java @@ -20,9 +20,9 @@ * @author Christian Schlipp - Initial contribution */ @NonNullByDefault -public class WlanThermoException extends Exception { +public abstract class WlanThermoException extends Exception { - static final long serialVersionUID = 1l; + static final long serialVersionUID = 1L; public WlanThermoException(String reason) { super(reason, null); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoInputException.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoInputException.java new file mode 100644 index 0000000000000..d24aa817ff125 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoInputException.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wlanthermo.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * The {@link WlanThermoInputException} is thrown if input is invalid or null + * + * @author Christian Schlipp - Initial contribution + */ +@NonNullByDefault +public class WlanThermoInputException extends WlanThermoException { + + static final long serialVersionUID = 1L; + public static final String INVALID_INPUT_EXCEPTION = "Input Data is invalid!"; + + public WlanThermoInputException() { + super(INVALID_INPUT_EXCEPTION); + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUnknownChannelException.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUnknownChannelException.java index e5ef7023e0dcc..3d02452219e50 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUnknownChannelException.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUnknownChannelException.java @@ -13,6 +13,7 @@ package org.openhab.binding.wlanthermo.internal; import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.core.thing.ChannelUID; /** * The {@link WlanThermoUnknownChannelException} is thrown if a channel or trigger is unknown @@ -22,9 +23,14 @@ @NonNullByDefault public class WlanThermoUnknownChannelException extends WlanThermoException { - static final long serialVersionUID = 1l; + static final long serialVersionUID = 1L; + public static final String UNKNOWN_CHANNEL_EXCEPTION = "Channel or Trigger unknown!"; public WlanThermoUnknownChannelException() { - super(WlanThermoBindingConstants.UNKNOWN_CHANNEL_EXCEPTION); + super(UNKNOWN_CHANNEL_EXCEPTION); + } + + public WlanThermoUnknownChannelException(ChannelUID channelUID) { + super(UNKNOWN_CHANNEL_EXCEPTION + "ChannelUID: " + channelUID.toString()); } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index add7e20495be5..242279508d174 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -23,7 +23,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.wlanthermo.internal.WlanThermoException; +import org.openhab.binding.wlanthermo.internal.WlanThermoInputException; import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Channel; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Data; @@ -49,9 +49,9 @@ public class WlanThermoEsp32CommandHandler { public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullable Settings settings) - throws WlanThermoException { + throws WlanThermoUnknownChannelException, WlanThermoInputException { if (channelUID.getGroupId() == null || data == null || settings == null) { - throw new WlanThermoException(INVALID_INPUT_EXCEPTION); + throw new WlanThermoInputException(); } String groupId = channelUID.getGroupId(); @@ -156,7 +156,7 @@ public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullab return UnDefType.UNDEF; } } - throw new WlanThermoUnknownChannelException(); + throw new WlanThermoUnknownChannelException(channelUID); } public static boolean setState(ChannelUID channelUID, Command command, @Nullable Data data) { @@ -245,9 +245,10 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable return false; } - public static String getTrigger(ChannelUID channelUID, @Nullable Data data) throws WlanThermoException { + public static String getTrigger(ChannelUID channelUID, @Nullable Data data) + throws WlanThermoUnknownChannelException, WlanThermoInputException { if (channelUID.getGroupId() == null || data == null) { - throw new WlanThermoException(INVALID_INPUT_EXCEPTION); + throw new WlanThermoInputException(); } String groupId = channelUID.getGroupId(); @@ -268,6 +269,6 @@ public static String getTrigger(ChannelUID channelUID, @Nullable Data data) thro } } } - throw new WlanThermoUnknownChannelException(); + throw new WlanThermoUnknownChannelException(channelUID); } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 0a980cd6c909d..5c38595fed0b3 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -75,8 +75,8 @@ public void initialize() { authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM, config.getUsername(), config.getPassword())); } - pollingScheduler = scheduler.schedule(this::checkConnectionAndUpdate, config.getPollingInterval(), - TimeUnit.SECONDS); + pollingScheduler = scheduler.scheduleWithFixedDelay(this::checkConnectionAndUpdate, 0, + config.getPollingInterval(), TimeUnit.SECONDS); } catch (URISyntaxException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Failed to initialize WlanThermo Nano: " + e.getMessage()); @@ -137,8 +137,12 @@ private void checkConnectionAndUpdate() { updateState(channel.getUID(), state); } catch (WlanThermoUnknownChannelException e) { // if we could not obtain a state, try trigger instead - String trigger = WlanThermoEsp32CommandHandler.getTrigger(channel.getUID(), data); - triggerChannel(channel.getUID(), trigger); + try { + String trigger = WlanThermoEsp32CommandHandler.getTrigger(channel.getUID(), data); + triggerChannel(channel.getUID(), trigger); + } catch (WlanThermoUnknownChannelException e1) { + logger.debug("{}", e.getMessage()); + } } } } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java index f43fb1682b665..bf2bf337ba831 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java @@ -22,7 +22,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; -import org.openhab.binding.wlanthermo.internal.WlanThermoException; +import org.openhab.binding.wlanthermo.internal.WlanThermoInputException; import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; import org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin.*; import org.openhab.core.library.types.*; @@ -43,9 +43,10 @@ public class WlanThermoMiniCommandHandler { public static final String ERROR = "er"; - public static State getState(ChannelUID channelUID, @Nullable App app) throws WlanThermoException { + public static State getState(ChannelUID channelUID, @Nullable App app) + throws WlanThermoUnknownChannelException, WlanThermoInputException { if (channelUID.getGroupId() == null || app == null) { - throw new WlanThermoException(INVALID_INPUT_EXCEPTION); + throw new WlanThermoInputException(); } String groupId = channelUID.getGroupId(); @@ -135,12 +136,13 @@ public static State getState(ChannelUID channelUID, @Nullable App app) throws Wl return new DecimalType(pit.getCh()); } } - throw new WlanThermoUnknownChannelException(); + throw new WlanThermoUnknownChannelException(channelUID); } - public static String getTrigger(ChannelUID channelUID, @Nullable App app) throws WlanThermoException { + public static String getTrigger(ChannelUID channelUID, @Nullable App app) + throws WlanThermoUnknownChannelException, WlanThermoInputException { if (channelUID.getGroupId() == null || app == null) { - throw new WlanThermoException(INVALID_INPUT_EXCEPTION); + throw new WlanThermoInputException(); } String groupId = channelUID.getGroupId(); @@ -150,7 +152,7 @@ public static String getTrigger(ChannelUID channelUID, @Nullable App app) throws if (channelId >= 0 && channelId <= 9) { Channel channel = app.getChannel(); if (channel == null) { - throw new WlanThermoException("Channel ID is unavailable!"); + throw new WlanThermoInputException(); } Data data = channel.getData(channelId); if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { @@ -164,6 +166,6 @@ public static String getTrigger(ChannelUID channelUID, @Nullable App app) throws } } } - throw new WlanThermoUnknownChannelException(); + throw new WlanThermoUnknownChannelException(channelUID); } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index 12833b53c9afc..00ac62ae188b9 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -60,7 +60,8 @@ public void initialize() { config = getConfigAs(WlanThermoConfiguration.class); updateStatus(ThingStatus.UNKNOWN); - pollingScheduler = scheduler.schedule(this::checkConnection, config.getPollingInterval(), TimeUnit.SECONDS); + pollingScheduler = scheduler.scheduleWithFixedDelay(this::checkConnection, 0, config.getPollingInterval(), + TimeUnit.SECONDS); } private void checkConnection() { @@ -92,8 +93,12 @@ private void checkConnection() { updateState(channel.getUID(), state); } catch (WlanThermoUnknownChannelException e) { // if we could not obtain a state, try trigger instead - String trigger = WlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app); - triggerChannel(channel.getUID(), trigger); + try { + String trigger = WlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app); + triggerChannel(channel.getUID(), trigger); + } catch (WlanThermoUnknownChannelException e1) { + logger.debug("{}", e.getMessage()); + } } } } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index 6d2a27d0cf7a4..74ad337afa8dc 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -23,7 +23,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.wlanthermo.internal.WlanThermoException; +import org.openhab.binding.wlanthermo.internal.WlanThermoInputException; import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Channel; import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Data; @@ -49,9 +49,9 @@ public class WlanThermoNanoV1CommandHandler { public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullable Settings settings) - throws WlanThermoException { + throws WlanThermoUnknownChannelException, WlanThermoInputException { if (channelUID.getGroupId() == null || data == null || settings == null) { - throw new WlanThermoException(INVALID_INPUT_EXCEPTION); + throw new WlanThermoInputException(); } String groupId = channelUID.getGroupId(); @@ -148,7 +148,7 @@ public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullab return UnDefType.UNDEF; } } - throw new WlanThermoUnknownChannelException(); + throw new WlanThermoUnknownChannelException(channelUID); } public static boolean setState(ChannelUID channelUID, Command command, @Nullable Data data) { @@ -237,9 +237,10 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable return false; } - public static String getTrigger(ChannelUID channelUID, @Nullable Data data) throws WlanThermoException { + public static String getTrigger(ChannelUID channelUID, @Nullable Data data) + throws WlanThermoUnknownChannelException, WlanThermoInputException { if (channelUID.getGroupId() == null || data == null) { - throw new WlanThermoException(INVALID_INPUT_EXCEPTION); + throw new WlanThermoInputException(); } String groupId = channelUID.getGroupId(); @@ -260,6 +261,6 @@ public static String getTrigger(ChannelUID channelUID, @Nullable Data data) thro } } } - throw new WlanThermoUnknownChannelException(); + throw new WlanThermoUnknownChannelException(channelUID); } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index c4a26693ddbd5..b6518b76849a5 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -73,8 +73,8 @@ public void initialize() { authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM, config.getUsername(), config.getPassword())); } - pollingScheduler = scheduler.schedule(this::checkConnectionAndUpdate, config.getPollingInterval(), - TimeUnit.SECONDS); + pollingScheduler = scheduler.scheduleWithFixedDelay(this::checkConnectionAndUpdate, 0, + config.getPollingInterval(), TimeUnit.SECONDS); } catch (URISyntaxException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Failed to initialize WlanThermo Nano: " + e.getMessage()); @@ -113,8 +113,12 @@ private void checkConnectionAndUpdate() { updateState(channel.getUID(), state); } catch (WlanThermoUnknownChannelException e) { // if we could not obtain a state, try trigger instead - String trigger = WlanThermoNanoV1CommandHandler.getTrigger(channel.getUID(), data); - triggerChannel(channel.getUID(), trigger); + try { + String trigger = WlanThermoNanoV1CommandHandler.getTrigger(channel.getUID(), data); + triggerChannel(channel.getUID(), trigger); + } catch (WlanThermoUnknownChannelException e1) { + logger.debug("{}", e.getMessage()); + } } } } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { From c3dab0e24208697fa824c7ae766fded8d19c00bc Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Wed, 13 Jan 2021 00:47:09 +0100 Subject: [PATCH 26/40] Make Pitmaster values writeable for ESP32 and NanoV1 Immediately update values if connected Support setting HEX Colors for ESP32 Support Additional Pitmaster channels for ESP32 Signed-off-by: Christian Schlipp --- .../internal/api/esp32/UtilEsp32.java | 20 ++++++++----- .../esp32/WlanThermoEsp32CommandHandler.java | 12 ++++++-- .../api/esp32/WlanThermoEsp32Handler.java | 30 ++++++++++++++++++- .../api/mini/WlanThermoMiniHandler.java | 4 ++- .../internal/api/nano/UtilNano.java | 10 +++---- .../api/nano/WlanThermoNanoV1Handler.java | 30 ++++++++++++++++++- .../OH-INF/thing/channel-group-types-nano.xml | 2 +- .../resources/OH-INF/thing/channel-types.xml | 1 - 8 files changed, 87 insertions(+), 22 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java index 9af2faf529d3b..cdde1329d3c19 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java @@ -16,6 +16,7 @@ import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.core.library.types.HSBType; /** * The {@link UtilEsp32} class provides conversion functions for the WlanThermo Nano V3 @@ -26,8 +27,8 @@ public class UtilEsp32 { private static final Map COLOR_MAPPINGS = createColorMap(); - private static final String DEFAULT_HEX = "#ffffff"; - private static final String DEFAULT_COLORNAME = "niagara"; + private static final String DEFAULT_HEX = "#FFFFFF"; + private static final String DEFAULT_COLORNAME = "undefined"; private UtilEsp32() { // hidden @@ -67,19 +68,22 @@ public static String toHex(String colorName) { return COLOR_MAPPINGS.getOrDefault(colorName, DEFAULT_HEX); } + public static String toHex(HSBType hsb) { + return "#" + String.format("%02X", hsb.getRed().intValue()) + String.format("%02X", hsb.getGreen().intValue()) + + String.format("%02X", hsb.getBlue().intValue()); + } + public static String toColorName(String colorHex) { - String colorName = null; if (!colorHex.startsWith("#")) { colorHex = "#" + colorHex; } + for (Map.Entry entry : COLOR_MAPPINGS.entrySet()) { if (entry.getValue().equalsIgnoreCase(colorHex)) { - colorName = entry.getKey(); + return entry.getKey(); } } - if (colorName == null) { - colorName = DEFAULT_COLORNAME; - } - return colorName; + + return DEFAULT_COLORNAME; } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index 242279508d174..923929fbe63fe 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -216,12 +216,18 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable channel.setColor(UtilEsp32.toHex(((StringType) command).toString())); return true; } + case CHANNEL_COLOR: + if (command instanceof HSBType) { + channel.setColor(UtilEsp32.toHex((HSBType) command)); + return true; + } } } - } else if (channelUID.getId().equals(CHANNEL_PITMASTER_1)) { + } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_PREFIX)) { + int channelId = Integer.parseInt(groupId.substring(CHANNEL_PITMASTER_PREFIX.length())) - 1; if (data.getPitmaster() != null && data.getPitmaster().getPm() != null - && data.getPitmaster().getPm().size() > 0) { - Pm pm = data.getPitmaster().getPm().get(0); + && data.getPitmaster().getPm().size() > channelId) { + Pm pm = data.getPitmaster().getPm().get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_PITMASTER_CHANNEL_ID: pm.setChannel(((QuantityType) command).intValue()); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 5c38595fed0b3..733d69b06320d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -84,10 +84,12 @@ public void initialize() { } private void checkConnectionAndUpdate() { - if (this.thing.getStatus() == ThingStatus.OFFLINE) { + if (this.thing.getStatus() != ThingStatus.ONLINE) { try { if (httpClient.GET(config.getUri()).getStatus() == 200) { updateStatus(ThingStatus.ONLINE); + // rerun immediately to update state + checkConnectionAndUpdate(); } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "WlanThermo not found under given address."); @@ -182,6 +184,8 @@ private void push() { if (data == null) { return; } + + // Push update for sensor channels for (org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Channel c : data.getChannel()) { try { String json = gson.toJson(c); @@ -206,6 +210,30 @@ private void push() { logger.debug("Push interrupted. {}", e.getMessage()); } } + + // push update for pitmaster channels + try { + String json = gson.toJson(data.getPitmaster().getPm()); + URI uri = config.getUri("/setpitmaster"); + int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") + .timeout(5, TimeUnit.SECONDS).send().getStatus(); + if (status == 401) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); + } else if (status != 200) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to update pitmaster channel on device, Statuscode " + status + " on URI " + + uri.toString()); + logger.debug("Payload sent: {}", json); + } else { + updateStatus(ThingStatus.ONLINE); + } + } catch (TimeoutException | ExecutionException | URISyntaxException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to update pitmaster channel on device: " + e.getMessage()); + } catch (InterruptedException e) { + logger.debug("Push interrupted. {}", e.getMessage()); + } } @Override diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index 00ac62ae188b9..7787ee3817416 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -65,10 +65,12 @@ public void initialize() { } private void checkConnection() { - if (this.thing.getStatus() == ThingStatus.OFFLINE) { + if (this.thing.getStatus() != ThingStatus.ONLINE) { try { if (httpClient.GET(config.getUri("/app.php")).getStatus() == 200) { updateStatus(ThingStatus.ONLINE); + // rerun immediately to update state + checkConnection(); } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "WlanThermo not found under given address."); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java index 38e34f9d4133d..5d756c10f8661 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java @@ -59,18 +59,16 @@ public static String toHex(String colorName) { } public static String toColorName(String colorHex) { - String colorName = null; if (!colorHex.startsWith("#")) { colorHex = "#" + colorHex; } + for (Map.Entry entry : COLOR_MAPPINGS.entrySet()) { if (entry.getValue().equalsIgnoreCase(colorHex)) { - colorName = entry.getKey(); + return entry.getKey(); } } - if (colorName == null) { - colorName = DEFAULT_COLORNAME; - } - return colorName; + + return DEFAULT_COLORNAME; } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index b6518b76849a5..863cea0065126 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -82,10 +82,12 @@ public void initialize() { } private void checkConnectionAndUpdate() { - if (this.thing.getStatus() == ThingStatus.OFFLINE) { + if (this.thing.getStatus() != ThingStatus.ONLINE) { try { if (httpClient.GET(config.getUri()).getStatus() == 200) { updateStatus(ThingStatus.ONLINE); + // rerun immediately to update state + checkConnectionAndUpdate(); } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "WlanThermo not found under given address."); @@ -158,6 +160,8 @@ private void push() { if (data == null) { return; } + + // push update for sensor channels for (org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Channel c : data.getChannel()) { try { String json = gson.toJson(c); @@ -182,6 +186,30 @@ private void push() { logger.debug("Push interrupted. {}", e.getMessage()); } } + + // push update for pitmaster channels + try { + String json = gson.toJson(data.getPitmaster().getPm()); + URI uri = config.getUri("/setpitmaster"); + int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") + .timeout(5, TimeUnit.SECONDS).send().getStatus(); + if (status == 401) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); + } else if (status != 200) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to update pitmaster channel on device, Statuscode " + status + " on URI " + + uri.toString()); + logger.debug("Payload sent: {}", json); + } else { + updateStatus(ThingStatus.ONLINE); + } + } catch (TimeoutException | ExecutionException | URISyntaxException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to update pitmaster channel on device: " + e.getMessage()); + } catch (InterruptedException e) { + logger.debug("Push interrupted. {}", e.getMessage()); + } } @Override diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-nano.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-nano.xml index 320d55b5ff047..8a178d5285ebf 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-nano.xml +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-group-types-nano.xml @@ -30,7 +30,7 @@ - + diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml index f27c758d098e0..b75a202535277 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml +++ b/bundles/org.openhab.binding.wlanthermo/src/main/resources/OH-INF/thing/channel-types.xml @@ -110,7 +110,6 @@ Color Colorpicker - From c1c9ac7f28764809641c2454e814ea14e9f54724 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Wed, 13 Jan 2021 18:36:46 +0100 Subject: [PATCH 27/40] Only push changes if thing is ONLINE Signed-off-by: Christian Schlipp --- .../internal/api/esp32/WlanThermoEsp32CommandHandler.java | 2 +- .../wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java | 2 +- .../internal/api/nano/WlanThermoNanoV1CommandHandler.java | 2 +- .../wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index 923929fbe63fe..d4bbf0435dfb9 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -160,7 +160,7 @@ public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullab } public static boolean setState(ChannelUID channelUID, Command command, @Nullable Data data) { - if (channelUID.getGroupId() == null || data == null) { + if (channelUID.getGroupId() == null || data == null || data.getSystem() == null) { return false; } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 733d69b06320d..f4efee77a75b6 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -181,7 +181,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { } private void push() { - if (data == null) { + if (data == null || this.thing.getStatus() != ThingStatus.ONLINE) { return; } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index 74ad337afa8dc..b89b2b5493e92 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -152,7 +152,7 @@ public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullab } public static boolean setState(ChannelUID channelUID, Command command, @Nullable Data data) { - if (channelUID.getGroupId() == null || data == null) { + if (channelUID.getGroupId() == null || data == null || data.getSystem() == null) { return false; } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 863cea0065126..04b6c43a1e39d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -157,7 +157,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { } private void push() { - if (data == null) { + if (data == null || this.thing.getStatus() != ThingStatus.ONLINE) { return; } From cf34d9c6431cd097e900c307a6f31a2e36a54b97 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 14 Jan 2021 08:02:30 +0100 Subject: [PATCH 28/40] Improve Triggers Signed-off-by: Christian Schlipp --- .../wlanthermo/internal/WlanThermoBindingConstants.java | 2 +- .../internal/api/esp32/WlanThermoEsp32CommandHandler.java | 2 ++ .../internal/api/esp32/WlanThermoEsp32Handler.java | 6 +++++- .../internal/api/mini/WlanThermoMiniCommandHandler.java | 2 ++ .../wlanthermo/internal/api/mini/WlanThermoMiniHandler.java | 6 +++++- .../internal/api/nano/WlanThermoNanoV1CommandHandler.java | 2 ++ .../internal/api/nano/WlanThermoNanoV1Handler.java | 6 +++++- 7 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java index 42632649c6112..2686bc2a76c22 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java @@ -80,7 +80,7 @@ public class WlanThermoBindingConstants { public static final String CHANNEL_PITMASTER_STATE = "state"; // Nano public static final String CHANNEL_PITMASTER_PIDPROFILE = "pid_id"; // Nano - public static final String TRIGGER_ALARM_OFF = "OFF"; + public static final String TRIGGER_NONE = ""; public static final String TRIGGER_ALARM_MIN = "MIN"; public static final String TRIGGER_ALARM_MAX = "MAX"; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index d4bbf0435dfb9..56a7bac69b839 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -270,6 +270,8 @@ public static String getTrigger(ChannelUID channelUID, @Nullable Data data) return TRIGGER_ALARM_MAX; } else if (channel.getTemp() < channel.getMin()) { return TRIGGER_ALARM_MIN; + } else { + return TRIGGER_NONE; } } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index f4efee77a75b6..8c5765229f382 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.wlanthermo.internal.api.esp32; +import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.TRIGGER_NONE; + import java.net.URI; import java.net.URISyntaxException; import java.util.Map; @@ -141,7 +143,9 @@ private void checkConnectionAndUpdate() { // if we could not obtain a state, try trigger instead try { String trigger = WlanThermoEsp32CommandHandler.getTrigger(channel.getUID(), data); - triggerChannel(channel.getUID(), trigger); + if (!trigger.equals(TRIGGER_NONE)) { + triggerChannel(channel.getUID(), trigger); + } } catch (WlanThermoUnknownChannelException e1) { logger.debug("{}", e.getMessage()); } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java index bf2bf337ba831..691a63a89d264 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java @@ -161,6 +161,8 @@ public static String getTrigger(ChannelUID channelUID, @Nullable App app) return TRIGGER_ALARM_MAX; } else if (data.getTemp() < data.getTempMin()) { return TRIGGER_ALARM_MIN; + } else { + return TRIGGER_NONE; } } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index 7787ee3817416..aef8ef9cc786d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.wlanthermo.internal.api.mini; +import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.TRIGGER_NONE; + import java.net.URISyntaxException; import java.util.concurrent.*; @@ -97,7 +99,9 @@ private void checkConnection() { // if we could not obtain a state, try trigger instead try { String trigger = WlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app); - triggerChannel(channel.getUID(), trigger); + if (!trigger.equals(TRIGGER_NONE)) { + triggerChannel(channel.getUID(), trigger); + } } catch (WlanThermoUnknownChannelException e1) { logger.debug("{}", e.getMessage()); } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index b89b2b5493e92..c5ab8aaac9e25 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -256,6 +256,8 @@ public static String getTrigger(ChannelUID channelUID, @Nullable Data data) return TRIGGER_ALARM_MAX; } else if (channel.getTemp() < channel.getMin()) { return TRIGGER_ALARM_MIN; + } else { + return TRIGGER_NONE; } } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 04b6c43a1e39d..4847d9cd3cd73 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.wlanthermo.internal.api.nano; +import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.TRIGGER_NONE; + import java.net.URI; import java.net.URISyntaxException; import java.util.concurrent.*; @@ -117,7 +119,9 @@ private void checkConnectionAndUpdate() { // if we could not obtain a state, try trigger instead try { String trigger = WlanThermoNanoV1CommandHandler.getTrigger(channel.getUID(), data); - triggerChannel(channel.getUID(), trigger); + if (!trigger.equals(TRIGGER_NONE)) { + triggerChannel(channel.getUID(), trigger); + } } catch (WlanThermoUnknownChannelException e1) { logger.debug("{}", e.getMessage()); } From eb1c960f6b0a76946a505ad85f39f46f5c344a96 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 14 Jan 2021 08:03:18 +0100 Subject: [PATCH 29/40] reduce updates to properties Signed-off-by: Christian Schlipp --- .../internal/api/esp32/WlanThermoEsp32Handler.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 8c5765229f382..aa1d7cad6c7fb 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -125,11 +125,11 @@ private void checkConnectionAndUpdate() { int tempChannels = data.getChannel().size(); // Update properties - properties.put(WlanThermoBindingConstants.PROPERTY_MODEL, settings.getDevice().getDevice()); - properties.put(WlanThermoBindingConstants.PROPERTY_SERIAL, settings.getDevice().getSerial()); - properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_BT_ENABLED, + properties.putIfAbsent(WlanThermoBindingConstants.PROPERTY_MODEL, settings.getDevice().getDevice()); + properties.putIfAbsent(WlanThermoBindingConstants.PROPERTY_SERIAL, settings.getDevice().getSerial()); + properties.putIfAbsent(WlanThermoBindingConstants.PROPERTY_ESP32_BT_ENABLED, settings.getFeatures().getBluetooth().toString()); - properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_PM_ENABLED, pmEnabled.toString()); + properties.putIfAbsent(WlanThermoBindingConstants.PROPERTY_ESP32_PM_ENABLED, pmEnabled.toString()); properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_TEMP_CHANNELS, String.valueOf(tempChannels)); properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_PM_CHANNELS, String.valueOf(pmChannels)); updateProperties(properties); From 0aaff6395abedf04f6d586a4729d8f0782e98239 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 14 Jan 2021 08:03:36 +0100 Subject: [PATCH 30/40] return early on InterruptedException Signed-off-by: Christian Schlipp --- .../wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java | 1 + .../wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java | 1 + 2 files changed, 2 insertions(+) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index aa1d7cad6c7fb..d451cb46a00d0 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -212,6 +212,7 @@ private void push() { "Failed to update channel " + c.getName() + " on device: " + e.getMessage()); } catch (InterruptedException e) { logger.debug("Push interrupted. {}", e.getMessage()); + return; } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 4847d9cd3cd73..68ec41b9b9a81 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -188,6 +188,7 @@ private void push() { "Failed to update channel " + c.getName() + " on device: " + e.getMessage()); } catch (InterruptedException e) { logger.debug("Push interrupted. {}", e.getMessage()); + return; } } From e34237471e1a1396febb22f8fca0bc0f5feca604 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 14 Jan 2021 22:39:22 +0100 Subject: [PATCH 31/40] fix pitmaster getState Signed-off-by: Christian Schlipp --- .../internal/api/nano/WlanThermoNanoV1CommandHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index c5ab8aaac9e25..2f4eb89c354a2 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -210,7 +210,7 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable } } } - } else if (channelUID.getId().equals(CHANNEL_PITMASTER_1)) { + } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_1)) { if (data.getPitmaster() != null && data.getPitmaster().getPm() != null && data.getPitmaster().getPm().size() > 0) { Pm pm = data.getPitmaster().getPm().get(0); From 2b7f277653a110317a13579a5541085a4c0c4fe8 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 14 Jan 2021 22:43:43 +0100 Subject: [PATCH 32/40] Changed QuantityType to DecimalType for channels without unit Signed-off-by: Christian Schlipp --- .../internal/api/esp32/WlanThermoEsp32CommandHandler.java | 4 ++-- .../internal/api/nano/WlanThermoNanoV1CommandHandler.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index 56a7bac69b839..cfca367926e16 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -230,10 +230,10 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable Pm pm = data.getPitmaster().getPm().get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_PITMASTER_CHANNEL_ID: - pm.setChannel(((QuantityType) command).intValue()); + pm.setChannel(((DecimalType) command).intValue()); return true; case CHANNEL_PITMASTER_PIDPROFILE: - pm.setPid(((QuantityType) command).intValue()); + pm.setPid(((DecimalType) command).intValue()); return true; case CHANNEL_PITMASTER_SETPOINT: pm.setSet(((QuantityType) command).toUnit(unit).doubleValue()); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index 2f4eb89c354a2..97cfeef26cc96 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -216,10 +216,10 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable Pm pm = data.getPitmaster().getPm().get(0); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_PITMASTER_CHANNEL_ID: - pm.setChannel(((QuantityType) command).intValue()); + pm.setChannel(((DecimalType) command).intValue()); return true; case CHANNEL_PITMASTER_PIDPROFILE: - pm.setPid(((QuantityType) command).intValue()); + pm.setPid(((DecimalType) command).intValue()); return true; case CHANNEL_PITMASTER_SETPOINT: pm.setSet(((QuantityType) command).toUnit(unit).doubleValue()); From 89a24245aa707305935fce86cec41b3ed986dfb6 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Thu, 14 Jan 2021 23:04:53 +0100 Subject: [PATCH 33/40] extract POST request to new method Signed-off-by: Christian Schlipp --- .../api/esp32/WlanThermoEsp32Handler.java | 60 +++++++++---------- .../api/nano/WlanThermoNanoV1Handler.java | 60 +++++++++---------- 2 files changed, 56 insertions(+), 64 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index d451cb46a00d0..a27af97176b13 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -184,6 +184,32 @@ public void handleCommand(ChannelUID channelUID, Command command) { } } + private boolean doPost(String endpoint, String json) throws InterruptedException { + try { + URI uri = config.getUri(endpoint); + int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") + .timeout(5, TimeUnit.SECONDS).send().getStatus(); + if (status == 401) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); + return false; + } else if (status != 200) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to update channel on device, Statuscode " + status + " on URI " + uri.toString()); + logger.debug("Payload sent: {}", json); + //Still continue to try next channel + return true; + } else { + updateStatus(ThingStatus.ONLINE); + return true; + } + } catch (TimeoutException | ExecutionException | URISyntaxException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to update channel on device: " + e.getMessage()); + return false; + } + } + private void push() { if (data == null || this.thing.getStatus() != ThingStatus.ONLINE) { return; @@ -193,23 +219,9 @@ private void push() { for (org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Channel c : data.getChannel()) { try { String json = gson.toJson(c); - URI uri = config.getUri("/setchannels"); - int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") - .timeout(5, TimeUnit.SECONDS).send().getStatus(); - if (status == 401) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); + if (!doPost("/setchannels", json)) { break; - } else if (status != 200) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " - + c.getName() + " on device, Statuscode " + status + " on URI " + uri.toString()); - logger.debug("Payload sent: {}", json); - } else { - updateStatus(ThingStatus.ONLINE); } - } catch (TimeoutException | ExecutionException | URISyntaxException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to update channel " + c.getName() + " on device: " + e.getMessage()); } catch (InterruptedException e) { logger.debug("Push interrupted. {}", e.getMessage()); return; @@ -219,23 +231,7 @@ private void push() { // push update for pitmaster channels try { String json = gson.toJson(data.getPitmaster().getPm()); - URI uri = config.getUri("/setpitmaster"); - int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") - .timeout(5, TimeUnit.SECONDS).send().getStatus(); - if (status == 401) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); - } else if (status != 200) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to update pitmaster channel on device, Statuscode " + status + " on URI " - + uri.toString()); - logger.debug("Payload sent: {}", json); - } else { - updateStatus(ThingStatus.ONLINE); - } - } catch (TimeoutException | ExecutionException | URISyntaxException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to update pitmaster channel on device: " + e.getMessage()); + doPost("/setpitmaster", json); } catch (InterruptedException e) { logger.debug("Push interrupted. {}", e.getMessage()); } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 68ec41b9b9a81..01281bb76b358 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -160,6 +160,32 @@ public void handleCommand(ChannelUID channelUID, Command command) { } } + private boolean doPost(String endpoint, String json) throws InterruptedException { + try { + URI uri = config.getUri(endpoint); + int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") + .timeout(5, TimeUnit.SECONDS).send().getStatus(); + if (status == 401) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); + return false; + } else if (status != 200) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to update channel on device, Statuscode " + status + " on URI " + uri.toString()); + logger.debug("Payload sent: {}", json); + //Still continue to try next channel + return true; + } else { + updateStatus(ThingStatus.ONLINE); + return true; + } + } catch (TimeoutException | ExecutionException | URISyntaxException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to update channel on device: " + e.getMessage()); + return false; + } + } + private void push() { if (data == null || this.thing.getStatus() != ThingStatus.ONLINE) { return; @@ -169,23 +195,9 @@ private void push() { for (org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Channel c : data.getChannel()) { try { String json = gson.toJson(c); - URI uri = config.getUri("/setchannels"); - int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") - .timeout(5, TimeUnit.SECONDS).send().getStatus(); - if (status == 401) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); + if (!doPost("/setchannels", json)) { break; - } else if (status != 200) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel " - + c.getName() + " on device, Statuscode " + status + " on URI " + uri.toString()); - logger.debug("Payload sent: {}", json); - } else { - updateStatus(ThingStatus.ONLINE); } - } catch (TimeoutException | ExecutionException | URISyntaxException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to update channel " + c.getName() + " on device: " + e.getMessage()); } catch (InterruptedException e) { logger.debug("Push interrupted. {}", e.getMessage()); return; @@ -195,23 +207,7 @@ private void push() { // push update for pitmaster channels try { String json = gson.toJson(data.getPitmaster().getPm()); - URI uri = config.getUri("/setpitmaster"); - int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") - .timeout(5, TimeUnit.SECONDS).send().getStatus(); - if (status == 401) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); - } else if (status != 200) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to update pitmaster channel on device, Statuscode " + status + " on URI " - + uri.toString()); - logger.debug("Payload sent: {}", json); - } else { - updateStatus(ThingStatus.ONLINE); - } - } catch (TimeoutException | ExecutionException | URISyntaxException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to update pitmaster channel on device: " + e.getMessage()); + doPost("/setpitmaster", json); } catch (InterruptedException e) { logger.debug("Push interrupted. {}", e.getMessage()); } From 26aef3fccc1c5dd2add505b9d2f1ea6b632e034f Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Fri, 15 Jan 2021 08:36:42 +0100 Subject: [PATCH 34/40] spotless:apply Signed-off-by: Christian Schlipp --- .../wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java | 2 +- .../wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index a27af97176b13..5538ee2b9f10e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -197,7 +197,7 @@ private boolean doPost(String endpoint, String json) throws InterruptedException updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel on device, Statuscode " + status + " on URI " + uri.toString()); logger.debug("Payload sent: {}", json); - //Still continue to try next channel + // Still continue to try next channel return true; } else { updateStatus(ThingStatus.ONLINE); diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index 01281bb76b358..f830a89a04a5f 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -173,7 +173,7 @@ private boolean doPost(String endpoint, String json) throws InterruptedException updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Failed to update channel on device, Statuscode " + status + " on URI " + uri.toString()); logger.debug("Payload sent: {}", json); - //Still continue to try next channel + // Still continue to try next channel return true; } else { updateStatus(ThingStatus.ONLINE); From a273604b8cba86e0b5d410e6feb5875592ab79e5 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sun, 17 Jan 2021 17:30:39 +0100 Subject: [PATCH 35/40] Add Unit Tests Ensure Gson objects are NonNull Generify Handlers Generify Utils Signed-off-by: Christian Schlipp --- .../internal/WlanThermoBindingConstants.java | 3 - .../internal/WlanThermoHandler.java | 190 ++++++ .../wlanthermo/internal/WlanThermoUtil.java | 53 ++ .../esp32/WlanThermoEsp32CommandHandler.java | 63 +- .../api/esp32/WlanThermoEsp32Handler.java | 233 ++----- ...tilEsp32.java => WlanThermoEsp32Util.java} | 27 +- .../mini/WlanThermoMiniCommandHandler.java | 20 +- .../api/mini/WlanThermoMiniHandler.java | 135 ++-- ...{UtilMini.java => WlanThermoMiniUtil.java} | 7 +- .../nano/WlanThermoNanoV1CommandHandler.java | 63 +- .../api/nano/WlanThermoNanoV1Handler.java | 195 ++---- ...tilNano.java => WlanThermoNanoV1Util.java} | 19 +- .../WlanThermoEsp32CommandHandlerTest.java | 600 ++++++++++++++++++ .../WlanThermoMiniCommandHandlerTest.java | 278 ++++++++ .../WlanThermoNanoV1CommandHandlerTest.java | 430 +++++++++++++ 15 files changed, 1772 insertions(+), 544 deletions(-) create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoHandler.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUtil.java rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/{UtilEsp32.java => WlanThermoEsp32Util.java} (73%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/{UtilMini.java => WlanThermoMiniUtil.java} (90%) rename bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/{UtilNano.java => WlanThermoNanoV1Util.java} (78%) create mode 100644 bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandlerTest.java create mode 100644 bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java index 2686bc2a76c22..0fa5a2465d07c 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoBindingConstants.java @@ -32,9 +32,6 @@ public class WlanThermoBindingConstants { public static final ThingTypeUID THING_TYPE_WLANTHERMO_MINI = new ThingTypeUID(BINDING_ID, "mini"); public static final ThingTypeUID THING_TYPE_WLANTHERMO_ESP32 = new ThingTypeUID(BINDING_ID, "esp32"); - // ThreadPool - public static final String WLANTHERMO_THREAD_POOL = "wlanthermo"; - // Properties public static final String PROPERTY_MODEL = "model"; public static final String PROPERTY_SERIAL = "serial"; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoHandler.java new file mode 100644 index 0000000000000..6370641e6f9b7 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoHandler.java @@ -0,0 +1,190 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wlanthermo.internal; + +import static org.openhab.binding.wlanthermo.internal.WlanThermoUtil.requireNonNull; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.client.api.Authentication; +import org.eclipse.jetty.client.api.AuthenticationStore; +import org.eclipse.jetty.client.util.DigestAuthentication; +import org.eclipse.jetty.client.util.StringContentProvider; +import org.openhab.core.thing.*; +import org.openhab.core.thing.binding.BaseThingHandler; +import org.openhab.core.types.Command; +import org.openhab.core.types.RefreshType; +import org.openhab.core.types.State; +import org.openhab.core.types.UnDefType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.Gson; + +/** + * The {@link WlanThermoHandler} is responsible for handling commands, which are + * sent to one of the channels. + * + * @author Christian Schlipp - Initial contribution + */ +@NonNullByDefault +public abstract class WlanThermoHandler extends BaseThingHandler { + + private final boolean extendedConfig; + protected WlanThermoConfiguration config = new WlanThermoConfiguration(); + protected final HttpClient httpClient; + protected final Logger logger = LoggerFactory.getLogger(WlanThermoHandler.class); + protected final Gson gson = new Gson(); + @Nullable + protected ScheduledFuture pollingScheduler; + + public WlanThermoHandler(Thing thing, HttpClient httpClient, boolean extendedConfig) { + super(thing); + this.httpClient = httpClient; + this.extendedConfig = extendedConfig; + } + + @Override + public void initialize() { + updateStatus(ThingStatus.UNKNOWN); + try { + if (extendedConfig) { + config = getConfigAs(WlanThermoExtendedConfiguration.class); + WlanThermoExtendedConfiguration extendedConfig = (WlanThermoExtendedConfiguration) config; + if (extendedConfig.getUsername().isEmpty() && !extendedConfig.getPassword().isEmpty()) { + AuthenticationStore authStore = httpClient.getAuthenticationStore(); + authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM, + extendedConfig.getUsername(), extendedConfig.getPassword())); + } + } else { + config = getConfigAs(WlanThermoConfiguration.class); + } + pollingScheduler = scheduler.scheduleWithFixedDelay(this::checkConnectionAndUpdate, 0, + config.getPollingInterval(), TimeUnit.SECONDS); + } catch (URISyntaxException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + "Failed to initialize WlanThermo: " + e.getMessage()); + } + } + + @Override + public void dispose() { + ScheduledFuture oldScheduler = pollingScheduler; + if (oldScheduler != null) { + boolean stopped = oldScheduler.cancel(true); + logger.debug("Stopped polling: {}", stopped); + } + pollingScheduler = null; + } + + protected void checkConnectionAndUpdate() { + if (this.thing.getStatus() != ThingStatus.ONLINE) { + try { + if (httpClient.GET(config.getUri()).getStatus() == 200) { + updateStatus(ThingStatus.ONLINE); + // rerun immediately to update state + checkConnectionAndUpdate(); + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + "WlanThermo not found under given address."); + } + } catch (URISyntaxException | ExecutionException | TimeoutException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); + } catch (InterruptedException e) { + logger.debug("Connection check interrupted. {}", e.getMessage()); + } + } else { + pull(); + } + } + + protected boolean doPost(String endpoint, String json) throws InterruptedException { + try { + URI uri = config.getUri(endpoint); + int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") + .timeout(5, TimeUnit.SECONDS).send().getStatus(); + if (status == 401) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); + return false; + } else if (status != 200) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to update channel on device, Statuscode " + status + " on URI " + uri.toString()); + logger.debug("Payload sent: {}", json); + // Still continue to try next channel + return true; + } else { + updateStatus(ThingStatus.ONLINE); + return true; + } + } catch (TimeoutException | ExecutionException | URISyntaxException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Failed to update channel on device: " + e.getMessage()); + return false; + } + } + + protected T doGet(String endpoint, Class object) throws InterruptedException, WlanThermoInputException { + try { + String json = httpClient.GET(config.getUri(endpoint)).getContentAsString(); + logger.debug("Received at {}: {}", endpoint, json); + return requireNonNull(gson.fromJson(json, object)); + } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Update failed: " + e.getMessage()); + for (Channel channel : thing.getChannels()) { + updateState(channel.getUID(), UnDefType.UNDEF); + } + throw new WlanThermoInputException(); + } + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + if (command instanceof RefreshType) { + try { + State s = getState(channelUID); + updateState(channelUID, s); + } catch (WlanThermoException e) { + logger.debug("Could not handle command of type {} for channel {}!", + command.getClass().toGenericString(), channelUID.getId()); + } + } else { + if (setState(channelUID, command) && thing.getStatus() == ThingStatus.ONLINE) { + logger.debug("Data updated, pushing changes"); + scheduler.execute(this::push); + } else { + logger.debug("Could not handle command of type {} for channel {}!", + command.getClass().toGenericString(), channelUID.getId()); + } + } + } + + protected abstract void push(); + + protected abstract void pull(); + + protected abstract State getState(ChannelUID channelUID) + throws WlanThermoInputException, WlanThermoUnknownChannelException; + + protected abstract boolean setState(ChannelUID channelUID, Command command); +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUtil.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUtil.java new file mode 100644 index 0000000000000..d6ff837509c02 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUtil.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wlanthermo.internal; + +import java.util.Map; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.core.library.types.HSBType; + +/** + * The {@link WlanThermoUtil} class provides conversion functions for the WlanThermo + * + * @author Christian Schlipp - Initial contribution + */ +@NonNullByDefault +public class WlanThermoUtil { + + public static String toColorName(String colorHex, Map colorMappings, String defaultColorName) { + if (!colorHex.startsWith("#")) { + colorHex = "#" + colorHex; + } + + for (Map.Entry entry : colorMappings.entrySet()) { + if (entry.getValue().equalsIgnoreCase(colorHex)) { + return entry.getKey(); + } + } + + return defaultColorName; + } + + public static String toHex(HSBType hsb) { + return "#" + String.format("%02X", hsb.getRed().intValue()) + String.format("%02X", hsb.getGreen().intValue()) + + String.format("%02X", hsb.getBlue().intValue()); + } + + public static T requireNonNull(@Nullable T obj) throws WlanThermoInputException { + if (obj == null) + throw new WlanThermoInputException(); + return obj; + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index cfca367926e16..5888fa917cb60 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -13,6 +13,7 @@ package org.openhab.binding.wlanthermo.internal.api.esp32; import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.*; +import static org.openhab.binding.wlanthermo.internal.WlanThermoUtil.requireNonNull; import java.awt.Color; import java.math.BigInteger; @@ -22,9 +23,9 @@ import javax.measure.quantity.Temperature; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.wlanthermo.internal.WlanThermoInputException; import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; +import org.openhab.binding.wlanthermo.internal.WlanThermoUtil; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Channel; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Data; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Pm; @@ -48,13 +49,10 @@ @NonNullByDefault public class WlanThermoEsp32CommandHandler { - public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullable Settings settings) + public static State getState(ChannelUID channelUID, Data data, Settings settings) throws WlanThermoUnknownChannelException, WlanThermoInputException { - if (channelUID.getGroupId() == null || data == null || settings == null) { - throw new WlanThermoInputException(); - } - String groupId = channelUID.getGroupId(); + String groupId = requireNonNull(channelUID.getGroupId()); System system = data.getSystem(); Unit unit = "F".equals(system.getUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; @@ -130,16 +128,17 @@ public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullab case CHANNEL_COLOR_NAME: String colorHex = channel.getColor(); if (colorHex != null && !colorHex.isEmpty()) { - return new StringType(UtilEsp32.toColorName(colorHex)); + return new StringType(WlanThermoEsp32Util.toColorName(colorHex)); } else { return UnDefType.UNDEF; } } } - } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_1)) { + } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_PREFIX)) { + int channelId = Integer.parseInt(groupId.substring(CHANNEL_PITMASTER_PREFIX.length())) - 1; if (data.getPitmaster() != null && data.getPitmaster().getPm() != null - && data.getPitmaster().getPm().size() > 0) { - Pm pm = data.getPitmaster().getPm().get(0); + && data.getPitmaster().getPm().size() > channelId) { + Pm pm = data.getPitmaster().getPm().get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_PITMASTER_CHANNEL_ID: return new DecimalType(pm.getChannel()); @@ -159,12 +158,14 @@ public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullab throw new WlanThermoUnknownChannelException(channelUID); } - public static boolean setState(ChannelUID channelUID, Command command, @Nullable Data data) { - if (channelUID.getGroupId() == null || data == null || data.getSystem() == null) { + public static boolean setState(ChannelUID channelUID, Command command, Data data) { + String groupId; + try { + groupId = requireNonNull(channelUID.getGroupId()); + } catch (WlanThermoInputException ignore) { return false; } - String groupId = channelUID.getGroupId(); List channelList = data.getChannel(); System system = data.getSystem(); Unit unit = "F".equals(system.getUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; @@ -181,13 +182,21 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable } case CHANNEL_MIN: if (command instanceof QuantityType) { - channel.setMin(((QuantityType) command).toUnit(unit).doubleValue()); - return true; + try { + channel.setMin(requireNonNull(((QuantityType) command).toUnit(unit)).doubleValue()); + return true; + } catch (WlanThermoInputException ignore) { + return false; + } } case CHANNEL_MAX: if (command instanceof QuantityType) { - channel.setMax(((QuantityType) command).toUnit(unit).doubleValue()); - return true; + try { + channel.setMax(requireNonNull(((QuantityType) command).toUnit(unit)).doubleValue()); + return true; + } catch (WlanThermoInputException ignore) { + return false; + } } case CHANNEL_ALARM_DEVICE: if (command instanceof OnOffType) { @@ -213,12 +222,12 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable } case CHANNEL_COLOR_NAME: if (command instanceof StringType) { - channel.setColor(UtilEsp32.toHex(((StringType) command).toString())); + channel.setColor(WlanThermoEsp32Util.toHex(((StringType) command).toString())); return true; } case CHANNEL_COLOR: if (command instanceof HSBType) { - channel.setColor(UtilEsp32.toHex((HSBType) command)); + channel.setColor(WlanThermoUtil.toHex((HSBType) command)); return true; } } @@ -236,8 +245,12 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable pm.setPid(((DecimalType) command).intValue()); return true; case CHANNEL_PITMASTER_SETPOINT: - pm.setSet(((QuantityType) command).toUnit(unit).doubleValue()); - return true; + try { + pm.setSet(requireNonNull(((QuantityType) command).toUnit(unit)).doubleValue()); + return true; + } catch (WlanThermoInputException ignore) { + return false; + } case CHANNEL_PITMASTER_STATE: String state = ((StringType) command).toString(); if (state.equalsIgnoreCase("off") || state.equalsIgnoreCase("manual") @@ -251,13 +264,9 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable return false; } - public static String getTrigger(ChannelUID channelUID, @Nullable Data data) + public static String getTrigger(ChannelUID channelUID, Data data) throws WlanThermoUnknownChannelException, WlanThermoInputException { - if (channelUID.getGroupId() == null || data == null) { - throw new WlanThermoInputException(); - } - - String groupId = channelUID.getGroupId(); + String groupId = requireNonNull(channelUID.getGroupId()); List channelList = data.getChannel(); if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index 5538ee2b9f10e..f61437b180835 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -14,34 +14,16 @@ import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.TRIGGER_NONE; -import java.net.URI; -import java.net.URISyntaxException; import java.util.Map; -import java.util.concurrent.*; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; -import org.eclipse.jetty.client.api.Authentication; -import org.eclipse.jetty.client.api.AuthenticationStore; -import org.eclipse.jetty.client.util.DigestAuthentication; -import org.eclipse.jetty.client.util.StringContentProvider; -import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; -import org.openhab.binding.wlanthermo.internal.WlanThermoException; -import org.openhab.binding.wlanthermo.internal.WlanThermoExtendedConfiguration; -import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; +import org.openhab.binding.wlanthermo.internal.*; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Data; import org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings.Settings; import org.openhab.core.thing.*; -import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.types.Command; -import org.openhab.core.types.RefreshType; import org.openhab.core.types.State; -import org.openhab.core.types.UnDefType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.Gson; /** * The {@link WlanThermoEsp32Handler} is responsible for handling commands, which are @@ -50,171 +32,27 @@ * @author Christian Schlipp - Initial contribution */ @NonNullByDefault -public class WlanThermoEsp32Handler extends BaseThingHandler { - - private final Logger logger = LoggerFactory.getLogger(WlanThermoEsp32Handler.class); +public class WlanThermoEsp32Handler extends WlanThermoHandler { - private WlanThermoExtendedConfiguration config = new WlanThermoExtendedConfiguration(); - private final HttpClient httpClient; - private @Nullable ScheduledFuture pollingScheduler; - private final Gson gson = new Gson(); - private @Nullable Data data = new Data(); - private @Nullable Settings settings = new Settings(); + private Data data = new Data(); + private Settings settings = new Settings(); public WlanThermoEsp32Handler(Thing thing, HttpClient httpClient) { - super(thing); - this.httpClient = httpClient; + super(thing, httpClient, true); } @Override - public void initialize() { - config = getConfigAs(WlanThermoExtendedConfiguration.class); - - updateStatus(ThingStatus.UNKNOWN); - try { - if (!config.getUsername().isEmpty() && !config.getPassword().isEmpty()) { - AuthenticationStore authStore = httpClient.getAuthenticationStore(); - authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM, - config.getUsername(), config.getPassword())); - } - pollingScheduler = scheduler.scheduleWithFixedDelay(this::checkConnectionAndUpdate, 0, - config.getPollingInterval(), TimeUnit.SECONDS); - } catch (URISyntaxException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Failed to initialize WlanThermo Nano: " + e.getMessage()); - } - } - - private void checkConnectionAndUpdate() { - if (this.thing.getStatus() != ThingStatus.ONLINE) { - try { - if (httpClient.GET(config.getUri()).getStatus() == 200) { - updateStatus(ThingStatus.ONLINE); - // rerun immediately to update state - checkConnectionAndUpdate(); - } else { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "WlanThermo not found under given address."); - } - } catch (URISyntaxException | ExecutionException | TimeoutException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); - } catch (InterruptedException e) { - logger.debug("Connection check interrupted. {}", e.getMessage()); - } - } else { - try { - // Update objects with data from device - String json = httpClient.GET(config.getUri("/data")).getContentAsString(); - data = gson.fromJson(json, Data.class); - logger.debug("Received at /data: {}", json); - json = httpClient.GET(config.getUri("/settings")).getContentAsString(); - settings = gson.fromJson(json, Settings.class); - logger.debug("Received at /settings: {}", json); - - if (data == null || settings == null) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to parse Data and/or Settings values!"); - return; - } - - // Update Channels if required - Map properties = editProperties(); - Boolean pmEnabled = settings.getFeatures().getBluetooth(); - int pmChannels = pmEnabled ? data.getPitmaster().getPm().size() : 0; - int tempChannels = data.getChannel().size(); - - // Update properties - properties.putIfAbsent(WlanThermoBindingConstants.PROPERTY_MODEL, settings.getDevice().getDevice()); - properties.putIfAbsent(WlanThermoBindingConstants.PROPERTY_SERIAL, settings.getDevice().getSerial()); - properties.putIfAbsent(WlanThermoBindingConstants.PROPERTY_ESP32_BT_ENABLED, - settings.getFeatures().getBluetooth().toString()); - properties.putIfAbsent(WlanThermoBindingConstants.PROPERTY_ESP32_PM_ENABLED, pmEnabled.toString()); - properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_TEMP_CHANNELS, String.valueOf(tempChannels)); - properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_PM_CHANNELS, String.valueOf(pmChannels)); - updateProperties(properties); - - // Update channel state - for (Channel channel : thing.getChannels()) { - try { - State state = WlanThermoEsp32CommandHandler.getState(channel.getUID(), data, settings); - updateState(channel.getUID(), state); - } catch (WlanThermoUnknownChannelException e) { - // if we could not obtain a state, try trigger instead - try { - String trigger = WlanThermoEsp32CommandHandler.getTrigger(channel.getUID(), data); - if (!trigger.equals(TRIGGER_NONE)) { - triggerChannel(channel.getUID(), trigger); - } - } catch (WlanThermoUnknownChannelException e1) { - logger.debug("{}", e.getMessage()); - } - } - } - } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Update failed: " + e.getMessage()); - for (Channel channel : thing.getChannels()) { - updateState(channel.getUID(), UnDefType.UNDEF); - } - } catch (InterruptedException e) { - logger.debug("Update interrupted. {}", e.getMessage()); - } - } + protected State getState(ChannelUID channelUID) throws WlanThermoInputException, WlanThermoUnknownChannelException { + return WlanThermoEsp32CommandHandler.getState(channelUID, data, settings); } @Override - public void handleCommand(ChannelUID channelUID, Command command) { - if (command instanceof RefreshType) { - try { - State s = WlanThermoEsp32CommandHandler.getState(channelUID, data, settings); - updateState(channelUID, s); - } catch (WlanThermoException e) { - logger.debug("Could not handle command of type {} for channel {}!", - command.getClass().toGenericString(), channelUID.getId()); - } - } else { - if (WlanThermoEsp32CommandHandler.setState(channelUID, command, data)) { - logger.debug("Data updated, pushing changes"); - scheduler.execute(this::push); - } else { - logger.debug("Could not handle command of type {} for channel {}!", - command.getClass().toGenericString(), channelUID.getId()); - } - } - } - - private boolean doPost(String endpoint, String json) throws InterruptedException { - try { - URI uri = config.getUri(endpoint); - int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") - .timeout(5, TimeUnit.SECONDS).send().getStatus(); - if (status == 401) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); - return false; - } else if (status != 200) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to update channel on device, Statuscode " + status + " on URI " + uri.toString()); - logger.debug("Payload sent: {}", json); - // Still continue to try next channel - return true; - } else { - updateStatus(ThingStatus.ONLINE); - return true; - } - } catch (TimeoutException | ExecutionException | URISyntaxException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to update channel on device: " + e.getMessage()); - return false; - } + protected boolean setState(ChannelUID channelUID, Command command) { + return WlanThermoEsp32CommandHandler.setState(channelUID, command, data); } - private void push() { - if (data == null || this.thing.getStatus() != ThingStatus.ONLINE) { - return; - } - + @Override + protected void push() { // Push update for sensor channels for (org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Channel c : data.getChannel()) { try { @@ -238,12 +76,49 @@ private void push() { } @Override - public void dispose() { - ScheduledFuture oldScheduler = pollingScheduler; - if (oldScheduler != null) { - boolean stopped = oldScheduler.cancel(true); - logger.debug("Stopped polling: {}", stopped); + protected void pull() { + try { + // Update objects with data from device + data = doGet("/data", Data.class); + settings = doGet("/settings", Settings.class); + + // Update Channels if required + Map properties = editProperties(); + Boolean pmEnabled = settings.getFeatures().getBluetooth(); + int pmChannels = pmEnabled ? data.getPitmaster().getPm().size() : 0; + int tempChannels = data.getChannel().size(); + + // Update properties + properties.putIfAbsent(WlanThermoBindingConstants.PROPERTY_MODEL, settings.getDevice().getDevice()); + properties.putIfAbsent(WlanThermoBindingConstants.PROPERTY_SERIAL, settings.getDevice().getSerial()); + properties.putIfAbsent(WlanThermoBindingConstants.PROPERTY_ESP32_BT_ENABLED, + settings.getFeatures().getBluetooth().toString()); + properties.putIfAbsent(WlanThermoBindingConstants.PROPERTY_ESP32_PM_ENABLED, pmEnabled.toString()); + properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_TEMP_CHANNELS, String.valueOf(tempChannels)); + properties.put(WlanThermoBindingConstants.PROPERTY_ESP32_PM_CHANNELS, String.valueOf(pmChannels)); + updateProperties(properties); + + // Update channel state + for (Channel channel : thing.getChannels()) { + try { + State state = WlanThermoEsp32CommandHandler.getState(channel.getUID(), data, settings); + updateState(channel.getUID(), state); + } catch (WlanThermoUnknownChannelException e) { + // if we could not obtain a state, try trigger instead + try { + String trigger = WlanThermoEsp32CommandHandler.getTrigger(channel.getUID(), data); + if (!trigger.equals(TRIGGER_NONE)) { + triggerChannel(channel.getUID(), trigger); + } + } catch (WlanThermoUnknownChannelException e1) { + logger.debug("{}", e.getMessage()); + } + } + } + } catch (WlanThermoException ignore) { + // Nothing more to do + } catch (InterruptedException e) { + logger.debug("Update interrupted. {}", e.getMessage()); } - pollingScheduler = null; } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Util.java similarity index 73% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Util.java index cdde1329d3c19..cef43ae8d5f33 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/UtilEsp32.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Util.java @@ -16,21 +16,21 @@ import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.core.library.types.HSBType; +import org.openhab.binding.wlanthermo.internal.WlanThermoUtil; /** - * The {@link UtilEsp32} class provides conversion functions for the WlanThermo Nano V3 + * The {@link WlanThermoEsp32Util} class provides conversion functions for the WlanThermo Nano V3 * * @author Christian Schlipp - Initial contribution */ @NonNullByDefault -public class UtilEsp32 { +public class WlanThermoEsp32Util extends WlanThermoUtil { private static final Map COLOR_MAPPINGS = createColorMap(); private static final String DEFAULT_HEX = "#FFFFFF"; private static final String DEFAULT_COLORNAME = "undefined"; - private UtilEsp32() { + private WlanThermoEsp32Util() { // hidden } @@ -60,7 +60,7 @@ private static Map createColorMap() { /** * Convert WlanThermo Color Name to Hex - * + * * @param colorName the WlanThermo color name * @return The color as Hex String */ @@ -68,22 +68,7 @@ public static String toHex(String colorName) { return COLOR_MAPPINGS.getOrDefault(colorName, DEFAULT_HEX); } - public static String toHex(HSBType hsb) { - return "#" + String.format("%02X", hsb.getRed().intValue()) + String.format("%02X", hsb.getGreen().intValue()) - + String.format("%02X", hsb.getBlue().intValue()); - } - public static String toColorName(String colorHex) { - if (!colorHex.startsWith("#")) { - colorHex = "#" + colorHex; - } - - for (Map.Entry entry : COLOR_MAPPINGS.entrySet()) { - if (entry.getValue().equalsIgnoreCase(colorHex)) { - return entry.getKey(); - } - } - - return DEFAULT_COLORNAME; + return toColorName(colorHex, COLOR_MAPPINGS, DEFAULT_COLORNAME); } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java index 691a63a89d264..ccdb0446262a5 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandler.java @@ -13,6 +13,7 @@ package org.openhab.binding.wlanthermo.internal.api.mini; import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.*; +import static org.openhab.binding.wlanthermo.internal.WlanThermoUtil.requireNonNull; import java.awt.*; @@ -20,7 +21,6 @@ import javax.measure.quantity.Temperature; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants; import org.openhab.binding.wlanthermo.internal.WlanThermoInputException; import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; @@ -43,13 +43,9 @@ public class WlanThermoMiniCommandHandler { public static final String ERROR = "er"; - public static State getState(ChannelUID channelUID, @Nullable App app) + public static State getState(ChannelUID channelUID, App app) throws WlanThermoUnknownChannelException, WlanThermoInputException { - if (channelUID.getGroupId() == null || app == null) { - throw new WlanThermoInputException(); - } - - String groupId = channelUID.getGroupId(); + String groupId = requireNonNull(channelUID.getGroupId()); Unit unit = "fahrenheit".equals(app.getTempUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; if (SYSTEM.equals(groupId)) { @@ -103,7 +99,7 @@ public static State getState(ChannelUID channelUID, @Nullable App app) return OnOffType.OFF; } case WlanThermoBindingConstants.CHANNEL_COLOR: - Color c = Color.decode(UtilMini.toHex(data.getColor())); + Color c = Color.decode(WlanThermoMiniUtil.toHex(data.getColor())); return HSBType.fromRGB(c.getRed(), c.getGreen(), c.getBlue()); case WlanThermoBindingConstants.CHANNEL_COLOR_NAME: return new StringType(data.getColor()); @@ -139,13 +135,9 @@ public static State getState(ChannelUID channelUID, @Nullable App app) throw new WlanThermoUnknownChannelException(channelUID); } - public static String getTrigger(ChannelUID channelUID, @Nullable App app) + public static String getTrigger(ChannelUID channelUID, App app) throws WlanThermoUnknownChannelException, WlanThermoInputException { - if (channelUID.getGroupId() == null || app == null) { - throw new WlanThermoInputException(); - } - - String groupId = channelUID.getGroupId(); + String groupId = requireNonNull(channelUID.getGroupId()); if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java index aef8ef9cc786d..b5a57c73784fb 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniHandler.java @@ -14,26 +14,13 @@ import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.TRIGGER_NONE; -import java.net.URISyntaxException; -import java.util.concurrent.*; - import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; -import org.openhab.binding.wlanthermo.internal.WlanThermoConfiguration; -import org.openhab.binding.wlanthermo.internal.WlanThermoException; -import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; +import org.openhab.binding.wlanthermo.internal.*; import org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin.App; import org.openhab.core.thing.*; -import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.types.Command; -import org.openhab.core.types.RefreshType; import org.openhab.core.types.State; -import org.openhab.core.types.UnDefType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.Gson; /** * The {@link WlanThermoMiniHandler} is responsible for handling commands, which are @@ -42,105 +29,57 @@ * @author Christian Schlipp - Initial contribution */ @NonNullByDefault -public class WlanThermoMiniHandler extends BaseThingHandler { - - private final Logger logger = LoggerFactory.getLogger(WlanThermoMiniHandler.class); +public class WlanThermoMiniHandler extends WlanThermoHandler { - private WlanThermoConfiguration config = new WlanThermoConfiguration(); - private final HttpClient httpClient; - private @Nullable ScheduledFuture pollingScheduler; - private final Gson gson = new Gson(); - private @Nullable App app = new App(); + private App app = new App(); public WlanThermoMiniHandler(Thing thing, HttpClient httpClient) { - super(thing); - this.httpClient = httpClient; + super(thing, httpClient, false); } @Override - public void initialize() { - config = getConfigAs(WlanThermoConfiguration.class); + protected State getState(ChannelUID channelUID) throws WlanThermoInputException, WlanThermoUnknownChannelException { + return WlanThermoMiniCommandHandler.getState(channelUID, app); + } - updateStatus(ThingStatus.UNKNOWN); - pollingScheduler = scheduler.scheduleWithFixedDelay(this::checkConnection, 0, config.getPollingInterval(), - TimeUnit.SECONDS); + @Override + protected boolean setState(ChannelUID channelUID, Command command) { + // Mini is read-only! + return false; } - private void checkConnection() { - if (this.thing.getStatus() != ThingStatus.ONLINE) { - try { - if (httpClient.GET(config.getUri("/app.php")).getStatus() == 200) { - updateStatus(ThingStatus.ONLINE); - // rerun immediately to update state - checkConnection(); - } else { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "WlanThermo not found under given address."); - } - } catch (URISyntaxException | ExecutionException | TimeoutException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); - } catch (InterruptedException e) { - logger.debug("Connection check interrupted. {}", e.getMessage()); - } - } else { - try { - // Update objects with data from device - String json = httpClient.GET(config.getUri("/app.php")).getContentAsString(); - app = gson.fromJson(json, App.class); - logger.debug("Received at /app.php: {}", json); + @Override + protected void push() { + // Unused, Mini is read-only! + } + + @Override + protected void pull() { + try { + // Update objects with data from device + app = doGet("/app.php", App.class); - // Update channels - for (Channel channel : thing.getChannels()) { + // Update channels + for (Channel channel : thing.getChannels()) { + try { + State state = WlanThermoMiniCommandHandler.getState(channel.getUID(), app); + updateState(channel.getUID(), state); + } catch (WlanThermoUnknownChannelException e) { + // if we could not obtain a state, try trigger instead try { - State state = WlanThermoMiniCommandHandler.getState(channel.getUID(), app); - updateState(channel.getUID(), state); - } catch (WlanThermoUnknownChannelException e) { - // if we could not obtain a state, try trigger instead - try { - String trigger = WlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app); - if (!trigger.equals(TRIGGER_NONE)) { - triggerChannel(channel.getUID(), trigger); - } - } catch (WlanThermoUnknownChannelException e1) { - logger.debug("{}", e.getMessage()); + String trigger = WlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app); + if (!trigger.equals(TRIGGER_NONE)) { + triggerChannel(channel.getUID(), trigger); } + } catch (WlanThermoUnknownChannelException e1) { + logger.debug("{}", e.getMessage()); } } - } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Update failed: " + e.getMessage()); - for (Channel channel : thing.getChannels()) { - updateState(channel.getUID(), UnDefType.UNDEF); - } - } catch (InterruptedException e) { - logger.debug("Update interrupted. {}", e.getMessage()); - } - } - } - - @Override - public void handleCommand(ChannelUID channelUID, Command command) { - // Mini is read only! - if (command instanceof RefreshType) { - try { - assert app != null; - State s = WlanThermoMiniCommandHandler.getState(channelUID, app); - updateState(channelUID, s); - } catch (WlanThermoException e) { - logger.debug("Could not handle command of type {} for channel {}!", - command.getClass().toGenericString(), channelUID.getId()); } + } catch (WlanThermoException ignore) { + // Nothing more to do + } catch (InterruptedException e) { + logger.debug("Update interrupted. {}", e.getMessage()); } } - - @Override - public void dispose() { - ScheduledFuture oldScheduler = pollingScheduler; - if (oldScheduler != null) { - boolean stopped = oldScheduler.cancel(true); - logger.debug("Stopped polling: {}", stopped); - } - pollingScheduler = null; - } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/UtilMini.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniUtil.java similarity index 90% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/UtilMini.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniUtil.java index f4075dbd10c93..69a84a7bad0d8 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/UtilMini.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniUtil.java @@ -16,18 +16,19 @@ import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.wlanthermo.internal.WlanThermoUtil; /** - * The {@link UtilMini} class provides conversion functions for the WlanThermo Mini + * The {@link WlanThermoMiniUtil} class provides conversion functions for the WlanThermo Mini * * @author Christian Schlipp - Initial contribution */ @NonNullByDefault -public class UtilMini { +public class WlanThermoMiniUtil extends WlanThermoUtil { private static final Map COLOR_MAPPINGS = createColorMap(); private static final String DEFAULT_HEX = "#ffffff"; - private UtilMini() { + private WlanThermoMiniUtil() { // hidden } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index 97cfeef26cc96..efbc46e8b5adc 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -13,6 +13,7 @@ package org.openhab.binding.wlanthermo.internal.api.nano; import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.*; +import static org.openhab.binding.wlanthermo.internal.WlanThermoUtil.requireNonNull; import java.awt.*; import java.math.BigInteger; @@ -22,7 +23,6 @@ import javax.measure.quantity.Temperature; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.wlanthermo.internal.WlanThermoInputException; import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Channel; @@ -48,13 +48,9 @@ @NonNullByDefault public class WlanThermoNanoV1CommandHandler { - public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullable Settings settings) + public static State getState(ChannelUID channelUID, Data data, Settings settings) throws WlanThermoUnknownChannelException, WlanThermoInputException { - if (channelUID.getGroupId() == null || data == null || settings == null) { - throw new WlanThermoInputException(); - } - - String groupId = channelUID.getGroupId(); + String groupId = requireNonNull(channelUID.getGroupId()); System system = data.getSystem(); Unit unit = "F".equals(system.getUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; List channelList = data.getChannel(); @@ -66,7 +62,7 @@ public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullab case SYSTEM_CHARGE: return OnOffType.from(system.getCharge()); case SYSTEM_RSSI_SIGNALSTRENGTH: - int dbm = system.getRssi(); + int dbm = (-1) * system.getRssi(); if (dbm >= -80) { return SIGNAL_STRENGTH_4; } else if (dbm >= -95) { @@ -77,11 +73,11 @@ public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullab return SIGNAL_STRENGTH_1; } case SYSTEM_RSSI: - return new QuantityType<>(system.getRssi(), Units.DECIBEL_MILLIWATTS); + return new QuantityType<>((-1) * system.getRssi(), Units.DECIBEL_MILLIWATTS); } } else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channelList.size() > 0 && channelId <= channelList.size()) { + if (channelList.size() > 0 && channelId < channelList.size()) { Channel channel = channelList.get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -122,7 +118,7 @@ public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullab case CHANNEL_COLOR_NAME: String colorHex = channel.getColor(); if (colorHex != null && !colorHex.isEmpty()) { - return new StringType(UtilNano.toColorName(colorHex)); + return new StringType(WlanThermoNanoV1Util.toColorName(colorHex)); } else { return UnDefType.UNDEF; } @@ -151,19 +147,21 @@ public static State getState(ChannelUID channelUID, @Nullable Data data, @Nullab throw new WlanThermoUnknownChannelException(channelUID); } - public static boolean setState(ChannelUID channelUID, Command command, @Nullable Data data) { - if (channelUID.getGroupId() == null || data == null || data.getSystem() == null) { + public static boolean setState(ChannelUID channelUID, Command command, Data data) { + String groupId; + try { + groupId = requireNonNull(channelUID.getGroupId()); + } catch (WlanThermoInputException e) { return false; } - String groupId = channelUID.getGroupId(); List channelList = data.getChannel(); System system = data.getSystem(); Unit unit = "F".equals(system.getUnit()) ? ImperialUnits.FAHRENHEIT : SIUnits.CELSIUS; if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channelList.size() > 0 && channelId <= channelList.size()) { + if (channelList.size() > 0 && channelId < channelList.size()) { Channel channel = channelList.get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_NAME: @@ -173,13 +171,21 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable } case CHANNEL_MIN: if (command instanceof QuantityType) { - channel.setMin(((QuantityType) command).toUnit(unit).doubleValue()); - return true; + try { + channel.setMin(requireNonNull(((QuantityType) command).toUnit(unit)).doubleValue()); + return true; + } catch (WlanThermoInputException ignore) { + return false; + } } case CHANNEL_MAX: if (command instanceof QuantityType) { - channel.setMax(((QuantityType) command).toUnit(unit).doubleValue()); - return true; + try { + channel.setMax(requireNonNull(((QuantityType) command).toUnit(unit)).doubleValue()); + return true; + } catch (WlanThermoInputException ignore) { + return false; + } } case CHANNEL_ALARM_DEVICE: if (command instanceof OnOffType) { @@ -205,7 +211,7 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable } case CHANNEL_COLOR_NAME: if (command instanceof StringType) { - channel.setColor(UtilNano.toHex(((StringType) command).toString())); + channel.setColor(WlanThermoNanoV1Util.toHex(((StringType) command).toString())); return true; } } @@ -222,8 +228,12 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable pm.setPid(((DecimalType) command).intValue()); return true; case CHANNEL_PITMASTER_SETPOINT: - pm.setSet(((QuantityType) command).toUnit(unit).doubleValue()); - return true; + try { + pm.setSet(requireNonNull(((QuantityType) command).toUnit(unit)).doubleValue()); + return true; + } catch (WlanThermoInputException ignore) { + return false; + } case CHANNEL_PITMASTER_STATE: String state = ((StringType) command).toString(); if (state.equalsIgnoreCase("off") || state.equalsIgnoreCase("manual") @@ -237,18 +247,15 @@ public static boolean setState(ChannelUID channelUID, Command command, @Nullable return false; } - public static String getTrigger(ChannelUID channelUID, @Nullable Data data) + public static String getTrigger(ChannelUID channelUID, Data data) throws WlanThermoUnknownChannelException, WlanThermoInputException { - if (channelUID.getGroupId() == null || data == null) { - throw new WlanThermoInputException(); - } - String groupId = channelUID.getGroupId(); + String groupId = requireNonNull(channelUID.getGroupId()); List channelList = data.getChannel(); if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; - if (channelList.size() > 0 && channelId <= channelList.size()) { + if (channelList.size() > 0 && channelId < channelList.size()) { Channel channel = channelList.get(channelId); if (CHANNEL_ALARM_OPENHAB.equals(channelUID.getIdWithoutGroup())) { if (channel.getTemp() != 999) { diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java index f830a89a04a5f..0232ccc9dd561 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Handler.java @@ -14,32 +14,14 @@ import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.TRIGGER_NONE; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.concurrent.*; - import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; -import org.eclipse.jetty.client.api.Authentication; -import org.eclipse.jetty.client.api.AuthenticationStore; -import org.eclipse.jetty.client.util.DigestAuthentication; -import org.eclipse.jetty.client.util.StringContentProvider; -import org.openhab.binding.wlanthermo.internal.WlanThermoException; -import org.openhab.binding.wlanthermo.internal.WlanThermoExtendedConfiguration; -import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; +import org.openhab.binding.wlanthermo.internal.*; import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Data; import org.openhab.binding.wlanthermo.internal.api.nano.dto.settings.Settings; import org.openhab.core.thing.*; -import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.types.Command; -import org.openhab.core.types.RefreshType; import org.openhab.core.types.State; -import org.openhab.core.types.UnDefType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.Gson; /** * The {@link WlanThermoNanoV1Handler} is responsible for handling commands, which are @@ -48,149 +30,27 @@ * @author Christian Schlipp - Initial contribution */ @NonNullByDefault -public class WlanThermoNanoV1Handler extends BaseThingHandler { - - private final Logger logger = LoggerFactory.getLogger(WlanThermoNanoV1Handler.class); +public class WlanThermoNanoV1Handler extends WlanThermoHandler { - private WlanThermoExtendedConfiguration config = new WlanThermoExtendedConfiguration(); - private final HttpClient httpClient; - private @Nullable ScheduledFuture pollingScheduler; - private final Gson gson = new Gson(); - private @Nullable Data data = new Data(); - private @Nullable Settings settings = new Settings(); + private Data data = new Data(); + private Settings settings = new Settings(); public WlanThermoNanoV1Handler(Thing thing, HttpClient httpClient) { - super(thing); - this.httpClient = httpClient; + super(thing, httpClient, true); } @Override - public void initialize() { - config = getConfigAs(WlanThermoExtendedConfiguration.class); - - updateStatus(ThingStatus.UNKNOWN); - try { - if (!config.getUsername().isEmpty() && !config.getPassword().isEmpty()) { - AuthenticationStore authStore = httpClient.getAuthenticationStore(); - authStore.addAuthentication(new DigestAuthentication(config.getUri(), Authentication.ANY_REALM, - config.getUsername(), config.getPassword())); - } - pollingScheduler = scheduler.scheduleWithFixedDelay(this::checkConnectionAndUpdate, 0, - config.getPollingInterval(), TimeUnit.SECONDS); - } catch (URISyntaxException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Failed to initialize WlanThermo Nano: " + e.getMessage()); - } - } - - private void checkConnectionAndUpdate() { - if (this.thing.getStatus() != ThingStatus.ONLINE) { - try { - if (httpClient.GET(config.getUri()).getStatus() == 200) { - updateStatus(ThingStatus.ONLINE); - // rerun immediately to update state - checkConnectionAndUpdate(); - } else { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "WlanThermo not found under given address."); - } - } catch (URISyntaxException | ExecutionException | TimeoutException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Could not connect to WlanThermo at " + config.getIpAddress() + ": " + e.getMessage()); - } catch (InterruptedException e) { - logger.debug("Connection check interrupted. {}", e.getMessage()); - } - } else { - try { - // Update objects with data from device - String json = httpClient.GET(config.getUri("/data")).getContentAsString(); - data = gson.fromJson(json, Data.class); - logger.debug("Received at /data: {}", json); - json = httpClient.GET(config.getUri("/settings")).getContentAsString(); - settings = gson.fromJson(json, Settings.class); - logger.debug("Received at /settings: {}", json); - - // Update channels - for (Channel channel : thing.getChannels()) { - try { - State state = WlanThermoNanoV1CommandHandler.getState(channel.getUID(), data, settings); - updateState(channel.getUID(), state); - } catch (WlanThermoUnknownChannelException e) { - // if we could not obtain a state, try trigger instead - try { - String trigger = WlanThermoNanoV1CommandHandler.getTrigger(channel.getUID(), data); - if (!trigger.equals(TRIGGER_NONE)) { - triggerChannel(channel.getUID(), trigger); - } - } catch (WlanThermoUnknownChannelException e1) { - logger.debug("{}", e.getMessage()); - } - } - } - } catch (URISyntaxException | ExecutionException | TimeoutException | WlanThermoException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Update failed: " + e.getMessage()); - for (Channel channel : thing.getChannels()) { - updateState(channel.getUID(), UnDefType.UNDEF); - } - } catch (InterruptedException e) { - logger.debug("Update interrupted. {}", e.getMessage()); - } - } + protected State getState(ChannelUID channelUID) throws WlanThermoInputException, WlanThermoUnknownChannelException { + return WlanThermoNanoV1CommandHandler.getState(channelUID, data, settings); } @Override - public void handleCommand(ChannelUID channelUID, Command command) { - if (command instanceof RefreshType) { - try { - State s = WlanThermoNanoV1CommandHandler.getState(channelUID, data, settings); - updateState(channelUID, s); - } catch (WlanThermoException e) { - logger.debug("Could not handle command of type {} for channel {}!", - command.getClass().toGenericString(), channelUID.getId()); - } - } else { - if (WlanThermoNanoV1CommandHandler.setState(channelUID, command, data)) { - logger.debug("Data updated, pushing changes"); - scheduler.execute(this::push); - } else { - logger.debug("Could not handle command of type {} for channel {}!", - command.getClass().toGenericString(), channelUID.getId()); - } - } - } - - private boolean doPost(String endpoint, String json) throws InterruptedException { - try { - URI uri = config.getUri(endpoint); - int status = httpClient.POST(uri).content(new StringContentProvider(json), "application/json") - .timeout(5, TimeUnit.SECONDS).send().getStatus(); - if (status == 401) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "No or wrong login credentials provided. Please configure username/password for write access to WlanThermo!"); - return false; - } else if (status != 200) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to update channel on device, Statuscode " + status + " on URI " + uri.toString()); - logger.debug("Payload sent: {}", json); - // Still continue to try next channel - return true; - } else { - updateStatus(ThingStatus.ONLINE); - return true; - } - } catch (TimeoutException | ExecutionException | URISyntaxException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Failed to update channel on device: " + e.getMessage()); - return false; - } + protected boolean setState(ChannelUID channelUID, Command command) { + return WlanThermoNanoV1CommandHandler.setState(channelUID, command, data); } - private void push() { - if (data == null || this.thing.getStatus() != ThingStatus.ONLINE) { - return; - } - + @Override + protected void push() { // push update for sensor channels for (org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Channel c : data.getChannel()) { try { @@ -214,12 +74,33 @@ private void push() { } @Override - public void dispose() { - ScheduledFuture oldScheduler = pollingScheduler; - if (oldScheduler != null) { - boolean stopped = oldScheduler.cancel(true); - logger.debug("Stopped polling: {}", stopped); + protected void pull() { + try { + // Update objects with data from device + data = doGet("/data", Data.class); + settings = doGet("/settings", Settings.class); + + // Update channels + for (Channel channel : thing.getChannels()) { + try { + State state = WlanThermoNanoV1CommandHandler.getState(channel.getUID(), data, settings); + updateState(channel.getUID(), state); + } catch (WlanThermoUnknownChannelException e) { + // if we could not obtain a state, try trigger instead + try { + String trigger = WlanThermoNanoV1CommandHandler.getTrigger(channel.getUID(), data); + if (!trigger.equals(TRIGGER_NONE)) { + triggerChannel(channel.getUID(), trigger); + } + } catch (WlanThermoUnknownChannelException e1) { + logger.debug("{}", e.getMessage()); + } + } + } + } catch (WlanThermoException ignore) { + // Nothing more to do + } catch (InterruptedException e) { + logger.debug("Update interrupted. {}", e.getMessage()); } - pollingScheduler = null; } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Util.java similarity index 78% rename from bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java rename to bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Util.java index 5d756c10f8661..950acc6dc456b 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/UtilNano.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1Util.java @@ -16,20 +16,21 @@ import java.util.Map; import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.wlanthermo.internal.WlanThermoUtil; /** - * The {@link UtilNano} class provides conversion functions for the WlanThermo Nano V1+ + * The {@link WlanThermoNanoV1Util} class provides conversion functions for the WlanThermo Nano V1+ * * @author Christian Schlipp - Initial contribution */ @NonNullByDefault -public class UtilNano { +public class WlanThermoNanoV1Util extends WlanThermoUtil { private static final Map COLOR_MAPPINGS = createColorMap(); private static final String DEFAULT_HEX = "#ffffff"; private static final String DEFAULT_COLORNAME = "niagara"; - private UtilNano() { + private WlanThermoNanoV1Util() { // hidden } @@ -59,16 +60,6 @@ public static String toHex(String colorName) { } public static String toColorName(String colorHex) { - if (!colorHex.startsWith("#")) { - colorHex = "#" + colorHex; - } - - for (Map.Entry entry : COLOR_MAPPINGS.entrySet()) { - if (entry.getValue().equalsIgnoreCase(colorHex)) { - return entry.getKey(); - } - } - - return DEFAULT_COLORNAME; + return toColorName(colorHex, COLOR_MAPPINGS, DEFAULT_COLORNAME); } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java new file mode 100644 index 0000000000000..7c2c4db41831d --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java @@ -0,0 +1,600 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wlanthermo.internal.api.esp32; + +import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.*; +import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.TRIGGER_NONE; + +import java.awt.*; +import java.util.stream.Stream; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.function.Executable; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.openhab.binding.wlanthermo.internal.WlanThermoException; +import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; +import org.openhab.binding.wlanthermo.internal.WlanThermoUtil; +import org.openhab.binding.wlanthermo.internal.api.esp32.dto.data.Data; +import org.openhab.binding.wlanthermo.internal.api.esp32.dto.settings.Settings; +import org.openhab.core.library.types.*; +import org.openhab.core.library.unit.SIUnits; +import org.openhab.core.library.unit.Units; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.ThingUID; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; +import org.openhab.core.types.UnDefType; + +import com.google.gson.Gson; + +/** + * The {@link WlanThermoEsp32CommandHandlerTest} class tests the {@link WlanThermoEsp32CommandHandler} + * + * @author Christian Schlipp - Initial contribution + */ +@NonNullByDefault +class WlanThermoEsp32CommandHandlerTest { + + private static final ThingUID THING_UID = new ThingUID("wlanthermo", "esp32", "test"); + + //@formatter:off + private static final String DATA_INPUT_JSON = "{\n" + + " \"system\": {\n" + + " \"time\": \"1610894101\",\n" + + " \"unit\": \"C\",\n" + + " \"soc\": 89,\n" + + " \"charge\": false,\n" + + " \"rssi\": -32,\n" + + " \"online\": 0\n" + + " },\n" + + " \"channel\": [\n" + + " {\n" + + " \"number\": 1,\n" + + " \"name\": \"Kanal Eins\",\n" + + " \"typ\": 0,\n" + + " \"temp\": 23.7,\n" + + " \"min\": 17,\n" + + " \"max\": 104,\n" + + " \"alarm\": 1,\n" + + " \"color\": \"#270000\",\n" + + " \"fixed\": false,\n" + + " \"connected\": false\n" + + " },\n" + + " {\n" + + " \"number\": 2,\n" + + " \"name\": \"Kanal 2\",\n" + + " \"typ\": 0,\n" + + " \"temp\": 999,\n" + + " \"min\": 50,\n" + + " \"max\": 95,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#22B14C\",\n" + + " \"fixed\": false,\n" + + " \"connected\": false\n" + + " },\n" + + " {\n" + + " \"number\": 3,\n" + + " \"name\": \"Kanal 3\",\n" + + " \"typ\": 0,\n" + + " \"temp\": 999,\n" + + " \"min\": 50,\n" + + " \"max\": 95,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#EF562D\",\n" + + " \"fixed\": false,\n" + + " \"connected\": false\n" + + " },\n" + + " {\n" + + " \"number\": 4,\n" + + " \"name\": \"Kanal 4\",\n" + + " \"typ\": 0,\n" + + " \"temp\": 999,\n" + + " \"min\": 50,\n" + + " \"max\": 95,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#FFC100\",\n" + + " \"fixed\": false,\n" + + " \"connected\": false\n" + + " },\n" + + " {\n" + + " \"number\": 5,\n" + + " \"name\": \"Kanal 5\",\n" + + " \"typ\": 0,\n" + + " \"temp\": 999,\n" + + " \"min\": 50,\n" + + " \"max\": 95,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#A349A4\",\n" + + " \"fixed\": false,\n" + + " \"connected\": false\n" + + " },\n" + + " {\n" + + " \"number\": 6,\n" + + " \"name\": \"Kanal 6\",\n" + + " \"typ\": 0,\n" + + " \"temp\": 999,\n" + + " \"min\": 50,\n" + + " \"max\": 95,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#804000\",\n" + + " \"fixed\": false,\n" + + " \"connected\": false\n" + + " },\n" + + " {\n" + + " \"number\": 7,\n" + + " \"name\": \"Kanal 7\",\n" + + " \"typ\": 0,\n" + + " \"temp\": 23.7,\n" + + " \"min\": 10,\n" + + " \"max\": 95,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#5587A2\",\n" + + " \"fixed\": false,\n" + + " \"connected\": false\n" + + " },\n" + + " {\n" + + " \"number\": 8,\n" + + " \"name\": \"Kanal 8\",\n" + + " \"typ\": 0,\n" + + " \"temp\": 999,\n" + + " \"min\": 50,\n" + + " \"max\": 95,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#5C7148\",\n" + + " \"fixed\": false,\n" + + " \"connected\": false\n" + + " },\n" + + " {\n" + + " \"number\": 9,\n" + + " \"name\": \"Kanal 9\",\n" + + " \"typ\": 16,\n" + + " \"temp\": 999,\n" + + " \"min\": 50,\n" + + " \"max\": 95,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#A349A4\",\n" + + " \"fixed\": true,\n" + + " \"connected\": false\n" + + " },\n" + + " {\n" + + " \"number\": 10,\n" + + " \"name\": \"Kanal 10\",\n" + + " \"typ\": 16,\n" + + " \"temp\": 999,\n" + + " \"min\": 50,\n" + + " \"max\": 95,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#5587A2\",\n" + + " \"fixed\": true,\n" + + " \"connected\": false\n" + + " }\n" + + " ],\n" + + " \"pitmaster\": {\n" + + " \"type\": [\n" + + " \"off\",\n" + + " \"manual\",\n" + + " \"auto\"\n" + + " ],\n" + + " \"pm\": [\n" + + " {\n" + + " \"id\": 0,\n" + + " \"channel\": 1,\n" + + " \"pid\": 1,\n" + + " \"value\": 70,\n" + + " \"set\": 50,\n" + + " \"typ\": \"manual\",\n" + + " \"set_color\": \"#ff0000\",\n" + + " \"value_color\": \"#000000\"\n" + + " }\n" + + " ]\n" + + " }\n" + + "}"; + + private static final String SETTINGS_INPUT_JSON = "{\n" + + " \"device\": {\n" + + " \"device\": \"nano\",\n" + + " \"serial\": \"98f4ab7570c0\",\n" + + " \"cpu\": \"esp32\",\n" + + " \"flash_size\": 16777216,\n" + + " \"item\": \"n3j04oA200B\",\n" + + " \"hw_version\": \"v3\",\n" + + " \"sw_version\": \"v1.1.0\",\n" + + " \"api_version\": \"1\",\n" + + " \"language\": \"de\"\n" + + " },\n" + + " \"system\": {\n" + + " \"time\": \"1610894186\",\n" + + " \"unit\": \"C\",\n" + + " \"ap\": \"WLANTHERMO-AP\",\n" + + " \"host\": \"NANO-98f4ab7570c0\",\n" + + " \"language\": \"de\",\n" + + " \"version\": \"v1.1.0\",\n" + + " \"getupdate\": \"false\",\n" + + " \"autoupd\": true,\n" + + " \"prerelease\": true,\n" + + " \"hwversion\": \"V3\"\n" + + " },\n" + + " \"hardware\": [\n" + + " \"V3\"\n" + + " ],\n" + + " \"api\": {\n" + + " \"version\": \"1\"\n" + + " },\n" + + " \"sensors\": [\n" + + " {\n" + + " \"type\": 0,\n" + + " \"name\": \"1000K/Maverick\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 1,\n" + + " \"name\": \"Fantast-Neu\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 2,\n" + + " \"name\": \"Fantast\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 3,\n" + + " \"name\": \"100K/iGrill2\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 4,\n" + + " \"name\": \"ET-73\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 5,\n" + + " \"name\": \"Perfektion\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 6,\n" + + " \"name\": \"50K\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 7,\n" + + " \"name\": \"Inkbird\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 8,\n" + + " \"name\": \"100K6A1B\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 9,\n" + + " \"name\": \"Weber_6743\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 10,\n" + + " \"name\": \"Santos\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 11,\n" + + " \"name\": \"5K3A1B\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 12,\n" + + " \"name\": \"PT100\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 13,\n" + + " \"name\": \"PT1000\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 14,\n" + + " \"name\": \"ThermoWorks\",\n" + + " \"fixed\": false\n" + + " },\n" + + " {\n" + + " \"type\": 15,\n" + + " \"name\": \"Typ K\",\n" + + " \"fixed\": true\n" + + " },\n" + + " {\n" + + " \"type\": 16,\n" + + " \"name\": \"Bluetooth\",\n" + + " \"fixed\": true\n" + + " },\n" + + " {\n" + + " \"type\": 17,\n" + + " \"name\": \"Maverick\",\n" + + " \"fixed\": true\n" + + " }\n" + + " ],\n" + + " \"features\": {\n" + + " \"bluetooth\": true,\n" + + " \"pitmaster\": true\n" + + " },\n" + + " \"pid\": [\n" + + " {\n" + + " \"name\": \"SSR SousVide\",\n" + + " \"id\": 0,\n" + + " \"aktor\": 0,\n" + + " \"Kp\": 104,\n" + + " \"Ki\": 0.2,\n" + + " \"Kd\": 0,\n" + + " \"DCmmin\": 0,\n" + + " \"DCmmax\": 100,\n" + + " \"opl\": 0,\n" + + " \"SPmin\": 0,\n" + + " \"SPmax\": 0,\n" + + " \"link\": 0,\n" + + " \"tune\": 0,\n" + + " \"jp\": 100\n" + + " },\n" + + " {\n" + + " \"name\": \"TITAN 50x50\",\n" + + " \"id\": 1,\n" + + " \"aktor\": 1,\n" + + " \"Kp\": 7,\n" + + " \"Ki\": 0.01,\n" + + " \"Kd\": 128,\n" + + " \"DCmmin\": 25,\n" + + " \"DCmmax\": 100,\n" + + " \"opl\": 0,\n" + + " \"SPmin\": 0,\n" + + " \"SPmax\": 0,\n" + + " \"link\": 0,\n" + + " \"tune\": 0,\n" + + " \"jp\": 70\n" + + " },\n" + + " {\n" + + " \"name\": \"Servo MG995\",\n" + + " \"id\": 2,\n" + + " \"aktor\": 2,\n" + + " \"Kp\": 104,\n" + + " \"Ki\": 0.2,\n" + + " \"Kd\": 0,\n" + + " \"DCmmin\": 0,\n" + + " \"DCmmax\": 100,\n" + + " \"opl\": 0,\n" + + " \"SPmin\": 25,\n" + + " \"SPmax\": 75,\n" + + " \"link\": 0,\n" + + " \"tune\": 0,\n" + + " \"jp\": 100\n" + + " },\n" + + " {\n" + + " \"name\": \"Custom\",\n" + + " \"id\": 3,\n" + + " \"aktor\": 1,\n" + + " \"Kp\": 7,\n" + + " \"Ki\": 0.2,\n" + + " \"Kd\": 0,\n" + + " \"DCmmin\": 0,\n" + + " \"DCmmax\": 100,\n" + + " \"opl\": 0,\n" + + " \"SPmin\": 0,\n" + + " \"SPmax\": 100,\n" + + " \"link\": 0,\n" + + " \"tune\": 0,\n" + + " \"jp\": 100\n" + + " }\n" + + " ],\n" + + " \"aktor\": [\n" + + " \"SSR\",\n" + + " \"FAN\",\n" + + " \"SERVO\"\n" + + " ],\n" + + " \"display\": {\n" + + " \"updname\": \"\",\n" + + " \"orientation\": 0\n" + + " },\n" + + " \"iot\": {\n" + + " \"PMQhost\": \"192.168.2.1\",\n" + + " \"PMQport\": 1883,\n" + + " \"PMQuser\": \"\",\n" + + " \"PMQpass\": \"\",\n" + + " \"PMQqos\": 0,\n" + + " \"PMQon\": false,\n" + + " \"PMQint\": 30,\n" + + " \"CLon\": false,\n" + + " \"CLtoken\": \"thisisnotatoken\",\n" + + " \"CLint\": 30,\n" + + " \"CLurl\": \"cloud.wlanthermo.de/index.html\"\n" + + " },\n" + + " \"notes\": {\n" + + " \"fcm\": [],\n" + + " \"ext\": {\n" + + " \"on\": 0,\n" + + " \"token\": \"\",\n" + + " \"id\": \"\",\n" + + " \"repeat\": 1,\n" + + " \"service\": 0,\n" + + " \"services\": [\n" + + " \"telegram\",\n" + + " \"pushover\"\n" + + " ]\n" + + " }\n" + + " }\n" + + "}"; + //@formatter:on + + @Nullable + private Data data; + @Nullable + private Settings settings; + + @BeforeEach + void setUp() { + Gson gson = new Gson(); + data = gson.fromJson(DATA_INPUT_JSON, Data.class); + settings = gson.fromJson(SETTINGS_INPUT_JSON, Settings.class); + } + + static Stream getState() { + return Stream.of( + // System channels + Arguments.of(SYSTEM, SYSTEM_SOC, new DecimalType(89), null), + Arguments.of(SYSTEM, SYSTEM_CHARGE, OnOffType.OFF, null), + Arguments.of(SYSTEM, SYSTEM_RSSI_SIGNALSTRENGTH, new DecimalType(4), null), + Arguments.of(SYSTEM, SYSTEM_RSSI, new QuantityType<>(-32, Units.DECIBEL_MILLIWATTS), null), + + // All channels + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_NAME, new StringType("Kanal Eins"), null), + Arguments.of(CHANNEL_PREFIX + "2", CHANNEL_NAME, new StringType("Kanal 2"), null), + Arguments.of(CHANNEL_PREFIX + "3", CHANNEL_NAME, new StringType("Kanal 3"), null), + Arguments.of(CHANNEL_PREFIX + "4", CHANNEL_NAME, new StringType("Kanal 4"), null), + Arguments.of(CHANNEL_PREFIX + "5", CHANNEL_NAME, new StringType("Kanal 5"), null), + Arguments.of(CHANNEL_PREFIX + "6", CHANNEL_NAME, new StringType("Kanal 6"), null), + Arguments.of(CHANNEL_PREFIX + "7", CHANNEL_NAME, new StringType("Kanal 7"), null), + Arguments.of(CHANNEL_PREFIX + "8", CHANNEL_NAME, new StringType("Kanal 8"), null), + Arguments.of(CHANNEL_PREFIX + "9", CHANNEL_NAME, new StringType("Kanal 9"), null), + Arguments.of(CHANNEL_PREFIX + "10", CHANNEL_NAME, new StringType("Kanal 10"), null), + // invalid channel number + Arguments.of(CHANNEL_PREFIX + "11", CHANNEL_NAME, UnDefType.UNDEF, + WlanThermoUnknownChannelException.class), + + // all channel values + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_NAME, new StringType("Kanal Eins"), null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_TYP, new StringType("1000K/Maverick"), null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_TEMP, new QuantityType<>(23.7, SIUnits.CELSIUS), null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_MIN, new QuantityType<>(17, SIUnits.CELSIUS), null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_MAX, new QuantityType<>(104, SIUnits.CELSIUS), null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_DEVICE, OnOffType.OFF, null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_PUSH, OnOffType.ON, null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_OPENHAB_HIGH, OnOffType.OFF, null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_OPENHAB_LOW, OnOffType.OFF, null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_COLOR, + HSBType.fromRGB(Color.decode("#270000").getRed(), Color.decode("#270000").getGreen(), + Color.decode("#270000").getBlue()), + null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_COLOR_NAME, + new StringType(WlanThermoEsp32Util.toColorName("#270000")), null), + + // all pitmaster + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_CHANNEL_ID, new DecimalType(1), null), + Arguments.of(CHANNEL_PITMASTER_2, CHANNEL_PITMASTER_CHANNEL_ID, UnDefType.UNDEF, null), + + // all pitmaster values + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_CHANNEL_ID, new DecimalType(1), null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_PIDPROFILE, new DecimalType(1), null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_DUTY_CYCLE, new DecimalType(70), null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_SETPOINT, new QuantityType<>(50, SIUnits.CELSIUS), + null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_STATE, new StringType("manual"), null)); + } + + static Stream getTrigger() { + return Stream.of( + // all channels + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_OPENHAB, TRIGGER_NONE, null), + Arguments.of(CHANNEL_PREFIX + "2", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "3", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "4", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "5", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "6", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "7", CHANNEL_ALARM_OPENHAB, TRIGGER_NONE, null), + Arguments.of(CHANNEL_PREFIX + "8", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "9", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "10", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + // invalid channel number + Arguments.of(CHANNEL_PREFIX + "11", CHANNEL_ALARM_OPENHAB, "", + WlanThermoUnknownChannelException.class)); + } + + static Stream setState() { + return Stream.of( + // All channels + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_NAME, new StringType("Kanal Eins"), true), + Arguments.of(CHANNEL_PREFIX + "2", CHANNEL_NAME, new StringType("Kanal 2"), true), + Arguments.of(CHANNEL_PREFIX + "3", CHANNEL_NAME, new StringType("Kanal 3"), true), + Arguments.of(CHANNEL_PREFIX + "4", CHANNEL_NAME, new StringType("Kanal 4"), true), + Arguments.of(CHANNEL_PREFIX + "5", CHANNEL_NAME, new StringType("Kanal 5"), true), + Arguments.of(CHANNEL_PREFIX + "6", CHANNEL_NAME, new StringType("Kanal 6"), true), + Arguments.of(CHANNEL_PREFIX + "7", CHANNEL_NAME, new StringType("Kanal 7"), true), + Arguments.of(CHANNEL_PREFIX + "8", CHANNEL_NAME, new StringType("Kanal 8"), true), + Arguments.of(CHANNEL_PREFIX + "9", CHANNEL_NAME, new StringType("Kanal 9"), true), + Arguments.of(CHANNEL_PREFIX + "10", CHANNEL_NAME, new StringType("Kanal 10"), true), + // invalid channel number + Arguments.of(CHANNEL_PREFIX + "11", CHANNEL_NAME, new StringType("Kanal 11"), false), + + // all channel values + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_NAME, new StringType("Kanal Eins"), true), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_TYP, new StringType("1000K/Maverick"), false), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_TEMP, new QuantityType<>(23.7, SIUnits.CELSIUS), false), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_MIN, new QuantityType<>(17, SIUnits.CELSIUS), true), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_MAX, new QuantityType<>(104, SIUnits.CELSIUS), true), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_DEVICE, OnOffType.OFF, true), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_PUSH, OnOffType.ON, true), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_OPENHAB_HIGH, OnOffType.OFF, false), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_OPENHAB_LOW, OnOffType.OFF, false), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_COLOR, + HSBType.fromRGB(Color.decode("#270000").getRed(), Color.decode("#270000").getGreen(), + Color.decode("#270000").getBlue()), + true), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_COLOR_NAME, + new StringType(WlanThermoEsp32Util.toColorName("#270000")), true), + + // all pitmaster + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_CHANNEL_ID, new DecimalType(1), true), + Arguments.of(CHANNEL_PITMASTER_2, CHANNEL_PITMASTER_CHANNEL_ID, new DecimalType(1), false), + + // all pitmaster values + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_CHANNEL_ID, new DecimalType(1), true), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_PIDPROFILE, new DecimalType(0), true), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_DUTY_CYCLE, new DecimalType(0), false), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_SETPOINT, new QuantityType<>(100, SIUnits.CELSIUS), + true), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_STATE, new StringType("off"), true)); + } + + @ParameterizedTest + @MethodSource("getTrigger") + void getTrigger(String groupId, String id, String expectedTrigger, + @Nullable Class exceptionClass) { + Executable test = () -> Assertions.assertEquals(expectedTrigger, WlanThermoEsp32CommandHandler + .getTrigger(new ChannelUID(THING_UID, groupId, id), WlanThermoUtil.requireNonNull(data))); + if (exceptionClass != null) { + Assertions.assertThrows(exceptionClass, test); + } else { + Assertions.assertDoesNotThrow(test); + } + } + + @ParameterizedTest + @MethodSource("getState") + void getState(String groupId, String id, State expectedState, @Nullable Class exceptionClass) { + Executable test = () -> Assertions.assertEquals(expectedState, + WlanThermoEsp32CommandHandler.getState(new ChannelUID(THING_UID, groupId, id), + WlanThermoUtil.requireNonNull(data), WlanThermoUtil.requireNonNull(settings))); + if (exceptionClass != null) { + Assertions.assertThrows(exceptionClass, test); + } else { + Assertions.assertDoesNotThrow(test); + } + } + + @ParameterizedTest + @MethodSource("setState") + void setState(String groupId, String id, Command command, boolean expectedResult) { + Assertions.assertDoesNotThrow(() -> Assertions.assertEquals(expectedResult, WlanThermoEsp32CommandHandler + .setState(new ChannelUID(THING_UID, groupId, id), command, WlanThermoUtil.requireNonNull(data)))); + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandlerTest.java b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandlerTest.java new file mode 100644 index 0000000000000..d70dd0e1f3860 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandlerTest.java @@ -0,0 +1,278 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wlanthermo.internal.api.mini; + +import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.*; + +import java.awt.*; +import java.util.stream.Stream; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.function.Executable; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.openhab.binding.wlanthermo.internal.WlanThermoException; +import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; +import org.openhab.binding.wlanthermo.internal.WlanThermoUtil; +import org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin.App; +import org.openhab.core.library.types.*; +import org.openhab.core.library.unit.ImperialUnits; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.ThingUID; +import org.openhab.core.types.State; +import org.openhab.core.types.UnDefType; + +import com.google.gson.Gson; + +/** + * The {@link WlanThermoMiniCommandHandlerTest} class tests the {@link WlanThermoMiniCommandHandler} + * + * @author Christian Schlipp - Initial contribution + */ +@NonNullByDefault +class WlanThermoMiniCommandHandlerTest { + + private static final ThingUID THING_UID = new ThingUID("wlanthermo", "mini", "test"); + + //@formatter:off + private static final String APP_INPUT_JSON = "{\n" + + " \"temp_unit\": \"fahrenheit\",\n" + + " \"pit\": {\n" + + " \"enabled\": true,\n" + + " \"timestamp\": \"2020-05-29T17:00:54-05:00\",\n" + + " \"setpoint\": 110,\n" + + " \"current\": 77.86,\n" + + " \"control_out\": 100,\n" + + " \"ch\": 0,\n" + + " \"type\": \"False\",\n" + + " \"open_lid\": \"False\"\n" + + " },\n" + + " \"pit2\": {\n" + + " \"enabled\": false\n" + + " },\n" + + " \"cpu_load\": 94.267515923567,\n" + + " \"cpu_temp\": 93.56,\n" + + " \"channel\": {\n" + + " \"0\": {\n" + + " \"temp\": 78.28,\n" + + " \"color\": \"green\",\n" + + " \"state\": \"ok\",\n" + + " \"temp_min\": -20,\n" + + " \"temp_max\": 200,\n" + + " \"name\": \"Kanal0\",\n" + + " \"alert\": false,\n" + + " \"show\": true\n" + + " },\n" + + " \"1\": {\n" + + " \"temp\": 0,\n" + + " \"color\": \"red\",\n" + + " \"state\": \"er\",\n" + + " \"temp_min\": -20,\n" + + " \"temp_max\": 200,\n" + + " \"name\": \"Kanal1\",\n" + + " \"alert\": false,\n" + + " \"show\": true\n" + + " },\n" + + " \"2\": {\n" + + " \"temp\": 0,\n" + + " \"color\": \"blue\",\n" + + " \"state\": \"er\",\n" + + " \"temp_min\": -20,\n" + + " \"temp_max\": 200,\n" + + " \"name\": \"Kanal2\",\n" + + " \"alert\": false,\n" + + " \"show\": true\n" + + " },\n" + + " \"3\": {\n" + + " \"temp\": 0,\n" + + " \"color\": \"olive\",\n" + + " \"state\": \"er\",\n" + + " \"temp_min\": -20,\n" + + " \"temp_max\": 200,\n" + + " \"name\": \"Kanal3\",\n" + + " \"alert\": false,\n" + + " \"show\": true\n" + + " },\n" + + " \"4\": {\n" + + " \"temp\": 0,\n" + + " \"color\": \"magenta\",\n" + + " \"state\": \"er\",\n" + + " \"temp_min\": -20,\n" + + " \"temp_max\": 200,\n" + + " \"name\": \"Kanal4\",\n" + + " \"alert\": false,\n" + + " \"show\": true\n" + + " },\n" + + " \"5\": {\n" + + " \"temp\": 0,\n" + + " \"color\": \"yellow\",\n" + + " \"state\": \"er\",\n" + + " \"temp_min\": -20,\n" + + " \"temp_max\": 200,\n" + + " \"name\": \"Kanal5\",\n" + + " \"alert\": false,\n" + + " \"show\": true\n" + + " },\n" + + " \"6\": {\n" + + " \"temp\": 0,\n" + + " \"color\": \"violet\",\n" + + " \"state\": \"er\",\n" + + " \"temp_min\": -20,\n" + + " \"temp_max\": 200,\n" + + " \"name\": \"Kanal6\",\n" + + " \"alert\": false,\n" + + " \"show\": true\n" + + " },\n" + + " \"7\": {\n" + + " \"temp\": 0,\n" + + " \"color\": \"purple\",\n" + + " \"state\": \"er\",\n" + + " \"temp_min\": -20,\n" + + " \"temp_max\": 200,\n" + + " \"name\": \"Kanal7\",\n" + + " \"alert\": false,\n" + + " \"show\": true\n" + + " },\n" + + " \"8\": {\n" + + " \"temp\": 0,\n" + + " \"color\": \"dark-violet\",\n" + + " \"state\": \"er\",\n" + + " \"temp_min\": -20,\n" + + " \"temp_max\": 200,\n" + + " \"name\": \"Kanal8 - Maverick 1\",\n" + + " \"alert\": false,\n" + + " \"show\": true\n" + + " },\n" + + " \"9\": {\n" + + " \"temp\": 0,\n" + + " \"color\": \"seagreen\",\n" + + " \"state\": \"er\",\n" + + " \"temp_min\": -20,\n" + + " \"temp_max\": 200,\n" + + " \"name\": \"Kanal9 - Maverick 2\",\n" + + " \"alert\": false,\n" + + " \"show\": true\n" + + " }\n" + + " },\n" + + " \"timestamp\": \"2020-05-29T16:06:00-05:00\"\n" + + "}"; + //@formatter:on + + @Nullable + private App app; + + @BeforeEach + void setUp() { + app = new Gson().fromJson(APP_INPUT_JSON, App.class); + } + + static Stream getState() { + return Stream.of( + // System channels + Arguments.of(SYSTEM, SYSTEM_CPU_TEMP, new DecimalType(93.56), null), + Arguments.of(SYSTEM, SYSTEM_CPU_LOAD, new DecimalType(94.267515923567), null), + + // all channels + Arguments.of(CHANNEL_PREFIX + "0", CHANNEL_NAME, new StringType("Kanal0"), null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_NAME, new StringType("Kanal1"), null), + Arguments.of(CHANNEL_PREFIX + "2", CHANNEL_NAME, new StringType("Kanal2"), null), + Arguments.of(CHANNEL_PREFIX + "3", CHANNEL_NAME, new StringType("Kanal3"), null), + Arguments.of(CHANNEL_PREFIX + "4", CHANNEL_NAME, new StringType("Kanal4"), null), + Arguments.of(CHANNEL_PREFIX + "5", CHANNEL_NAME, new StringType("Kanal5"), null), + Arguments.of(CHANNEL_PREFIX + "6", CHANNEL_NAME, new StringType("Kanal6"), null), + Arguments.of(CHANNEL_PREFIX + "7", CHANNEL_NAME, new StringType("Kanal7"), null), + Arguments.of(CHANNEL_PREFIX + "8", CHANNEL_NAME, new StringType("Kanal8 - Maverick 1"), null), + Arguments.of(CHANNEL_PREFIX + "9", CHANNEL_NAME, new StringType("Kanal9 - Maverick 2"), null), + // invalid channel number + Arguments.of(CHANNEL_PREFIX + "10", CHANNEL_NAME, UnDefType.UNDEF, + WlanThermoUnknownChannelException.class), + + // all channel values + Arguments.of(CHANNEL_PREFIX + "0", CHANNEL_NAME, new StringType("Kanal0"), null), + Arguments.of(CHANNEL_PREFIX + "0", CHANNEL_TEMP, new QuantityType<>(78.28, ImperialUnits.FAHRENHEIT), + null), + Arguments.of(CHANNEL_PREFIX + "0", CHANNEL_MIN, new QuantityType<>(-20, ImperialUnits.FAHRENHEIT), + null), + Arguments.of(CHANNEL_PREFIX + "0", CHANNEL_MAX, new QuantityType<>(200, ImperialUnits.FAHRENHEIT), + null), + Arguments.of(CHANNEL_PREFIX + "0", CHANNEL_ALARM_DEVICE, OnOffType.from("false"), null), + Arguments.of(CHANNEL_PREFIX + "0", CHANNEL_ALARM_OPENHAB_HIGH, OnOffType.OFF, null), + Arguments.of(CHANNEL_PREFIX + "0", CHANNEL_ALARM_OPENHAB_LOW, OnOffType.OFF, null), + Arguments.of(CHANNEL_PREFIX + "0", CHANNEL_COLOR, + HSBType.fromRGB(Color.decode(WlanThermoMiniUtil.toHex("green")).getRed(), + Color.decode(WlanThermoMiniUtil.toHex("green")).getGreen(), + Color.decode(WlanThermoMiniUtil.toHex("green")).getBlue()), + null), + Arguments.of(CHANNEL_PREFIX + "0", CHANNEL_COLOR_NAME, new StringType("green"), null), + + // all pitmaster + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_ENABLED, OnOffType.from(true), null), + Arguments.of(CHANNEL_PITMASTER_2, CHANNEL_PITMASTER_ENABLED, UnDefType.UNDEF, null), + + // all pitmaster values + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_ENABLED, OnOffType.from(true), null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_CURRENT, new DecimalType(77.86), null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_SETPOINT, + new QuantityType<>(110, ImperialUnits.FAHRENHEIT), null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_DUTY_CYCLE, new DecimalType(100), null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_LID_OPEN, OnOffType.OFF, null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_CHANNEL_ID, new DecimalType(0), null)); + } + + static Stream getTrigger() { + return Stream.of( + // all channels + Arguments.of(CHANNEL_PREFIX + "0", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_OPENHAB, TRIGGER_NONE, null), + Arguments.of(CHANNEL_PREFIX + "2", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "3", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "4", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "5", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "6", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "7", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "8", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "9", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + // invalid channel number + Arguments.of(CHANNEL_PREFIX + "10", CHANNEL_ALARM_OPENHAB, "", + WlanThermoUnknownChannelException.class)); + } + + @ParameterizedTest + @MethodSource("getTrigger") + void getTrigger(String groupId, String id, String expectedTrigger, + @Nullable Class exceptionClass) { + Executable test = () -> Assertions.assertEquals(expectedTrigger, WlanThermoMiniCommandHandler + .getTrigger(new ChannelUID(THING_UID, groupId, id), WlanThermoUtil.requireNonNull(app))); + if (exceptionClass != null) { + Assertions.assertThrows(exceptionClass, test); + } else { + Assertions.assertDoesNotThrow(test); + } + } + + @ParameterizedTest + @MethodSource("getState") + void getState(String groupId, String id, State expectedState, @Nullable Class exceptionClass) { + Executable test = () -> Assertions.assertEquals(expectedState, WlanThermoMiniCommandHandler + .getState(new ChannelUID(THING_UID, groupId, id), WlanThermoUtil.requireNonNull(app))); + if (exceptionClass != null) { + Assertions.assertThrows(exceptionClass, test); + } else { + Assertions.assertDoesNotThrow(test); + } + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java new file mode 100644 index 0000000000000..0b5d45f050085 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java @@ -0,0 +1,430 @@ +/** + * Copyright (c) 2010-2021 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.wlanthermo.internal.api.nano; + +import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.*; + +import java.awt.*; +import java.util.stream.Stream; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.function.Executable; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.openhab.binding.wlanthermo.internal.WlanThermoException; +import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException; +import org.openhab.binding.wlanthermo.internal.WlanThermoUtil; +import org.openhab.binding.wlanthermo.internal.api.nano.dto.data.Data; +import org.openhab.binding.wlanthermo.internal.api.nano.dto.settings.Settings; +import org.openhab.core.library.types.*; +import org.openhab.core.library.unit.SIUnits; +import org.openhab.core.library.unit.Units; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.ThingUID; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; + +import com.google.gson.Gson; + +/** + * The {@link WlanThermoNanoV1CommandHandlerTest} class tests the {@link WlanThermoNanoV1CommandHandler} + * + * @author Christian Schlipp - Initial contribution + */ +@NonNullByDefault +class WlanThermoNanoV1CommandHandlerTest { + private static final ThingUID THING_UID = new ThingUID("wlanthermo", "nano", "test"); + + //@formatter:off + private static final String DATA_INPUT_JSON = "{\n" + + " \"system\": {\n" + + " \"time\": \"1610899485\",\n" + + " \"unit\": \"C\",\n" + + " \"soc\": 32,\n" + + " \"charge\": false,\n" + + " \"rssi\": 31,\n" + + " \"online\": 0\n" + + " },\n" + + " \"channel\": [\n" + + " {\n" + + " \"number\": 1,\n" + + " \"name\": \"Kanal 1\",\n" + + " \"typ\": 0,\n" + + " \"temp\": 23.7,\n" + + " \"min\": 11,\n" + + " \"max\": 155,\n" + + " \"alarm\": 1,\n" + + " \"color\": \"#EF562D\"\n" + + " },\n" + + " {\n" + + " \"number\": 2,\n" + + " \"name\": \"Kanal 2\",\n" + + " \"typ\": 3,\n" + + " \"temp\": 999,\n" + + " \"min\": 0,\n" + + " \"max\": 48,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#22B14C\"\n" + + " },\n" + + " {\n" + + " \"number\": 3,\n" + + " \"name\": \"Kanal 3\",\n" + + " \"typ\": 3,\n" + + " \"temp\": 999,\n" + + " \"min\": 10,\n" + + " \"max\": 35,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#EF562D\"\n" + + " },\n" + + " {\n" + + " \"number\": 4,\n" + + " \"name\": \"Kanal 4\",\n" + + " \"typ\": 3,\n" + + " \"temp\": 999,\n" + + " \"min\": 10,\n" + + " \"max\": 54,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#FFC100\"\n" + + " },\n" + + " {\n" + + " \"number\": 5,\n" + + " \"name\": \"Kanal 5\",\n" + + " \"typ\": 3,\n" + + " \"temp\": 999,\n" + + " \"min\": 0,\n" + + " \"max\": 69,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#A349A4\"\n" + + " },\n" + + " {\n" + + " \"number\": 6,\n" + + " \"name\": \"Kanal 6\",\n" + + " \"typ\": 0,\n" + + " \"temp\": 999,\n" + + " \"min\": 150,\n" + + " \"max\": 170,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#804000\"\n" + + " },\n" + + " {\n" + + " \"number\": 7,\n" + + " \"name\": \"Kanal 7\",\n" + + " \"typ\": 0,\n" + + " \"temp\": 23.6,\n" + + " \"min\": 0,\n" + + " \"max\": 54,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#5587A2\"\n" + + " },\n" + + " {\n" + + " \"number\": 8,\n" + + " \"name\": \"Kanal 8\",\n" + + " \"typ\": 0,\n" + + " \"temp\": 999,\n" + + " \"min\": 10,\n" + + " \"max\": 35,\n" + + " \"alarm\": 0,\n" + + " \"color\": \"#5C7148\"\n" + + " }\n" + + " ],\n" + + " \"pitmaster\": {\n" + + " \"type\": [\n" + + " \"off\"\n" + + " ],\n" + + " \"pm\": [\n" + + " {\n" + + " \"id\": 0,\n" + + " \"channel\": 1,\n" + + " \"pid\": 0,\n" + + " \"value\": 0,\n" + + " \"set\": 50,\n" + + " \"typ\": \"off\",\n" + + " \"set_color\": \"#ff0000\",\n" + + " \"value_color\": \"#000000\"\n" + + " }\n" + + " ]\n" + + " }\n" + + "}"; + + private static final String SETTINGS_INPUT_JSON = "{\n" + + " \"device\": {\n" + + " \"device\": \"nano\",\n" + + " \"serial\": \"33e8bb\",\n" + + " \"item\": \"n2E04o42000\",\n" + + " \"hw_version\": \"v2\",\n" + + " \"sw_version\": \"v1.0.6\",\n" + + " \"api_version\": \"1\",\n" + + " \"language\": \"de\"\n" + + " },\n" + + " \"system\": {\n" + + " \"time\": \"1610899506\",\n" + + " \"unit\": \"C\",\n" + + " \"ap\": \"NANO-AP\",\n" + + " \"host\": \"NANO-33e8bb\",\n" + + " \"language\": \"de\",\n" + + " \"version\": \"v1.0.6\",\n" + + " \"getupdate\": \"false\",\n" + + " \"autoupd\": true,\n" + + " \"hwversion\": \"V1+\",\n" + + " \"god\": 0\n" + + " },\n" + + " \"hardware\": [\n" + + " \"V1\",\n" + + " \"V1+\"\n" + + " ],\n" + + " \"api\": {\n" + + " \"version\": \"1\"\n" + + " },\n" + + " \"sensors\": [\n" + + " \"1000K/Maverick\",\n" + + " \"Fantast-Neu\",\n" + + " \"Fantast\",\n" + + " \"100K/iGrill2\",\n" + + " \"ET-73\",\n" + + " \"Perfektion\",\n" + + " \"50K\",\n" + + " \"Inkbird\",\n" + + " \"100K6A1B\",\n" + + " \"Weber_6743\",\n" + + " \"Santos\",\n" + + " \"5K3A1B\"\n" + + " ],\n" + + " \"pid\": [\n" + + " {\n" + + " \"name\": \"SSR SousVide\",\n" + + " \"id\": 0,\n" + + " \"aktor\": 0,\n" + + " \"Kp\": 104,\n" + + " \"Ki\": 0.2,\n" + + " \"Kd\": 0,\n" + + " \"DCmmin\": 0,\n" + + " \"DCmmax\": 100,\n" + + " \"opl\": 0,\n" + + " \"tune\": 0,\n" + + " \"jp\": 100\n" + + " },\n" + + " {\n" + + " \"name\": \"TITAN 50x50\",\n" + + " \"id\": 1,\n" + + " \"aktor\": 1,\n" + + " \"Kp\": 3.8,\n" + + " \"Ki\": 0.01,\n" + + " \"Kd\": 128,\n" + + " \"DCmmin\": 25,\n" + + " \"DCmmax\": 100,\n" + + " \"opl\": 0,\n" + + " \"tune\": 0,\n" + + " \"jp\": 70\n" + + " },\n" + + " {\n" + + " \"name\": \"Kamado 50x50\",\n" + + " \"id\": 2,\n" + + " \"aktor\": 1,\n" + + " \"Kp\": 7,\n" + + " \"Ki\": 0.02,\n" + + " \"Kd\": 630,\n" + + " \"DCmmin\": 25,\n" + + " \"DCmmax\": 100,\n" + + " \"opl\": 0,\n" + + " \"tune\": 0,\n" + + " \"jp\": 70\n" + + " }\n" + + " ],\n" + + " \"aktor\": [\n" + + " \"SSR\",\n" + + " \"FAN\",\n" + + " \"SERVO\"\n" + + " ],\n" + + " \"iot\": {\n" + + " \"PMQhost\": \"192.168.2.1\",\n" + + " \"PMQport\": 1883,\n" + + " \"PMQuser\": \"\",\n" + + " \"PMQpass\": \"\",\n" + + " \"PMQqos\": 0,\n" + + " \"PMQon\": false,\n" + + " \"PMQint\": 30,\n" + + " \"CLon\": false,\n" + + " \"CLtoken\": \"thisisnotatoken\",\n" + + " \"CLint\": 30,\n" + + " \"CLurl\": \"cloud.wlanthermo.de/index.html\"\n" + + " },\n" + + " \"notes\": {\n" + + " \"fcm\": [],\n" + + " \"ext\": {\n" + + " \"on\": 0,\n" + + " \"token\": \"\",\n" + + " \"id\": \"\",\n" + + " \"repeat\": 1,\n" + + " \"service\": 0,\n" + + " \"services\": [\n" + + " \"telegram\",\n" + + " \"pushover\"\n" + + " ]\n" + + " }\n" + + " }\n" + + "}"; + //@formatter:on + + @Nullable + private Data data; + @Nullable + private Settings settings; + + @BeforeEach + void setUp() { + Gson gson = new Gson(); + data = gson.fromJson(DATA_INPUT_JSON, Data.class); + settings = gson.fromJson(SETTINGS_INPUT_JSON, Settings.class); + } + + static Stream getState() { + return Stream.of( + // System channels + Arguments.of(SYSTEM, SYSTEM_SOC, new DecimalType(32), null), + Arguments.of(SYSTEM, SYSTEM_CHARGE, OnOffType.OFF, null), + Arguments.of(SYSTEM, SYSTEM_RSSI_SIGNALSTRENGTH, new DecimalType(4), null), + Arguments.of(SYSTEM, SYSTEM_RSSI, new QuantityType<>(-31, Units.DECIBEL_MILLIWATTS), null), + + // All channels + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_NAME, new StringType("Kanal 1"), null), + Arguments.of(CHANNEL_PREFIX + "2", CHANNEL_NAME, new StringType("Kanal 2"), null), + Arguments.of(CHANNEL_PREFIX + "3", CHANNEL_NAME, new StringType("Kanal 3"), null), + Arguments.of(CHANNEL_PREFIX + "4", CHANNEL_NAME, new StringType("Kanal 4"), null), + Arguments.of(CHANNEL_PREFIX + "5", CHANNEL_NAME, new StringType("Kanal 5"), null), + Arguments.of(CHANNEL_PREFIX + "6", CHANNEL_NAME, new StringType("Kanal 6"), null), + Arguments.of(CHANNEL_PREFIX + "7", CHANNEL_NAME, new StringType("Kanal 7"), null), + Arguments.of(CHANNEL_PREFIX + "8", CHANNEL_NAME, new StringType("Kanal 8"), null), + // invalid channel number + Arguments.of(CHANNEL_PREFIX + "9", CHANNEL_NAME, new StringType("Kanal 9"), + WlanThermoUnknownChannelException.class), + + // all channel values + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_NAME, new StringType("Kanal 1"), null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_TYP, new StringType("1000K/Maverick"), null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_TEMP, new QuantityType<>(23.7, SIUnits.CELSIUS), null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_MIN, new QuantityType<>(11, SIUnits.CELSIUS), null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_MAX, new QuantityType<>(155, SIUnits.CELSIUS), null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_DEVICE, OnOffType.OFF, null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_PUSH, OnOffType.ON, null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_OPENHAB_HIGH, OnOffType.OFF, null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_OPENHAB_LOW, OnOffType.OFF, null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_COLOR, + HSBType.fromRGB(Color.decode("#EF562D").getRed(), Color.decode("#EF562D").getGreen(), + Color.decode("#EF562D").getBlue()), + null), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_COLOR_NAME, + new StringType(WlanThermoNanoV1Util.toColorName("#EF562D")), null), + + // all pitmaster values + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_CHANNEL_ID, new DecimalType(1), null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_PIDPROFILE, new DecimalType(0), null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_DUTY_CYCLE, new DecimalType(0), null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_SETPOINT, new QuantityType<>(50, SIUnits.CELSIUS), + null), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_STATE, new StringType("off"), null)); + } + + static Stream getTrigger() { + return Stream.of( + // all channels + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_OPENHAB, TRIGGER_NONE, null), + Arguments.of(CHANNEL_PREFIX + "2", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "3", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "4", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "5", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "6", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + Arguments.of(CHANNEL_PREFIX + "7", CHANNEL_ALARM_OPENHAB, TRIGGER_NONE, null), + Arguments.of(CHANNEL_PREFIX + "8", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class), + // invalid channel number + Arguments.of(CHANNEL_PREFIX + "9", CHANNEL_ALARM_OPENHAB, "", WlanThermoUnknownChannelException.class)); + } + + static Stream setState() { + return Stream.of( + // All channels + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_NAME, new StringType("Kanal 1"), true), + Arguments.of(CHANNEL_PREFIX + "2", CHANNEL_NAME, new StringType("Kanal 2"), true), + Arguments.of(CHANNEL_PREFIX + "3", CHANNEL_NAME, new StringType("Kanal 3"), true), + Arguments.of(CHANNEL_PREFIX + "4", CHANNEL_NAME, new StringType("Kanal 4"), true), + Arguments.of(CHANNEL_PREFIX + "5", CHANNEL_NAME, new StringType("Kanal 5"), true), + Arguments.of(CHANNEL_PREFIX + "6", CHANNEL_NAME, new StringType("Kanal 6"), true), + Arguments.of(CHANNEL_PREFIX + "7", CHANNEL_NAME, new StringType("Kanal 7"), true), + Arguments.of(CHANNEL_PREFIX + "8", CHANNEL_NAME, new StringType("Kanal 8"), true), + // invalid channel number + Arguments.of(CHANNEL_PREFIX + "9", CHANNEL_NAME, new StringType("Kanal 9"), false), + + // all channel values + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_NAME, new StringType("Kanal 1"), true), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_TYP, new StringType("1000K/Maverick"), false), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_TEMP, new QuantityType<>(23.7, SIUnits.CELSIUS), false), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_MIN, new QuantityType<>(11, SIUnits.CELSIUS), true), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_MAX, new QuantityType<>(155, SIUnits.CELSIUS), true), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_DEVICE, OnOffType.OFF, true), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_PUSH, OnOffType.ON, true), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_OPENHAB_HIGH, OnOffType.OFF, false), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_ALARM_OPENHAB_LOW, OnOffType.OFF, false), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_COLOR, + HSBType.fromRGB(Color.decode("#EF562D").getRed(), Color.decode("#EF562D").getGreen(), + Color.decode("#EF562D").getBlue()), + false), + Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_COLOR_NAME, + new StringType(WlanThermoNanoV1Util.toColorName("#EF562D")), true), + + // all pitmaster values + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_CHANNEL_ID, new DecimalType(1), true), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_PIDPROFILE, new DecimalType(0), true), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_DUTY_CYCLE, new DecimalType(0), false), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_SETPOINT, new QuantityType<>(50, SIUnits.CELSIUS), + true), + Arguments.of(CHANNEL_PITMASTER_1, CHANNEL_PITMASTER_STATE, new StringType("off"), true) + + ); + } + + @ParameterizedTest + @MethodSource("getTrigger") + void getTrigger(String groupId, String id, String expectedTrigger, + @Nullable Class exceptionClass) { + Executable test = () -> Assertions.assertEquals(expectedTrigger, WlanThermoNanoV1CommandHandler + .getTrigger(new ChannelUID(THING_UID, groupId, id), WlanThermoUtil.requireNonNull(data))); + if (exceptionClass != null) { + Assertions.assertThrows(exceptionClass, test); + } else { + Assertions.assertDoesNotThrow(test); + } + } + + @ParameterizedTest + @MethodSource("getState") + void getState(String groupId, String id, State expectedState, @Nullable Class exceptionClass) { + Executable test = () -> Assertions.assertEquals(expectedState, + WlanThermoNanoV1CommandHandler.getState(new ChannelUID(THING_UID, groupId, id), + WlanThermoUtil.requireNonNull(data), WlanThermoUtil.requireNonNull(settings))); + if (exceptionClass != null) { + Assertions.assertThrows(exceptionClass, test); + } else { + Assertions.assertDoesNotThrow(test); + } + } + + @ParameterizedTest + @MethodSource("setState") + void setState(String groupId, String id, Command command, boolean expectedResult) { + Assertions.assertDoesNotThrow(() -> Assertions.assertEquals(expectedResult, WlanThermoNanoV1CommandHandler + .setState(new ChannelUID(THING_UID, groupId, id), command, WlanThermoUtil.requireNonNull(data)))); + } +} From d7c3d69678bd102e37d16a689eb28c222cfacc59 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sun, 17 Jan 2021 18:05:16 +0100 Subject: [PATCH 36/40] Check if pitmaster is enabled for ESP32 devices Signed-off-by: Christian Schlipp --- .../api/esp32/WlanThermoEsp32CommandHandler.java | 10 +++++----- .../internal/api/esp32/WlanThermoEsp32Handler.java | 2 +- .../api/esp32/WlanThermoEsp32CommandHandlerTest.java | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index 5888fa917cb60..cfe4ad1b87876 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -136,8 +136,8 @@ public static State getState(ChannelUID channelUID, Data data, Settings settings } } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PITMASTER_PREFIX.length())) - 1; - if (data.getPitmaster() != null && data.getPitmaster().getPm() != null - && data.getPitmaster().getPm().size() > channelId) { + if (settings.getFeatures().getPitmaster() && data.getPitmaster() != null + && data.getPitmaster().getPm() != null && data.getPitmaster().getPm().size() > channelId) { Pm pm = data.getPitmaster().getPm().get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_PITMASTER_CHANNEL_ID: @@ -158,7 +158,7 @@ public static State getState(ChannelUID channelUID, Data data, Settings settings throw new WlanThermoUnknownChannelException(channelUID); } - public static boolean setState(ChannelUID channelUID, Command command, Data data) { + public static boolean setState(ChannelUID channelUID, Command command, Data data, Settings settings) { String groupId; try { groupId = requireNonNull(channelUID.getGroupId()); @@ -234,8 +234,8 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data } } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PITMASTER_PREFIX.length())) - 1; - if (data.getPitmaster() != null && data.getPitmaster().getPm() != null - && data.getPitmaster().getPm().size() > channelId) { + if (settings.getFeatures().getPitmaster() && data.getPitmaster() != null + && data.getPitmaster().getPm() != null && data.getPitmaster().getPm().size() > channelId) { Pm pm = data.getPitmaster().getPm().get(channelId); switch (channelUID.getIdWithoutGroup()) { case CHANNEL_PITMASTER_CHANNEL_ID: diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java index f61437b180835..b42c882c0aa2e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32Handler.java @@ -48,7 +48,7 @@ protected State getState(ChannelUID channelUID) throws WlanThermoInputException, @Override protected boolean setState(ChannelUID channelUID, Command command) { - return WlanThermoEsp32CommandHandler.setState(channelUID, command, data); + return WlanThermoEsp32CommandHandler.setState(channelUID, command, data, settings); } @Override diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java index 7c2c4db41831d..3f6983225b504 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java +++ b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java @@ -594,7 +594,8 @@ void getState(String groupId, String id, State expectedState, @Nullable Class Assertions.assertEquals(expectedResult, WlanThermoEsp32CommandHandler - .setState(new ChannelUID(THING_UID, groupId, id), command, WlanThermoUtil.requireNonNull(data)))); + Assertions.assertDoesNotThrow(() -> Assertions.assertEquals(expectedResult, + WlanThermoEsp32CommandHandler.setState(new ChannelUID(THING_UID, groupId, id), command, + WlanThermoUtil.requireNonNull(data), WlanThermoUtil.requireNonNull(settings)))); } } From 483da477f329def4b5438d2ef1e3839552c901a0 Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Sun, 17 Jan 2021 18:12:50 +0100 Subject: [PATCH 37/40] Revert RSSI conversion for NanoV1 devices Signed-off-by: Christian Schlipp --- .../internal/api/nano/WlanThermoNanoV1CommandHandler.java | 4 ++-- .../internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index efbc46e8b5adc..505bbbce18e9b 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -62,7 +62,7 @@ public static State getState(ChannelUID channelUID, Data data, Settings settings case SYSTEM_CHARGE: return OnOffType.from(system.getCharge()); case SYSTEM_RSSI_SIGNALSTRENGTH: - int dbm = (-1) * system.getRssi(); + int dbm = system.getRssi(); if (dbm >= -80) { return SIGNAL_STRENGTH_4; } else if (dbm >= -95) { @@ -73,7 +73,7 @@ public static State getState(ChannelUID channelUID, Data data, Settings settings return SIGNAL_STRENGTH_1; } case SYSTEM_RSSI: - return new QuantityType<>((-1) * system.getRssi(), Units.DECIBEL_MILLIWATTS); + return new QuantityType<>(system.getRssi(), Units.DECIBEL_MILLIWATTS); } } else if (channelUID.getId().startsWith(CHANNEL_PREFIX)) { int channelId = Integer.parseInt(groupId.substring(CHANNEL_PREFIX.length())) - 1; diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java index 0b5d45f050085..ca0f5591ef10d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java +++ b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java @@ -56,7 +56,7 @@ class WlanThermoNanoV1CommandHandlerTest { " \"unit\": \"C\",\n" + " \"soc\": 32,\n" + " \"charge\": false,\n" + - " \"rssi\": 31,\n" + + " \"rssi\": -47,\n" + " \"online\": 0\n" + " },\n" + " \"channel\": [\n" + @@ -297,7 +297,7 @@ static Stream getState() { Arguments.of(SYSTEM, SYSTEM_SOC, new DecimalType(32), null), Arguments.of(SYSTEM, SYSTEM_CHARGE, OnOffType.OFF, null), Arguments.of(SYSTEM, SYSTEM_RSSI_SIGNALSTRENGTH, new DecimalType(4), null), - Arguments.of(SYSTEM, SYSTEM_RSSI, new QuantityType<>(-31, Units.DECIBEL_MILLIWATTS), null), + Arguments.of(SYSTEM, SYSTEM_RSSI, new QuantityType<>(-47, Units.DECIBEL_MILLIWATTS), null), // All channels Arguments.of(CHANNEL_PREFIX + "1", CHANNEL_NAME, new StringType("Kanal 1"), null), From 1270e69000d427c6eefe94a1462b8c1f20c6a77e Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Mon, 18 Jan 2021 07:48:57 +0100 Subject: [PATCH 38/40] fix Fallthrough bug introduced by change of return handling move test json to resources Signed-off-by: Christian Schlipp --- .../internal/WlanThermoException.java | 13 +- .../internal/WlanThermoHandler.java | 7 +- .../internal/WlanThermoInputException.java | 4 + .../WlanThermoUnknownChannelException.java | 4 + .../esp32/WlanThermoEsp32CommandHandler.java | 8 + .../nano/WlanThermoNanoV1CommandHandler.java | 7 + .../WlanThermoEsp32CommandHandlerTest.java | 398 +----------------- .../WlanThermoMiniCommandHandlerTest.java | 132 +----- .../WlanThermoNanoV1CommandHandlerTest.java | 241 +---------- .../src/test/resources/esp32/data.json | 151 +++++++ .../src/test/resources/esp32/settings.json | 229 ++++++++++ .../src/test/resources/mini/app.json | 121 ++++++ .../src/test/resources/nanov1/data.json | 109 +++++ .../src/test/resources/nanov1/settings.json | 117 +++++ 14 files changed, 792 insertions(+), 749 deletions(-) create mode 100644 bundles/org.openhab.binding.wlanthermo/src/test/resources/esp32/data.json create mode 100644 bundles/org.openhab.binding.wlanthermo/src/test/resources/esp32/settings.json create mode 100644 bundles/org.openhab.binding.wlanthermo/src/test/resources/mini/app.json create mode 100644 bundles/org.openhab.binding.wlanthermo/src/test/resources/nanov1/data.json create mode 100644 bundles/org.openhab.binding.wlanthermo/src/test/resources/nanov1/settings.json diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoException.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoException.java index 28f7dbcb690b2..f334838e2bda7 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoException.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoException.java @@ -20,11 +20,22 @@ * @author Christian Schlipp - Initial contribution */ @NonNullByDefault -public abstract class WlanThermoException extends Exception { +public class WlanThermoException extends Exception { static final long serialVersionUID = 1L; public WlanThermoException(String reason) { super(reason, null); } + + public WlanThermoException(String message, Throwable cause) { + super(message, cause); + } + + public WlanThermoException(Throwable cause) { + super(cause); + } + + public WlanThermoException() { + } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoHandler.java index 6370641e6f9b7..3a8bacc5696e6 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoHandler.java @@ -53,8 +53,7 @@ public abstract class WlanThermoHandler extends BaseThingHandler { protected final HttpClient httpClient; protected final Logger logger = LoggerFactory.getLogger(WlanThermoHandler.class); protected final Gson gson = new Gson(); - @Nullable - protected ScheduledFuture pollingScheduler; + protected @Nullable ScheduledFuture pollingScheduler; public WlanThermoHandler(Thing thing, HttpClient httpClient, boolean extendedConfig) { super(thing); @@ -143,7 +142,7 @@ protected boolean doPost(String endpoint, String json) throws InterruptedExcepti } } - protected T doGet(String endpoint, Class object) throws InterruptedException, WlanThermoInputException { + protected T doGet(String endpoint, Class object) throws InterruptedException, WlanThermoException { try { String json = httpClient.GET(config.getUri(endpoint)).getContentAsString(); logger.debug("Received at {}: {}", endpoint, json); @@ -154,7 +153,7 @@ protected T doGet(String endpoint, Class object) throws InterruptedExcept for (Channel channel : thing.getChannels()) { updateState(channel.getUID(), UnDefType.UNDEF); } - throw new WlanThermoInputException(); + throw new WlanThermoException(e); } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoInputException.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoInputException.java index d24aa817ff125..3955a3fb3958d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoInputException.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoInputException.java @@ -28,4 +28,8 @@ public class WlanThermoInputException extends WlanThermoException { public WlanThermoInputException() { super(INVALID_INPUT_EXCEPTION); } + + public WlanThermoInputException(Throwable cause) { + super(INVALID_INPUT_EXCEPTION, cause); + } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUnknownChannelException.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUnknownChannelException.java index 3d02452219e50..ca01536138cb5 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUnknownChannelException.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/WlanThermoUnknownChannelException.java @@ -33,4 +33,8 @@ public WlanThermoUnknownChannelException() { public WlanThermoUnknownChannelException(ChannelUID channelUID) { super(UNKNOWN_CHANNEL_EXCEPTION + "ChannelUID: " + channelUID.toString()); } + + public WlanThermoUnknownChannelException(ChannelUID channelUID, Throwable cause) { + super(UNKNOWN_CHANNEL_EXCEPTION + "ChannelUID: " + channelUID.toString(), cause); + } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java index cfe4ad1b87876..cf72a89ebaf93 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandler.java @@ -180,6 +180,7 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data channel.setName(command.toFullString()); return true; } + return false; case CHANNEL_MIN: if (command instanceof QuantityType) { try { @@ -189,6 +190,7 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data return false; } } + return false; case CHANNEL_MAX: if (command instanceof QuantityType) { try { @@ -198,6 +200,7 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data return false; } } + return false; case CHANNEL_ALARM_DEVICE: if (command instanceof OnOffType) { BigInteger value; @@ -209,6 +212,7 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data channel.setAlarm(value.intValue()); return true; } + return false; case CHANNEL_ALARM_PUSH: if (command instanceof OnOffType) { BigInteger value; @@ -220,16 +224,19 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data channel.setAlarm(value.intValue()); return true; } + return false; case CHANNEL_COLOR_NAME: if (command instanceof StringType) { channel.setColor(WlanThermoEsp32Util.toHex(((StringType) command).toString())); return true; } + return false; case CHANNEL_COLOR: if (command instanceof HSBType) { channel.setColor(WlanThermoUtil.toHex((HSBType) command)); return true; } + return false; } } } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_PREFIX)) { @@ -258,6 +265,7 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data pm.setTyp(state); return true; } + return false; } } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java index 505bbbce18e9b..a8b6a04c41f59 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java +++ b/bundles/org.openhab.binding.wlanthermo/src/main/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandler.java @@ -169,6 +169,7 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data channel.setName(command.toFullString()); return true; } + return false; case CHANNEL_MIN: if (command instanceof QuantityType) { try { @@ -178,6 +179,7 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data return false; } } + return false; case CHANNEL_MAX: if (command instanceof QuantityType) { try { @@ -187,6 +189,7 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data return false; } } + return false; case CHANNEL_ALARM_DEVICE: if (command instanceof OnOffType) { BigInteger value; @@ -198,6 +201,7 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data channel.setAlarm(value.intValue()); return true; } + return false; case CHANNEL_ALARM_PUSH: if (command instanceof OnOffType) { BigInteger value; @@ -209,11 +213,13 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data channel.setAlarm(value.intValue()); return true; } + return false; case CHANNEL_COLOR_NAME: if (command instanceof StringType) { channel.setColor(WlanThermoNanoV1Util.toHex(((StringType) command).toString())); return true; } + return false; } } } else if (channelUID.getId().startsWith(CHANNEL_PITMASTER_1)) { @@ -241,6 +247,7 @@ public static boolean setState(ChannelUID channelUID, Command command, Data data pm.setTyp(state); return true; } + return false; } } } diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java index 3f6983225b504..56f718ecc5b99 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java +++ b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java @@ -16,6 +16,11 @@ import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.TRIGGER_NONE; import java.awt.*; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; +import java.util.Objects; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -52,400 +57,19 @@ class WlanThermoEsp32CommandHandlerTest { private static final ThingUID THING_UID = new ThingUID("wlanthermo", "esp32", "test"); - //@formatter:off - private static final String DATA_INPUT_JSON = "{\n" + - " \"system\": {\n" + - " \"time\": \"1610894101\",\n" + - " \"unit\": \"C\",\n" + - " \"soc\": 89,\n" + - " \"charge\": false,\n" + - " \"rssi\": -32,\n" + - " \"online\": 0\n" + - " },\n" + - " \"channel\": [\n" + - " {\n" + - " \"number\": 1,\n" + - " \"name\": \"Kanal Eins\",\n" + - " \"typ\": 0,\n" + - " \"temp\": 23.7,\n" + - " \"min\": 17,\n" + - " \"max\": 104,\n" + - " \"alarm\": 1,\n" + - " \"color\": \"#270000\",\n" + - " \"fixed\": false,\n" + - " \"connected\": false\n" + - " },\n" + - " {\n" + - " \"number\": 2,\n" + - " \"name\": \"Kanal 2\",\n" + - " \"typ\": 0,\n" + - " \"temp\": 999,\n" + - " \"min\": 50,\n" + - " \"max\": 95,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#22B14C\",\n" + - " \"fixed\": false,\n" + - " \"connected\": false\n" + - " },\n" + - " {\n" + - " \"number\": 3,\n" + - " \"name\": \"Kanal 3\",\n" + - " \"typ\": 0,\n" + - " \"temp\": 999,\n" + - " \"min\": 50,\n" + - " \"max\": 95,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#EF562D\",\n" + - " \"fixed\": false,\n" + - " \"connected\": false\n" + - " },\n" + - " {\n" + - " \"number\": 4,\n" + - " \"name\": \"Kanal 4\",\n" + - " \"typ\": 0,\n" + - " \"temp\": 999,\n" + - " \"min\": 50,\n" + - " \"max\": 95,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#FFC100\",\n" + - " \"fixed\": false,\n" + - " \"connected\": false\n" + - " },\n" + - " {\n" + - " \"number\": 5,\n" + - " \"name\": \"Kanal 5\",\n" + - " \"typ\": 0,\n" + - " \"temp\": 999,\n" + - " \"min\": 50,\n" + - " \"max\": 95,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#A349A4\",\n" + - " \"fixed\": false,\n" + - " \"connected\": false\n" + - " },\n" + - " {\n" + - " \"number\": 6,\n" + - " \"name\": \"Kanal 6\",\n" + - " \"typ\": 0,\n" + - " \"temp\": 999,\n" + - " \"min\": 50,\n" + - " \"max\": 95,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#804000\",\n" + - " \"fixed\": false,\n" + - " \"connected\": false\n" + - " },\n" + - " {\n" + - " \"number\": 7,\n" + - " \"name\": \"Kanal 7\",\n" + - " \"typ\": 0,\n" + - " \"temp\": 23.7,\n" + - " \"min\": 10,\n" + - " \"max\": 95,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#5587A2\",\n" + - " \"fixed\": false,\n" + - " \"connected\": false\n" + - " },\n" + - " {\n" + - " \"number\": 8,\n" + - " \"name\": \"Kanal 8\",\n" + - " \"typ\": 0,\n" + - " \"temp\": 999,\n" + - " \"min\": 50,\n" + - " \"max\": 95,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#5C7148\",\n" + - " \"fixed\": false,\n" + - " \"connected\": false\n" + - " },\n" + - " {\n" + - " \"number\": 9,\n" + - " \"name\": \"Kanal 9\",\n" + - " \"typ\": 16,\n" + - " \"temp\": 999,\n" + - " \"min\": 50,\n" + - " \"max\": 95,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#A349A4\",\n" + - " \"fixed\": true,\n" + - " \"connected\": false\n" + - " },\n" + - " {\n" + - " \"number\": 10,\n" + - " \"name\": \"Kanal 10\",\n" + - " \"typ\": 16,\n" + - " \"temp\": 999,\n" + - " \"min\": 50,\n" + - " \"max\": 95,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#5587A2\",\n" + - " \"fixed\": true,\n" + - " \"connected\": false\n" + - " }\n" + - " ],\n" + - " \"pitmaster\": {\n" + - " \"type\": [\n" + - " \"off\",\n" + - " \"manual\",\n" + - " \"auto\"\n" + - " ],\n" + - " \"pm\": [\n" + - " {\n" + - " \"id\": 0,\n" + - " \"channel\": 1,\n" + - " \"pid\": 1,\n" + - " \"value\": 70,\n" + - " \"set\": 50,\n" + - " \"typ\": \"manual\",\n" + - " \"set_color\": \"#ff0000\",\n" + - " \"value_color\": \"#000000\"\n" + - " }\n" + - " ]\n" + - " }\n" + - "}"; - - private static final String SETTINGS_INPUT_JSON = "{\n" + - " \"device\": {\n" + - " \"device\": \"nano\",\n" + - " \"serial\": \"98f4ab7570c0\",\n" + - " \"cpu\": \"esp32\",\n" + - " \"flash_size\": 16777216,\n" + - " \"item\": \"n3j04oA200B\",\n" + - " \"hw_version\": \"v3\",\n" + - " \"sw_version\": \"v1.1.0\",\n" + - " \"api_version\": \"1\",\n" + - " \"language\": \"de\"\n" + - " },\n" + - " \"system\": {\n" + - " \"time\": \"1610894186\",\n" + - " \"unit\": \"C\",\n" + - " \"ap\": \"WLANTHERMO-AP\",\n" + - " \"host\": \"NANO-98f4ab7570c0\",\n" + - " \"language\": \"de\",\n" + - " \"version\": \"v1.1.0\",\n" + - " \"getupdate\": \"false\",\n" + - " \"autoupd\": true,\n" + - " \"prerelease\": true,\n" + - " \"hwversion\": \"V3\"\n" + - " },\n" + - " \"hardware\": [\n" + - " \"V3\"\n" + - " ],\n" + - " \"api\": {\n" + - " \"version\": \"1\"\n" + - " },\n" + - " \"sensors\": [\n" + - " {\n" + - " \"type\": 0,\n" + - " \"name\": \"1000K/Maverick\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 1,\n" + - " \"name\": \"Fantast-Neu\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 2,\n" + - " \"name\": \"Fantast\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 3,\n" + - " \"name\": \"100K/iGrill2\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 4,\n" + - " \"name\": \"ET-73\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 5,\n" + - " \"name\": \"Perfektion\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 6,\n" + - " \"name\": \"50K\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 7,\n" + - " \"name\": \"Inkbird\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 8,\n" + - " \"name\": \"100K6A1B\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 9,\n" + - " \"name\": \"Weber_6743\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 10,\n" + - " \"name\": \"Santos\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 11,\n" + - " \"name\": \"5K3A1B\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 12,\n" + - " \"name\": \"PT100\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 13,\n" + - " \"name\": \"PT1000\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 14,\n" + - " \"name\": \"ThermoWorks\",\n" + - " \"fixed\": false\n" + - " },\n" + - " {\n" + - " \"type\": 15,\n" + - " \"name\": \"Typ K\",\n" + - " \"fixed\": true\n" + - " },\n" + - " {\n" + - " \"type\": 16,\n" + - " \"name\": \"Bluetooth\",\n" + - " \"fixed\": true\n" + - " },\n" + - " {\n" + - " \"type\": 17,\n" + - " \"name\": \"Maverick\",\n" + - " \"fixed\": true\n" + - " }\n" + - " ],\n" + - " \"features\": {\n" + - " \"bluetooth\": true,\n" + - " \"pitmaster\": true\n" + - " },\n" + - " \"pid\": [\n" + - " {\n" + - " \"name\": \"SSR SousVide\",\n" + - " \"id\": 0,\n" + - " \"aktor\": 0,\n" + - " \"Kp\": 104,\n" + - " \"Ki\": 0.2,\n" + - " \"Kd\": 0,\n" + - " \"DCmmin\": 0,\n" + - " \"DCmmax\": 100,\n" + - " \"opl\": 0,\n" + - " \"SPmin\": 0,\n" + - " \"SPmax\": 0,\n" + - " \"link\": 0,\n" + - " \"tune\": 0,\n" + - " \"jp\": 100\n" + - " },\n" + - " {\n" + - " \"name\": \"TITAN 50x50\",\n" + - " \"id\": 1,\n" + - " \"aktor\": 1,\n" + - " \"Kp\": 7,\n" + - " \"Ki\": 0.01,\n" + - " \"Kd\": 128,\n" + - " \"DCmmin\": 25,\n" + - " \"DCmmax\": 100,\n" + - " \"opl\": 0,\n" + - " \"SPmin\": 0,\n" + - " \"SPmax\": 0,\n" + - " \"link\": 0,\n" + - " \"tune\": 0,\n" + - " \"jp\": 70\n" + - " },\n" + - " {\n" + - " \"name\": \"Servo MG995\",\n" + - " \"id\": 2,\n" + - " \"aktor\": 2,\n" + - " \"Kp\": 104,\n" + - " \"Ki\": 0.2,\n" + - " \"Kd\": 0,\n" + - " \"DCmmin\": 0,\n" + - " \"DCmmax\": 100,\n" + - " \"opl\": 0,\n" + - " \"SPmin\": 25,\n" + - " \"SPmax\": 75,\n" + - " \"link\": 0,\n" + - " \"tune\": 0,\n" + - " \"jp\": 100\n" + - " },\n" + - " {\n" + - " \"name\": \"Custom\",\n" + - " \"id\": 3,\n" + - " \"aktor\": 1,\n" + - " \"Kp\": 7,\n" + - " \"Ki\": 0.2,\n" + - " \"Kd\": 0,\n" + - " \"DCmmin\": 0,\n" + - " \"DCmmax\": 100,\n" + - " \"opl\": 0,\n" + - " \"SPmin\": 0,\n" + - " \"SPmax\": 100,\n" + - " \"link\": 0,\n" + - " \"tune\": 0,\n" + - " \"jp\": 100\n" + - " }\n" + - " ],\n" + - " \"aktor\": [\n" + - " \"SSR\",\n" + - " \"FAN\",\n" + - " \"SERVO\"\n" + - " ],\n" + - " \"display\": {\n" + - " \"updname\": \"\",\n" + - " \"orientation\": 0\n" + - " },\n" + - " \"iot\": {\n" + - " \"PMQhost\": \"192.168.2.1\",\n" + - " \"PMQport\": 1883,\n" + - " \"PMQuser\": \"\",\n" + - " \"PMQpass\": \"\",\n" + - " \"PMQqos\": 0,\n" + - " \"PMQon\": false,\n" + - " \"PMQint\": 30,\n" + - " \"CLon\": false,\n" + - " \"CLtoken\": \"thisisnotatoken\",\n" + - " \"CLint\": 30,\n" + - " \"CLurl\": \"cloud.wlanthermo.de/index.html\"\n" + - " },\n" + - " \"notes\": {\n" + - " \"fcm\": [],\n" + - " \"ext\": {\n" + - " \"on\": 0,\n" + - " \"token\": \"\",\n" + - " \"id\": \"\",\n" + - " \"repeat\": 1,\n" + - " \"service\": 0,\n" + - " \"services\": [\n" + - " \"telegram\",\n" + - " \"pushover\"\n" + - " ]\n" + - " }\n" + - " }\n" + - "}"; - //@formatter:on - @Nullable private Data data; @Nullable private Settings settings; @BeforeEach - void setUp() { + void setUp() throws UnsupportedEncodingException { Gson gson = new Gson(); - data = gson.fromJson(DATA_INPUT_JSON, Data.class); - settings = gson.fromJson(SETTINGS_INPUT_JSON, Settings.class); + ClassLoader classLoader = Objects.requireNonNull(WlanThermoEsp32CommandHandlerTest.class.getClassLoader()); + InputStream dataStream = Objects.requireNonNull(classLoader.getResourceAsStream("esp32/data.json")); + InputStream settingsStream = Objects.requireNonNull(classLoader.getResourceAsStream("esp32/settings.json")); + data = gson.fromJson(new InputStreamReader(dataStream, StandardCharsets.UTF_8), Data.class); + settings = gson.fromJson(new InputStreamReader(settingsStream, StandardCharsets.UTF_8), Settings.class); } static Stream getState() { diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandlerTest.java b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandlerTest.java index d70dd0e1f3860..2145711328281 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandlerTest.java +++ b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/mini/WlanThermoMiniCommandHandlerTest.java @@ -15,6 +15,10 @@ import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.*; import java.awt.*; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.Objects; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -48,136 +52,14 @@ class WlanThermoMiniCommandHandlerTest { private static final ThingUID THING_UID = new ThingUID("wlanthermo", "mini", "test"); - //@formatter:off - private static final String APP_INPUT_JSON = "{\n" + - " \"temp_unit\": \"fahrenheit\",\n" + - " \"pit\": {\n" + - " \"enabled\": true,\n" + - " \"timestamp\": \"2020-05-29T17:00:54-05:00\",\n" + - " \"setpoint\": 110,\n" + - " \"current\": 77.86,\n" + - " \"control_out\": 100,\n" + - " \"ch\": 0,\n" + - " \"type\": \"False\",\n" + - " \"open_lid\": \"False\"\n" + - " },\n" + - " \"pit2\": {\n" + - " \"enabled\": false\n" + - " },\n" + - " \"cpu_load\": 94.267515923567,\n" + - " \"cpu_temp\": 93.56,\n" + - " \"channel\": {\n" + - " \"0\": {\n" + - " \"temp\": 78.28,\n" + - " \"color\": \"green\",\n" + - " \"state\": \"ok\",\n" + - " \"temp_min\": -20,\n" + - " \"temp_max\": 200,\n" + - " \"name\": \"Kanal0\",\n" + - " \"alert\": false,\n" + - " \"show\": true\n" + - " },\n" + - " \"1\": {\n" + - " \"temp\": 0,\n" + - " \"color\": \"red\",\n" + - " \"state\": \"er\",\n" + - " \"temp_min\": -20,\n" + - " \"temp_max\": 200,\n" + - " \"name\": \"Kanal1\",\n" + - " \"alert\": false,\n" + - " \"show\": true\n" + - " },\n" + - " \"2\": {\n" + - " \"temp\": 0,\n" + - " \"color\": \"blue\",\n" + - " \"state\": \"er\",\n" + - " \"temp_min\": -20,\n" + - " \"temp_max\": 200,\n" + - " \"name\": \"Kanal2\",\n" + - " \"alert\": false,\n" + - " \"show\": true\n" + - " },\n" + - " \"3\": {\n" + - " \"temp\": 0,\n" + - " \"color\": \"olive\",\n" + - " \"state\": \"er\",\n" + - " \"temp_min\": -20,\n" + - " \"temp_max\": 200,\n" + - " \"name\": \"Kanal3\",\n" + - " \"alert\": false,\n" + - " \"show\": true\n" + - " },\n" + - " \"4\": {\n" + - " \"temp\": 0,\n" + - " \"color\": \"magenta\",\n" + - " \"state\": \"er\",\n" + - " \"temp_min\": -20,\n" + - " \"temp_max\": 200,\n" + - " \"name\": \"Kanal4\",\n" + - " \"alert\": false,\n" + - " \"show\": true\n" + - " },\n" + - " \"5\": {\n" + - " \"temp\": 0,\n" + - " \"color\": \"yellow\",\n" + - " \"state\": \"er\",\n" + - " \"temp_min\": -20,\n" + - " \"temp_max\": 200,\n" + - " \"name\": \"Kanal5\",\n" + - " \"alert\": false,\n" + - " \"show\": true\n" + - " },\n" + - " \"6\": {\n" + - " \"temp\": 0,\n" + - " \"color\": \"violet\",\n" + - " \"state\": \"er\",\n" + - " \"temp_min\": -20,\n" + - " \"temp_max\": 200,\n" + - " \"name\": \"Kanal6\",\n" + - " \"alert\": false,\n" + - " \"show\": true\n" + - " },\n" + - " \"7\": {\n" + - " \"temp\": 0,\n" + - " \"color\": \"purple\",\n" + - " \"state\": \"er\",\n" + - " \"temp_min\": -20,\n" + - " \"temp_max\": 200,\n" + - " \"name\": \"Kanal7\",\n" + - " \"alert\": false,\n" + - " \"show\": true\n" + - " },\n" + - " \"8\": {\n" + - " \"temp\": 0,\n" + - " \"color\": \"dark-violet\",\n" + - " \"state\": \"er\",\n" + - " \"temp_min\": -20,\n" + - " \"temp_max\": 200,\n" + - " \"name\": \"Kanal8 - Maverick 1\",\n" + - " \"alert\": false,\n" + - " \"show\": true\n" + - " },\n" + - " \"9\": {\n" + - " \"temp\": 0,\n" + - " \"color\": \"seagreen\",\n" + - " \"state\": \"er\",\n" + - " \"temp_min\": -20,\n" + - " \"temp_max\": 200,\n" + - " \"name\": \"Kanal9 - Maverick 2\",\n" + - " \"alert\": false,\n" + - " \"show\": true\n" + - " }\n" + - " },\n" + - " \"timestamp\": \"2020-05-29T16:06:00-05:00\"\n" + - "}"; - //@formatter:on - @Nullable private App app; @BeforeEach void setUp() { - app = new Gson().fromJson(APP_INPUT_JSON, App.class); + ClassLoader classLoader = Objects.requireNonNull(WlanThermoMiniCommandHandlerTest.class.getClassLoader()); + InputStream stream = Objects.requireNonNull(classLoader.getResourceAsStream("mini/app.json")); + app = new Gson().fromJson(new InputStreamReader(stream, StandardCharsets.UTF_8), App.class); } static Stream getState() { diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java index ca0f5591ef10d..1d32bde307c02 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java +++ b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/nano/WlanThermoNanoV1CommandHandlerTest.java @@ -15,6 +15,10 @@ import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.*; import java.awt.*; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.Objects; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -49,236 +53,6 @@ class WlanThermoNanoV1CommandHandlerTest { private static final ThingUID THING_UID = new ThingUID("wlanthermo", "nano", "test"); - //@formatter:off - private static final String DATA_INPUT_JSON = "{\n" + - " \"system\": {\n" + - " \"time\": \"1610899485\",\n" + - " \"unit\": \"C\",\n" + - " \"soc\": 32,\n" + - " \"charge\": false,\n" + - " \"rssi\": -47,\n" + - " \"online\": 0\n" + - " },\n" + - " \"channel\": [\n" + - " {\n" + - " \"number\": 1,\n" + - " \"name\": \"Kanal 1\",\n" + - " \"typ\": 0,\n" + - " \"temp\": 23.7,\n" + - " \"min\": 11,\n" + - " \"max\": 155,\n" + - " \"alarm\": 1,\n" + - " \"color\": \"#EF562D\"\n" + - " },\n" + - " {\n" + - " \"number\": 2,\n" + - " \"name\": \"Kanal 2\",\n" + - " \"typ\": 3,\n" + - " \"temp\": 999,\n" + - " \"min\": 0,\n" + - " \"max\": 48,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#22B14C\"\n" + - " },\n" + - " {\n" + - " \"number\": 3,\n" + - " \"name\": \"Kanal 3\",\n" + - " \"typ\": 3,\n" + - " \"temp\": 999,\n" + - " \"min\": 10,\n" + - " \"max\": 35,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#EF562D\"\n" + - " },\n" + - " {\n" + - " \"number\": 4,\n" + - " \"name\": \"Kanal 4\",\n" + - " \"typ\": 3,\n" + - " \"temp\": 999,\n" + - " \"min\": 10,\n" + - " \"max\": 54,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#FFC100\"\n" + - " },\n" + - " {\n" + - " \"number\": 5,\n" + - " \"name\": \"Kanal 5\",\n" + - " \"typ\": 3,\n" + - " \"temp\": 999,\n" + - " \"min\": 0,\n" + - " \"max\": 69,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#A349A4\"\n" + - " },\n" + - " {\n" + - " \"number\": 6,\n" + - " \"name\": \"Kanal 6\",\n" + - " \"typ\": 0,\n" + - " \"temp\": 999,\n" + - " \"min\": 150,\n" + - " \"max\": 170,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#804000\"\n" + - " },\n" + - " {\n" + - " \"number\": 7,\n" + - " \"name\": \"Kanal 7\",\n" + - " \"typ\": 0,\n" + - " \"temp\": 23.6,\n" + - " \"min\": 0,\n" + - " \"max\": 54,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#5587A2\"\n" + - " },\n" + - " {\n" + - " \"number\": 8,\n" + - " \"name\": \"Kanal 8\",\n" + - " \"typ\": 0,\n" + - " \"temp\": 999,\n" + - " \"min\": 10,\n" + - " \"max\": 35,\n" + - " \"alarm\": 0,\n" + - " \"color\": \"#5C7148\"\n" + - " }\n" + - " ],\n" + - " \"pitmaster\": {\n" + - " \"type\": [\n" + - " \"off\"\n" + - " ],\n" + - " \"pm\": [\n" + - " {\n" + - " \"id\": 0,\n" + - " \"channel\": 1,\n" + - " \"pid\": 0,\n" + - " \"value\": 0,\n" + - " \"set\": 50,\n" + - " \"typ\": \"off\",\n" + - " \"set_color\": \"#ff0000\",\n" + - " \"value_color\": \"#000000\"\n" + - " }\n" + - " ]\n" + - " }\n" + - "}"; - - private static final String SETTINGS_INPUT_JSON = "{\n" + - " \"device\": {\n" + - " \"device\": \"nano\",\n" + - " \"serial\": \"33e8bb\",\n" + - " \"item\": \"n2E04o42000\",\n" + - " \"hw_version\": \"v2\",\n" + - " \"sw_version\": \"v1.0.6\",\n" + - " \"api_version\": \"1\",\n" + - " \"language\": \"de\"\n" + - " },\n" + - " \"system\": {\n" + - " \"time\": \"1610899506\",\n" + - " \"unit\": \"C\",\n" + - " \"ap\": \"NANO-AP\",\n" + - " \"host\": \"NANO-33e8bb\",\n" + - " \"language\": \"de\",\n" + - " \"version\": \"v1.0.6\",\n" + - " \"getupdate\": \"false\",\n" + - " \"autoupd\": true,\n" + - " \"hwversion\": \"V1+\",\n" + - " \"god\": 0\n" + - " },\n" + - " \"hardware\": [\n" + - " \"V1\",\n" + - " \"V1+\"\n" + - " ],\n" + - " \"api\": {\n" + - " \"version\": \"1\"\n" + - " },\n" + - " \"sensors\": [\n" + - " \"1000K/Maverick\",\n" + - " \"Fantast-Neu\",\n" + - " \"Fantast\",\n" + - " \"100K/iGrill2\",\n" + - " \"ET-73\",\n" + - " \"Perfektion\",\n" + - " \"50K\",\n" + - " \"Inkbird\",\n" + - " \"100K6A1B\",\n" + - " \"Weber_6743\",\n" + - " \"Santos\",\n" + - " \"5K3A1B\"\n" + - " ],\n" + - " \"pid\": [\n" + - " {\n" + - " \"name\": \"SSR SousVide\",\n" + - " \"id\": 0,\n" + - " \"aktor\": 0,\n" + - " \"Kp\": 104,\n" + - " \"Ki\": 0.2,\n" + - " \"Kd\": 0,\n" + - " \"DCmmin\": 0,\n" + - " \"DCmmax\": 100,\n" + - " \"opl\": 0,\n" + - " \"tune\": 0,\n" + - " \"jp\": 100\n" + - " },\n" + - " {\n" + - " \"name\": \"TITAN 50x50\",\n" + - " \"id\": 1,\n" + - " \"aktor\": 1,\n" + - " \"Kp\": 3.8,\n" + - " \"Ki\": 0.01,\n" + - " \"Kd\": 128,\n" + - " \"DCmmin\": 25,\n" + - " \"DCmmax\": 100,\n" + - " \"opl\": 0,\n" + - " \"tune\": 0,\n" + - " \"jp\": 70\n" + - " },\n" + - " {\n" + - " \"name\": \"Kamado 50x50\",\n" + - " \"id\": 2,\n" + - " \"aktor\": 1,\n" + - " \"Kp\": 7,\n" + - " \"Ki\": 0.02,\n" + - " \"Kd\": 630,\n" + - " \"DCmmin\": 25,\n" + - " \"DCmmax\": 100,\n" + - " \"opl\": 0,\n" + - " \"tune\": 0,\n" + - " \"jp\": 70\n" + - " }\n" + - " ],\n" + - " \"aktor\": [\n" + - " \"SSR\",\n" + - " \"FAN\",\n" + - " \"SERVO\"\n" + - " ],\n" + - " \"iot\": {\n" + - " \"PMQhost\": \"192.168.2.1\",\n" + - " \"PMQport\": 1883,\n" + - " \"PMQuser\": \"\",\n" + - " \"PMQpass\": \"\",\n" + - " \"PMQqos\": 0,\n" + - " \"PMQon\": false,\n" + - " \"PMQint\": 30,\n" + - " \"CLon\": false,\n" + - " \"CLtoken\": \"thisisnotatoken\",\n" + - " \"CLint\": 30,\n" + - " \"CLurl\": \"cloud.wlanthermo.de/index.html\"\n" + - " },\n" + - " \"notes\": {\n" + - " \"fcm\": [],\n" + - " \"ext\": {\n" + - " \"on\": 0,\n" + - " \"token\": \"\",\n" + - " \"id\": \"\",\n" + - " \"repeat\": 1,\n" + - " \"service\": 0,\n" + - " \"services\": [\n" + - " \"telegram\",\n" + - " \"pushover\"\n" + - " ]\n" + - " }\n" + - " }\n" + - "}"; - //@formatter:on - @Nullable private Data data; @Nullable @@ -287,8 +61,11 @@ class WlanThermoNanoV1CommandHandlerTest { @BeforeEach void setUp() { Gson gson = new Gson(); - data = gson.fromJson(DATA_INPUT_JSON, Data.class); - settings = gson.fromJson(SETTINGS_INPUT_JSON, Settings.class); + ClassLoader classLoader = Objects.requireNonNull(WlanThermoNanoV1CommandHandlerTest.class.getClassLoader()); + InputStream dataStream = Objects.requireNonNull(classLoader.getResourceAsStream("nanov1/data.json")); + InputStream settingsStream = Objects.requireNonNull(classLoader.getResourceAsStream("nanov1/settings.json")); + data = gson.fromJson(new InputStreamReader(dataStream, StandardCharsets.UTF_8), Data.class); + settings = gson.fromJson(new InputStreamReader(settingsStream, StandardCharsets.UTF_8), Settings.class); } static Stream getState() { diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/resources/esp32/data.json b/bundles/org.openhab.binding.wlanthermo/src/test/resources/esp32/data.json new file mode 100644 index 0000000000000..24eddd0eb4608 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/test/resources/esp32/data.json @@ -0,0 +1,151 @@ +{ + "system": { + "time": "1610894101", + "unit": "C", + "soc": 89, + "charge": false, + "rssi": -32, + "online": 0 + }, + "channel": [ + { + "number": 1, + "name": "Kanal Eins", + "typ": 0, + "temp": 23.7, + "min": 17, + "max": 104, + "alarm": 1, + "color": "#270000", + "fixed": false, + "connected": false + }, + { + "number": 2, + "name": "Kanal 2", + "typ": 0, + "temp": 999, + "min": 50, + "max": 95, + "alarm": 0, + "color": "#22B14C", + "fixed": false, + "connected": false + }, + { + "number": 3, + "name": "Kanal 3", + "typ": 0, + "temp": 999, + "min": 50, + "max": 95, + "alarm": 0, + "color": "#EF562D", + "fixed": false, + "connected": false + }, + { + "number": 4, + "name": "Kanal 4", + "typ": 0, + "temp": 999, + "min": 50, + "max": 95, + "alarm": 0, + "color": "#FFC100", + "fixed": false, + "connected": false + }, + { + "number": 5, + "name": "Kanal 5", + "typ": 0, + "temp": 999, + "min": 50, + "max": 95, + "alarm": 0, + "color": "#A349A4", + "fixed": false, + "connected": false + }, + { + "number": 6, + "name": "Kanal 6", + "typ": 0, + "temp": 999, + "min": 50, + "max": 95, + "alarm": 0, + "color": "#804000", + "fixed": false, + "connected": false + }, + { + "number": 7, + "name": "Kanal 7", + "typ": 0, + "temp": 23.7, + "min": 10, + "max": 95, + "alarm": 0, + "color": "#5587A2", + "fixed": false, + "connected": false + }, + { + "number": 8, + "name": "Kanal 8", + "typ": 0, + "temp": 999, + "min": 50, + "max": 95, + "alarm": 0, + "color": "#5C7148", + "fixed": false, + "connected": false + }, + { + "number": 9, + "name": "Kanal 9", + "typ": 16, + "temp": 999, + "min": 50, + "max": 95, + "alarm": 0, + "color": "#A349A4", + "fixed": true, + "connected": false + }, + { + "number": 10, + "name": "Kanal 10", + "typ": 16, + "temp": 999, + "min": 50, + "max": 95, + "alarm": 0, + "color": "#5587A2", + "fixed": true, + "connected": false + } + ], + "pitmaster": { + "type": [ + "off", + "manual", + "auto" + ], + "pm": [ + { + "id": 0, + "channel": 1, + "pid": 1, + "value": 70, + "set": 50, + "typ": "manual", + "set_color": "#ff0000", + "value_color": "#000000" + } + ] + } +} \ No newline at end of file diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/resources/esp32/settings.json b/bundles/org.openhab.binding.wlanthermo/src/test/resources/esp32/settings.json new file mode 100644 index 0000000000000..49f6e503e99c0 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/test/resources/esp32/settings.json @@ -0,0 +1,229 @@ +{ + "device": { + "device": "nano", + "serial": "98f4ab7570c0", + "cpu": "esp32", + "flash_size": 16777216, + "item": "n3j04oA200B", + "hw_version": "v3", + "sw_version": "v1.1.0", + "api_version": "1", + "language": "de" + }, + "system": { + "time": "1610894186", + "unit": "C", + "ap": "WLANTHERMO-AP", + "host": "NANO-98f4ab7570c0", + "language": "de", + "version": "v1.1.0", + "getupdate": "false", + "autoupd": true, + "prerelease": true, + "hwversion": "V3" + }, + "hardware": [ + "V3" + ], + "api": { + "version": "1" + }, + "sensors": [ + { + "type": 0, + "name": "1000K/Maverick", + "fixed": false + }, + { + "type": 1, + "name": "Fantast-Neu", + "fixed": false + }, + { + "type": 2, + "name": "Fantast", + "fixed": false + }, + { + "type": 3, + "name": "100K/iGrill2", + "fixed": false + }, + { + "type": 4, + "name": "ET-73", + "fixed": false + }, + { + "type": 5, + "name": "Perfektion", + "fixed": false + }, + { + "type": 6, + "name": "50K", + "fixed": false + }, + { + "type": 7, + "name": "Inkbird", + "fixed": false + }, + { + "type": 8, + "name": "100K6A1B", + "fixed": false + }, + { + "type": 9, + "name": "Weber_6743", + "fixed": false + }, + { + "type": 10, + "name": "Santos", + "fixed": false + }, + { + "type": 11, + "name": "5K3A1B", + "fixed": false + }, + { + "type": 12, + "name": "PT100", + "fixed": false + }, + { + "type": 13, + "name": "PT1000", + "fixed": false + }, + { + "type": 14, + "name": "ThermoWorks", + "fixed": false + }, + { + "type": 15, + "name": "Typ K", + "fixed": true + }, + { + "type": 16, + "name": "Bluetooth", + "fixed": true + }, + { + "type": 17, + "name": "Maverick", + "fixed": true + } + ], + "features": { + "bluetooth": true, + "pitmaster": true + }, + "pid": [ + { + "name": "SSR SousVide", + "id": 0, + "aktor": 0, + "Kp": 104, + "Ki": 0.2, + "Kd": 0, + "DCmmin": 0, + "DCmmax": 100, + "opl": 0, + "SPmin": 0, + "SPmax": 0, + "link": 0, + "tune": 0, + "jp": 100 + }, + { + "name": "TITAN 50x50", + "id": 1, + "aktor": 1, + "Kp": 7, + "Ki": 0.01, + "Kd": 128, + "DCmmin": 25, + "DCmmax": 100, + "opl": 0, + "SPmin": 0, + "SPmax": 0, + "link": 0, + "tune": 0, + "jp": 70 + }, + { + "name": "Servo MG995", + "id": 2, + "aktor": 2, + "Kp": 104, + "Ki": 0.2, + "Kd": 0, + "DCmmin": 0, + "DCmmax": 100, + "opl": 0, + "SPmin": 25, + "SPmax": 75, + "link": 0, + "tune": 0, + "jp": 100 + }, + { + "name": "Custom", + "id": 3, + "aktor": 1, + "Kp": 7, + "Ki": 0.2, + "Kd": 0, + "DCmmin": 0, + "DCmmax": 100, + "opl": 0, + "SPmin": 0, + "SPmax": 100, + "link": 0, + "tune": 0, + "jp": 100 + } + ], + "aktor": [ + "SSR", + "FAN", + "SERVO" + ], + "display": { + "updname": "", + "orientation": 0 + }, + "iot": { + "PMQhost": "192.168.2.1", + "PMQport": 1883, + "PMQuser": "", + "PMQpass": "", + "PMQqos": 0, + "PMQon": false, + "PMQint": 30, + "CLon": false, + "CLtoken": "thisisnotatoken", + "CLint": 30, + "CLurl": "cloud.wlanthermo.de/index.html" + }, + "notes": { + "fcm": [], + "ext": { + "on": 0, + "token": "", + "id": "", + "repeat": 1, + "service": 0, + "services": [ + "telegram", + "pushover" + ] + } + } +} \ No newline at end of file diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/resources/mini/app.json b/bundles/org.openhab.binding.wlanthermo/src/test/resources/mini/app.json new file mode 100644 index 0000000000000..a88861a20d0c9 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/test/resources/mini/app.json @@ -0,0 +1,121 @@ +{ + "temp_unit": "fahrenheit", + "pit": { + "enabled": true, + "timestamp": "2020-05-29T17:00:54-05:00", + "setpoint": 110, + "current": 77.86, + "control_out": 100, + "ch": 0, + "type": "False", + "open_lid": "False" + }, + "pit2": { + "enabled": false + }, + "cpu_load": 94.267515923567, + "cpu_temp": 93.56, + "channel": { + "0": { + "temp": 78.28, + "color": "green", + "state": "ok", + "temp_min": -20, + "temp_max": 200, + "name": "Kanal0", + "alert": false, + "show": true + }, + "1": { + "temp": 0, + "color": "red", + "state": "er", + "temp_min": -20, + "temp_max": 200, + "name": "Kanal1", + "alert": false, + "show": true + }, + "2": { + "temp": 0, + "color": "blue", + "state": "er", + "temp_min": -20, + "temp_max": 200, + "name": "Kanal2", + "alert": false, + "show": true + }, + "3": { + "temp": 0, + "color": "olive", + "state": "er", + "temp_min": -20, + "temp_max": 200, + "name": "Kanal3", + "alert": false, + "show": true + }, + "4": { + "temp": 0, + "color": "magenta", + "state": "er", + "temp_min": -20, + "temp_max": 200, + "name": "Kanal4", + "alert": false, + "show": true + }, + "5": { + "temp": 0, + "color": "yellow", + "state": "er", + "temp_min": -20, + "temp_max": 200, + "name": "Kanal5", + "alert": false, + "show": true + }, + "6": { + "temp": 0, + "color": "violet", + "state": "er", + "temp_min": -20, + "temp_max": 200, + "name": "Kanal6", + "alert": false, + "show": true + }, + "7": { + "temp": 0, + "color": "purple", + "state": "er", + "temp_min": -20, + "temp_max": 200, + "name": "Kanal7", + "alert": false, + "show": true + }, + "8": { + "temp": 0, + "color": "dark-violet", + "state": "er", + "temp_min": -20, + "temp_max": 200, + "name": "Kanal8 - Maverick 1", + "alert": false, + "show": true + }, + "9": { + "temp": 0, + "color": "seagreen", + "state": "er", + "temp_min": -20, + "temp_max": 200, + "name": "Kanal9 - Maverick 2", + "alert": false, + "show": true + } + }, + "timestamp": "2020-05-29T16:06:00-05:00" +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/resources/nanov1/data.json b/bundles/org.openhab.binding.wlanthermo/src/test/resources/nanov1/data.json new file mode 100644 index 0000000000000..7ed291b0ca48f --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/test/resources/nanov1/data.json @@ -0,0 +1,109 @@ +{ + "system": { + "time": "1610899485", + "unit": "C", + "soc": 32, + "charge": false, + "rssi": -47, + "online": 0 + }, + "channel": [ + { + "number": 1, + "name": "Kanal 1", + "typ": 0, + "temp": 23.7, + "min": 11, + "max": 155, + "alarm": 1, + "color": "#EF562D" + }, + { + "number": 2, + "name": "Kanal 2", + "typ": 3, + "temp": 999, + "min": 0, + "max": 48, + "alarm": 0, + "color": "#22B14C" + }, + { + "number": 3, + "name": "Kanal 3", + "typ": 3, + "temp": 999, + "min": 10, + "max": 35, + "alarm": 0, + "color": "#EF562D" + }, + { + "number": 4, + "name": "Kanal 4", + "typ": 3, + "temp": 999, + "min": 10, + "max": 54, + "alarm": 0, + "color": "#FFC100" + }, + { + "number": 5, + "name": "Kanal 5", + "typ": 3, + "temp": 999, + "min": 0, + "max": 69, + "alarm": 0, + "color": "#A349A4" + }, + { + "number": 6, + "name": "Kanal 6", + "typ": 0, + "temp": 999, + "min": 150, + "max": 170, + "alarm": 0, + "color": "#804000" + }, + { + "number": 7, + "name": "Kanal 7", + "typ": 0, + "temp": 23.6, + "min": 0, + "max": 54, + "alarm": 0, + "color": "#5587A2" + }, + { + "number": 8, + "name": "Kanal 8", + "typ": 0, + "temp": 999, + "min": 10, + "max": 35, + "alarm": 0, + "color": "#5C7148" + } + ], + "pitmaster": { + "type": [ + "off" + ], + "pm": [ + { + "id": 0, + "channel": 1, + "pid": 0, + "value": 0, + "set": 50, + "typ": "off", + "set_color": "#ff0000", + "value_color": "#000000" + } + ] + } +} diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/resources/nanov1/settings.json b/bundles/org.openhab.binding.wlanthermo/src/test/resources/nanov1/settings.json new file mode 100644 index 0000000000000..0bad2390500b3 --- /dev/null +++ b/bundles/org.openhab.binding.wlanthermo/src/test/resources/nanov1/settings.json @@ -0,0 +1,117 @@ +{ + "device": { + "device": "nano", + "serial": "33e8bb", + "item": "n2E04o42000", + "hw_version": "v2", + "sw_version": "v1.0.6", + "api_version": "1", + "language": "de" + }, + "system": { + "time": "1610899506", + "unit": "C", + "ap": "NANO-AP", + "host": "NANO-33e8bb", + "language": "de", + "version": "v1.0.6", + "getupdate": "false", + "autoupd": true, + "hwversion": "V1+", + "god": 0 + }, + "hardware": [ + "V1", + "V1+" + ], + "api": { + "version": "1" + }, + "sensors": [ + "1000K/Maverick", + "Fantast-Neu", + "Fantast", + "100K/iGrill2", + "ET-73", + "Perfektion", + "50K", + "Inkbird", + "100K6A1B", + "Weber_6743", + "Santos", + "5K3A1B" + ], + "pid": [ + { + "name": "SSR SousVide", + "id": 0, + "aktor": 0, + "Kp": 104, + "Ki": 0.2, + "Kd": 0, + "DCmmin": 0, + "DCmmax": 100, + "opl": 0, + "tune": 0, + "jp": 100 + }, + { + "name": "TITAN 50x50", + "id": 1, + "aktor": 1, + "Kp": 3.8, + "Ki": 0.01, + "Kd": 128, + "DCmmin": 25, + "DCmmax": 100, + "opl": 0, + "tune": 0, + "jp": 70 + }, + { + "name": "Kamado 50x50", + "id": 2, + "aktor": 1, + "Kp": 7, + "Ki": 0.02, + "Kd": 630, + "DCmmin": 25, + "DCmmax": 100, + "opl": 0, + "tune": 0, + "jp": 70 + } + ], + "aktor": [ + "SSR", + "FAN", + "SERVO" + ], + "iot": { + "PMQhost": "192.168.2.1", + "PMQport": 1883, + "PMQuser": "", + "PMQpass": "", + "PMQqos": 0, + "PMQon": false, + "PMQint": 30, + "CLon": false, + "CLtoken": "thisisnotatoken", + "CLint": 30, + "CLurl": "cloud.wlanthermo.de/index.html" + }, + "notes": { + "fcm": [], + "ext": { + "on": 0, + "token": "", + "id": "", + "repeat": 1, + "service": 0, + "services": [ + "telegram", + "pushover" + ] + } + } +} \ No newline at end of file From 00c450f4e2f81ed1cf6d0b02a3dc41c6434b098f Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Mon, 18 Jan 2021 07:53:55 +0100 Subject: [PATCH 39/40] remove unused throws Signed-off-by: Christian Schlipp --- .../internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java index 56f718ecc5b99..af40d650b5d2d 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java +++ b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java @@ -63,7 +63,7 @@ class WlanThermoEsp32CommandHandlerTest { private Settings settings; @BeforeEach - void setUp() throws UnsupportedEncodingException { + void setUp() { Gson gson = new Gson(); ClassLoader classLoader = Objects.requireNonNull(WlanThermoEsp32CommandHandlerTest.class.getClassLoader()); InputStream dataStream = Objects.requireNonNull(classLoader.getResourceAsStream("esp32/data.json")); From 7b15ff901766669c455bc69a2c9e55bdf33da8db Mon Sep 17 00:00:00 2001 From: Christian Schlipp Date: Mon, 18 Jan 2021 22:26:14 +0100 Subject: [PATCH 40/40] remove unused import Signed-off-by: Christian Schlipp --- .../internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java index af40d650b5d2d..6184268f51c5e 100644 --- a/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java +++ b/bundles/org.openhab.binding.wlanthermo/src/test/java/org/openhab/binding/wlanthermo/internal/api/esp32/WlanThermoEsp32CommandHandlerTest.java @@ -18,7 +18,6 @@ import java.awt.*; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.Objects; import java.util.stream.Stream;