测试涂鸦
This commit is contained in:
parent
9921429c26
commit
3ee5ef1071
@ -17,6 +17,11 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.tuya</groupId>
|
||||
<artifactId>tuya-spring-boot-starter</artifactId>
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.qiuguo.iot.user.api.controller.device;
|
||||
|
||||
import cn.hutool.crypto.digest.MD5;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.qiuguo.iot.base.enums.DeviceTypeEnum;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceInfoEntity;
|
||||
@ -35,7 +36,7 @@ public class DeviceController {
|
||||
|
||||
@Resource
|
||||
private DeviceBatchService deviceBatchService;
|
||||
|
||||
|
||||
|
||||
private static Long timeOut = 120000l;//2分钟
|
||||
@GetMapping("/init")
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
package com.qiuguo.iot.user.api.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.tuya.connector.api.annotations.Body;
|
||||
import com.tuya.connector.api.annotations.DELETE;
|
||||
import com.tuya.connector.api.annotations.GET;
|
||||
import com.tuya.connector.api.annotations.POST;
|
||||
import com.tuya.connector.api.annotations.PUT;
|
||||
import com.tuya.connector.api.annotations.Path;
|
||||
import java.util.Map;
|
||||
import com.tuya.connector.api.annotations.Query;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* XXX
|
||||
@ -23,19 +25,19 @@ public interface TuyaDeviceConnector {
|
||||
|
||||
// 查询空间下设备列表
|
||||
@GET("/v2.0/cloud/thing/space/device")
|
||||
JSONObject getDevicesBySpaceIds(String spaces);
|
||||
JsonArray getDevicesBySpaceIds(@Query("space_ids") String spaces,@Query("page_size") Integer size);
|
||||
|
||||
// 控制设备动作
|
||||
@POST("/v2.0/cloud/thing/{device_id}/shadow/actions")
|
||||
JSONObject controlDevice(@Path("device_id") String deviceId, @Body JSONObject commands);
|
||||
@POST("/v1.0/iot-03/devices/{device_id}/commands")
|
||||
Object controlDevice(@Path("device_id") String deviceId, @Body JSONObject commands);
|
||||
|
||||
// 创建空间
|
||||
@POST("/v2.0/cloud/space/creation")
|
||||
JSONObject creatSpace(@Body JSONObject jsonObject);
|
||||
Long creatSpace(@Body JSONObject jsonObject);
|
||||
|
||||
// 删除空间
|
||||
@DELETE("/v2.0/cloud/space/{space_id}")
|
||||
JSONObject deleteSpace(@Path("space_id") String spaceId);
|
||||
Boolean deleteSpace(@Path("space_id") String spaceId);
|
||||
|
||||
// 查询空间
|
||||
@GET("/v2.0/cloud/space/{space_id}")
|
||||
@ -43,6 +45,10 @@ public interface TuyaDeviceConnector {
|
||||
|
||||
// 修改空间信息
|
||||
@PUT("/v2.0/cloud/space/{space_id}")
|
||||
JSONObject updateSpace(@Path("space_id") String spaceId, @Body JSONObject JSONObject);
|
||||
Boolean updateSpace(@Path("space_id") String spaceId, @Body JSONObject JSONObject);
|
||||
|
||||
// 获取设备支持的指令集
|
||||
@GET("/v1.0/iot-03/devices/{device_id}/functions")
|
||||
Object getFunctions(@Path("device_id") String deviceId);
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package com.qiuguo.iot.user.api.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* XXX
|
||||
*
|
||||
* @author weiyachao
|
||||
* @since 2023/9/19 15:13
|
||||
*/
|
||||
@Service
|
||||
public class TuyaDeviceService {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,4 +1,13 @@
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.qiuguo.iot.user.api.IotBoxUserApiApplication;
|
||||
import com.qiuguo.iot.user.api.service.TuyaDeviceConnector;
|
||||
import com.tuya.connector.api.annotations.Path;
|
||||
import java.util.Arrays;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
/**
|
||||
* XXX
|
||||
@ -6,11 +15,83 @@ import com.tuya.connector.api.annotations.Path;
|
||||
* @author weiyachao
|
||||
* @since 2023/9/5 16:03
|
||||
*/
|
||||
|
||||
@SpringBootTest(classes = IotBoxUserApiApplication.class)
|
||||
@Slf4j
|
||||
public class UserTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
public String deviceId = "6c4a153095be2b7f8baofp";
|
||||
|
||||
public String spaceId = "163257138";
|
||||
|
||||
@Autowired
|
||||
private TuyaDeviceConnector tuyaDeviceConnector;
|
||||
|
||||
@Test
|
||||
public void 获取设备支持的指令集() {
|
||||
Object functions = tuyaDeviceConnector.getFunctions(deviceId);
|
||||
System.out.println(functions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 修改空间() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name", "testname");
|
||||
Boolean jsonObject1 = tuyaDeviceConnector.updateSpace(spaceId, jsonObject);
|
||||
System.out.println(jsonObject1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 查询空间() {
|
||||
//40001900
|
||||
JSONObject spaceInfo = tuyaDeviceConnector.getSpaceInfo("163258893");
|
||||
System.out.println(spaceInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 删除空间() {
|
||||
//40001900
|
||||
Boolean jsonObject = tuyaDeviceConnector.deleteSpace("163258893");
|
||||
System.out.println(jsonObject);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 创建空间() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name", "space1_2");
|
||||
jsonObject.put("description", "space1_2的空间描述");
|
||||
Long jsonObject1 = tuyaDeviceConnector.creatSpace(jsonObject);
|
||||
System.out.println(jsonObject1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 控制设备动作() {
|
||||
JSONObject commands = new JSONObject();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("code", "switch_led");
|
||||
jsonObject.put("value", true);
|
||||
JSONObject js2 = new JSONObject();
|
||||
js2.put("code", "work_mode");
|
||||
js2.put("value", "colour");
|
||||
JSONObject js3 = new JSONObject();
|
||||
js3.put("code", "bright_value_v2");
|
||||
js3.put("value", 10);
|
||||
commands.put("commands", Arrays.asList( js3));
|
||||
|
||||
Object controlDevice = tuyaDeviceConnector.controlDevice(deviceId,commands);
|
||||
System.out.println(controlDevice);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 查询空间下设备列表() {
|
||||
JsonArray devicesBySpaceIds = tuyaDeviceConnector.getDevicesBySpaceIds(spaceId, 20);
|
||||
System.out.println(devicesBySpaceIds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void 查询设备信息() {
|
||||
JSONObject byid = tuyaDeviceConnector.getByid(deviceId);
|
||||
System.out.println(byid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user