diff --git a/src/app/clusters/level-control/level-control.cpp b/src/app/clusters/level-control/level-control.cpp index 5677b25dc1b160..968f1bd6e7d683 100644 --- a/src/app/clusters/level-control/level-control.cpp +++ b/src/app/clusters/level-control/level-control.cpp @@ -227,22 +227,21 @@ void emberAfLevelControlClusterServerTickCallback(EndpointId endpoint) { setOnOffValue(endpoint, (currentLevel.Value() != state->minLevel)); } - else + + if (state->storedLevel != INVALID_STORED_LEVEL) { - if (state->storedLevel != INVALID_STORED_LEVEL) + uint8_t storedLevel8u = (uint8_t) state->storedLevel; + status = Attributes::CurrentLevel::Set(endpoint, storedLevel8u); + if (status != EMBER_ZCL_STATUS_SUCCESS) { - uint8_t storedLevel8u = (uint8_t) state->storedLevel; - status = Attributes::CurrentLevel::Set(endpoint, storedLevel8u); - if (status != EMBER_ZCL_STATUS_SUCCESS) - { - emberAfLevelControlClusterPrintln("ERR: writing current level %x", status); - } - else - { - updateCoupledColorTemp(endpoint); - } + emberAfLevelControlClusterPrintln("ERR: writing current level %x", status); + } + else + { + updateCoupledColorTemp(endpoint); } } + writeRemainingTime(endpoint, 0); } else @@ -1070,16 +1069,15 @@ void emberAfOnOffClusterLevelControlEffectCallback(EndpointId endpoint, bool new // time period OnOffTransitionTime." if (useOnLevel) { - // If OnLevel is defined, don't revert to stored level. - moveToLevelHandler(endpoint, Commands::MoveToLevel::Id, minimumLevelAllowedForTheDevice, transitionTime, 0xFF, 0xFF, - INVALID_STORED_LEVEL); + moveToLevelHandler(endpoint, Commands::MoveToLevelWithOnOff::Id, minimumLevelAllowedForTheDevice, transitionTime, 0xFF, + 0xFF, INVALID_STORED_LEVEL); } else { // If OnLevel is not defined, set the CurrentLevel to the stored level. - moveToLevelHandler(endpoint, Commands::MoveToLevel::Id, minimumLevelAllowedForTheDevice, transitionTime, 0xFF, 0xFF, - temporaryCurrentLevelCache.Value()); + moveToLevelHandler(endpoint, Commands::MoveToLevelWithOnOff::Id, minimumLevelAllowedForTheDevice, transitionTime, 0xFF, + 0xFF, temporaryCurrentLevelCache.Value()); } } } diff --git a/src/app/clusters/on-off-server/on-off-server.cpp b/src/app/clusters/on-off-server/on-off-server.cpp index 03eff53c5a0978..832e5d7aae982a 100644 --- a/src/app/clusters/on-off-server/on-off-server.cpp +++ b/src/app/clusters/on-off-server/on-off-server.cpp @@ -187,15 +187,19 @@ EmberAfStatus OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::Comman { emberAfOnOffClusterLevelControlEffectCallback(endpoint, newValue); } -#endif - - // write the new on/off value - status = Attributes::OnOff::Set(endpoint, newValue); - if (status != EMBER_ZCL_STATUS_SUCCESS) + else { - emberAfOnOffClusterPrintln("ERR: writing on/off %x", status); - return status; +#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 } +#endif } #ifdef EMBER_AF_PLUGIN_SCENES @@ -241,7 +245,7 @@ void OnOffServer::initOnOffServer(chip::EndpointId endpoint) EmberAfStatus status = getOnOffValueForStartUp(endpoint, onOffValueForStartUp); if (status == EMBER_ZCL_STATUS_SUCCESS) { - status = setOnOffValue(endpoint, onOffValueForStartUp, false); + status = setOnOffValue(endpoint, onOffValueForStartUp, true); } #ifdef EMBER_AF_PLUGIN_MODE_SELECT diff --git a/src/darwin/Framework/CHIPTests/MTRDeviceTests.m b/src/darwin/Framework/CHIPTests/MTRDeviceTests.m index 71baaee0308a8f..950b2149c0b176 100644 --- a/src/darwin/Framework/CHIPTests/MTRDeviceTests.m +++ b/src/darwin/Framework/CHIPTests/MTRDeviceTests.m @@ -751,7 +751,8 @@ - (void)test011_ReadCachedAttribute XCTestExpectation * subscribeExpectation = [self expectationWithDescription:@"Subscription complete"]; NSLog(@"Subscribing..."); - __block void (^reportHandler)(NSArray * _Nullable value, NSError * _Nullable error); + // reportHandler returns TRUE if it got the things it was looking for or if there's an error. + __block BOOL (^reportHandler)(NSArray * _Nullable value, NSError * _Nullable error); __auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(60)]; [device subscribeWithQueue:queue params:params @@ -761,7 +762,11 @@ - (void)test011_ReadCachedAttribute if (reportHandler) { __auto_type handler = reportHandler; reportHandler = nil; - handler(value, nil); + BOOL done = handler(value, nil); + if (done == NO) { + // Keep waiting. + reportHandler = handler; + } } } eventReportHandler:nil @@ -827,6 +832,9 @@ - (void)test011_ReadCachedAttribute __auto_type reportExpectation = [self expectationWithDescription:@"Report handler called"]; reportHandler = ^(NSArray * _Nullable value, NSError * _Nullable error) { + if (error != nil) { + return YES; + } NSLog(@"Report received: %@, error: %@", value, error); for (MTRAttributeReport * report in value) { if ([report.path.endpoint isEqualToNumber:@1] && [report.path.cluster isEqualToNumber:@6] && @@ -836,9 +844,11 @@ - (void)test011_ReadCachedAttribute XCTAssertTrue([report.value isKindOfClass:[NSNumber class]]); XCTAssertEqual([report.value boolValue], NO); [reportExpectation fulfill]; - break; + return YES; } } + + return NO; }; NSLog(@"Invoking another command...");