fix(miot): 米家已删除设备从缓存、控制器与订阅中彻底剔除

在米家 App 删除设备后设备列表仍能获取到:删除检测只 delete(deviceListCloud),
deviceListCache 仅置 online=false,而对外 DeviceList()/GetDevices() 读的正是
cache;缓存又会在停机时落盘到 .dict、启动时原样恢复,已删设备跨重启复活。

- pruneRemovedDevicesLocked:候选集改为「缓存 ∪ 云列表」,云端不存在且网关/
  局域网非在线的设备从四张表彻底删除(旧实现只遍历 deviceListCloud,启动时它
  为空,停机期间被删的设备永远检测不到)
- 护栏:云端返回空列表时跳过剔除,避免接口异常清库
- homeScope:只刷新部分家庭时不再误删其它家庭的云列表
- 子设备(xxx.s1)不参与判定,它被归并到父设备的 sub_devices
- 命中剔除的设备同时清理 c.devices 实例与 MQTT 订阅路由
- bridge: pruneControllers 剔除已删设备的控制器,AC()/Switch() 不再返回实例
- 新增 7 个 miot 用例(含 httptest 打桩的端到端)+ 3 个 bridge 用例
This commit is contained in:
2026-09-12 19:29:46 +08:00
parent c18c0adaae
commit a595330144
5 changed files with 437 additions and 15 deletions
+13
View File
@@ -180,6 +180,19 @@ func (b *Bridge) Devices() map[string]string {
return out
}
// pruneControllers 从本地控制器集合中剔除「米家已不存在」的设备,返回被剔除的 DID。
// 没有这一步,AC()/Switch()/Fan() 等访问器会继续为已删设备返回控制器,控制必然失败。
func pruneControllers(dv map[string]interface{}, alive map[string]struct{}) []string {
var removed []string
for did := range dv {
if _, ok := alive[did]; !ok {
delete(dv, did)
removed = append(removed, did)
}
}
return removed
}
func deviceTypeName(d interface{}) string {
switch d.(type) {
case devices.AirConditioner: return devices.TypeAirConditioner