电源配置 Cluster(PowerSourceConfiguration)

Cluster ID: 0x002E  |  所在 Endpoint: Endpoint 0(Root Node)

PowerSourceConfiguration 是一个极其简单的 Cluster —— 只有一个属性、没有命令。 它的唯一职责是告诉你:这台设备的电源信息分别在哪些 Endpoint 上,以及它们的优先级顺序。

和 PowerSource 的关系

这两个 Cluster 是搭档关系,分工明确:

  • PowerSourceConfiguration(本页)—— 在 Endpoint 0,回答「电源信息在哪」:哪些 Endpoint 承载了 PowerSource Cluster,优先级怎么排
  • PowerSource(0x002F)—— 在各功能 Endpoint 上,回答「电源状态是什么」:电量多少、在不在充电、电压多少

App 的典型流程:先读 PowerSourceConfiguration 拿到端点列表 → 再逐个去对应 Endpoint 读 PowerSource 拿实际数据。

属性总览

PowerSourceConfiguration 只有一个属性,是必须支持的。

ID 名称 类型 读写 说明
0x00 Sources list<endpoint-no> 只读 承载 PowerSource Cluster 的端点列表,按优先级排序

Sources(电源端点列表)

一个有序列表,每个元素是一个 Endpoint 编号,指向一个承载了 PowerSource Cluster 的端点。 列表的顺序即优先级:第一个元素是主电源,后续依次为备用电源。

为什么需要这个列表

一台设备可能有多个电源(市电 + 电池、USB + 太阳能),每个电源的详细信息各自在不同的 Endpoint 上。 Sources 列表就是这些 Endpoint 的「目录」,App 不需要遍历所有 Endpoint 去猜哪个有电源信息 —— 直接读这个列表就知道该去哪些 Endpoint 拿数据。

如果列表为空,说明设备没有报告任何电源信息。列表中的 Endpoint 编号与 Descriptor Cluster 中的 PartsList 一致。

命令(Commands)

PowerSourceConfiguration 没有任何命令。它是一个纯只读的配置型 Cluster,所有信息通过读取 Sources 属性获得。

示例数据

读取 Endpoint 0 上的 PowerSourceConfiguration Cluster:

{
  // --- 属性 ---
  "0x0": [1, 2]    // Sources = [Endpoint 1, Endpoint 2]
                    // 优先级:Endpoint 1 是主电源,Endpoint 2 是备用电源
}

场景一:单电源设备(电池门锁)

一台电池供电的智能门锁,只有一个电源。PowerSourceConfiguration 的 Sources 列表只包含一个 Endpoint, App 直接去那个 Endpoint 读取 PowerSource 就能拿到电池电量。

// 场景一:只有一个电源的简单设备(如电池门锁)
// Endpoint 0 — PowerSourceConfiguration
{
  "0x0": [1]       // Sources = [Endpoint 1]
                   // 只有一个电源,在 Endpoint 1 的 PowerSource Cluster 里查看详情
}

// Endpoint 1 — PowerSource(去这里读电池电量)
{
  "0x0": 1,        // Status = Active
  "0x1": 0,        // Order = 0(唯一电源)
  "0x2": "Battery",
  "0xC": 180       // BatPercentRemaining = 180 → 实际 90%
}
开发建议

对于只有一个电源的设备,Sources 列表长度为 1,App 逻辑可以简化 —— 直接读第一个 Endpoint 的 PowerSource 即可,不需要展示优先级或切换逻辑。

场景二:双电源设备(UPS 网关)

一台网关设备同时支持市电和内置电池供电。PowerSourceConfiguration 列出两个 Endpoint, 第一个是市电(主电源),第二个是电池(备用电源)。停电时设备自动切换到电池,App 可以据此展示当前供电状态。

// 场景二:双电源设备(如 UPS 供电的网关)
// Endpoint 0 — PowerSourceConfiguration
{
  "0x0": [1, 2]    // Sources = [Endpoint 1, Endpoint 2]
                   // Endpoint 1 优先级更高(主电源),Endpoint 2 是备用
}

// Endpoint 1 — PowerSource(主电源:市电)
{
  "0x0": 1,        // Status = Active(正在供电)
  "0x1": 0,        // Order = 0(最高优先级)
  "0x2": "Mains"   // Description = "Mains"(市电)
}

// Endpoint 2 — PowerSource(备用电源:内置电池)
{
  "0x0": 0,        // Status = Unspecified(待命中)
  "0x1": 1,        // Order = 1(次优先级)
  "0x2": "Battery",
  "0xC": 200       // BatPercentRemaining = 200 → 实际 100%
}
开发建议

双电源场景下,App 可以这样处理:

  1. 读取 Sources 列表,遍历每个 Endpoint 的 PowerSource
  2. 检查每个电源的 Status 属性,找到当前 Active 的那个
  3. 如果主电源(列表第一个)不是 Active,说明设备在用备用电源,可以提示用户
  4. 订阅各 PowerSource 的 Status 变化,实时感知电源切换