From b8cd38d6f30e9f31d734ead128a13eafa09c52b8 Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Mon, 31 Jan 2022 18:38:40 +0100 Subject: [PATCH] [hdpowerview] Add shade identify command (#12175) * Add shade identify command. Fixes #12174 Signed-off-by: Jacob Laursen --- .../org.openhab.binding.hdpowerview/README.md | 2 +- .../internal/HDPowerViewWebTargets.java | 17 +++++++++++ .../internal/api/requests/ShadeJog.java | 30 +++++++++++++++++++ .../internal/api/requests/ShadeMotion.java | 1 + .../handler/HDPowerViewShadeHandler.java | 11 ++++++- .../OH-INF/i18n/hdpowerview.properties | 1 + .../resources/OH-INF/thing/thing-types.xml | 1 + 7 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/requests/ShadeJog.java diff --git a/bundles/org.openhab.binding.hdpowerview/README.md b/bundles/org.openhab.binding.hdpowerview/README.md index d913d53416a82..b116dfbd04811 100644 --- a/bundles/org.openhab.binding.hdpowerview/README.md +++ b/bundles/org.openhab.binding.hdpowerview/README.md @@ -92,7 +92,7 @@ All of these channels appear in the binding, but only those which have a physica | position | Rollershutter | The vertical position of the shade's rail -- see [next chapter](#Roller-Shutter-Up/Down-Position-vs.-Open/Close-State). Up/Down commands will move the rail completely up or completely down. Percentage commands will move the rail to an intermediate position. Stop commands will halt any current movement of the rail. | | secondary | Rollershutter | The vertical position of the secondary rail (if any). Its function is similar to the `position` channel above -- but see [next chapter](#Roller-Shutter-Up/Down-Position-vs.-Open/Close-State). | | vane | Dimmer | The degree of opening of the slats or vanes. Setting this to a non-zero value will first move the shade `position` fully down, since the slats or vanes can only have a defined state if the shade is in its down position -- see [Interdependency between Channel positions](#Interdependency-between-Channel-positions). | -| command | String | Send a command to the shade. Valid values are: `CALIBRATE` | +| command | String | Send a command to the shade. Valid values are: `CALIBRATE`, `IDENTIFY` | | lowBattery | Switch | Indicates ON when the battery level of the shade is low, as determined by the hub's internal rules. | | batteryLevel | Number | Battery level (10% = low, 50% = medium, 100% = high) | batteryVoltage | Number:ElectricPotential | Battery voltage reported by the shade. | diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/HDPowerViewWebTargets.java b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/HDPowerViewWebTargets.java index dd1748fafbfbd..99c96eded31e1 100644 --- a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/HDPowerViewWebTargets.java +++ b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/HDPowerViewWebTargets.java @@ -29,6 +29,7 @@ import org.openhab.binding.hdpowerview.internal.api.ShadePosition; import org.openhab.binding.hdpowerview.internal.api.requests.RepeaterBlinking; import org.openhab.binding.hdpowerview.internal.api.requests.ShadeCalibrate; +import org.openhab.binding.hdpowerview.internal.api.requests.ShadeJog; import org.openhab.binding.hdpowerview.internal.api.requests.ShadeMove; import org.openhab.binding.hdpowerview.internal.api.requests.ShadeStop; import org.openhab.binding.hdpowerview.internal.api.responses.FirmwareVersion; @@ -247,6 +248,22 @@ public ShadeData stopShade(int shadeId) return shadeDataFromJson(jsonResponse); } + /** + * Instructs the hub to jog a specific shade + * + * @param shadeId id of the shade to be jogged + * @return ShadeData class instance + * @throws HubInvalidResponseException if response is invalid + * @throws HubProcessingException if there is any processing error + * @throws HubMaintenanceException if the hub is down for maintenance + */ + public ShadeData jogShade(int shadeId) + throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException { + String jsonRequest = gson.toJson(new ShadeJog()); + String jsonResponse = invoke(HttpMethod.PUT, shades + Integer.toString(shadeId), null, jsonRequest); + return shadeDataFromJson(jsonResponse); + } + /** * Instructs the hub to calibrate a specific shade * diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/requests/ShadeJog.java b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/requests/ShadeJog.java new file mode 100644 index 0000000000000..71fb0477a09ec --- /dev/null +++ b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/requests/ShadeJog.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2010-2022 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.hdpowerview.internal.api.requests; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * A request to jog a shade for identification + * + * @author Jacob Laursen - Initial contribution + */ +@NonNullByDefault +public class ShadeJog { + + public ShadeMotion shade; + + public ShadeJog() { + this.shade = new ShadeMotion(ShadeMotion.Type.JOG); + } +} diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/requests/ShadeMotion.java b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/requests/ShadeMotion.java index f4c9d784a5aa8..c6b16a000065e 100644 --- a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/requests/ShadeMotion.java +++ b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/requests/ShadeMotion.java @@ -24,6 +24,7 @@ class ShadeMotion { public enum Type { STOP("stop"), + JOG("jog"), CALIBRATE("calibrate"); private String motion; diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/handler/HDPowerViewShadeHandler.java b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/handler/HDPowerViewShadeHandler.java index 701cf480547d9..8118dfd39b1d8 100644 --- a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/handler/HDPowerViewShadeHandler.java +++ b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/handler/HDPowerViewShadeHandler.java @@ -72,6 +72,7 @@ private enum RefreshKind { } private static final String COMMAND_CALIBRATE = "CALIBRATE"; + private static final String COMMAND_IDENTIFY = "IDENTIFY"; private final Logger logger = LoggerFactory.getLogger(HDPowerViewShadeHandler.class); private final ShadeCapabilitiesDatabase db = new ShadeCapabilitiesDatabase(); @@ -226,7 +227,10 @@ private void handleShadeCommand(String channelId, Command command, HDPowerViewWe case CHANNEL_SHADE_COMMAND: if (command instanceof StringType) { - if (COMMAND_CALIBRATE.equals(((StringType) command).toString())) { + if (COMMAND_IDENTIFY.equals(((StringType) command).toString())) { + logger.debug("Identify shade {}", shadeId); + identifyShade(webTargets, shadeId); + } else if (COMMAND_CALIBRATE.equals(((StringType) command).toString())) { logger.debug("Calibrate shade {}", shadeId); calibrateShade(webTargets, shadeId); } @@ -447,6 +451,11 @@ private void stopShade(HDPowerViewWebTargets webTargets, int shadeId) requestRefreshShadePosition(); } + private void identifyShade(HDPowerViewWebTargets webTargets, int shadeId) + throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException { + updateShadePositions(webTargets.jogShade(shadeId)); + } + private void calibrateShade(HDPowerViewWebTargets webTargets, int shadeId) throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException { updateShadePositions(webTargets.calibrateShade(shadeId)); diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/i18n/hdpowerview.properties b/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/i18n/hdpowerview.properties index 9419bceac40be..ef907e9262961 100644 --- a/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/i18n/hdpowerview.properties +++ b/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/i18n/hdpowerview.properties @@ -40,6 +40,7 @@ channel-type.hdpowerview.repeater-identify.description = Flash repeater to ident channel-type.hdpowerview.repeater-identify.command.option.IDENTIFY = Identify channel-type.hdpowerview.shade-command.label = Command channel-type.hdpowerview.shade-command.description = Send a command to the shade +channel-type.hdpowerview.shade-command.command.option.IDENTIFY = Identify channel-type.hdpowerview.shade-command.command.option.CALIBRATE = Calibrate channel-type.hdpowerview.shade-position.label = Position channel-type.hdpowerview.shade-position.description = The vertical position of the shade diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/thing-types.xml index 7de48494cc1d4..a0c845f803a73 100644 --- a/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/thing-types.xml @@ -127,6 +127,7 @@ Send a command to the shade +