mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-16 18:39:09 -07:00
Move logging devices on startup to controller.js. #45
This commit is contained in:
parent
e3c9448656
commit
ca40cf622a
@ -27,6 +27,12 @@ class Controller {
|
||||
if (error) {
|
||||
logger.error('Failed to start');
|
||||
} else {
|
||||
// Log zigbee clients on startup.
|
||||
const devices = this.zigbee.getAllClients();
|
||||
logger.info(`Currently ${devices.length} devices are joined:`);
|
||||
devices.forEach((device) => logger.info(this.getDeviceStartupLogMessage(device)));
|
||||
|
||||
// Connect to MQTT broker
|
||||
const subscriptions = [
|
||||
`${settings.get().mqtt.base_topic}/+/set`,
|
||||
`${settings.get().mqtt.base_topic}/+/+/set`,
|
||||
@ -62,6 +68,21 @@ class Controller {
|
||||
this.zigbee.stop(callback);
|
||||
}
|
||||
|
||||
getDeviceStartupLogMessage(device) {
|
||||
let friendlyName = 'unknown';
|
||||
let friendlyDevice = {model: 'unkown', description: 'unknown'};
|
||||
|
||||
if (deviceMapping[device.modelId]) {
|
||||
friendlyDevice = deviceMapping[device.modelId];
|
||||
}
|
||||
|
||||
if (settings.getDevice(device.ieeeAddr)) {
|
||||
friendlyName = settings.getDevice(device.ieeeAddr).friendly_name
|
||||
}
|
||||
|
||||
return `${friendlyName} (${device.ieeeAddr}): ${friendlyDevice.model} - ${friendlyDevice.vendor} ${friendlyDevice.description}`;
|
||||
}
|
||||
|
||||
handleZigbeeMessage(message) {
|
||||
debug('Recieved zigbee message with data', message.data);
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
const ZShepherd = require('zigbee-shepherd');
|
||||
const logger = require('./util/logger');
|
||||
const settings = require('./util/settings');
|
||||
const deviceMapping = require('./devices');
|
||||
const data = require('./util/data');
|
||||
|
||||
const shepherdSettings = {
|
||||
@ -46,15 +45,9 @@ class Zigbee {
|
||||
}
|
||||
|
||||
handleReady() {
|
||||
logger.info('zigbee-shepherd ready');
|
||||
|
||||
const devices = this.getAllClients();
|
||||
|
||||
logger.info(`Currently ${devices.length} devices are joined:`);
|
||||
devices.forEach((device) => logger.info(this.getDeviceLogMessage(device)));
|
||||
|
||||
// Set all Xiaomi devices (manufId === 4151) to be online, so shepherd won't try
|
||||
// to query info from devices (which would fail because they go tosleep).
|
||||
const devices = this.getAllClients();
|
||||
devices.forEach((device) => {
|
||||
if (device.manufId === 4151) {
|
||||
this.shepherd.find(device.ieeeAddr, 1).getDevice().update({
|
||||
@ -63,6 +56,8 @@ class Zigbee {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
logger.info('zigbee-shepherd ready');
|
||||
}
|
||||
|
||||
permitJoin(permit) {
|
||||
@ -89,21 +84,6 @@ class Zigbee {
|
||||
}
|
||||
}
|
||||
|
||||
getDeviceLogMessage(device) {
|
||||
let friendlyName = 'unknown';
|
||||
let friendlyDevice = {model: 'unkown', description: 'unknown'};
|
||||
|
||||
if (deviceMapping[device.modelId]) {
|
||||
friendlyDevice = deviceMapping[device.modelId];
|
||||
}
|
||||
|
||||
if (settings.getDevice(device.ieeeAddr)) {
|
||||
friendlyName = settings.getDevice(device.ieeeAddr).friendly_name
|
||||
}
|
||||
|
||||
return `${friendlyName} (${device.ieeeAddr}): ${friendlyDevice.model} - ${friendlyDevice.vendor} ${friendlyDevice.description}`;
|
||||
}
|
||||
|
||||
getDevice(deviceID) {
|
||||
return this.shepherd.list().find((d) => d.ieeeAddr === deviceID);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user