Skip to content

Commit c818081

Browse files
committed
add handling for Power Topology cluster
1 parent fb3f845 commit c818081

25 files changed

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

0 commit comments

Comments
 (0)