Skip to content

Commit 04adc52

Browse files
[OnOff] Fix OffWaitTime delayed state off (#25172)
* Fix issue where OnTime was set to 0 and the updateOnOffTimeCommand callback was called before OnOff off State was set causing OffWaitTime to wrongly be reseted. * Fix expected string in Cirque MobileDeviceTest since The log changed in the on off server
1 parent 738205d commit 04adc52

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/app/clusters/on-off-server/on-off-server.cpp

+9-14
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ EmberAfStatus OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::Comman
110110
EmberAfStatus status;
111111
bool currentValue, newValue;
112112

113-
emberAfOnOffClusterPrintln("On/Off set value: %x %x", endpoint, static_cast<uint8_t>(command));
114-
115113
// read current on/off value
116114
status = Attributes::OnOff::Get(endpoint, &currentValue);
117115
if (status != EMBER_ZCL_STATUS_SUCCESS)
@@ -123,14 +121,14 @@ EmberAfStatus OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::Comman
123121
// if the value is already what we want to set it to then do nothing
124122
if ((!currentValue && command == Commands::Off::Id) || (currentValue && command == Commands::On::Id))
125123
{
126-
emberAfOnOffClusterPrintln("On/off already set to new value");
124+
emberAfOnOffClusterPrintln("Endpoint %x On/off already set to new value", endpoint);
127125
return EMBER_ZCL_STATUS_SUCCESS;
128126
}
129127

130128
// we either got a toggle, or an on when off, or an off when on,
131129
// so we need to swap the value
132130
newValue = !currentValue;
133-
emberAfOnOffClusterPrintln("Toggle on/off from %x to %x", currentValue, newValue);
131+
emberAfOnOffClusterPrintln("Toggle ep%x on/off from state %x to %x", endpoint, currentValue, newValue);
134132

135133
// the sequence of updating on/off attribute and kick off level change effect should
136134
// be depend on whether we are turning on or off. If we are turning on the light, we
@@ -193,12 +191,6 @@ EmberAfStatus OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::Comman
193191
}
194192
else // Set Off
195193
{
196-
if (SupportsLightingApplications(endpoint))
197-
{
198-
emberAfOnOffClusterPrintln("Off Command - OnTime : 0");
199-
Attributes::OnTime::Set(endpoint, 0); // Reset onTime
200-
}
201-
202194
#ifdef EMBER_AF_PLUGIN_LEVEL_CONTROL
203195
// If initiatedByLevelChange is false, then we assume that the level change
204196
// ZCL stuff has not happened and we do it here
@@ -207,18 +199,22 @@ EmberAfStatus OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::Comman
207199
emberAfOnOffClusterLevelControlEffectCallback(endpoint, newValue);
208200
}
209201
else
210-
{
211202
#endif
203+
{
212204
// write the new on/off value
213205
status = Attributes::OnOff::Set(endpoint, newValue);
214206
if (status != EMBER_ZCL_STATUS_SUCCESS)
215207
{
216208
emberAfOnOffClusterPrintln("ERR: writing on/off %x", status);
217209
return status;
218210
}
219-
#ifdef EMBER_AF_PLUGIN_LEVEL_CONTROL
211+
212+
if (SupportsLightingApplications(endpoint))
213+
{
214+
emberAfOnOffClusterPrintln("Off completed. reset OnTime to 0");
215+
Attributes::OnTime::Set(endpoint, 0); // Reset onTime
216+
}
220217
}
221-
#endif
222218
}
223219

224220
#ifdef EMBER_AF_PLUGIN_SCENES
@@ -383,7 +379,6 @@ bool OnOffServer::offWithEffectCommand(app::CommandHandler * commandObj, const a
383379
#endif // EMBER_AF_PLUGIN_SCENES
384380

385381
OnOff::Attributes::GlobalSceneControl::Set(endpoint, false);
386-
Attributes::OnTime::Set(endpoint, 0);
387382
}
388383

389384
// Only apply effect if OnOff is on

src/test_driver/linux-cirque/MobileDeviceTest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ def run_controller_test(self):
121121
self.get_device_pretty_id(device_id)))
122122
self.assertTrue(self.sequenceMatch(self.get_device_log(device_id).decode('utf-8'), [
123123
"Received command for Endpoint=1 Cluster=0x0000_0006 Command=0x0000_0001",
124-
"Toggle on/off from 0 to 1",
124+
"Toggle ep1 on/off from state 0 to 1",
125125
"Received command for Endpoint=1 Cluster=0x0000_0006 Command=0x0000_0000",
126-
"Toggle on/off from 1 to 0",
126+
"Toggle ep1 on/off from state 1 to 0",
127127
"No command 0x0000_0001 in Cluster 0x0000_0006 on Endpoint 0xe9"]),
128128
"Datamodel test failed: cannot find matching string from device {}".format(device_id))
129129

0 commit comments

Comments
 (0)