chore: 提交高层 xiaomi 封装库及示例
- 新增 xiaomi/examples/ 下 8 个示例程序(用户/家庭查询、设备列表、开关/灯光/空调控制、属性订阅、高级过滤分类、SPEC 解析) - miot_client_sub.go: 重构 SubProp/SubEvent,使用 buildPropTopic/buildEventTopic 支持通配符订阅(siid/piid=0 → +),并修复锁顺序问题(将 RequestRefreshProp 移到 Lock 外) - spec_parser.go: 新增 downloadSpecFile 方法,本地 SPEC 文件缺失时自动从 miot-spec.org 下载 - ARCH_PLAN.md: 架构设计从 Proposed 更新为 Accepted(v1.0→v1.1),补充设备分类/工厂/SPEC 映射等模块设计 - xiaomi/: 新增 miot 上层强类型封装模块,包含 Client 主入口、用户/家庭/设备 API、属性读写、动作调用、订阅通知,以及 devices/ 设备控制抽象(Switch/Light/AirConditioner/Fan/Cover/Humidifier/Vacuum/WaterHeater/Thermostat)和 specs/ SPEC 查询辅助 - 更多 xiaomi 示例(风扇/窗帘/传感器控制)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package xiaomi
|
||||
|
||||
import "context"
|
||||
|
||||
// Action 调用设备 Action
|
||||
func (c *Client) Action(ctx context.Context, did string, siid, aiid int, params []interface{}) (*ActionResult, error) {
|
||||
result, err := c.inner.Action(did, siid, aiid, params)
|
||||
if err != nil {
|
||||
return nil, wrapErr("Action", did, err)
|
||||
}
|
||||
|
||||
return &ActionResult{
|
||||
DID: did,
|
||||
SIID: siid,
|
||||
AIID: aiid,
|
||||
Out: parseActionResultOut(result),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// parseActionResultOut 解析 Action 返回的 out 列表
|
||||
func parseActionResultOut(result map[string]interface{}) []map[string]interface{} {
|
||||
if outRaw, ok := result["out"]; ok {
|
||||
if outList, ok := outRaw.([]interface{}); ok {
|
||||
out := make([]map[string]interface{}, 0, len(outList))
|
||||
for _, item := range outList {
|
||||
if m, ok := item.(map[string]interface{}); ok {
|
||||
out = append(out, m)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user