Skip to content

Commit 46d35f5

Browse files
committed
fix(matter): it shuold work even when no callback is set
1 parent 0a99d69 commit 46d35f5

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

Diff for: libraries/Matter/src/MatterEndpoints/MatterDimmableLight.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ bool MatterDimmableLight::attributeChangeCB(uint16_t endpoint_id, uint32_t clust
3333
log_d("Dimmable Attr update callback: endpoint: %u, cluster: %u, attribute: %u, val: %u", endpoint_id, cluster_id, attribute_id, val->val.u32);
3434

3535
if (endpoint_id == getEndPointId()) {
36-
bool ret = false;
36+
bool ret = true;
3737
switch(cluster_id) {
3838
case OnOff::Id:
3939
if (attribute_id == OnOff::Attributes::OnOff::Id) {
4040
log_d("DimmableLight On/Off State changed to %d", val->val.b);
4141
if (_onChangeOnOffCB != NULL) {
42-
ret |= _onChangeOnOffCB(val->val.b);
42+
ret &= _onChangeOnOffCB(val->val.b);
4343
}
4444
if (_onChangeCB != NULL) {
45-
ret |= _onChangeCB(val->val.b, brightnessLevel);
45+
ret &= _onChangeCB(val->val.b, brightnessLevel);
4646
}
4747
if (ret == true) {
4848
onOffState = val->val.b;
@@ -53,10 +53,10 @@ bool MatterDimmableLight::attributeChangeCB(uint16_t endpoint_id, uint32_t clust
5353
if (attribute_id == LevelControl::Attributes::CurrentLevel::Id) {
5454
log_d("DimmableLight Brightness changed to %d", val->val.u8);
5555
if (_onChangeBrightnessCB != NULL) {
56-
ret |= _onChangeBrightnessCB(val->val.u8);
56+
ret &= _onChangeBrightnessCB(val->val.u8);
5757
}
5858
if (_onChangeCB != NULL) {
59-
ret |= _onChangeCB(onOffState, val->val.u8);
59+
ret &= _onChangeCB(onOffState, val->val.u8);
6060
}
6161
if (ret == true) {
6262
brightnessLevel = val->val.u8;

Diff for: libraries/Matter/src/MatterEndpoints/MatterOnOffLight.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ bool MatterOnOffLight::attributeChangeCB(uint16_t endpoint_id, uint32_t cluster_
3333
log_d("OnOff Attr update callback: endpoint: %u, cluster: %u, attribute: %u, val: %u", endpoint_id, cluster_id, attribute_id, val->val.u32);
3434

3535
if (endpoint_id == getEndPointId()) {
36+
log_d("OnOffLight state changed to %d", val->val.b);
37+
bool ret = true;
3638
if (cluster_id == OnOff::Id) {
3739
if (attribute_id == OnOff::Attributes::OnOff::Id) {
40+
if (_onChangeOnOffCB != NULL) {
41+
ret &= _onChangeOnOffCB(val->val.b);
42+
}
3843
if (_onChangeCB != NULL) {
39-
ret = _onChangeCB(val->val.b);
40-
log_d("OnOffLight state changed to %d", val->val.b);
41-
if (ret == true) {
42-
onOffState = val->val.b;
43-
}
44+
ret &= _onChangeCB(val->val.b);
45+
}
46+
if (ret == true) {
47+
onOffState = val->val.b;
4448
}
4549
}
4650
}

Diff for: libraries/Matter/src/MatterEndpoints/MatterOnOffLight.h

+4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ class MatterOnOffLight : public MatterEndPoint {
4343
void onChange(EndPointCB onChangeCB) {
4444
_onChangeCB = onChangeCB;
4545
}
46+
void onChangeOnOff(EndPointCB onChangeCB) {
47+
_onChangeOnOffCB = onChangeCB;
48+
}
4649

4750
protected:
4851
bool started = false;
4952
bool onOffState = false; // default initial state is off, but it can be changed by begin(bool)
5053
EndPointCB _onChangeCB = NULL;
54+
EndPointCB _onChangeOnOffCB = NULL;
5155
};
5256
#endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */

0 commit comments

Comments
 (0)