-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix OnOff state shadowing by the LevelControl cluster while OnOff tra… #36922
Open
lmapii
wants to merge
1
commit into
project-chip:master
Choose a base branch
from
lmapii:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -373,16 +373,78 @@ Status OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::CommandId com | |
return status; | ||
} | ||
|
||
// 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)) | ||
#ifdef MATTER_DM_PLUGIN_LEVEL_CONTROL | ||
// the level control cluster supports on/off transitions or effects, e.g., controlled via | ||
// the OnOffTransitionTime attribute: in a transition to "off", the level control cluster | ||
// changes the CurrentLevel attribute using a timer until it reaches the minimum supported value | ||
// and only then changes the OnOff value in the OnOff cluster. therefore, comparing the current | ||
// OnOff state with the required state is not sufficient for OnOff cluster values that support | ||
// level control: | ||
// - the current state might be "On" | ||
// - even though the level control cluster changes the state towards "Off" | ||
// - and thus any other "On" value should prevent the cluster from turning off. | ||
// | ||
// this restriction does not exist for the "Off" command since level movements by definition | ||
// are only available while the OnOff state is "On". | ||
if (!LevelControlWithOnOffFeaturePresent(endpoint) || (command == Commands::Off::Id)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be necessary to restrict this to lighting applications in the future. I don't, however, see how not having this behavior can be useful for other applications - but I might be missing the bigger picture here. |
||
#endif | ||
{ | ||
ChipLogProgress(Zcl, "Endpoint %x On/off already set to new value", endpoint); | ||
return Status::Success; | ||
// 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)) | ||
{ | ||
ChipLogProgress(Zcl, "Endpoint %x On/off already set to new value", endpoint); | ||
return Status::Success; | ||
} | ||
} | ||
|
||
switch (command) | ||
{ | ||
case Commands::Off::Id: | ||
newValue = false; | ||
break; | ||
|
||
case Commands::On::Id: | ||
newValue = true; | ||
break; | ||
|
||
case Commands::Toggle::Id: | ||
newValue = !currentValue; | ||
#ifdef MATTER_DM_PLUGIN_LEVEL_CONTROL | ||
if (LevelControlWithOnOffFeaturePresent(endpoint)) | ||
{ | ||
bool targetValueOn = false; | ||
bool transitionActive = LevelControlIsOnOffTransitionActive(endpoint, &targetValueOn); | ||
if (transitionActive) | ||
{ | ||
newValue = !targetValueOn; | ||
} | ||
} | ||
#endif | ||
break; | ||
|
||
case Commands::OffWithEffect::Id: | ||
case Commands::OnWithRecallGlobalScene::Id: | ||
case Commands::OnWithTimedOff::Id: | ||
default: | ||
// this function is only supposed to be called for the commands On, Off, and Toggle | ||
ChipLogProgress(Zcl, "ERR: unknown/unsupported command " ChipLogFormatMEI, ChipLogValueMEI(command)); | ||
return Status::Failure; | ||
break; | ||
} | ||
|
||
// we either got a toggle, or an on when off, or an off when on, | ||
// so we need to swap the value | ||
newValue = !currentValue; | ||
#ifdef MATTER_DM_PLUGIN_LEVEL_CONTROL | ||
if (LevelControlWithOnOffFeaturePresent(endpoint)) | ||
{ | ||
bool targetValueOn = false; | ||
bool transitionActive = LevelControlIsOnOffTransitionActive(endpoint, &targetValueOn); | ||
if (!transitionActive && (newValue == currentValue)) | ||
{ | ||
ChipLogProgress(Zcl, "Endpoint %x On/off already set to new value", endpoint); | ||
return Status::Success; | ||
} | ||
} | ||
#endif | ||
|
||
ChipLogProgress(Zcl, "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 | ||
|
@@ -415,11 +477,14 @@ Status OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::CommandId com | |
} | ||
|
||
// write the new on/off value | ||
status = Attributes::OnOff::Set(endpoint, newValue); | ||
if (status != Status::Success) | ||
if (newValue != currentValue) | ||
{ | ||
ChipLogProgress(Zcl, "ERR: writing on/off %x", to_underlying(status)); | ||
return status; | ||
status = Attributes::OnOff::Set(endpoint, newValue); | ||
if (status != Status::Success) | ||
{ | ||
ChipLogProgress(Zcl, "ERR: writing on/off %x", to_underlying(status)); | ||
return status; | ||
} | ||
} | ||
|
||
#ifdef MATTER_DM_PLUGIN_LEVEL_CONTROL | ||
|
@@ -461,11 +526,14 @@ Status OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::CommandId com | |
#endif | ||
{ | ||
// write the new on/off value | ||
status = Attributes::OnOff::Set(endpoint, newValue); | ||
if (status != Status::Success) | ||
if (newValue != currentValue) | ||
{ | ||
ChipLogProgress(Zcl, "ERR: writing on/off %x", to_underlying(status)); | ||
return status; | ||
status = Attributes::OnOff::Set(endpoint, newValue); | ||
if (status != Status::Success) | ||
{ | ||
ChipLogProgress(Zcl, "ERR: writing on/off %x", to_underlying(status)); | ||
return status; | ||
} | ||
} | ||
|
||
if (SupportsLightingApplications(endpoint)) | ||
|
@@ -517,7 +585,7 @@ void OnOffServer::initOnOffServer(chip::EndpointId endpoint) | |
Status status = getOnOffValueForStartUp(endpoint, onOffValueForStartUp); | ||
if (status == Status::Success) | ||
{ | ||
status = setOnOffValue(endpoint, onOffValueForStartUp, true); | ||
status = setOnOffValue(endpoint, onOffValueForStartUp ? Commands::On::Id : Commands::Off::Id, true); | ||
} | ||
|
||
#if defined(MATTER_DM_PLUGIN_SCENES_MANAGEMENT) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be possible to introduce some state instead of comparing the
moveToLevel
against the limits?