From 13900666b4ed3240a75f90b88606e730d430c528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Josefsen?= <69624991+ReneJosefsen@users.noreply.github.com> Date: Fri, 26 Jan 2024 14:08:37 +0100 Subject: [PATCH] Improved handling of SetAllEnabledAlarmsActive and ClearAllAlarms (#31649) --- .../boolean-state-configuration-server.cpp | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/app/clusters/boolean-state-configuration-server/boolean-state-configuration-server.cpp b/src/app/clusters/boolean-state-configuration-server/boolean-state-configuration-server.cpp index dd81c90cd00191..9ca68da511980d 100644 --- a/src/app/clusters/boolean-state-configuration-server/boolean-state-configuration-server.cpp +++ b/src/app/clusters/boolean-state-configuration-server/boolean-state-configuration-server.cpp @@ -274,8 +274,11 @@ CHIP_ERROR SetAllEnabledAlarmsActive(EndpointId ep) VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == AlarmsEnabled::Get(ep, &alarmsEnabled), CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute)); - VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == AlarmsActive::Set(ep, alarmsEnabled), CHIP_IM_GLOBAL_STATUS(Failure)); - emitAlarmsStateChangedEvent(ep); + if (alarmsEnabled.HasAny()) + { + VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == AlarmsActive::Set(ep, alarmsEnabled), CHIP_IM_GLOBAL_STATUS(Failure)); + emitAlarmsStateChangedEvent(ep); + } return CHIP_NO_ERROR; } @@ -283,21 +286,34 @@ CHIP_ERROR SetAllEnabledAlarmsActive(EndpointId ep) CHIP_ERROR ClearAllAlarms(EndpointId ep) { BitMask alarmsActive, alarmsSuppressed; + bool emitEvent = false; + VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == AlarmsActive::Get(ep, &alarmsActive), CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute)); VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == AlarmsSuppressed::Get(ep, &alarmsSuppressed), CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute)); - if (alarmsActive.HasAny() || alarmsSuppressed.HasAny()) + if (alarmsActive.HasAny()) { alarmsActive.ClearAll(); - alarmsSuppressed.ClearAll(); VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == AlarmsActive::Set(ep, alarmsActive), CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute)); + emitEvent = true; + } + + if (alarmsSuppressed.HasAny()) + { + alarmsSuppressed.ClearAll(); VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == AlarmsSuppressed::Set(ep, alarmsSuppressed), CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute)); + emitEvent = true; + } + + if (emitEvent) + { emitAlarmsStateChangedEvent(ep); } + return CHIP_NO_ERROR; }