mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-07-09 13:31:41 +00:00
ADD Rename Function via MQTT Command
This commit is contained in:
+36
-1
@@ -400,7 +400,42 @@ class Controller {
|
||||
} else {
|
||||
cleanup();
|
||||
}
|
||||
} else {
|
||||
} else if (option === 'rename') {
|
||||
// Convert the MQTT message to a Zigbee message.
|
||||
let json = null;
|
||||
try {
|
||||
json = JSON.parse(message);
|
||||
} catch (e) {
|
||||
// Cannot be parsed to JSON, assume state message.
|
||||
return;
|
||||
}
|
||||
if (!json.hasOwnProperty('oldname')) {
|
||||
logger.error('Failed to renamed - oldname property is missing');
|
||||
return;
|
||||
}
|
||||
if (!json.hasOwnProperty('newname')) {
|
||||
logger.error('Failed to renamed - newname property is missing');
|
||||
return;
|
||||
}
|
||||
if(json.oldname.toString() == null || json.oldname.toString() == '' || json.oldname.toString().length <= 0) {
|
||||
logger.error('Failed to renamed - oldname value is missing or Null');
|
||||
return;
|
||||
}
|
||||
if(json.newname.toString() == null || json.newname.toString() == '' || json.newname.toString().length <= 0) {
|
||||
logger.error('Failed to renamed - newname value is missing or Null');
|
||||
return;
|
||||
}
|
||||
if(json.newname.toString() === json.oldname.toString()) {
|
||||
logger.error(`Failed to renamed - ${json.oldname} and ${json.newname} seem to be eqal.`);
|
||||
return;
|
||||
}
|
||||
const renamed = settings.RenameFriendlyName(json.oldname,json.newname);
|
||||
if(renamed) {
|
||||
logger.info(`Successfully renamed - ${json.oldname} to ${json.newname} `);
|
||||
}else {
|
||||
logger.error(`Failed to renamed - ${json.oldname} to ${json.newname}`);
|
||||
}
|
||||
} else {
|
||||
logger.warn(`Cannot handle MQTT config option '${option}' with message '${message}'`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user