111 lines
3.3 KiB
Java
111 lines
3.3 KiB
Java
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.qiuguo.iot.user.api.IotBoxUserApiApplication;
|
|
import com.qiuguo.iot.user.api.service.TuyaDeviceConnector;
|
|
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
|
|
*
|
|
* @author weiyachao
|
|
* @since 2023/9/5 16:03
|
|
*/
|
|
@SpringBootTest(classes = IotBoxUserApiApplication.class)
|
|
@Slf4j
|
|
public class UserTest {
|
|
|
|
public String deviceId = "6c4a153095be2b7f8baofp";
|
|
|
|
public String spaceId = "163257138";
|
|
|
|
@Autowired
|
|
private TuyaDeviceConnector tuyaDeviceConnector;
|
|
|
|
@Test
|
|
public void 查询所有分类() {
|
|
JSONArray aa = tuyaDeviceConnector.categories();
|
|
aa.forEach(System.out::println);
|
|
}
|
|
|
|
@Test
|
|
public void 转移设备() {
|
|
JSONObject jsonObject = new JSONObject();
|
|
jsonObject.put("space_id", "163257138");
|
|
Boolean aBoolean = tuyaDeviceConnector.transferDevice(deviceId, jsonObject);
|
|
System.out.println(aBoolean);
|
|
}
|
|
|
|
@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("163257138");
|
|
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("163257138", 20);
|
|
System.out.println(devicesBySpaceIds);
|
|
}
|
|
|
|
@Test
|
|
public void 查询设备信息() {
|
|
JSONArray byid = tuyaDeviceConnector.getByid(deviceId);
|
|
System.out.println(byid);
|
|
}
|
|
|
|
}
|