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

Add option to remove the device addr from json payload #10355

Merged
merged 3 commits into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions tasmota/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t mi32_enable : 1; // bit 1 (v9.1.0.1) - SetOption115 - (ESP32 BLE) Enable ESP32 MI32 BLE (1)
uint32_t zb_disable_autoquery : 1; // bit 2 (v9.1.0.1) - SetOption116 - (Zigbee) Disable auto-query of zigbee lights and devices (1)
uint32_t fade_fixed_duration : 1; // bit 3 (v9.1.0.2) - SetOption117 - (Light) run fading at fixed duration instead of fixed slew rate
uint32_t spare04 : 1; // bit 4
uint32_t spare05 : 1; // bit 5
uint32_t zb_received_as_subtopic : 1; // bit 4 (v9.2.0.3) - SetOption118 - (Zigbee) Move ZbReceived form JSON message and into the subtopic replacing "SENSOR" default
uint32_t zb_omit_json_addr : 1; // bit 5 (v9.2.0.3) - SetOption119 - (Zigbee) Remove the device addr from json payload, can be used with zb_topic_fname where the addr is already known from the topic
uint32_t spare06 : 1; // bit 6
uint32_t spare07 : 1; // bit 7
uint32_t spare08 : 1; // bit 8
Expand Down
27 changes: 19 additions & 8 deletions tasmota/xdrv_23_zigbee_2a_devices_impl.ino
Original file line number Diff line number Diff line change
Expand Up @@ -511,25 +511,33 @@ void Z_Device::jsonPublishAttrList(const char * json_prefix, const Z_attribute_l

TasmotaGlobal.mqtt_data[0] = 0; // clear string
// Do we prefix with `ZbReceived`?
if (!Settings.flag4.remove_zbreceived) {
if (!Settings.flag4.remove_zbreceived && !Settings.flag5.zb_received_as_subtopic) {
Response_P(PSTR("{\"%s\":"), json_prefix);
}
// What key do we use, shortaddr or name?
if (use_fname) {
Response_P(PSTR("%s{\"%s\":{"), TasmotaGlobal.mqtt_data, friendlyName);
} else {
Response_P(PSTR("%s{\"0x%04X\":{"), TasmotaGlobal.mqtt_data, shortaddr);
if (!Settings.flag5.zb_omit_json_addr) {
if (use_fname) {
Response_P(PSTR("%s{\"%s\":"), TasmotaGlobal.mqtt_data, friendlyName);
} else {
Response_P(PSTR("%s{\"0x%04X\":"), TasmotaGlobal.mqtt_data, shortaddr);
}
}
ResponseAppend_P(PSTR("{"));

// Add "Device":"0x...."
ResponseAppend_P(PSTR("\"" D_JSON_ZIGBEE_DEVICE "\":\"0x%04X\","), shortaddr);
// Add "Name":"xxx" if name is present
if (friendlyName) {
ResponseAppend_P(PSTR("\"" D_JSON_ZIGBEE_NAME "\":\"%s\","), EscapeJSONString(friendlyName).c_str());
}
// Add all other attributes
ResponseAppend_P(PSTR("%s}}"), attr_list.toString(false).c_str());
ResponseAppend_P(PSTR("%s}"), attr_list.toString(false).c_str());

if (!Settings.flag5.zb_omit_json_addr) {
ResponseAppend_P(PSTR("}"));
}

if (!Settings.flag4.remove_zbreceived) {
if (!Settings.flag4.remove_zbreceived && !Settings.flag5.zb_received_as_subtopic) {
ResponseAppend_P(PSTR("}"));
}

Expand All @@ -545,7 +553,10 @@ void Z_Device::jsonPublishAttrList(const char * json_prefix, const Z_attribute_l
snprintf_P(subtopic, sizeof(subtopic), PSTR("%s/%04X"), TasmotaGlobal.mqtt_topic, shortaddr);
}
char stopic[TOPSZ];
GetTopic_P(stopic, TELE, subtopic, D_RSLT_SENSOR);
if (Settings.flag5.zb_received_as_subtopic)
GetTopic_P(stopic, TELE, subtopic, json_prefix);
else
GetTopic_P(stopic, TELE, subtopic, D_RSLT_SENSOR);
MqttPublish(stopic, Settings.flag.mqtt_sensor_retain);
} else {
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
Expand Down