Skip to content

Commit e1f7ee2

Browse files
authored
Matter prepare for ICD cluster (#23158)
1 parent a97d306 commit e1f7ee2

10 files changed

+1333
-1271
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
- Berry load `.tapp` files in `/.extensions/` then in `/` (#23113)
99
- Support Vango Technologies V924x ultralow power, single-phase, power measurement (#23127)
1010
- Support for HLK-LD2402 24GHz smart wave motion sensor (#23133)
11+
- Matter prepare for ICD cluster
1112

1213
### Breaking Changed
1314
- Berry remove `Leds.create_matrix` from the standard library waiting for reimplementation (#23114)

lib/libesp32/berry_matter/src/embedded/Matter_0_Inspect.be

+10-1
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,18 @@ matter.inspect = inspect
8787
#
8888
# Build a consolidated map of all the `CLUSTERS` static vars
8989
# from the inheritance hierarchy
90+
#
91+
# `cl` can be a the class to get the superclass, or a `map`
9092
#@ solidify:matter.consolidate_clusters,weak
9193
def consolidate_clusters(cl, m)
92-
var cl_parent = (super(cl) != nil) ? super(cl).CLUSTERS : {}
94+
var cl_parent
95+
if cl == nil
96+
cl_parent = {}
97+
elif type(cl) == 'class'
98+
cl_parent = (super(cl) != nil) ? super(cl).CLUSTERS : {}
99+
elif type(cl) == 'instance'
100+
cl_parent = cl
101+
end
93102
var ret = {}
94103
# clone cl_parent
95104
for k: cl_parent.keys()

lib/libesp32/berry_matter/src/embedded/Matter_Plugin_0.be

+6-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Matter_Plugin
4848
# `FEATURE_MAPS` contains any non-zero value per cluster, if not present default to `0`
4949
static var FEATURE_MAPS = { # feature map per cluster
5050
0x0031: 0x04, # Put Eth for now which should work for any on-network
51+
# 0x0046: 0x04, # LITS: LongIdleTimeSupport
5152
0x0102: 1 + 4, # Lift + PA_LF
5253
0x0202: 2, # Fan: Auto
5354
}
@@ -77,6 +78,7 @@ class Matter_Plugin
7778
# 0x0040: 1, # Initial Release
7879
# 0x0041: 1, # Initial Release
7980
# 0x0042: 1, # Initial Release
81+
# 0x0046: 3, # ICD v3
8082
# 0x005B: 1, # Initial Release
8183
# 0x005C: 1, # Initial Release
8284
0x0101: 7, # Added support for European door locks (unbolt feature)
@@ -283,20 +285,20 @@ matter_device.events.dump()
283285
return self.endpoint
284286
end
285287
def get_cluster_list_sorted()
286-
return self.device.k2l(self.CLUSTERS)
288+
return self.device.k2l(self.get_clusters())
287289
end
288290
def contains_cluster(cluster)
289-
return self.CLUSTERS.contains(cluster)
291+
return self.get_clusters().contains(cluster)
290292
end
291293
# def get_attribute_list(cluster)
292294
# return self.clusters.find(cluster, [])
293295
# end
294296
# returns as a constant bytes of 16-bit ints, big endian
295297
def get_attribute_list_bytes(cluster)
296-
return self.CLUSTERS.find(cluster, nil)
298+
return self.get_clusters().find(cluster, nil)
297299
end
298300
def contains_attribute(cluster, attribute)
299-
var attr_list = self.CLUSTERS.find(cluster)
301+
var attr_list = self.get_clusters().find(cluster)
300302
# log(f"MTR: contains_attribute {cluster=} {attribute=} {attr_list=}")
301303
if attr_list != nil
302304
var idx = 0

lib/libesp32/berry_matter/src/embedded/Matter_Plugin_1_Root.be

+37
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,42 @@ class Matter_Plugin_Root : Matter_Plugin
4343
0x003E: [0,1,2,3,4,5], # Node Operational Credentials Cluster 11.17 p.704
4444
0x003F: [] # Group Key Management Cluster 11.2 p.572
4545
})
46+
# static var CLUSTERS_ICD = matter.consolidate_clusters(_class.CLUSTERS, {
47+
# 0x0046: [0,1,2] # ICD Management Cluster
48+
# })
4649
static var TYPES = { 0x0016: 1 } # Root node
4750

51+
# # ICD options
52+
# var icd_idle, icd_active, icd_threshold
53+
4854
#############################################################
4955
# Constructor
5056
def init(device, endpoint, config)
5157
super(self).init(device, endpoint, config)
58+
# # check if we have ICD parameters
59+
# self.icd_idle = config.find("icd_idle", nil)
60+
# if (self.icd_idle != nil)
61+
# self.icd_active = config.find("icd_active", 5000) # default 5s
62+
# self.icd_threshold = config.find("icd_threshold", 300) # default 300ms
63+
# end
64+
# publish mandatory events
5265
self.publish_event(0x0028, 0x00, matter.EVENT_CRITICAL, matter.TLV.Matter_TLV_item().set(matter.TLV.U4, tasmota.version())) # Event StartUp - Software Version
5366
self.publish_event(0x0033, 0x03, matter.EVENT_CRITICAL, matter.TLV.Matter_TLV_item().set(matter.TLV.U1, 1)) # Event BootReason - PowerOnReboot - TODO if we need to refine
5467
end
5568

69+
#############################################################
70+
# consolidate_clusters
71+
#
72+
# Build a consolidated map of all the `CLUSTERS` static vars
73+
# from the inheritance hierarchy
74+
# def get_clusters()
75+
# if (self.icd_idle == nil)
76+
# return self.CLUSTERS
77+
# else
78+
# return self.CLUSTERS_ICD
79+
# end
80+
# end
81+
5682
#############################################################
5783
# read an attribute
5884
#
@@ -323,6 +349,17 @@ class Matter_Plugin_Root : Matter_Plugin
323349
return pl
324350
end
325351

352+
# ====================================================================================================
353+
# elif cluster == 0x0046 # ========== ICD Management Cluster ==========
354+
355+
# if attribute == 0x0000 # ---------- IdleModeDuration / uint32 (seconds) ----------
356+
# return tlv_solo.set_or_nil(TLV.U4, self.icd_idle)
357+
# elif attribute == 0x0001 # ---------- ActiveModeDuration / uint32 (milliseconds) ----------
358+
# return tlv_solo.set_or_nil(TLV.U4, self.icd_active)
359+
# elif attribute == 0x0002 # ---------- ActiveModeThreshold / uint16 (milliseconds) ----------
360+
# return tlv_solo.set_or_nil(TLV.U2, self.icd_threshold)
361+
# end
362+
326363
end
327364
return super(self).read_attribute(session, ctx, tlv_solo)
328365
end

lib/libesp32/berry_matter/src/embedded/Matter_z_Autoconf.be

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Matter_Autoconf
4040
var plugins = self.device.plugins
4141

4242
# start with mandatory endpoint 0 for root node
43-
plugins.push(matter.Plugin_Root(self.device, 0, {}))
43+
plugins.push(matter.Plugin_Root(self.device, 0, config.find("0", {})))
4444
log("MTR: Configuring endpoints", 2)
4545
log(format("MTR: endpoint = %5i type:%s%s", 0, 'root', ''), 2)
4646

lib/libesp32/berry_matter/src/embedded/Matter_zz_Device.be

+1-5
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,7 @@ class Matter_Device
732732
var keys = []
733733
for k: self.plugins_config.keys() keys.push(int(k)) end
734734
for ep: keys
735-
if ep == 0
736-
log("MTR: invalid entry with ep '0'", 2)
737-
self.plugins_config.remove(str(ep))
738-
dirty = true
739-
elif ep == matter.AGGREGATOR_ENDPOINT
735+
if ep == matter.AGGREGATOR_ENDPOINT
740736
dirty = true
741737
log(f"MTR: endpoint {ep} collides wit aggregator, relocating to {self.next_ep}", 2)
742738
self.plugins_config[str(self.next_ep)] = self.plugins_config[str(ep)]

0 commit comments

Comments
 (0)