docs: 补充「与 Python 原版的有意差异」说明与设备剔除/风速映射文档

- README 新增有意差异一节:设备列表语义(剔除米家已删设备)与缓存持久化内容的两条有意偏离及其原因、剔除判定规则
- README 架构概览补齐 xiaomi/、bridge/ 两层目录说明
- xiaomi/README 更新 GetDevices/RefreshDevices 签名(ctx),补充设备列表语义、家庭范围刷新示例与数字档位风速映射说明
This commit is contained in:
2026-09-15 19:51:38 +08:00
parent a595330144
commit 7ae32bd012
2 changed files with 67 additions and 6 deletions
+26 -3
View File
@@ -64,11 +64,27 @@ dids, err := client.GetRoomDevices(homeID, roomID) // → []string
### 设备列表 (`devices.go`)
```go
devices, err := client.GetDevices(opts...) // → []*DeviceInfo
device, err := client.GetDevice(did) // → *DeviceInfo
err := client.RefreshDevices() // 强制刷新设备列表
devices, err := client.GetDevices(ctx, opts...) // → []*DeviceInfo
device, err := client.GetDevice(ctx, did) // → *DeviceInfo
err = client.RefreshDevices(ctx) // 强制刷新设备列表(全量)
```
**设备列表语义:`GetDevices()` 返回的即「米家当前设备」**
`GetDevices()` 读的是 SDK 的设备缓存,而 `RefreshDevices()` 会在刷新时**剔除米家在 App 里
已删除的设备**(底层 `miot.pruneRemovedDevicesLocked`),所以列表不会返回已删设备;
磁盘缓存 `miot_devices/*.dict` 也会同步清理,不会在重启后复活。
```go
// 全量刷新:所有家庭;云端返回空列表时不会清库(接口异常保护)
err = client.RefreshDevices(ctx)
// 只刷新指定家庭:剔除范围也限定在该家庭内,不影响其它家庭
err = client.RefreshDevices(ctx, "984001863127")
```
注意:离线设备仍在列表里(`DeviceInfo.Online == false`),只有**从米家删除**的设备才会消失。
**过滤器(组合使用):**
```go
@@ -221,6 +237,13 @@ ac.SetEco(true)
ac.OnPropsChanged(func(state ACState) { ... })
```
> **风速档位映射(数字档位设备)**:部分设备的 `fan-level` 枚举是 `Auto + Level1~Level5`,
> 没有 `low/medium/high` 字面值(如 `klwdz1.airc.001`、`tofan.airrtc.wk01`)。此时按数字档位的
> **相对位置**映射:`low`→最低档、`medium`→中间档、`high`→最高档(`0`/Auto 不参与)。
> 设备上报的数字档位会**反向解析**回 `low/medium/high`,保证「控制写什么、通知就回报什么」;
> 落在映射之外的档位仍返回 SPEC 描述原文。枚举本身就是 `low/medium/high` 的设备走精确匹配,
> 行为不受影响。
#### 风扇 (`Fan`)
```go