Support both DeviceID and FriendlyName in device control topic (#476)

This commit is contained in:
Stanislav Demydiuk
2018-10-30 21:23:34 +01:00
committed by Koen Kanters
parent 61c4ff33e0
commit 1e7f985d4e
+3 -7
View File
@@ -42,15 +42,11 @@ class DeviceCommand {
// Parse topic
const hasPrefix = topic.match(setWithPrefixTopic);
const friendlyName = topic.split('/').slice(hasPrefix ? -3 : -2)[0];
const deviceKey = topic.split('/').slice(hasPrefix ? -3 : -2)[0]; // Could be friendlyName or ieeeAddr
const prefix = hasPrefix ? topic.split('/').slice(-2)[0] : '';
// Map friendlyName to ieeeAddr.
const ieeeAddr = settings.getIeeAddrByFriendlyName(friendlyName);
if (!ieeeAddr) {
logger.error(`Cannot handle '${topic}' because ieeAddr of '${friendlyName}' cannot be found`);
return;
}
// Map friendlyName to ieeeAddr if possible.
const ieeeAddr = settings.getIeeAddrByFriendlyName(deviceKey) || deviceKey;
// Get device
const device = this.zigbee.getDevice(ieeeAddr);