From badf064ab4f490742f379d4fdd604d9fdef16404 Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Sun, 11 Jun 2023 23:10:26 +0200 Subject: [PATCH] Matter fix local Occupancy sensor (#18857) * Matter fix local Occupancy sensor * Fix also OnOff --- CHANGELOG.md | 1 + .../Matter_Plugin_Sensor_Occupancy.be | 19 ++-- .../embedded/Matter_Plugin_Sensor_OnOff.be | 19 ++-- ...olidified_Matter_Plugin_Sensor_Occupancy.h | 94 +++++++++---------- .../solidified_Matter_Plugin_Sensor_OnOff.h | 94 +++++++++---------- 5 files changed, 107 insertions(+), 120 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b26a93f6b..173cbb92d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Interaction of ``SetOption92``, ``VirtualCT``, and ``RGBWWTable`` (#18768) - Fixed HASPmota event when value is non-integer (fixes #18229) +- Matter fix local Occupancy sensor ### Removed diff --git a/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_Occupancy.be b/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_Occupancy.be index 0203874dd..e036bada5 100644 --- a/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_Occupancy.be +++ b/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_Occupancy.be @@ -54,20 +54,17 @@ class Matter_Plugin_Sensor_Occupancy : Matter_Plugin_Device # def update_shadow() super(self).update_shadow() + var switch_str = "Switch" + str(self.tasmota_switch_index) - import json - var ret = tasmota.cmd("Status 8", true) - if ret != nil - var j = json.load(ret) - if j != nil - var state = false - state = (j.find("Switch" + str(self.tasmota_switch_index)) == "ON") + var j = tasmota.cmd("Status 8", 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_occupancy != nil && self.shadow_occupancy != bool(state) - self.attribute_updated(0x0406, 0x0000) - end - self.shadow_occupancy = state + if (self.shadow_occupancy != state) + self.attribute_updated(0x0406, 0x0000) end + self.shadow_occupancy = state end end diff --git a/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_OnOff.be b/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_OnOff.be index c675c1f0f..e754c4466 100644 --- a/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_OnOff.be +++ b/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_OnOff.be @@ -52,20 +52,17 @@ class Matter_Plugin_Sensor_OnOff : Matter_Plugin_Device # def update_shadow() super(self).update_shadow() + var switch_str = "Switch" + str(self.tasmota_switch_index) - import json - var ret = tasmota.cmd("Status 8", true) - if ret != nil - var j = json.load(ret) - if j != nil - var state = false - state = (j.find("Switch" + str(self.tasmota_switch_index)) == "ON") + var j = tasmota.cmd("Status 8", 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_onoff != nil && self.shadow_onoff != bool(state) - self.attribute_updated(0x0406, 0x0000) - end - self.shadow_onoff = state + if (self.shadow_onoff != state) + self.attribute_updated(0x0006, 0x0000) end + self.shadow_onoff = state end end diff --git a/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_Occupancy.h b/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_Occupancy.h index 0c35bd94c..d114a216d 100644 --- a/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_Occupancy.h +++ b/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_Occupancy.h @@ -187,7 +187,7 @@ be_local_closure(Matter_Plugin_Sensor_Occupancy_read_attribute, /* name */ ********************************************************************/ be_local_closure(Matter_Plugin_Sensor_Occupancy_update_shadow, /* name */ be_nested_proto( - 9, /* nstack */ + 8, /* nstack */ 1, /* argc */ 2, /* varg */ 0, /* has upvals */ @@ -197,14 +197,14 @@ be_local_closure(Matter_Plugin_Sensor_Occupancy_update_shadow, /* name */ 1, /* has constants */ ( &(const bvalue[13]) { /* constants */ /* K0 */ be_nested_str_weak(update_shadow), - /* K1 */ be_nested_str_weak(json), - /* K2 */ be_nested_str_weak(tasmota), - /* K3 */ be_nested_str_weak(cmd), - /* K4 */ be_nested_str_weak(Status_X208), - /* K5 */ be_nested_str_weak(load), + /* K1 */ be_nested_str_weak(Switch), + /* K2 */ be_nested_str_weak(tasmota_switch_index), + /* K3 */ be_nested_str_weak(tasmota), + /* K4 */ be_nested_str_weak(cmd), + /* K5 */ be_nested_str_weak(Status_X208), /* K6 */ be_nested_str_weak(find), - /* K7 */ be_nested_str_weak(Switch), - /* K8 */ be_nested_str_weak(tasmota_switch_index), + /* K7 */ be_nested_str_weak(StatusSNS), + /* K8 */ be_nested_str_weak(contains), /* K9 */ be_nested_str_weak(ON), /* K10 */ be_nested_str_weak(shadow_occupancy), /* K11 */ be_nested_str_weak(attribute_updated), @@ -212,52 +212,48 @@ be_local_closure(Matter_Plugin_Sensor_Occupancy_update_shadow, /* name */ }), be_str_weak(update_shadow), &be_const_str_solidified, - ( &(const binstruction[45]) { /* code */ + ( &(const binstruction[41]) { /* code */ 0x60040003, // 0000 GETGBL R1 G3 0x5C080000, // 0001 MOVE R2 R0 0x7C040200, // 0002 CALL R1 1 0x8C040300, // 0003 GETMET R1 R1 K0 0x7C040200, // 0004 CALL R1 1 - 0xA4060200, // 0005 IMPORT R1 K1 - 0xB80A0400, // 0006 GETNGBL R2 K2 - 0x8C080503, // 0007 GETMET R2 R2 K3 - 0x58100004, // 0008 LDCONST R4 K4 - 0x50140200, // 0009 LDBOOL R5 1 0 - 0x7C080600, // 000A CALL R2 3 - 0x4C0C0000, // 000B LDNIL R3 - 0x200C0403, // 000C NE R3 R2 R3 - 0x780E001D, // 000D JMPF R3 #002C - 0x8C0C0305, // 000E GETMET R3 R1 K5 - 0x5C140400, // 000F MOVE R5 R2 - 0x7C0C0400, // 0010 CALL R3 2 - 0x4C100000, // 0011 LDNIL R4 - 0x20100604, // 0012 NE R4 R3 R4 - 0x78120017, // 0013 JMPF R4 #002C - 0x50100000, // 0014 LDBOOL R4 0 0 - 0x8C140706, // 0015 GETMET R5 R3 K6 - 0x601C0008, // 0016 GETGBL R7 G8 - 0x88200108, // 0017 GETMBR R8 R0 K8 - 0x7C1C0200, // 0018 CALL R7 1 - 0x001E0E07, // 0019 ADD R7 K7 R7 - 0x7C140400, // 001A CALL R5 2 - 0x1C140B09, // 001B EQ R5 R5 K9 - 0x5C100A00, // 001C MOVE R4 R5 - 0x8814010A, // 001D GETMBR R5 R0 K10 - 0x4C180000, // 001E LDNIL R6 - 0x20140A06, // 001F NE R5 R5 R6 - 0x78160009, // 0020 JMPF R5 #002B - 0x8814010A, // 0021 GETMBR R5 R0 K10 - 0x60180017, // 0022 GETGBL R6 G23 - 0x5C1C0800, // 0023 MOVE R7 R4 - 0x7C180200, // 0024 CALL R6 1 - 0x20140A06, // 0025 NE R5 R5 R6 - 0x78160003, // 0026 JMPF R5 #002B - 0x8C14010B, // 0027 GETMET R5 R0 K11 - 0x541E0405, // 0028 LDINT R7 1030 - 0x5820000C, // 0029 LDCONST R8 K12 - 0x7C140600, // 002A CALL R5 3 - 0x90021404, // 002B SETMBR R0 K10 R4 - 0x80000000, // 002C RET 0 + 0x60040008, // 0005 GETGBL R1 G8 + 0x88080102, // 0006 GETMBR R2 R0 K2 + 0x7C040200, // 0007 CALL R1 1 + 0x00060201, // 0008 ADD R1 K1 R1 + 0xB80A0600, // 0009 GETNGBL R2 K3 + 0x8C080504, // 000A GETMET R2 R2 K4 + 0x58100005, // 000B LDCONST R4 K5 + 0x50140200, // 000C LDBOOL R5 1 0 + 0x7C080600, // 000D CALL R2 3 + 0x4C0C0000, // 000E LDNIL R3 + 0x200C0403, // 000F NE R3 R2 R3 + 0x780E0003, // 0010 JMPF R3 #0015 + 0x8C0C0506, // 0011 GETMET R3 R2 K6 + 0x58140007, // 0012 LDCONST R5 K7 + 0x7C0C0400, // 0013 CALL R3 2 + 0x5C080600, // 0014 MOVE R2 R3 + 0x4C0C0000, // 0015 LDNIL R3 + 0x200C0403, // 0016 NE R3 R2 R3 + 0x780E000F, // 0017 JMPF R3 #0028 + 0x8C0C0508, // 0018 GETMET R3 R2 K8 + 0x5C140200, // 0019 MOVE R5 R1 + 0x7C0C0400, // 001A CALL R3 2 + 0x780E000B, // 001B JMPF R3 #0028 + 0x8C0C0506, // 001C GETMET R3 R2 K6 + 0x5C140200, // 001D MOVE R5 R1 + 0x7C0C0400, // 001E CALL R3 2 + 0x1C0C0709, // 001F EQ R3 R3 K9 + 0x8810010A, // 0020 GETMBR R4 R0 K10 + 0x20100803, // 0021 NE R4 R4 R3 + 0x78120003, // 0022 JMPF R4 #0027 + 0x8C10010B, // 0023 GETMET R4 R0 K11 + 0x541A0405, // 0024 LDINT R6 1030 + 0x581C000C, // 0025 LDCONST R7 K12 + 0x7C100600, // 0026 CALL R4 3 + 0x90021403, // 0027 SETMBR R0 K10 R3 + 0x80000000, // 0028 RET 0 }) ) ); diff --git a/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_OnOff.h b/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_OnOff.h index b061f2b05..7e701f289 100644 --- a/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_OnOff.h +++ b/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_OnOff.h @@ -160,7 +160,7 @@ be_local_closure(Matter_Plugin_Sensor_OnOff_read_attribute, /* name */ ********************************************************************/ be_local_closure(Matter_Plugin_Sensor_OnOff_update_shadow, /* name */ be_nested_proto( - 9, /* nstack */ + 8, /* nstack */ 1, /* argc */ 2, /* varg */ 0, /* has upvals */ @@ -170,14 +170,14 @@ be_local_closure(Matter_Plugin_Sensor_OnOff_update_shadow, /* name */ 1, /* has constants */ ( &(const bvalue[13]) { /* constants */ /* K0 */ be_nested_str_weak(update_shadow), - /* K1 */ be_nested_str_weak(json), - /* K2 */ be_nested_str_weak(tasmota), - /* K3 */ be_nested_str_weak(cmd), - /* K4 */ be_nested_str_weak(Status_X208), - /* K5 */ be_nested_str_weak(load), + /* K1 */ be_nested_str_weak(Switch), + /* K2 */ be_nested_str_weak(tasmota_switch_index), + /* K3 */ be_nested_str_weak(tasmota), + /* K4 */ be_nested_str_weak(cmd), + /* K5 */ be_nested_str_weak(Status_X208), /* K6 */ be_nested_str_weak(find), - /* K7 */ be_nested_str_weak(Switch), - /* K8 */ be_nested_str_weak(tasmota_switch_index), + /* K7 */ be_nested_str_weak(StatusSNS), + /* K8 */ be_nested_str_weak(contains), /* K9 */ be_nested_str_weak(ON), /* K10 */ be_nested_str_weak(shadow_onoff), /* K11 */ be_nested_str_weak(attribute_updated), @@ -185,52 +185,48 @@ be_local_closure(Matter_Plugin_Sensor_OnOff_update_shadow, /* name */ }), be_str_weak(update_shadow), &be_const_str_solidified, - ( &(const binstruction[45]) { /* code */ + ( &(const binstruction[41]) { /* code */ 0x60040003, // 0000 GETGBL R1 G3 0x5C080000, // 0001 MOVE R2 R0 0x7C040200, // 0002 CALL R1 1 0x8C040300, // 0003 GETMET R1 R1 K0 0x7C040200, // 0004 CALL R1 1 - 0xA4060200, // 0005 IMPORT R1 K1 - 0xB80A0400, // 0006 GETNGBL R2 K2 - 0x8C080503, // 0007 GETMET R2 R2 K3 - 0x58100004, // 0008 LDCONST R4 K4 - 0x50140200, // 0009 LDBOOL R5 1 0 - 0x7C080600, // 000A CALL R2 3 - 0x4C0C0000, // 000B LDNIL R3 - 0x200C0403, // 000C NE R3 R2 R3 - 0x780E001D, // 000D JMPF R3 #002C - 0x8C0C0305, // 000E GETMET R3 R1 K5 - 0x5C140400, // 000F MOVE R5 R2 - 0x7C0C0400, // 0010 CALL R3 2 - 0x4C100000, // 0011 LDNIL R4 - 0x20100604, // 0012 NE R4 R3 R4 - 0x78120017, // 0013 JMPF R4 #002C - 0x50100000, // 0014 LDBOOL R4 0 0 - 0x8C140706, // 0015 GETMET R5 R3 K6 - 0x601C0008, // 0016 GETGBL R7 G8 - 0x88200108, // 0017 GETMBR R8 R0 K8 - 0x7C1C0200, // 0018 CALL R7 1 - 0x001E0E07, // 0019 ADD R7 K7 R7 - 0x7C140400, // 001A CALL R5 2 - 0x1C140B09, // 001B EQ R5 R5 K9 - 0x5C100A00, // 001C MOVE R4 R5 - 0x8814010A, // 001D GETMBR R5 R0 K10 - 0x4C180000, // 001E LDNIL R6 - 0x20140A06, // 001F NE R5 R5 R6 - 0x78160009, // 0020 JMPF R5 #002B - 0x8814010A, // 0021 GETMBR R5 R0 K10 - 0x60180017, // 0022 GETGBL R6 G23 - 0x5C1C0800, // 0023 MOVE R7 R4 - 0x7C180200, // 0024 CALL R6 1 - 0x20140A06, // 0025 NE R5 R5 R6 - 0x78160003, // 0026 JMPF R5 #002B - 0x8C14010B, // 0027 GETMET R5 R0 K11 - 0x541E0405, // 0028 LDINT R7 1030 - 0x5820000C, // 0029 LDCONST R8 K12 - 0x7C140600, // 002A CALL R5 3 - 0x90021404, // 002B SETMBR R0 K10 R4 - 0x80000000, // 002C RET 0 + 0x60040008, // 0005 GETGBL R1 G8 + 0x88080102, // 0006 GETMBR R2 R0 K2 + 0x7C040200, // 0007 CALL R1 1 + 0x00060201, // 0008 ADD R1 K1 R1 + 0xB80A0600, // 0009 GETNGBL R2 K3 + 0x8C080504, // 000A GETMET R2 R2 K4 + 0x58100005, // 000B LDCONST R4 K5 + 0x50140200, // 000C LDBOOL R5 1 0 + 0x7C080600, // 000D CALL R2 3 + 0x4C0C0000, // 000E LDNIL R3 + 0x200C0403, // 000F NE R3 R2 R3 + 0x780E0003, // 0010 JMPF R3 #0015 + 0x8C0C0506, // 0011 GETMET R3 R2 K6 + 0x58140007, // 0012 LDCONST R5 K7 + 0x7C0C0400, // 0013 CALL R3 2 + 0x5C080600, // 0014 MOVE R2 R3 + 0x4C0C0000, // 0015 LDNIL R3 + 0x200C0403, // 0016 NE R3 R2 R3 + 0x780E000F, // 0017 JMPF R3 #0028 + 0x8C0C0508, // 0018 GETMET R3 R2 K8 + 0x5C140200, // 0019 MOVE R5 R1 + 0x7C0C0400, // 001A CALL R3 2 + 0x780E000B, // 001B JMPF R3 #0028 + 0x8C0C0506, // 001C GETMET R3 R2 K6 + 0x5C140200, // 001D MOVE R5 R1 + 0x7C0C0400, // 001E CALL R3 2 + 0x1C0C0709, // 001F EQ R3 R3 K9 + 0x8810010A, // 0020 GETMBR R4 R0 K10 + 0x20100803, // 0021 NE R4 R4 R3 + 0x78120003, // 0022 JMPF R4 #0027 + 0x8C10010B, // 0023 GETMET R4 R0 K11 + 0x541A0005, // 0024 LDINT R6 6 + 0x581C000C, // 0025 LDCONST R7 K12 + 0x7C100600, // 0026 CALL R4 3 + 0x90021403, // 0027 SETMBR R0 K10 R3 + 0x80000000, // 0028 RET 0 }) ) );