[hdpowerview] Add shade identify command (#12175)

* Add shade identify command.

Fixes #12174 

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen
2022-01-31 18:38:40 +01:00
committed by GitHub
parent 58d6123696
commit fd6c8eeb80
7 changed files with 61 additions and 2 deletions

View File

@@ -29,6 +29,7 @@ import org.eclipse.jetty.http.HttpStatus;
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 class HDPowerViewWebTargets {
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
*

View File

@@ -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);
}
}

View File

@@ -24,6 +24,7 @@ class ShadeMotion {
public enum Type {
STOP("stop"),
JOG("jog"),
CALIBRATE("calibrate");
private String motion;

View File

@@ -72,6 +72,7 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
}
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 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
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 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
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));

View File

@@ -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

View File

@@ -127,6 +127,7 @@
<description>Send a command to the shade</description>
<command>
<options>
<option value="IDENTIFY">Identify</option>
<option value="CALIBRATE">Calibrate</option>
</options>
</command>