Skip to content

Commit 7cb8c02

Browse files
authored
Matter support for Rain sensor (#21633)
1 parent 75c47b6 commit 7cb8c02

27 files changed

+2284
-2417
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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
- Support for Sonoff WTS01 temperature sensor using SerialBridge in ``SSerialMode 3``
99
- Berry `classof` extended to class methods (#21615)
1010
- Extend command ``SetOption147 1`` to disable publish of IRReceived MQTT messages (#21574)
11+
- Matter support for Rain sensor
1112

1213
### Breaking Changed
1314

lib/libesp32/berry_matter/src/be_matter_module.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,15 @@ extern const bclass be_class_Matter_TLV; // need to declare it upfront because
252252
#include "solidify/solidified_Matter_Plugin_9_Virt_Sensor_Illuminance.h"
253253
#include "solidify/solidified_Matter_Plugin_3_Sensor_Humidity.h"
254254
#include "solidify/solidified_Matter_Plugin_9_Virt_Sensor_Humidity.h"
255-
#include "solidify/solidified_Matter_Plugin_2_Sensor_Occupancy.h"
256-
#include "solidify/solidified_Matter_Plugin_2_Sensor_OnOff.h"
257-
#include "solidify/solidified_Matter_Plugin_2_Sensor_Contact.h"
258-
#include "solidify/solidified_Matter_Plugin_2_Sensor_Waterleak.h"
255+
#include "solidify/solidified_Matter_Plugin_2_Sensor_Boolean.h"
256+
#include "solidify/solidified_Matter_Plugin_3_Sensor_Occupancy.h"
257+
#include "solidify/solidified_Matter_Plugin_3_Sensor_OnOff.h"
258+
#include "solidify/solidified_Matter_Plugin_3_Sensor_Contact.h"
259+
#include "solidify/solidified_Matter_Plugin_3_Sensor_Rain.h"
260+
#include "solidify/solidified_Matter_Plugin_3_Sensor_Waterleak.h"
259261
#include "solidify/solidified_Matter_Plugin_9_Virt_Sensor_Contact.h"
260262
#include "solidify/solidified_Matter_Plugin_9_Virt_Sensor_Occupancy.h"
263+
#include "solidify/solidified_Matter_Plugin_9_Virt_Sensor_Rain.h"
261264
#include "solidify/solidified_Matter_Plugin_9_Virt_Sensor_Waterleak.h"
262265
#include "solidify/solidified_Matter_Plugin_8_Bridge_OnOff.h"
263266
#include "solidify/solidified_Matter_Plugin_8_Bridge_Light0.h"
@@ -272,6 +275,7 @@ extern const bclass be_class_Matter_TLV; // need to declare it upfront because
272275
#include "solidify/solidified_Matter_Plugin_8_Bridge_Sensor_Contact.h"
273276
#include "solidify/solidified_Matter_Plugin_8_Bridge_Sensor_Flow.h"
274277
#include "solidify/solidified_Matter_Plugin_8_Bridge_Sensor_Air_Quality.h"
278+
#include "solidify/solidified_Matter_Plugin_8_Bridge_Sensor_Rain.h"
275279
#include "solidify/solidified_Matter_Plugin_8_Bridge_Sensor_Waterleak.h"
276280
#include "solidify/solidified_Matter_Plugin_z_All.h"
277281
#include "solidify/solidified_Matter_zz_Device.h"

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Matter_Plugin
116116
def init(device, endpoint, config)
117117
self.device = device
118118
self.endpoint = endpoint
119-
self.clusters = self.consolidate_clusters()
119+
self.clusters = self.get_clusters()
120120
self.parse_configuration(config)
121121
self.node_label = config.find("name", "")
122122
end
@@ -179,11 +179,11 @@ class Matter_Plugin
179179
end
180180

181181
#############################################################
182-
# consolidate_clusters
182+
# get_clusters
183183
#
184184
# Build a consolidated map of all the `CLUSTERS` static vars
185185
# from the inheritance hierarchy
186-
def consolidate_clusters()
186+
def get_clusters()
187187
return self.CLUSTERS
188188
# def real_super(o) return super(o) end # enclose `super()` in a static function to disable special behavior for super in instances
189189
# var ret = {}
@@ -257,12 +257,6 @@ class Matter_Plugin
257257
return false
258258
end
259259

260-
#############################################################
261-
# Does it handle this endpoint and this cluster
262-
def has(cluster, endpoint)
263-
return self.clusters.contains(cluster) && self.endpoints.find(endpoint) != nil
264-
end
265-
266260
def set_name(n)
267261
if n != self.node_label
268262
self.attribute_updated(0x0039, 0x0005)
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#
2+
# Matter_Plugin_Sensor_Boolean.be - implements the behavior for an abstract boolean sensor - to be inherited
3+
#
4+
# Copyright (C) 2023 Stephan Hadinger & Theo Arends
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
20+
import matter
21+
22+
# Matter plug-in for core behavior
23+
24+
#@ solidify:Matter_Plugin_Sensor_Boolean,weak
25+
26+
class Matter_Plugin_Sensor_Boolean : Matter_Plugin_Device
27+
# static var TYPE = "" # name of the plug-in in json
28+
# static var DISPLAY_NAME = "" # display name of the plug-in
29+
static var ARG = "switch" # additional argument name (or empty if none)
30+
static var ARG_HINT = "Switch<x> number"
31+
static var ARG_TYPE = / x -> int(x) # function to convert argument to the right type
32+
static var UPDATE_TIME = 750 # update every 750ms
33+
34+
var tasmota_switch_index # Switch number in Tasmota (one based)
35+
var shadow_bool_value
36+
37+
#############################################################
38+
# Constructor
39+
def init(device, endpoint, config)
40+
super(self).init(device, endpoint, config)
41+
self.shadow_bool_value = false
42+
end
43+
44+
#############################################################
45+
# parse_configuration
46+
#
47+
# Parse configuration map
48+
def parse_configuration(config)
49+
self.tasmota_switch_index = int(config.find(self.ARG #-'switch'-#, 1))
50+
if self.tasmota_switch_index <= 0 self.tasmota_switch_index = 1 end
51+
end
52+
53+
#############################################################
54+
# Update shadow
55+
#
56+
def update_shadow()
57+
super(self).update_shadow()
58+
if !self.VIRTUAL
59+
var switch_str = "Switch" + str(self.tasmota_switch_index)
60+
61+
var j = tasmota.cmd("Status 10", true)
62+
if j != nil j = j.find("StatusSNS") end
63+
if j != nil && j.contains(switch_str)
64+
var state = (j.find(switch_str) == "ON")
65+
66+
if (self.shadow_bool_value != state)
67+
self.value_updated()
68+
end
69+
self.shadow_bool_value = state
70+
end
71+
end
72+
end
73+
74+
#############################################################
75+
# value_updated
76+
#
77+
# This is triggered when a new value is changed, for subscription
78+
# This method is meant to be overloaded and maximize shared code
79+
def value_updated()
80+
end
81+
82+
#############################################################
83+
# For Bridge devices
84+
#############################################################
85+
#############################################################
86+
# Stub for updating shadow values (local copies of what we published to the Matter gateway)
87+
#
88+
# This call is synnchronous and blocking.
89+
def parse_status(data, index)
90+
if index == 10 # Status 10
91+
var state = false
92+
93+
state = (data.find("Switch" + str(self.tasmota_switch_index)) == "ON")
94+
95+
if self.shadow_bool_value != nil && self.shadow_bool_value != bool(state)
96+
self.value_updated()
97+
end
98+
self.shadow_bool_value = state
99+
end
100+
end
101+
#############################################################
102+
#############################################################
103+
end
104+
matter.Plugin_Sensor_Boolean = Matter_Plugin_Sensor_Boolean

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

Lines changed: 0 additions & 157 deletions
This file was deleted.

0 commit comments

Comments
 (0)