Skip to content

Commit

Permalink
[OnOff] Fix OffWaitTime delayed state off (#25172)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jmartinez-silabs committed Feb 19, 2023
1 parent 738205d commit 04adc52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
23 changes: 9 additions & 14 deletions src/app/clusters/on-off-server/on-off-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ EmberAfStatus OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::Comman
EmberAfStatus status;
bool currentValue, newValue;

emberAfOnOffClusterPrintln("On/Off set value: %x %x", endpoint, static_cast<uint8_t>(command));

// read current on/off value
status = Attributes::OnOff::Get(endpoint, &currentValue);
if (status != EMBER_ZCL_STATUS_SUCCESS)
Expand All @@ -123,14 +121,14 @@ EmberAfStatus OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::Comman
// if the value is already what we want to set it to then do nothing
if ((!currentValue && command == Commands::Off::Id) || (currentValue && command == Commands::On::Id))
{
emberAfOnOffClusterPrintln("On/off already set to new value");
emberAfOnOffClusterPrintln("Endpoint %x On/off already set to new value", endpoint);
return EMBER_ZCL_STATUS_SUCCESS;
}

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

// the sequence of updating on/off attribute and kick off level change effect should
// be depend on whether we are turning on or off. If we are turning on the light, we
Expand Down Expand Up @@ -193,12 +191,6 @@ EmberAfStatus OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::Comman
}
else // Set Off
{
if (SupportsLightingApplications(endpoint))
{
emberAfOnOffClusterPrintln("Off Command - OnTime : 0");
Attributes::OnTime::Set(endpoint, 0); // Reset onTime
}

#ifdef EMBER_AF_PLUGIN_LEVEL_CONTROL
// If initiatedByLevelChange is false, then we assume that the level change
// ZCL stuff has not happened and we do it here
Expand All @@ -207,18 +199,22 @@ EmberAfStatus OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::Comman
emberAfOnOffClusterLevelControlEffectCallback(endpoint, newValue);
}
else
{
#endif
{
// write the new on/off value
status = Attributes::OnOff::Set(endpoint, newValue);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfOnOffClusterPrintln("ERR: writing on/off %x", status);
return status;
}
#ifdef EMBER_AF_PLUGIN_LEVEL_CONTROL

if (SupportsLightingApplications(endpoint))
{
emberAfOnOffClusterPrintln("Off completed. reset OnTime to 0");
Attributes::OnTime::Set(endpoint, 0); // Reset onTime
}
}
#endif
}

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

OnOff::Attributes::GlobalSceneControl::Set(endpoint, false);
Attributes::OnTime::Set(endpoint, 0);
}

// Only apply effect if OnOff is on
Expand Down
4 changes: 2 additions & 2 deletions src/test_driver/linux-cirque/MobileDeviceTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def run_controller_test(self):
self.get_device_pretty_id(device_id)))
self.assertTrue(self.sequenceMatch(self.get_device_log(device_id).decode('utf-8'), [
"Received command for Endpoint=1 Cluster=0x0000_0006 Command=0x0000_0001",
"Toggle on/off from 0 to 1",
"Toggle ep1 on/off from state 0 to 1",
"Received command for Endpoint=1 Cluster=0x0000_0006 Command=0x0000_0000",
"Toggle on/off from 1 to 0",
"Toggle ep1 on/off from state 1 to 0",
"No command 0x0000_0001 in Cluster 0x0000_0006 on Endpoint 0xe9"]),
"Datamodel test failed: cannot find matching string from device {}".format(device_id))

Expand Down

0 comments on commit 04adc52

Please sign in to comment.