feat: AC 三合一设备支持 + 新增 Plug/Gateway 驱动 + Cover 结构化重构

**AC 驱动增强**
- 支持 thermostat + air-conditioner + air-fresh 多服务三合一设备,属性跨服务合并解析
- 新增 specResolver.findValListInService/findInService/hasService/serviceShortName 方法
- 移除 KindThermostat,heater/electric-blanket/thermostat 重新归类为 KindAirConditioner

**Cover 窗帘重构**
- CoverProps 结构化:Position/Status/Fault 分离
- SetPosition 优先写 target-position,回退 current-position
- OnPropsChanged/FetchProps 支持多属性同步刷新

**新增设备类型**
- Plug 驱动:插座/插头,支持开合、在线状态、属性变更订阅
- Gateway 驱动:网关设备类型识别
- miot/miot_errors.go:新增 MIoT 云端错误码定义

**MIoT 客户端健壮性**
- SetProp 空结果视为失败;设备被移除或离线时自动刷新设备列表
- GetDevices 的 has_more 改用 parseBool 严格解析
- MIPS SubscribeMany 批量订阅减少往返
- matchURN 改为按段精确匹配,避免 tofan 误匹配 fan

**Bridge**
- 移除 Thermostat case,Cover 改用结构化 CoverProps
- 新增设备创建后自动订阅属性变更

**其他**
- 日志整体 Info → Debug 降噪
- .gitignore 忽略 /.codebuddy/memory
- 更新 devices_test 与 08_adv_filter_classify 示例
This commit is contained in:
2026-08-23 19:42:55 +08:00
parent 04333750ab
commit 86c21ce91c
25 changed files with 1129 additions and 155 deletions
+47 -2
View File
@@ -142,7 +142,8 @@ func (d *BaseDevice) getSpecResolver() *specResolver {
// specResolver is a thin wrapper to avoid importing specs package in every device file.
type specResolver struct {
byType map[string]*miot.MIoTSpecProperty
byType map[string]*miot.MIoTSpecProperty // property short name → first match
services []*miot.MIoTSpecService // 保留服务列表(支持按服务查找)
}
func newSpecResolver(spec *miot.MIoTSpecInstance) *specResolver {
@@ -150,7 +151,8 @@ func newSpecResolver(spec *miot.MIoTSpecInstance) *specResolver {
return nil
}
r := &specResolver{
byType: make(map[string]*miot.MIoTSpecProperty),
byType: make(map[string]*miot.MIoTSpecProperty),
services: spec.Services,
}
for _, svc := range spec.Services {
for i := range svc.Properties {
@@ -176,6 +178,17 @@ func propertyShortName(urn string) string {
return urn
}
// serviceShortName extracts the short name from a SPEC service URN.
// E.g., "urn:miot-spec-v2:service:thermostat:0000784A:..." → "thermostat".
// 注意:不能用 propertyShortName 解析服务 URN(其只认 parts[2]=="property")。
func serviceShortName(urn string) string {
parts := strings.Split(urn, ":")
if len(parts) >= 4 && parts[2] == "service" {
return parts[3]
}
return urn
}
func (r *specResolver) find(propType string) (siid, piid int, found bool) {
if r == nil {
return 0, 0, false
@@ -186,6 +199,38 @@ func (r *specResolver) find(propType string) (siid, piid int, found bool) {
return 0, 0, false
}
// findInService 在指定服务(短名,如 "thermostat")内查找属性。
// 用于多服务同名属性冲突时按服务精确定位(如三合一设备空调实体在 thermostat 服务)。
func (r *specResolver) findInService(svcName, propType string) (siid, piid int, found bool) {
if r == nil {
return 0, 0, false
}
for _, svc := range r.services {
if svc == nil || serviceShortName(svc.Type) != svcName {
continue
}
for _, prop := range svc.Properties {
if prop != nil && propertyShortName(prop.Type) == propType {
return svc.IID, prop.PIID, true
}
}
}
return 0, 0, false
}
// hasService 判断设备是否包含指定服务(短名)。
func (r *specResolver) hasService(svcName string) bool {
if r == nil {
return false
}
for _, svc := range r.services {
if svc != nil && serviceShortName(svc.Type) == svcName {
return true
}
}
return false
}
// prop returns the full SPEC property for the given type name.
func (r *specResolver) prop(propType string) *miot.MIoTSpecProperty {
if r == nil {