Fixes & improvements. #8

This commit is contained in:
Koen Kanters
2018-04-18 20:53:22 +02:00
parent dec470fb51
commit 3b317535d3
4 changed files with 15 additions and 20 deletions
+5 -6
View File
@@ -62,8 +62,8 @@ class Controller {
const mappedModel = deviceMapping[modelID];
if (!mappedModel) {
logger.error(`Device with modelID '${modelID}' is not supported.`);
logger.error('Please create an issue on https://github.com/Koenkk/zigbee2mqtt/issues to add support for your device');
logger.warn(`Device with modelID '${modelID}' is not supported.`);
logger.warn('Please create an issue on https://github.com/Koenkk/zigbee2mqtt/issues to add support for your device');
return;
}
@@ -72,22 +72,21 @@ class Controller {
const converters = zigbee2mqtt.filter((c) => c.devices.includes(mappedModel.model) && c.cid === cid && c.type === message.type);
if (!converters.length) {
logger.error(`No converter available for '${mappedModel.model}' with cid '${cid}' and type '${message.type}'`);
logger.error('Please create an issue on https://github.com/Koenkk/zigbee2mqtt/issues with this message.');
logger.warn(`No converter available for '${mappedModel.model}' with cid '${cid}' and type '${message.type}'`);
logger.warn('Please create an issue on https://github.com/Koenkk/zigbee2mqtt/issues with this message.');
return;
}
// Convert this Zigbee message to a MQTT message.
const friendlyName = settings.get().devices[device.ieeeAddr].friendly_name;
const retain = settings.get().devices[device.ieeeAddr].retain;
const topic = `${settings.get().mqtt.base_topic}/${friendlyName}`;
const publish = (payload) => {
if (this.stateCache[device.ieeeAddr]) {
payload = {...this.stateCache[device.ieeeAddr], ...payload};
}
this.mqtt.publish(topic, JSON.stringify(payload), retain);
this.mqtt.publish(friendlyName, JSON.stringify(payload), retain);
}
// Get payload for the message.
+6 -6
View File
@@ -41,10 +41,10 @@ class MQTT {
clearTimeout(this.connectionTimer);
this.connectionTimer = null;
this.publish('bridge/state', 'offline', true);
logger.info('Disconnecting from MQTT server');
this.client.end();
this.publish('bridge/state', 'offline', true, () => {
logger.info('Disconnecting from MQTT server');
this.client.end();
});
}
handleConnect() {
@@ -59,7 +59,7 @@ class MQTT {
}
}
publish(topic, payload, retain) {
publish(topic, payload, retain, callback) {
topic = `${settings.get().mqtt.base_topic}/${topic}`;
if (!this.client || this.client.reconnecting) {
@@ -69,7 +69,7 @@ class MQTT {
}
logger.info(`MQTT publish, topic: '${topic}', payload: '${payload}'`);
this.client.publish(topic, payload, {retain: retain});
this.client.publish(topic, payload, {retain: retain}, callback);
}
}
+1
View File
@@ -20,4 +20,5 @@ function read() {
module.exports = {
get: () => settings,
write: () => write(),
}
+3 -8
View File
@@ -39,12 +39,7 @@ class Zigbee {
stop(callback) {
this.shepherd.stop((error) => {
if (error) {
logger.error('Error while stopping zigbee-shepherd');
} else {
logger.error('zigbee-shepherd stopped')
}
logger.info('zigbee-shepherd stopped')
callback(error);
});
}
@@ -97,7 +92,7 @@ class Zigbee {
}
if (settings.get().devices[device.ieeeAddr]) {
friendlyName = settings.devices[device.ieeeAddr].friendly_name
friendlyName = settings.get().devices[device.ieeeAddr].friendly_name
}
return `${friendlyName} (${device.ieeeAddr}): ${friendlyDevice.model} - ${friendlyDevice.description}`;
@@ -110,7 +105,7 @@ class Zigbee {
logger.error(`Zigbee cannot publish message to device because '${deviceID}' is not known by zigbee-shepherd`);
}
logger.info(`Zigbee publish to '${deviceID}', ${cId} - ${cmd} - ${zclData}`);
logger.info(`Zigbee publish to '${deviceID}', ${cId} - ${cmd} - ${JSON.stringify(zclData)}`);
device.functional(cId, cmd, zclData, callback);
}
}