Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matter support for Rain sensor #21633

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- Support for Sonoff WTS01 temperature sensor using SerialBridge in ``SSerialMode 3``
- Berry `classof` extended to class methods (#21615)
- Extend command ``SetOption147 1`` to disable publish of IRReceived MQTT messages (#21574)
- Matter support for Rain sensor

### Breaking Changed

Expand Down
12 changes: 8 additions & 4 deletions lib/libesp32/berry_matter/src/be_matter_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,15 @@ extern const bclass be_class_Matter_TLV; // need to declare it upfront because
#include "solidify/solidified_Matter_Plugin_9_Virt_Sensor_Illuminance.h"
#include "solidify/solidified_Matter_Plugin_3_Sensor_Humidity.h"
#include "solidify/solidified_Matter_Plugin_9_Virt_Sensor_Humidity.h"
#include "solidify/solidified_Matter_Plugin_2_Sensor_Occupancy.h"
#include "solidify/solidified_Matter_Plugin_2_Sensor_OnOff.h"
#include "solidify/solidified_Matter_Plugin_2_Sensor_Contact.h"
#include "solidify/solidified_Matter_Plugin_2_Sensor_Waterleak.h"
#include "solidify/solidified_Matter_Plugin_2_Sensor_Boolean.h"
#include "solidify/solidified_Matter_Plugin_3_Sensor_Occupancy.h"
#include "solidify/solidified_Matter_Plugin_3_Sensor_OnOff.h"
#include "solidify/solidified_Matter_Plugin_3_Sensor_Contact.h"
#include "solidify/solidified_Matter_Plugin_3_Sensor_Rain.h"
#include "solidify/solidified_Matter_Plugin_3_Sensor_Waterleak.h"
#include "solidify/solidified_Matter_Plugin_9_Virt_Sensor_Contact.h"
#include "solidify/solidified_Matter_Plugin_9_Virt_Sensor_Occupancy.h"
#include "solidify/solidified_Matter_Plugin_9_Virt_Sensor_Rain.h"
#include "solidify/solidified_Matter_Plugin_9_Virt_Sensor_Waterleak.h"
#include "solidify/solidified_Matter_Plugin_8_Bridge_OnOff.h"
#include "solidify/solidified_Matter_Plugin_8_Bridge_Light0.h"
Expand All @@ -272,6 +275,7 @@ extern const bclass be_class_Matter_TLV; // need to declare it upfront because
#include "solidify/solidified_Matter_Plugin_8_Bridge_Sensor_Contact.h"
#include "solidify/solidified_Matter_Plugin_8_Bridge_Sensor_Flow.h"
#include "solidify/solidified_Matter_Plugin_8_Bridge_Sensor_Air_Quality.h"
#include "solidify/solidified_Matter_Plugin_8_Bridge_Sensor_Rain.h"
#include "solidify/solidified_Matter_Plugin_8_Bridge_Sensor_Waterleak.h"
#include "solidify/solidified_Matter_Plugin_z_All.h"
#include "solidify/solidified_Matter_zz_Device.h"
Expand Down
12 changes: 3 additions & 9 deletions lib/libesp32/berry_matter/src/embedded/Matter_Plugin_0.be
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Matter_Plugin
def init(device, endpoint, config)
self.device = device
self.endpoint = endpoint
self.clusters = self.consolidate_clusters()
self.clusters = self.get_clusters()
self.parse_configuration(config)
self.node_label = config.find("name", "")
end
Expand Down Expand Up @@ -179,11 +179,11 @@ class Matter_Plugin
end

#############################################################
# consolidate_clusters
# get_clusters
#
# Build a consolidated map of all the `CLUSTERS` static vars
# from the inheritance hierarchy
def consolidate_clusters()
def get_clusters()
return self.CLUSTERS
# def real_super(o) return super(o) end # enclose `super()` in a static function to disable special behavior for super in instances
# var ret = {}
Expand Down Expand Up @@ -257,12 +257,6 @@ class Matter_Plugin
return false
end

#############################################################
# Does it handle this endpoint and this cluster
def has(cluster, endpoint)
return self.clusters.contains(cluster) && self.endpoints.find(endpoint) != nil
end

def set_name(n)
if n != self.node_label
self.attribute_updated(0x0039, 0x0005)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#
# Matter_Plugin_Sensor_Boolean.be - implements the behavior for an abstract boolean sensor - to be inherited
#
# 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 <http://www.gnu.org/licenses/>.
#

import matter

# Matter plug-in for core behavior

#@ solidify:Matter_Plugin_Sensor_Boolean,weak

class Matter_Plugin_Sensor_Boolean : Matter_Plugin_Device
# static var TYPE = "" # name of the plug-in in json
# static var DISPLAY_NAME = "" # display name of the plug-in
static var ARG = "switch" # additional argument name (or empty if none)
static var ARG_HINT = "Switch<x> number"
static var ARG_TYPE = / x -> int(x) # function to convert argument to the right type
static var UPDATE_TIME = 750 # update every 750ms

var tasmota_switch_index # Switch number in Tasmota (one based)
var shadow_bool_value

#############################################################
# Constructor
def init(device, endpoint, config)
super(self).init(device, endpoint, config)
self.shadow_bool_value = false
end

#############################################################
# parse_configuration
#
# Parse configuration map
def parse_configuration(config)
self.tasmota_switch_index = int(config.find(self.ARG #-'switch'-#, 1))
if self.tasmota_switch_index <= 0 self.tasmota_switch_index = 1 end
end

#############################################################
# Update shadow
#
def update_shadow()
super(self).update_shadow()
if !self.VIRTUAL
var switch_str = "Switch" + str(self.tasmota_switch_index)

var j = tasmota.cmd("Status 10", true)
if j != nil j = j.find("StatusSNS") end
if j != nil && j.contains(switch_str)
var state = (j.find(switch_str) == "ON")

if (self.shadow_bool_value != state)
self.value_updated()
end
self.shadow_bool_value = state
end
end
end

#############################################################
# value_updated
#
# This is triggered when a new value is changed, for subscription
# This method is meant to be overloaded and maximize shared code
def value_updated()
end

#############################################################
# For Bridge devices
#############################################################
#############################################################
# Stub for updating shadow values (local copies of what we published to the Matter gateway)
#
# This call is synnchronous and blocking.
def parse_status(data, index)
if index == 10 # Status 10
var state = false

state = (data.find("Switch" + str(self.tasmota_switch_index)) == "ON")

if self.shadow_bool_value != nil && self.shadow_bool_value != bool(state)
self.value_updated()
end
self.shadow_bool_value = state
end
end
#############################################################
#############################################################
end
matter.Plugin_Sensor_Boolean = Matter_Plugin_Sensor_Boolean

This file was deleted.

Loading