Skip to content
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: ias zone using wrong endpoint #61

Merged
merged 1 commit into from
May 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions templates/src/extenders/sensors/ias_zone.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ static const struct gpio_dt_spec {{.Sensor.Pin.Label}} = GPIO_DT_SPEC_GET(DT_NOD
#define ZBHOME_IAS_ZONE_TOP_LEVEL

#define ZB_SCHEDULE_CALLBACK ZB_SCHEDULE_APP_CALLBACK
void update_zone_status(zb_bufid_t bufid, bool status) {
void update_zone_status(zb_bufid_t bufid, zb_uint16_t cb_data) {
// TODO: Probably this function needs to free bufid somewhere,
// but I am not sure if it is actually the case.
// Would need to double-check.

// Decode values from the argument.
bool status = cb_data & 1;
zb_uint8_t endpoint = cb_data >> 1;

switch (status) {
case true:
ZB_ZCL_IAS_ZONE_SET_BITS(bufid, 2, ZB_ZCL_IAS_ZONE_ZONE_STATUS_ALARM1);
ZB_ZCL_IAS_ZONE_SET_BITS(bufid, endpoint, ZB_ZCL_IAS_ZONE_ZONE_STATUS_ALARM1);
break;
case false:
ZB_ZCL_IAS_ZONE_CLEAR_BITS(bufid, 2, ZB_ZCL_IAS_ZONE_ZONE_STATUS_ALARM1);
ZB_ZCL_IAS_ZONE_CLEAR_BITS(bufid, endpoint, ZB_ZCL_IAS_ZONE_ZONE_STATUS_ALARM1);
break;
}
}
Expand All @@ -29,9 +34,13 @@ void update_zone_status(zb_bufid_t bufid, bool status) {
{{ define "button_changed"}}
button_status = has_button_changed(&{{.Sensor.Pin.Label}}, button_state, has_changed);
if (button_status.has_changed) {
// Pack data.
// Endpoint can be >127, so we can't pack it and state into single uint8.
zb_uint16_t data = {{.Endpoint}} << 1 | button_status.state;

/* Allocate output buffer and send on/off command. */
zb_ret_t zb_err_code = zb_buf_get_out_delayed_ext(
update_zone_status, button_status.state, 0);
update_zone_status, data, 0);
ZB_ERROR_CHECK(zb_err_code);
}
{{end}}
Expand Down