Skip to content

控制因子

一些因子,比如开关,支持开启关闭等操作,可通过api控制因子。

开启

http
POST /api/v2/devices/{device_id}/factors/{factor_id}/on/

响应

json
{
    "success": true,
    "data": {
        "message": "操作成功",
        "token": "command_token"
    },
    "error": null
}

示例

Python

python
import requests

# 配置
API_BASE = "https://ums.holdingbyte.com/api/v2"
ACCESS_TOKEN = "your_access_token"

def control_factor(device_id, factor_id, action):
    """控制因子开关
    
    Args:
        device_id: 设备主键ID(整数)
        factor_id: 因子主键ID(整数)
        action: 动作,'on' 或 'off'
    """
    headers = {
        "Authorization": f"Bearer {ACCESS_TOKEN}",
        "Content-Type": "application/json"
    }
    
    url = f"{API_BASE}/devices/{device_id}/factors/{factor_id}/{action}/"
    
    response = requests.post(url, headers=headers)
    return response.json()

# 使用示例
device_id = 1  # 设备主键ID
factor_id = 1  # 因子主键ID

# 开启因子
result = control_factor(device_id, factor_id, "on")
print(f"开启结果: {result}")

# 关闭因子
result = control_factor(device_id, factor_id, "off")
print(f"关闭结果: {result}")

cURL

bash
# 开启因子
curl -X POST "https://ums.holdingbyte.com/api/v2/devices/1/factors/1/on/" \
     -H "Authorization: Bearer your_access_token" \
     -H "Content-Type: application/json"

# 关闭因子
curl -X POST "https://ums.holdingbyte.com/api/v2/devices/1/factors/1/off/" \
     -H "Authorization: Bearer your_access_token" \
     -H "Content-Type: application/json"

关闭

http
POST /api/v2/devices/{device_id}/factors/{factor_id}/off/

响应

json
{
    "success": true,
    "data": {
        "message": "操作成功",
        "token": "command_token"
    },
    "error": null
}

复制因子

http
POST /api/v2/devices/{device_id}/factors/{factor_id}/copy/

参数

响应

json
{
    "success": true,
    "data": {
        // 返回复制后的新因子信息,新因子的名称会在原因子名称后添加"_copy"后缀,
        // data_index会自动递增
    },
    "error": null
}