feat: State→Props 命名统一 + 新增 Plug/Gateway 设备 + 分类系统重构
**命名统一(State → Props)** - 所有设备类型:XxxState → XxxProps,GetState() → GetProps(),FetchState() → FetchProps() - 回调接口:OnStateChanged → OnPropsChanged - Bridge 层类型别名、示例代码、文档同步更名 **新增设备类型** - KindPlug + Plug 驱动:智能插座/插头(TurnOn/TurnOff/IsOn/OnPropsChanged) - KindGateway + Gateway 驱动:网关设备类型识别 - KindOccupancySensor 从 KindSensor 独立,添加 OccupancyProps **设备分类系统改进** - classifyByModel 改为按 key 长度降序匹配(防止 sensor 先于 sensor-occupy) - 新增下划线变体识别(sensor_occupy、sensor_temp 等) - outlet 重新归类为 Plug(非 Switch) - 新增 Or() 组合过滤器 **连接桥增强** - 设备创建成功后自动订阅属性变更 - 新增 nil 防护检查 - 支持 Plug/Speaker/Gateway/Occupancy 类型的 FetchProps 刷新 - 日志级别 Info → Debug **AC 驱动增强** - 新增 HasPower()、GetElectricPower()、GetPowerConsumption() 功率接口 - ACProps 新增 ElectricPower、PowerConsumption 字段 - valMapper:Desc 为空时 fallback 用 Name,key 统一小写 **MIoT 核心** - 设备列表刷新改用 reflect.DeepEqual 全字段变更检测 - 移除 BLE/代理设备默认在线 hack - RefreshDeviceAllProps 增加离线检查 - 新增 miot_errors.go:MIoT 错误码定义 - 全局日志级别 Info→Debug/Warn(降低噪音) **示例与文档** - 所有示例代码同步 API 变更 - 传感器示例改用 Or 组合过滤器 - ARCH_PLAN 等迁移文档同步更新
This commit is contained in:
+10
-10
@@ -25,7 +25,7 @@ func (c *MIoTClient) SubProp(did string, handler func(map[string]interface{}, in
|
||||
subID := fmt.Sprintf("%p", handler)
|
||||
c.subTree.Sub(topic, handler, nil)
|
||||
|
||||
c.lgr.Infof("[MIoTClient] Subscribed to property: %s (topic=%s, subID=%s)\n", did, topic, subID)
|
||||
c.lgr.Debugf("[MIoTClient] Subscribed to property: %s (topic=%s, subID=%s)\n", did, topic, subID)
|
||||
|
||||
c.mu.Unlock()
|
||||
|
||||
@@ -52,7 +52,7 @@ func (c *MIoTClient) UnsubProp(did string, subID string) {
|
||||
// TODO: Implement proper tracking of per-device subscription count
|
||||
// For now, just log
|
||||
|
||||
c.lgr.Infof("[MIoTClient] Unsubscribed from property: %s (subID=%s)\n", did, subID)
|
||||
c.lgr.Debugf("[MIoTClient] Unsubscribed from property: %s (subID=%s)\n", did, subID)
|
||||
}
|
||||
|
||||
// SubEvent subscribes to device events.
|
||||
@@ -69,7 +69,7 @@ func (c *MIoTClient) SubEvent(did string, handler func(map[string]interface{}, i
|
||||
subID := fmt.Sprintf("%p", handler)
|
||||
c.subTree.Sub(topic, handler, nil)
|
||||
|
||||
c.lgr.Infof("[MIoTClient] Subscribed to event: %s (topic=%s, subID=%s)\n", did, topic, subID)
|
||||
c.lgr.Debugf("[MIoTClient] Subscribed to event: %s (topic=%s, subID=%s)\n", did, topic, subID)
|
||||
|
||||
return subID
|
||||
}
|
||||
@@ -83,7 +83,7 @@ func (c *MIoTClient) UnsubEvent(did string, subID string) {
|
||||
// Remove from subTree by subID
|
||||
c.subTree.Unsub(subID)
|
||||
|
||||
c.lgr.Infof("[MIoTClient] Unsubscribed from event: %s (subID=%s)\n", did, subID)
|
||||
c.lgr.Debugf("[MIoTClient] Unsubscribed from event: %s (subID=%s)\n", did, subID)
|
||||
}
|
||||
|
||||
// updateDeviceMsgSub updates device message subscription.
|
||||
@@ -260,7 +260,7 @@ func (c *MIoTClient) handleMIPSMessage(did string, payload []byte) {
|
||||
// Fallback: binary MIPS protocol (used by gateway mipsLocal)
|
||||
msg := UnpackMipsMessage(payload)
|
||||
if msg == nil || msg.Payload == "" {
|
||||
c.lgr.Infof("[MIoTClient] handleMIPSMessage: empty or invalid payload for %s (%d bytes)\n", did, len(payload))
|
||||
c.lgr.Debugf("[MIoTClient] handleMIPSMessage: empty or invalid payload for %s (%d bytes)\n", did, len(payload))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ func (c *MIoTClient) dispatchMIPSMessage(did string, params map[string]interface
|
||||
} else if _, ok := params["eiid"]; ok {
|
||||
c.OnEventMsg(params, nil)
|
||||
} else {
|
||||
c.lgr.Infof("[MIoTClient] handleMIPSMessage: unknown message format for %s: %v\n", did, params)
|
||||
c.lgr.Debugf("[MIoTClient] handleMIPSMessage: unknown message format for %s: %v\n", did, params)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ func (c *MIoTClient) handleMIPSStateMessage(did string, payload []byte) {
|
||||
// Fallback: binary MIPS protocol
|
||||
msg := UnpackMipsMessage(payload)
|
||||
if msg == nil || msg.Payload == "" {
|
||||
c.lgr.Infof("[MIoTClient] handleMIPSStateMessage: empty payload for %s (%d bytes)\n", did, len(payload))
|
||||
c.lgr.Debugf("[MIoTClient] handleMIPSStateMessage: empty payload for %s (%d bytes)\n", did, len(payload))
|
||||
return
|
||||
}
|
||||
if err := json.Unmarshal([]byte(msg.Payload), ¶ms); err != nil {
|
||||
@@ -326,7 +326,7 @@ func (c *MIoTClient) handleMIPSStateMessage(did string, payload []byte) {
|
||||
}
|
||||
|
||||
if len(state) == 0 {
|
||||
c.lgr.Infof("[MIoTClient] handleMIPSStateMessage: no state info in payload for %s: %v\n", did, params)
|
||||
c.lgr.Debugf("[MIoTClient] handleMIPSStateMessage: no state info in payload for %s: %v\n", did, params)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -372,7 +372,7 @@ func (c *MIoTClient) OnPropMsg(params map[string]interface{}, ctx interface{}) {
|
||||
}
|
||||
|
||||
if did == "" {
|
||||
c.lgr.Infof("[MIoTClient] OnPropMsg: missing did in params=%v\n", params)
|
||||
c.lgr.Debugf("[MIoTClient] OnPropMsg: missing did in params=%v\n", params)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ func (c *MIoTClient) OnEventMsg(params map[string]interface{}, ctx interface{})
|
||||
}
|
||||
|
||||
if did == "" {
|
||||
c.lgr.Infof("[MIoTClient] OnEventMsg: missing did in params=%v\n", params)
|
||||
c.lgr.Debugf("[MIoTClient] OnEventMsg: missing did in params=%v\n", params)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user