Enforce code style. #45

This commit is contained in:
Koenkk
2018-05-17 17:20:46 +02:00
parent 5a95e2fc8c
commit c5cb60e998
16 changed files with 222 additions and 188 deletions
+25 -13
View File
@@ -6,14 +6,15 @@ const deviceMapping = require('./devices');
const zigbee2mqtt = require('./converters/zigbee2mqtt');
const mqtt2zigbee = require('./converters/mqtt2zigbee');
const homeassistant = require('./homeassistant');
const debug = require('debug')('zigbee2mqtt')
const debug = require('debug')('zigbee2mqtt');
const mqttConfigRegex = new RegExp(`${settings.get().mqtt.base_topic}/bridge/config/\\w+`, 'g');
const mqttDeviceRegex = new RegExp(`${settings.get().mqtt.base_topic}/\\w+/set`, 'g');
const mqttDevicePrefixRegex = new RegExp(`${settings.get().mqtt.base_topic}/\\w+/\\w+/set`, 'g');
class Controller {
const issueLink = 'https://github.com/Koenkk/zigbee2mqtt/issues';
class Controller {
constructor() {
this.zigbee = new Zigbee();
this.mqtt = new MQTT();
@@ -36,7 +37,7 @@ class Controller {
const subscriptions = [
`${settings.get().mqtt.base_topic}/+/set`,
`${settings.get().mqtt.base_topic}/+/+/set`,
`${settings.get().mqtt.base_topic}/bridge/config/+`
`${settings.get().mqtt.base_topic}/bridge/config/+`,
];
this.mqtt.connect(this.handleMQTTMessage, subscriptions, () => this.handleStarted());
}
@@ -56,7 +57,7 @@ class Controller {
// Enable zigbee join.
if (settings.get().permit_join) {
logger.warn('`permit_join` set to `true` in configuration.yaml.')
logger.warn('`permit_join` set to `true` in configuration.yaml.');
logger.warn('Allowing new devices to join.');
logger.warn('Set `permit_join` to `false` once you joined all devices.');
this.zigbee.permitJoin(true);
@@ -77,10 +78,11 @@ class Controller {
}
if (settings.getDevice(device.ieeeAddr)) {
friendlyName = settings.getDevice(device.ieeeAddr).friendly_name
friendlyName = settings.getDevice(device.ieeeAddr).friendly_name;
}
return `${friendlyName} (${device.ieeeAddr}): ${friendlyDevice.model} - ${friendlyDevice.vendor} ${friendlyDevice.description}`;
return `${friendlyName} (${device.ieeeAddr}): ${friendlyDevice.model} - ` +
`${friendlyDevice.vendor} ${friendlyDevice.description}`;
}
handleZigbeeMessage(message) {
@@ -121,7 +123,7 @@ class Controller {
if (!mappedModel) {
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');
logger.warn(`Please create an issue on ${issueLink} to add support for your device`);
return;
}
@@ -137,11 +139,15 @@ class Controller {
// Find a conveter for this message.
const cid = message.data.cid;
const converters = zigbee2mqtt.filter((c) => c.devices.includes(mappedModel.model) && c.cid === cid && c.type === message.type);
const converters = zigbee2mqtt.filter((c) =>
c.devices.includes(mappedModel.model) && c.cid === cid && c.type === message.type
);
if (!converters.length) {
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.');
logger.warn(
`No converter available for '${mappedModel.model}' with cid '${cid}' and type '${message.type}'`
);
logger.warn(`Please create an issue on ${issueLink} with this message.`);
return;
}
@@ -151,7 +157,10 @@ class Controller {
// - If NO payload is returned do nothing. This is for non-standard behaviour
// for e.g. click switches where we need to count number of clicks and detect long presses.
converters.forEach((converter) => {
const publish = (payload) => this.mqttPublishDeviceState(device.ieeeAddr, payload, converter.disableCache !== true);
const publish = (payload) => this.mqttPublishDeviceState(
device.ieeeAddr, payload, converter.disableCache !== true
);
const payload = converter.convert(message, publish, settings.getDevice(device.ieeeAddr));
if (payload) {
@@ -185,7 +194,10 @@ class Controller {
const topicPrefix = withPrefix ? topic.split('/')[2] : '';
// Map friendlyName to deviceID.
const deviceID = Object.keys(settings.get().devices).find((id) => settings.getDevice(id).friendly_name === friendlyName);
const deviceID = Object.keys(settings.get().devices).find((id) =>
settings.getDevice(id).friendly_name === friendlyName
);
if (!deviceID) {
logger.error(`Cannot handle '${topic}' because deviceID of '${friendlyName}' cannot be found`);
return;
@@ -247,4 +259,4 @@ class Controller {
}
}
module.exports = Controller;
module.exports = Controller;