mirror of https://github.com/arendst/Tasmota.git
Minor Zigbee improvements
This commit is contained in:
parent
4a44b9fc5f
commit
b2c0a34979
|
@ -123,6 +123,7 @@ public:
|
||||||
|
|
||||||
// Mark data as 'dirty' and requiring to save in Flash
|
// Mark data as 'dirty' and requiring to save in Flash
|
||||||
void dirty(void);
|
void dirty(void);
|
||||||
|
void clean(void); // avoid writing to flash the last changes
|
||||||
|
|
||||||
// Find device by name, can be short_addr, long_addr, number_in_array or name
|
// Find device by name, can be short_addr, long_addr, number_in_array or name
|
||||||
uint16_t parseDeviceParam(const char * param, bool short_must_be_known = false) const;
|
uint16_t parseDeviceParam(const char * param, bool short_must_be_known = false) const;
|
||||||
|
@ -469,23 +470,29 @@ void Z_Devices::setManufId(uint16_t shortaddr, const char * str) {
|
||||||
Z_Device & device = getShortAddr(shortaddr);
|
Z_Device & device = getShortAddr(shortaddr);
|
||||||
if (&device == nullptr) { return; } // don't crash if not found
|
if (&device == nullptr) { return; } // don't crash if not found
|
||||||
_updateLastSeen(device);
|
_updateLastSeen(device);
|
||||||
device.manufacturerId = str;
|
if (!device.manufacturerId.equals(str)) {
|
||||||
dirty();
|
dirty();
|
||||||
}
|
}
|
||||||
|
device.manufacturerId = str;
|
||||||
|
}
|
||||||
void Z_Devices::setModelId(uint16_t shortaddr, const char * str) {
|
void Z_Devices::setModelId(uint16_t shortaddr, const char * str) {
|
||||||
Z_Device & device = getShortAddr(shortaddr);
|
Z_Device & device = getShortAddr(shortaddr);
|
||||||
if (&device == nullptr) { return; } // don't crash if not found
|
if (&device == nullptr) { return; } // don't crash if not found
|
||||||
_updateLastSeen(device);
|
_updateLastSeen(device);
|
||||||
device.modelId = str;
|
if (!device.modelId.equals(str)) {
|
||||||
dirty();
|
dirty();
|
||||||
}
|
}
|
||||||
|
device.modelId = str;
|
||||||
|
}
|
||||||
void Z_Devices::setFriendlyName(uint16_t shortaddr, const char * str) {
|
void Z_Devices::setFriendlyName(uint16_t shortaddr, const char * str) {
|
||||||
Z_Device & device = getShortAddr(shortaddr);
|
Z_Device & device = getShortAddr(shortaddr);
|
||||||
if (&device == nullptr) { return; } // don't crash if not found
|
if (&device == nullptr) { return; } // don't crash if not found
|
||||||
_updateLastSeen(device);
|
_updateLastSeen(device);
|
||||||
device.friendlyName = str;
|
if (!device.friendlyName.equals(str)) {
|
||||||
dirty();
|
dirty();
|
||||||
}
|
}
|
||||||
|
device.friendlyName = str;
|
||||||
|
}
|
||||||
|
|
||||||
const String * Z_Devices::getFriendlyName(uint16_t shortaddr) const {
|
const String * Z_Devices::getFriendlyName(uint16_t shortaddr) const {
|
||||||
int32_t found = findShortAddr(shortaddr);
|
int32_t found = findShortAddr(shortaddr);
|
||||||
|
@ -691,6 +698,9 @@ void Z_Devices::jsonPublishNow(uint16_t shortaddr, JsonObject & values) {
|
||||||
void Z_Devices::dirty(void) {
|
void Z_Devices::dirty(void) {
|
||||||
_saveTimer = kZigbeeSaveDelaySeconds * 1000 + millis();
|
_saveTimer = kZigbeeSaveDelaySeconds * 1000 + millis();
|
||||||
}
|
}
|
||||||
|
void Z_Devices::clean(void) {
|
||||||
|
_saveTimer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse the command parameters for either:
|
// Parse the command parameters for either:
|
||||||
// - a short address starting with "0x", example: 0x1234
|
// - a short address starting with "0x", example: 0x1234
|
||||||
|
|
|
@ -268,6 +268,7 @@ void loadZigbeeDevices(void) {
|
||||||
buf.addBuffer(z_dev_start + sizeof(z_flashdata_t), buf_len);
|
buf.addBuffer(z_dev_start + sizeof(z_flashdata_t), buf_len);
|
||||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Zigbee devices data in Flash (%d bytes)"), buf_len);
|
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Zigbee devices data in Flash (%d bytes)"), buf_len);
|
||||||
hidrateDevices(buf);
|
hidrateDevices(buf);
|
||||||
|
zigbee_devices.clean(); // don't write back to Flash what we just loaded
|
||||||
} else {
|
} else {
|
||||||
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "No zigbee devices data in Flash"));
|
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "No zigbee devices data in Flash"));
|
||||||
}
|
}
|
||||||
|
@ -308,6 +309,7 @@ void saveZigbeeDevices(void) {
|
||||||
|
|
||||||
// Erase the flash area containing the ZigbeeData
|
// Erase the flash area containing the ZigbeeData
|
||||||
void eraseZigbeeDevices(void) {
|
void eraseZigbeeDevices(void) {
|
||||||
|
zigbee_devices.clean(); // avoid writing data to flash after erase
|
||||||
// first copy SPI buffer into ram
|
// first copy SPI buffer into ram
|
||||||
uint8_t *spi_buffer = (uint8_t*) malloc(z_spi_len);
|
uint8_t *spi_buffer = (uint8_t*) malloc(z_spi_len);
|
||||||
if (!spi_buffer) {
|
if (!spi_buffer) {
|
||||||
|
|
|
@ -463,7 +463,7 @@ void CmndZigbeeSend(void) {
|
||||||
if (nullptr != &val_device) { device = strToUInt(val_device); }
|
if (nullptr != &val_device) { device = strToUInt(val_device); }
|
||||||
const JsonVariant &val_endpoint = getCaseInsensitive(json, PSTR("endpoint"));
|
const JsonVariant &val_endpoint = getCaseInsensitive(json, PSTR("endpoint"));
|
||||||
if (nullptr != &val_endpoint) { endpoint = strToUInt(val_endpoint); }
|
if (nullptr != &val_endpoint) { endpoint = strToUInt(val_endpoint); }
|
||||||
const JsonVariant val_cmd = getCaseInsensitive(json, PSTR("Send"));
|
const JsonVariant &val_cmd = getCaseInsensitive(json, PSTR("Send"));
|
||||||
if (nullptr != &val_cmd) {
|
if (nullptr != &val_cmd) {
|
||||||
// probe the type of the argument
|
// probe the type of the argument
|
||||||
// If JSON object, it's high level commands
|
// If JSON object, it's high level commands
|
||||||
|
|
Loading…
Reference in New Issue