Add eslint & fixes. #8

This commit is contained in:
Koen Kanters
2018-04-18 19:10:33 +02:00
committed by Koenkk
parent 3872d58561
commit dec470fb51
6 changed files with 1004 additions and 10 deletions
+24
View File
@@ -0,0 +1,24 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
"experimentalObjectRestSpread": true
},
"sourceType": "module"
},
"rules": {
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"constructor-super": "warn",
"valid-typeof": "warn"
}
}
+7 -6
View File
@@ -1,6 +1,7 @@
const MQTT = require('./mqtt');
const Zigbee = require('./zigbee');
const logger = require('./util/logger');
const settings = require('./util/settings');
const deviceMapping = require('./devices');
const zigbee2mqtt = require('./converters/zigbee2mqtt');
const mqtt2zigbee = require('./converters/mqtt2zigbee');
@@ -57,7 +58,7 @@ class Controller {
}
// Map Zigbee modelID to vendor modelID.
const modelID = msg.endpoints[0].device.modelId;
const modelID = message.endpoints[0].device.modelId;
const mappedModel = deviceMapping[modelID];
if (!mappedModel) {
@@ -67,11 +68,11 @@ class Controller {
}
// Find a conveter for this message.
const cid = msg.data.cid;
const converters = zigbee2mqtt.filter((c) => c.devices.includes(mappedModel.model) && c.cid === cid && c.type === msg.type);
const cid = message.data.cid;
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 '${msg.type}'`);
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.');
return;
}
@@ -94,7 +95,7 @@ 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 payload = converter.convert(msg, publish);
const payload = converter.convert(message, publish);
if (payload) {
this.stateCache[device.ieeeAddr] = {...this.stateCache[device.ieeeAddr], ...payload};
@@ -126,7 +127,7 @@ class Controller {
}
const message = converter(json[key]);
const callback = (error, response) => {
const callback = (error) => {
// Devices do not report when they go off, this ensures state (on/off) is always in sync.
if (!error && key === 'state') {
this.mqtt.publish(friendlyName, JSON.stringify({state: json[key]}), true);
+3 -3
View File
@@ -29,7 +29,7 @@ const parsers = [
cid: 'genBasic',
type: 'attReport',
disablePublish: true,
convert: (msg, publish) => {
convert: (msg) => {
let voltage = null;
if (msg.data.data['65281']) {
@@ -130,13 +130,13 @@ const parsers = [
devices: ['LED1545G12'],
cid: 'genOnOff',
type: 'devChange',
convert: (msg) => null
convert: () => null
},
{
devices: ['WXKG01LM'],
cid: 'genOnOff',
type: 'devChange',
convert: (msg) => null
convert: () => null
},
];
+1 -1
View File
@@ -55,7 +55,7 @@ class Zigbee {
const devices = this.shepherd.list().filter((device) => device.type !== 'Coordinator');
logger.info(`Currently ${devices.length} devices are joined:`);
devices.forEach((device) => logger.info(getDeviceLogMessage(device)));
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).
+966
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -32,5 +32,8 @@
"zigbee-shepherd": "*",
"zcl-packet": "git+https://github.com/koenkk/zcl-packet.git",
"yaml-config": "*"
},
"devDependencies": {
"eslint": "*"
}
}