From 6fdfdb847597f91086d9fb5c1fa0593c63fd6d2b Mon Sep 17 00:00:00 2001
From: s-hadinger <49731213+s-hadinger@users.noreply.github.com>
Date: Sat, 3 Jun 2023 19:01:36 +0200
Subject: [PATCH] Matter Bridge mode always on (#18785)
---
CHANGELOG.md | 1 +
.../berry_matter/src/be_matter_module.c | 2 +
.../src/embedded/Matter_Device.be | 13 +-
.../src/embedded/Matter_Plugin.be | 7 +
.../src/embedded/Matter_Plugin_Aggregator.be | 71 +
.../src/embedded/Matter_Plugin_Bridge_HTTP.be | 6 +-
.../embedded/Matter_Plugin_Sensor_OnOff.be | 97 +
.../berry_matter/src/embedded/Matter_UI.be | 141 +-
.../src/solidify/solidified_Matter_Device.h | 1113 ++++----
.../src/solidify/solidified_Matter_Plugin.h | 32 +-
.../solidified_Matter_Plugin_Aggregator.h | 128 +
.../solidified_Matter_Plugin_Bridge_HTTP.h | 65 +-
.../solidified_Matter_Plugin_Sensor_OnOff.h | 295 ++
.../src/solidify/solidified_Matter_UI.h | 2432 +++++++++--------
14 files changed, 2555 insertions(+), 1848 deletions(-)
create mode 100644 lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Aggregator.be
create mode 100644 lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_OnOff.be
create mode 100644 lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Aggregator.h
create mode 100644 lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_OnOff.h
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4c5d75448..dc6daa042 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
### Changed
- Berry `webclient.url_encode()` is now a static class method, no change required to existing code (#18775)
+- Matter Bridge mode always on
### Fixed
- Interaction of ``SetOption92``, ``VirtualCT``, and ``RGBWWTable`` (#18768)
diff --git a/lib/libesp32/berry_matter/src/be_matter_module.c b/lib/libesp32/berry_matter/src/be_matter_module.c
index b335cd147..bef0a4253 100644
--- a/lib/libesp32/berry_matter/src/be_matter_module.c
+++ b/lib/libesp32/berry_matter/src/be_matter_module.c
@@ -189,6 +189,7 @@ extern const bclass be_class_Matter_TLV; // need to declare it upfront because
#include "../generate/be_matter_certs.h"
#include "solidify/solidified_Matter_Plugin_Root.h"
+#include "solidify/solidified_Matter_Plugin_Aggregator.h"
#include "solidify/solidified_Matter_Plugin_Device.h"
#include "solidify/solidified_Matter_Plugin_OnOff.h"
#include "solidify/solidified_Matter_Plugin_Light0.h"
@@ -388,6 +389,7 @@ module matter (scope: global, strings: weak) {
// Plugins
Plugin_Root, class(be_class_Matter_Plugin_Root) // Generic behavior common to all devices
+ Plugin_Aggregator, class(be_class_Matter_Plugin_Aggregator) // Aggregator
Plugin_Device, class(be_class_Matter_Plugin_Device) // Generic device (abstract)
Plugin_OnOff, class(be_class_Matter_Plugin_OnOff) // Relay/Light behavior (OnOff)
Plugin_Light0, class(be_class_Matter_Plugin_Light0) // OnOff Light
diff --git a/lib/libesp32/berry_matter/src/embedded/Matter_Device.be b/lib/libesp32/berry_matter/src/embedded/Matter_Device.be
index 4db220670..4f4c215ca 100644
--- a/lib/libesp32/berry_matter/src/embedded/Matter_Device.be
+++ b/lib/libesp32/berry_matter/src/embedded/Matter_Device.be
@@ -680,13 +680,23 @@ class Matter_Device
var endpoints = self.k2l_num(config)
tasmota.log("MTR: endpoints to be configured "+str(endpoints), 3)
+ # start with mandatory endpoint 0 for root node
+ self.plugins.push(matter.Plugin_Root(self, 0, {}))
+ tasmota.log(string.format("MTR: endpoint:%i type:%s%s", 0, 'root', ''), 2)
+
+ # always include an aggregator for dynamic endpoints
+ self.plugins.push(matter.Plugin_Aggregator(self, 0xFF00, {}))
+ tasmota.log(string.format("MTR: endpoint:%i type:%s%s", 0xFF00, 'aggregator', ''), 2)
+
for ep: endpoints
+ if ep == 0 continue end # skip endpoint 0
try
var plugin_conf = config[str(ep)]
tasmota.log(string.format("MTR: endpoint %i config %s", ep, plugin_conf), 3)
var pi_class_name = plugin_conf.find('type')
if pi_class_name == nil tasmota.log("MTR: no class name, skipping", 3) continue end
+ if pi_class_name == 'root' tasmota.log("MTR: only one root node allowed", 3) continue end
var pi_class = self.plugins_classes.find(pi_class_name)
if pi_class == nil tasmota.log("MTR: unknown class name '"+str(pi_class_name)+"' skipping", 2) continue end
@@ -1004,9 +1014,6 @@ class Matter_Device
import json
var m = {}
- # add the default plugin
- m["0"] = {'type':'root'}
-
# check if we have a light
var endpoint = 1
var light_present = false
diff --git a/lib/libesp32/berry_matter/src/embedded/Matter_Plugin.be b/lib/libesp32/berry_matter/src/embedded/Matter_Plugin.be
index 03e8d8734..dafeb7793 100644
--- a/lib/libesp32/berry_matter/src/embedded/Matter_Plugin.be
+++ b/lib/libesp32/berry_matter/src/embedded/Matter_Plugin.be
@@ -36,6 +36,7 @@ class Matter_Plugin
# Configuration of the plugin: clusters and type
static var CLUSTERS = {
0x001D: [0,1,2,3,0xFFFC,0xFFFD], # Descriptor Cluster 9.5 p.453
+ 0x0039: [0x11], # Bridged Device Basic Information 9.13 p.485
}
var device # reference to the `device` global object
var endpoint # current endpoint
@@ -180,6 +181,12 @@ class Matter_Plugin
return TLV.create_TLV(TLV.U4, 1) # "Initial Release"
end
+ # ====================================================================================================
+ elif cluster == 0x0039 # ========== Bridged Device Basic Information 9.13 p.485 ==========
+
+ if attribute == 0x0011 # ---------- Reachable / bool ----------
+ return TLV.create_TLV(TLV.BOOL, 1) # by default we are reachable
+ end
else
return nil
end
diff --git a/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Aggregator.be b/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Aggregator.be
new file mode 100644
index 000000000..90a9255ac
--- /dev/null
+++ b/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Aggregator.be
@@ -0,0 +1,71 @@
+#
+# Matter_Plugin_Aggregator.be - implements the Aggregator endpoint
+#
+# Copyright (C) 2023 Stephan Hadinger & Theo Arends
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see