Skip to content

Commit afc7076

Browse files
committed
add handling for Power Topology cluster
1 parent d572842 commit afc7076

26 files changed

+1577
-274
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: light-energy-powerConsumption
2+
components:
3+
- id: main
4+
capabilities:
5+
- id: switch
6+
version: 1
7+
- id: energyMeter
8+
version: 1
9+
- id: powerConsumptionReport
10+
version: 1
11+
- id: firmwareUpdate
12+
version: 1
13+
- id: refresh
14+
version: 1
15+
categories:
16+
- name: Light
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: light-level-energy-powerConsumption
2+
components:
3+
- id: main
4+
capabilities:
5+
- id: switch
6+
version: 1
7+
- id: switchLevel
8+
version: 1
9+
config:
10+
values:
11+
- key: "level.value"
12+
range: [1, 100]
13+
- id: energyMeter
14+
version: 1
15+
- id: powerConsumptionReport
16+
version: 1
17+
- id: firmwareUpdate
18+
version: 1
19+
- id: refresh
20+
version: 1
21+
categories:
22+
- name: Light
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: light-level-power
2+
components:
3+
- id: main
4+
capabilities:
5+
- id: switch
6+
version: 1
7+
- id: switchLevel
8+
version: 1
9+
config:
10+
values:
11+
- key: "level.value"
12+
range: [1, 100]
13+
- id: powerMeter
14+
version: 1
15+
- id: firmwareUpdate
16+
version: 1
17+
- id: refresh
18+
version: 1
19+
categories:
20+
- name: Light
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: light-power
2+
components:
3+
- id: main
4+
capabilities:
5+
- id: switch
6+
version: 1
7+
- id: powerMeter
8+
version: 1
9+
- id: firmwareUpdate
10+
version: 1
11+
- id: refresh
12+
version: 1
13+
categories:
14+
- name: Light
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
-- Copyright © 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local cluster_base = require "st.matter.cluster_base"
5+
local DescriptorServerAttributes = require "embedded_clusters.Descriptor.server.attributes"
6+
7+
local Descriptor = {}
8+
9+
Descriptor.ID = 0x001D
10+
Descriptor.NAME = "Descriptor"
11+
Descriptor.server = {}
12+
Descriptor.client = {}
13+
Descriptor.server.attributes = DescriptorServerAttributes:set_parent_cluster(Descriptor)
14+
15+
function Descriptor:get_attribute_by_id(attr_id)
16+
local attr_id_map = {
17+
[0x0003] = "PartsList",
18+
}
19+
local attr_name = attr_id_map[attr_id]
20+
if attr_name ~= nil then
21+
return self.attributes[attr_name]
22+
end
23+
return nil
24+
end
25+
26+
function Descriptor:get_server_command_by_id(command_id)
27+
local server_id_map = {
28+
}
29+
if server_id_map[command_id] ~= nil then
30+
return self.server.commands[server_id_map[command_id]]
31+
end
32+
return nil
33+
end
34+
35+
Descriptor.attribute_direction_map = {
36+
["PartsList"] = "server",
37+
}
38+
39+
local attribute_helper_mt = {}
40+
attribute_helper_mt.__index = function(self, key)
41+
local direction = Descriptor.attribute_direction_map[key]
42+
if direction == nil then
43+
error(string.format("Referenced unknown attribute %s on cluster %s", key, Descriptor.NAME))
44+
end
45+
return Descriptor[direction].attributes[key]
46+
end
47+
Descriptor.attributes = {}
48+
setmetatable(Descriptor.attributes, attribute_helper_mt)
49+
50+
setmetatable(Descriptor, {__index = cluster_base})
51+
52+
return Descriptor
53+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
-- Copyright © 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local cluster_base = require "st.matter.cluster_base"
5+
local data_types = require "st.matter.data_types"
6+
local TLVParser = require "st.matter.TLV.TLVParser"
7+
8+
local PartsList = {
9+
ID = 0x0003,
10+
NAME = "PartsList",
11+
base_type = require "st.matter.data_types.Array",
12+
element_type = require "st.matter.data_types.Uint16",
13+
}
14+
15+
function PartsList:augment_type(data_type_obj)
16+
for i, v in ipairs(data_type_obj.elements) do
17+
data_type_obj.elements[i] = data_types.validate_or_build_type(v, PartsList.element_type)
18+
end
19+
end
20+
21+
function PartsList:new_value(...)
22+
local o = self.base_type(table.unpack({...}))
23+
24+
return o
25+
end
26+
27+
function PartsList:read(device, endpoint_id)
28+
return cluster_base.read(
29+
device,
30+
endpoint_id,
31+
self._cluster.ID,
32+
self.ID,
33+
nil
34+
)
35+
end
36+
37+
function PartsList:subscribe(device, endpoint_id)
38+
return cluster_base.subscribe(
39+
device,
40+
endpoint_id,
41+
self._cluster.ID,
42+
self.ID,
43+
nil
44+
)
45+
end
46+
47+
function PartsList:set_parent_cluster(cluster)
48+
self._cluster = cluster
49+
return self
50+
end
51+
52+
function PartsList:build_test_report_data(
53+
device,
54+
endpoint_id,
55+
value,
56+
status
57+
)
58+
local data = data_types.validate_or_build_type(value, self.base_type)
59+
60+
return cluster_base.build_test_report_data(
61+
device,
62+
endpoint_id,
63+
self._cluster.ID,
64+
self.ID,
65+
data,
66+
status
67+
)
68+
end
69+
70+
function PartsList:deserialize(tlv_buf)
71+
local data = TLVParser.decode_tlv(tlv_buf)
72+
73+
return data
74+
end
75+
76+
setmetatable(PartsList, {__call = PartsList.new_value, __index = PartsList.base_type})
77+
return PartsList
78+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Copyright © 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local attr_mt = {}
5+
attr_mt.__attr_cache = {}
6+
attr_mt.__index = function(self, key)
7+
if attr_mt.__attr_cache[key] == nil then
8+
local req_loc = string.format("embedded_clusters.Descriptor.server.attributes.%s", key)
9+
local raw_def = require(req_loc)
10+
local cluster = rawget(self, "_cluster")
11+
raw_def:set_parent_cluster(cluster)
12+
attr_mt.__attr_cache[key] = raw_def
13+
end
14+
return attr_mt.__attr_cache[key]
15+
end
16+
17+
local DescriptorServerAttributes = {}
18+
19+
function DescriptorServerAttributes:set_parent_cluster(cluster)
20+
self._cluster = cluster
21+
return self
22+
end
23+
24+
setmetatable(DescriptorServerAttributes, attr_mt)
25+
26+
return DescriptorServerAttributes
27+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
-- Copyright © 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local cluster_base = require "st.matter.cluster_base"
5+
local PowerTopologyServerAttributes = require "embedded_clusters.PowerTopology.server.attributes"
6+
local PowerTopologyTypes = require "embedded_clusters.PowerTopology.types"
7+
8+
local PowerTopology = {}
9+
10+
PowerTopology.ID = 0x009C
11+
PowerTopology.NAME = "PowerTopology"
12+
PowerTopology.server = {}
13+
PowerTopology.client = {}
14+
PowerTopology.server.attributes = PowerTopologyServerAttributes:set_parent_cluster(PowerTopology)
15+
PowerTopology.types = PowerTopologyTypes
16+
17+
function PowerTopology:get_attribute_by_id(attr_id)
18+
local attr_id_map = {
19+
[0x0000] = "AvailableEndpoints",
20+
}
21+
local attr_name = attr_id_map[attr_id]
22+
if attr_name ~= nil then
23+
return self.attributes[attr_name]
24+
end
25+
return nil
26+
end
27+
28+
PowerTopology.attribute_direction_map = {
29+
["AvailableEndpoints"] = "server",
30+
}
31+
32+
PowerTopology.FeatureMap = PowerTopology.types.Feature
33+
34+
function PowerTopology.are_features_supported(feature, feature_map)
35+
if (PowerTopology.FeatureMap.bits_are_valid(feature)) then
36+
return (feature & feature_map) == feature
37+
end
38+
return false
39+
end
40+
41+
local attribute_helper_mt = {}
42+
attribute_helper_mt.__index = function(self, key)
43+
local direction = PowerTopology.attribute_direction_map[key]
44+
if direction == nil then
45+
error(string.format("Referenced unknown attribute %s on cluster %s", key, PowerTopology.NAME))
46+
end
47+
return PowerTopology[direction].attributes[key]
48+
end
49+
PowerTopology.attributes = {}
50+
setmetatable(PowerTopology.attributes, attribute_helper_mt)
51+
52+
setmetatable(PowerTopology, {__index = cluster_base})
53+
54+
return PowerTopology
55+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
-- Copyright © 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local cluster_base = require "st.matter.cluster_base"
5+
local data_types = require "st.matter.data_types"
6+
local TLVParser = require "st.matter.TLV.TLVParser"
7+
8+
local AvailableEndpoints = {
9+
ID = 0x0000,
10+
NAME = "AvailableEndpoints",
11+
base_type = require "st.matter.data_types.Array",
12+
element_type = require "st.matter.data_types.Uint16",
13+
}
14+
15+
function AvailableEndpoints:new_value(...)
16+
local o = self.base_type(table.unpack({...}))
17+
18+
return o
19+
end
20+
21+
function AvailableEndpoints:read(device, endpoint_id)
22+
return cluster_base.read(
23+
device,
24+
endpoint_id,
25+
self._cluster.ID,
26+
self.ID,
27+
nil
28+
)
29+
end
30+
31+
function AvailableEndpoints:subscribe(device, endpoint_id)
32+
return cluster_base.subscribe(
33+
device,
34+
endpoint_id,
35+
self._cluster.ID,
36+
self.ID,
37+
nil
38+
)
39+
end
40+
41+
function AvailableEndpoints:set_parent_cluster(cluster)
42+
self._cluster = cluster
43+
return self
44+
end
45+
46+
function AvailableEndpoints:build_test_report_data(
47+
device,
48+
endpoint_id,
49+
value,
50+
status
51+
)
52+
local data = data_types.validate_or_build_type(value, self.base_type)
53+
54+
return cluster_base.build_test_report_data(
55+
device,
56+
endpoint_id,
57+
self._cluster.ID,
58+
self.ID,
59+
data,
60+
status
61+
)
62+
end
63+
64+
function AvailableEndpoints:deserialize(tlv_buf)
65+
local data = TLVParser.decode_tlv(tlv_buf)
66+
67+
return data
68+
end
69+
70+
setmetatable(AvailableEndpoints, {__call = AvailableEndpoints.new_value, __index = AvailableEndpoints.base_type})
71+
return AvailableEndpoints
72+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Copyright © 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local attr_mt = {}
5+
attr_mt.__index = function(self, key)
6+
local req_loc = string.format("embedded_clusters.PowerTopology.server.attributes.%s", key)
7+
local raw_def = require(req_loc)
8+
local cluster = rawget(self, "_cluster")
9+
raw_def:set_parent_cluster(cluster)
10+
return raw_def
11+
end
12+
13+
local PowerTopologyServerAttributes = {}
14+
15+
function PowerTopologyServerAttributes:set_parent_cluster(cluster)
16+
self._cluster = cluster
17+
return self
18+
end
19+
20+
setmetatable(PowerTopologyServerAttributes, attr_mt)
21+
22+
return PowerTopologyServerAttributes
23+

0 commit comments

Comments
 (0)