ScenesService.java
3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package cn.com.glsx.modules.service;
import cn.com.glsx.modules.model.param.Automation;
import cn.com.glsx.modules.model.param.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* @author fengzhi
* @date 2021/3/5 17:26
* @description 场景自动化
*/
@Service
@Slf4j
public class ScenesService {
/*
GET /v1.0/homes/{home_id}/scenes 查询家庭下的场景列表
GET /v1.0/scenes/default-pictures 查询默认场景图片列表
POST /v1.0/homes/{home_id}/scenes/{scene_id}/trigger 触发场景
POST /v1.0/homes/{home_id}/scenes 添加场景
DELETE /v1.0/homes/{home_id}/scenes/{scene_id} 删除场景
PUT /v1.0/homes/{home_id}/scenes/{scene_id} 修改场景
GET /v1.0/homes/{home_id}/scene/devices 查询家庭下支持场景的设备列表
POST /v1.0/devices/{device_id}/scenes/{scene_id} 场景绑定
DELETE /v1.0/devices/{device_id}/scenes/{scene_id} 场景解绑
GET /v1.0/devices/{device_id}/scenes 查询设备已绑定的场景列表
DELETE /v1.0/homes/{home_id}/automations
/{automation_id} 删除自动化
GET /v1.0/homes/{home_id}/automations 查询自动化列表
GET /v1.0/homes/{home_id}/automations
/{automation_id} 查询家庭下的某个自动化
POST /v1.0/homes/{home_id}/automations
/{automation_id}/conditions/trigger 触发家庭下某个自动化的外部条件
GET /v1.0/homes/{home_id}/automation
/devices 查询家庭下支持自动化的设备列表
GET /v1.0/homes/automation/weather/conditions 查询自动化支持的天气条件
GET /v1.0/homes/{home_id}/enable-linkage/codes 查询家庭下支持的动作列表
PUT /v1.0/homes/{home_id}/automations
/{automation_id}/actions/enable 启用自动化
PUT /v1.0/homes/{home_id}/automations
/{automation_id}/actions/disable 停用自动化*/
/********************************创建,修改自动化********************************/
@Value("${tuya.baseUrl}")
private String baseUrl;
@Autowired
private SendRequestService requestService;
/**
* POST /v1.0/homes/{home_id}/automations
* 添加自动化
* 说明:为家庭添加自动化功能。
*
* @param home_id 用户家庭 ID
* @param automation 自动化对象参数
*/
public void addAutomations(String home_id, Automation automation) {
ResponseBody responseBody = requestService.sendRequestPost(baseUrl + "/homes/"+home_id+"/automations", JSONObject.toJSONString(automation));
log.info("回调:" + responseBody);
}
/**
* PUT /v1.0/homes/{home_id}/automations/{automation_id}
* 修改自动化
* 说明:修改家庭的自动化配置。
*
* @param home_id 用户家庭 ID
* @param automation_id 自动化 ID
* @param automation 自动化对象参数
*/
public void editAutomations(String home_id,String automation_id,Automation automation) {
ResponseBody responseBody = requestService.sendRequestPut(baseUrl + "/homes/"+home_id+"/automations/"+automation_id, JSONObject.toJSONString(automation));
log.info("回调:" + responseBody);
}
}