Skip to content

Commit

Permalink
change for on off transitiontime feature (#21569)
Browse files Browse the repository at this point in the history
* change for on off transitiontime feature

* Restyled by clang-format

* update for build error

* Restyled by clang-format

* Fix subscription test to handle separate reports for different attributes better.

Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
  • Loading branch information
3 people authored and pull[bot] committed Sep 15, 2023
1 parent 1ed4738 commit 1566642
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
32 changes: 15 additions & 17 deletions src/app/clusters/level-control/level-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions src/app/clusters/on-off-server/on-off-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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] &&
Expand All @@ -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...");
Expand Down

0 comments on commit 1566642

Please sign in to comment.