ClusterChangeAttribute.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. *
  3. * Copyright (c) 2021 Project CHIP Authors
  4. * All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "LevelManager.h"
  19. #include "OnOffManager.h"
  20. #include <app-common/zap-generated/ids/Attributes.h>
  21. #include <app-common/zap-generated/ids/Clusters.h>
  22. #include <app/ConcreteAttributePath.h>
  23. #include <lib/support/logging/CHIPLogging.h>
  24. using namespace chip;
  25. using namespace ::chip::app::Clusters;
  26. void MatterPostAttributeChangeCallback(const app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size,
  27. uint8_t * value)
  28. {
  29. if (attributePath.mClusterId == OnOff::Id && attributePath.mAttributeId == OnOff::Attributes::OnOff::Id)
  30. {
  31. bool onoff = static_cast<bool>(*value);
  32. ChipLogProgress(Zcl, "Received on/off command endpoint %d value = %d", static_cast<int>(attributePath.mEndpointId), onoff);
  33. OnOffManager().PostOnOffChanged(attributePath.mEndpointId, onoff);
  34. }
  35. else if (attributePath.mClusterId == LevelControl::Id &&
  36. attributePath.mAttributeId == LevelControl::Attributes::CurrentLevel::Id)
  37. {
  38. uint8_t level = *value;
  39. ChipLogProgress(Zcl, "Received level command endpoint %d value = %d", static_cast<int>(attributePath.mEndpointId), level);
  40. LevelManager().PostLevelChanged(attributePath.mEndpointId, level);
  41. }
  42. }