Skip to content

Commit

Permalink
[veSync] Device support enhancements
Browse files Browse the repository at this point in the history
Device support enhancements
Signed-off-by: David Goodyear <[email protected]>
  • Loading branch information
dag81 committed Aug 1, 2023
1 parent 0fe1447 commit 475513f
Show file tree
Hide file tree
Showing 23 changed files with 1,306 additions and 206 deletions.
195 changes: 155 additions & 40 deletions bundles/org.openhab.binding.vesync/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class VeSyncConstants {

public static final Gson GSON = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).setPrettyPrinting()
.disableHtmlEscaping().serializeNulls().create();
.disableHtmlEscaping().create();

private static final String BINDING_ID = "vesync";

Expand Down Expand Up @@ -65,6 +65,8 @@ public class VeSyncConstants {
public static final String DEVICE_CHANNEL_AF_CONFIG_AUTO_ROOM_SIZE = "configAutoRoomSize";
public static final String DEVICE_CHANNEL_AF_SCHEDULES_COUNT = "schedulesCount";
public static final String DEVICE_CHANNEL_AF_NIGHT_LIGHT = "nightLightMode";
public static final String DEVICE_CHANNEL_AF_LIGHT_DETECTION = "lightDetection";
public static final String DEVICE_CHANNEL_AF_LIGHT_DETECTED = "lightDetected";

// Humidity related channels
public static final String DEVICE_CHANNEL_WATER_LACKS = "waterLacking";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,13 @@ public String reqV1Authorized(final String url, final VeSyncAuthenticatedRequest
private String directReqV1Authorized(final String url, final VeSyncAuthenticatedRequest requestData)
throws AuthenticationException {
try {
Request request = httpClient.POST(url);
Request request = httpClient.newRequest(url).method(requestData.httpMethod);

// No headers for login
request.content(new StringContentProvider(VeSyncConstants.GSON.toJson(requestData)));

logger.debug("POST @ {} with content\r\n{}", url, VeSyncConstants.GSON.toJson(requestData));
logger.debug("{} @ {} with content\r\n{}", requestData.httpMethod, url,
VeSyncConstants.GSON.toJson(requestData));

request.header(HttpHeader.CONTENT_TYPE, "application/json; utf-8");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ protected void stopBackgroundDiscovery() {

@Override
protected void startScan() {
if (bridgeHandler == null) {
return;
}
// If the bridge is not online no other thing devices can be found, so no reason to scan at this moment.
removeOlderResults(getTimestampOfLastScan());
if (ThingStatus.ONLINE.equals(bridgeHandler.getThing().getStatus())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public interface VeSyncProtocolConstants {
String MODE_AUTO = "auto";
String MODE_MANUAL = "manual";
String MODE_SLEEP = "sleep";
String MODE_PET = "pet";
String MODE_AUTO_HUMIDITY = "humidity";

String MODE_ON = "on";
String MODE_DIM = "dim";
Expand All @@ -42,19 +44,24 @@ public interface VeSyncProtocolConstants {
String DEVICE_GET_HUMIDIFIER_STATUS = "getHumidifierStatus";

String DEVICE_LEVEL_TYPE_MIST = "mist";
String DEVICE_LEVEL_TYPE_WARM_MIST = "warm";

// Air Purifier Commands
String DEVICE_SET_PURIFIER_MODE = "setPurifierMode";
String DEVICE_SET_CHILD_LOCK = "setChildLock";
String DEVICE_SET_NIGHT_LIGHT = "setNightLight";
String DEVICE_GET_PURIFIER_STATUS = "getPurifierStatus";
String DEVICE_LEVEL_TYPE_WIND = "wind";
String DEVICE_SET_LIGHT_DETECTION = "setLightDetection";

/**
* Base URL for AUTHENTICATION REQUESTS
*/
String PROTOCOL = "https";
String HOST_ENDPOINT = PROTOCOL + "://smartapi.vesync.com/cloud";
String SERVER_ADDRESS = "smartapi.vesync.com";
String SERVER_ENDPOINT = PROTOCOL + "://" + SERVER_ADDRESS;

String HOST_ENDPOINT = SERVER_ENDPOINT + "/cloud";
String V1_LOGIN_ENDPOINT = HOST_ENDPOINT + "/v1/user/login";
String V1_MANAGED_DEVICES_ENDPOINT = HOST_ENDPOINT + "/v1/deviceManaged/devices";
String V2_BYPASS_ENDPOINT = HOST_ENDPOINT + "/v2/deviceManaged/bypassV2";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.openhab.binding.vesync.internal.dto.requests;

import javax.ws.rs.HttpMethod;

import com.google.gson.annotations.SerializedName;

/**
Expand All @@ -21,6 +23,8 @@
*/
public class VeSyncRequest {

public transient String httpMethod;

@SerializedName("timeZone")
public String timeZone = "America/New_York";

Expand All @@ -44,5 +48,6 @@ public class VeSyncRequest {

public VeSyncRequest() {
traceId = String.valueOf(System.currentTimeMillis());
httpMethod = HttpMethod.POST;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,75 @@ public class VesyncManagedDeviceBase {
public static class EmptyPayload {
}

public static class SetLightDetectionPayload extends EmptyPayload {

public SetLightDetectionPayload(final boolean enabled) {
lightDetectionSwitch = enabled ? 1 : 0;
}

@SerializedName("lightDetectionSwitch")
public int lightDetectionSwitch = -1;
}

public static class SetPowerPayload extends EmptyPayload {

public SetPowerPayload(final boolean enabled, final int switchIdx) {
this.powerSwitch = enabled ? 1 : 0;
this.switchIdx = switchIdx;
}

@SerializedName("switchIdx")
public int switchIdx = -1;

@SerializedName("powerSwitch")
public int powerSwitch = -1;
}

public static class SetChildLockPayload extends EmptyPayload {

public SetChildLockPayload(final boolean enabled) {
this.childLockSwitch = enabled ? 1 : 0;
}

@SerializedName("childLockSwitch")
public int childLockSwitch = -1;
}

public static class SetScreenSwitchPayload extends EmptyPayload {

public SetScreenSwitchPayload(final boolean enabled) {
this.screenSwitch = enabled ? 1 : 0;
}

@SerializedName("screenSwitch")
public int screenSwitch = -1;
}

public static class SetManualSpeedLevelPayload extends EmptyPayload {

public SetManualSpeedLevelPayload(final int manualSpeedLevel) {
this.manualSpeedLevel = manualSpeedLevel;
}

@SerializedName("levelIdx")
public int levelIdx = 0;

@SerializedName("levelType")
public String levelType = "wind";

@SerializedName("manualSpeedLevel")
public int manualSpeedLevel = -1;
}

public static class SetWorkModePayload extends EmptyPayload {
public SetWorkModePayload(final String workMode) {
this.workMode = workMode;
}

@SerializedName("workMode")
public String workMode = "";
}

public static class SetSwitchPayload extends EmptyPayload {

public SetSwitchPayload(final boolean enabled, final int id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) 2010-2023 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.vesync.internal.dto.requests;

import javax.ws.rs.HttpMethod;

import com.google.gson.annotations.SerializedName;

/**
* The {@link VeSyncRequestV1Command} is the Java class as a DTO to define the base implementation of a V1 command for
* the Vesync
* API.
*
* @author David Goodyear - Initial contribution
*/
public class VeSyncRequestV1Command extends VeSyncAuthenticatedRequest {

@SerializedName("uuid")
public String uuid = null;

public VeSyncRequestV1Command(final String deviceUuid) {
// Exclude fields that shouldn't be there by setting to null
super.phoneOS = null;
super.phoneBrand = null;
super.method = null;
super.appVersion = null;
super.httpMethod = HttpMethod.PUT;
// Set the required payload parameters
uuid = deviceUuid;
}

public String getUuid() {
return uuid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import com.google.gson.annotations.SerializedName;

/**
* The {@link VeSyncRequestV1ManagedDeviceDetails} is the Java class as a DTO to hold login credentials for the Vesync
* The {@link VeSyncRequestV1ManagedDeviceDetails} is the Java class as a DTO to request the managed device details for
* the Vesync
* API.
*
* @author David Goodyear - Initial contribution
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2010-2023 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.vesync.internal.dto.requests;

import com.google.gson.annotations.SerializedName;

/**
* The {@link VeSyncRequestV1SetLevel} is the Java class as a DTO define a V1 Set Level command for the Vesync
* API.
*
* @author David Goodyear - Initial contribution
*/
public class VeSyncRequestV1SetLevel extends VeSyncRequestV1Command {

@SerializedName("level")
public Integer level = null;

public VeSyncRequestV1SetLevel(final String deviceUuid, final int level) {
super(deviceUuid);
this.level = level;
}

public Integer getLevel() {
return level;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2010-2023 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.vesync.internal.dto.requests;

import com.google.gson.annotations.SerializedName;

/**
* The {@link VeSyncRequestV1SetMode} is the Java class as a DTO define a V1 Set Mode command for the Vesync
* API.
*
* @author David Goodyear - Initial contribution
*/
public class VeSyncRequestV1SetMode extends VeSyncRequestV1Command {

@SerializedName("mode")
public String mode = null;

public VeSyncRequestV1SetMode(final String deviceUuid, final String mode) {
super(deviceUuid);
this.mode = mode;
}

public String getMode() {
return mode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2010-2023 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.vesync.internal.dto.requests;

import com.google.gson.annotations.SerializedName;

/**
* The {@link VeSyncRequestV1SetStatus} is the Java class as a DTO define a V1 Set Status command for the Vesync
* API.
*
* @author David Goodyear - Initial contribution
*/
public class VeSyncRequestV1SetStatus extends VeSyncRequestV1Command {

@SerializedName("status")
public String status = null;

public VeSyncRequestV1SetStatus(final String deviceUuid, final String status) {
super(deviceUuid);
this.status = status;
}

public String getStatus() {
return status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

/**
* The {@link VeSyncV2BypassPurifierStatus} is a Java class used as a DTO to hold the Vesync's API's common response
* data,
* in regards to an Air Purifier device.
* data, in regards to an Air Purifier device.
*
* @author David Goodyear - Initial contribution
*/
Expand Down
Loading

0 comments on commit 475513f

Please sign in to comment.