Compare commits

...
27 Commits
Author SHA1 Message Date
Koenkk a4da482225 0.1.7 2018-10-15 17:37:06 +02:00
Koenkk 98302bebd1 Update zigbee-shepherd-converters to 4.0.3 2018-10-09 21:28:32 +02:00
AnhDuc85 2197328db5 add homeassistant config for Osram Outdoor Lantern W RGBW OSRAM (#464) 2018-10-09 20:47:29 +02:00
Koen Kanters c5b9176614 Fix unique_id being set when not all devices have a friendly_name. 2018-10-08 20:25:04 +02:00
Laurent 0322354c37 [RFC] graphviz network map, display all devices (#443)
* network map, more info

* add a get(All)Devices method to zigbee

* graphviz: display all devices

loop through all devices, display all devices even those that haven't
responded to the lqi scan.

* makes eslint happy :)

* remove null chars from network map graphviz output

makes graphviz happy :-)

* Improvements to graphviz network map

* Always add device type
2018-10-07 21:46:54 +02:00
Koenkk b692c94fe9 Update zigbee-shepherd. https://github.com/Koenkk/zigbee-shepherd/pull/6 2018-10-05 22:08:47 +02:00
Koenkk 1496861811 Fix https://github.com/Koenkk/zigbee2mqtt/issues/373 again. 2018-10-05 20:54:57 +02:00
Koen Kanters 5459152f01 Fix Koenkk. #451 2018-10-05 19:35:23 +02:00
Koenkk 1db926173d Refactor router polling & only poll Xiaomi routers, refactor soft reset timeout and disable by default. #274 2018-10-02 21:15:12 +02:00
Koenkk da9ee71d80 Fix crash when deviceSettings are missing. 2018-10-02 20:35:14 +02:00
Phil Hawthorne d9f02230a0 Add autodiscovery support for Sylvania MR16 (#435)
Adds auto discovery support for the MR16 smart bulbs from
Osram/Sylvania.
2018-10-01 16:39:23 +02:00
Koenkk bf68f4575f Update zigbee-shepherd-converters to 4.0.2 2018-09-29 23:05:18 +02:00
Koenkk 33ea08ad22 Update dependencies for. #388 2018-09-29 23:05:18 +02:00
UnrealKazu 3a17db7c79 Add support for TRADFRI Control Outlet (#413)
The control outlet is a switch, hence the switch configuration.
2018-09-29 23:05:18 +02:00
Koenkk e55252b9ff Mock state ON when moveToLevelWithOnOff succeeds. https://github.com/Koenkk/zigbee-shepherd-converters/pull/81 2018-09-29 23:05:18 +02:00
Koenkk 71d12c3c71 Revert "Allow joining through specified device."
This reverts commit bf85ea1494.
2018-09-29 23:05:18 +02:00
Koenkk bc7b2bd5e0 Allow joining through specified device. 2018-09-29 23:05:18 +02:00
Koenkk 50d58d3dff Always call zigbee shepherd permit join (in both true and false). 2018-09-29 23:05:18 +02:00
Koenkk 4180bd8933 Add friendly_name to graphviz network map. #252 2018-09-29 23:05:18 +02:00
Koenkk 172d11677b Update zigbee-shepherd-converters. 2018-09-29 23:05:18 +02:00
Plácido Revilla ab5537e18c Add support for GE 45857 in-wall smart dimmer (#394)
* Add support for homeassistant discovery of E11-N1EA

* Add support for GE 45857 in-wall smart dimmer
2018-09-29 23:05:18 +02:00
Viet Dzung b06e3b61f2 Support cfg in foundation and functional (#390)
* Support cfg in foundation and functional

* Update zigbee-shepherd-converters.
2018-09-29 23:05:18 +02:00
Stanislav Demydiuk 03d913defc Add ability to send device information in MQTT message payload (#374) 2018-09-29 23:05:18 +02:00
Koenkk e4bcac5411 Update zigbee-shepherd. https://github.com/Koenkk/zigbee-shepherd/pull/4 2018-09-29 23:05:18 +02:00
Koenkk 5ed29d045b 0.1.6 2018-09-23 11:21:24 +02:00
Koen Kanters 75acffa8c7 Fix topicPrefix parsing. #387 2018-09-21 11:12:51 +02:00
Koenkk ade84dc6c0 Fix MQTT command with prefix, introduced in #c22f8b3. #387 2018-09-20 16:16:57 +02:00
12 changed files with 321 additions and 169 deletions
+2 -1
View File
@@ -1,10 +1,11 @@
{
"env": {
"es6": true,
"node": true
},
"extends": ["eslint:recommended", "google"],
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
+1 -1
View File
@@ -39,6 +39,6 @@ If you need assistance you can check [opened issues](https://github.com/Koenkk/z
* [AndrewLinden](https://github.com/AndrewLinden)
* [oskarn97](https://github.com/oskarn97)
* [dgomes](https://github.com/dgomes)
* [Koenkk](https://github.com/Koenk)
* [Koenkk](https://github.com/Koenkk)
* [kirovilya](https://github.com/kirovilya)
* [ciotlosm](https://github.com/ciotlosm)
+57 -77
View File
@@ -4,17 +4,16 @@ const State = require('./state');
const logger = require('./util/logger');
const settings = require('./util/settings');
const ExtensionNetworkMap = require('./extension/networkMap');
const ExtensionSoftReset = require('./extension/softReset');
const ExtensionRouterPollXiaomi = require('./extension/routerPollXiaomi');
const zigbeeShepherdConverters = require('zigbee-shepherd-converters');
const homeassistant = require('./homeassistant');
const objectAssignDeep = require(`object-assign-deep`);
const objectAssignDeep = require('object-assign-deep');
const mqttConfigRegex = new RegExp(`${settings.get().mqtt.base_topic}/bridge/config/\\w+`, 'g');
const mqttDeviceRegex = new RegExp(`${settings.get().mqtt.base_topic}/[\\w\\s\\d.-]+/set`, 'g');
const mqttDevicePrefixRegex = new RegExp(`${settings.get().mqtt.base_topic}/[\\w\\s\\d.-]
+/[\\w\\s\\d.-]+/set`, 'g');
const mqttDevicePrefixRegex = new RegExp(`${settings.get().mqtt.base_topic}/[\\w\\s\\d.-]+/[\\w\\s\\d.-]+/set`, 'g');
const pollInterval = 60 * 1000; // seconds * 1000.
const softResetTimeout = 3600 * 1000; // seconds * 1000.
const allowedLogLevels = ['error', 'warn', 'info', 'debug'];
@@ -33,17 +32,19 @@ if (settings.get().homeassistant && !cacheState) {
class Controller {
constructor() {
this.zigbee = new Zigbee();
this.handleZigbeeMessage = this.handleZigbeeMessage.bind(this);
this.handleMQTTMessage = this.handleMQTTMessage.bind(this);
this.zigbee = new Zigbee(this.handleZigbeeMessage);
this.mqtt = new MQTT();
this.state = new State();
this.configured = [];
this.handleZigbeeMessage = this.handleZigbeeMessage.bind(this);
this.handleMQTTMessage = this.handleMQTTMessage.bind(this);
this.extensions = [];
}
start() {
this.startupLogVersion(() => {
this.zigbee.start(this.handleZigbeeMessage, (error) => {
this.zigbee.start((error) => {
if (error) {
logger.error('Failed to start', error);
} else {
@@ -60,12 +61,9 @@ class Controller {
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);
}
// Start timers.
this.pollTimer(true);
this.softResetTimeout(true);
this.zigbee.permitJoin(settings.get().permit_join);
// Connect to MQTT broker
const subscriptions = [
@@ -99,6 +97,8 @@ class Controller {
// Initialize extensions.
this.extensions = [
new ExtensionNetworkMap(this.zigbee, this.mqtt, this.state),
new ExtensionSoftReset(this.zigbee, this.mqtt, this.state),
new ExtensionRouterPollXiaomi(this.zigbee, this.mqtt, this.state),
];
// Resend all cached states.
@@ -108,62 +108,15 @@ class Controller {
sendAllCachedStates() {
this.zigbee.getAllClients().forEach((device) => {
if (this.state.exists(device.ieeeAddr)) {
this.mqttPublishDeviceState(device.ieeeAddr, this.state.get(device.ieeeAddr), false);
this.mqttPublishDeviceState(device, this.state.get(device.ieeeAddr), false);
}
});
}
softResetTimeout(start) {
if (this._softResetTimer) {
clearTimeout(this._softResetTimer);
this._softResetTimer = null;
}
if (start) {
this._softResetTimer = setTimeout(() => {
this.zigbee.softReset((error) => {
if (error) {
logger.warn('Soft reset error', error);
this.zigbee.stop((error) => {
logger.warn('Zigbee stopped');
this.zigbee.start(this.handleZigbeeMessage, (error) => {
if (error) {
logger.error('Failed to restart!');
}
});
});
} else {
logger.warn('Soft resetted zigbee');
}
this.softResetTimeout(true);
});
}, softResetTimeout);
}
}
pollTimer(start) {
// Some routers need polling to prevent them from sleeping.
if (start && !this._pollTimer) {
this._pollTimer = setInterval(() => {
const devices = this.zigbee.getAllClients().filter((d) => {
const power = d.powerSource ? d.powerSource.toLowerCase().split(' ')[0] : 'unknown';
return power !== 'battery' && power !== 'unknown' && d.type === 'Router';
});
devices.forEach((d) => this.zigbee.ping(d.ieeeAddr));
}, pollInterval);
} else if (!start && this._pollTimer) {
clearTimeout(this._pollTimer);
this._pollTimer = null;
}
}
stop(callback) {
this.extensions.filter((e) => e.stop).forEach((e) => e.stop());
this.state.save();
this.mqtt.disconnect();
this.pollTimer(false);
this.softResetTimeout(false);
this.zigbee.stop(callback);
}
@@ -217,9 +170,26 @@ class Controller {
`${friendlyDevice.vendor} ${friendlyDevice.description} (${type})`;
}
getDeviceInfoForMqtt(device) {
const {type, ieeeAddr, nwkAddr, manufId, manufName, powerSource, modelId, status} = device;
const deviceSettings = settings.getDevice(device.ieeeAddr);
return {
ieeeAddr,
friendlyName: deviceSettings.friendly_name || '',
type,
nwkAddr,
manufId,
manufName,
powerSource,
modelId,
status,
};
}
handleZigbeeMessage(message) {
// Zigbee message receieved, reset soft reset timeout.
this.softResetTimeout(true);
// Call extensions.
this.extensions.filter((e) => e.handleZigbeeMessage).forEach((e) => e.handleZigbeeMessage(message));
// Log the message.
let logMessage = `Recieved zigbee message of type '${message.type}' ` +
@@ -338,7 +308,7 @@ class Controller {
payload.linkquality = message.linkquality;
}
this.mqttPublishDeviceState(device.ieeeAddr, payload, cache);
this.mqttPublishDeviceState(device, payload, cache);
};
const payload = converter.convert(mappedModel, message, publish, settings.getDevice(device.ieeeAddr));
@@ -479,8 +449,8 @@ class Controller {
}
handleMQTTMessageDevice(topic, message, withPrefix) {
const friendlyName = topic.split('/').slice(-2)[0];
const topicPrefix = withPrefix ? topic.split('/').slice(-3)[0] : '';
const friendlyName = topic.split('/').slice(withPrefix ? -3 : -2)[0];
const topicPrefix = withPrefix ? topic.split('/').slice(-2)[0] : '';
// Map friendlyName to deviceID.
const deviceID = settings.getIDByFriendlyName(friendlyName);
@@ -533,15 +503,16 @@ class Controller {
const callback = (error) => {
// Devices do not report when they go off, this ensures state (on/off) is always in sync.
if (!error && key.startsWith('state')) {
if (!error && (key.startsWith('state') || key === 'brightness')) {
const msg = {};
const _key = topicPrefix ? `${key}_${topicPrefix}` : key;
msg[_key] = json[key];
this.mqttPublishDeviceState(deviceID, msg, true);
const _key = topicPrefix ? `state_${topicPrefix}` : 'state';
msg[_key] = key === 'brightness' ? 'ON' : json['state'];
this.mqttPublishDeviceState(device, msg, true);
}
};
this.zigbee.publish(deviceID, message.cid, message.cmd, message.zclData, ep, message.type, callback);
this.zigbee.publish(deviceID, message.cid, message.cmd, message.zclData,
message.cfg, ep, message.type, callback);
published.push({message: message, converter: converter});
});
@@ -576,11 +547,15 @@ class Controller {
});
}
mqttPublishDeviceState(deviceID, payload, cache) {
mqttPublishDeviceState(device, payload, cache) {
const deviceID = device.ieeeAddr;
const appSettings = settings.get();
let messagePayload = {...payload};
if (cacheState) {
// Add cached state to payload
if (this.state.exists(deviceID)) {
payload = objectAssignDeep.noMutate(this.state.get(deviceID), payload);
messagePayload = objectAssignDeep.noMutate(this.state.get(deviceID), payload);
}
// Update state cache with new state.
@@ -590,12 +565,17 @@ class Controller {
}
const deviceSettings = settings.getDevice(deviceID);
const friendlyName = deviceSettings ? deviceSettings.friendly_name : deviceID;
const options = {
retain: deviceSettings.retain,
qos: deviceSettings.qos ? deviceSettings.qos : 0,
retain: deviceSettings ? deviceSettings.retain : false,
qos: deviceSettings && deviceSettings.qos ? deviceSettings.qos : 0,
};
this.mqtt.publish(deviceSettings.friendly_name, JSON.stringify(payload), options);
if (appSettings.mqtt.include_device_information) {
messagePayload.device = this.getDeviceInfoForMqtt(device);
}
this.mqtt.publish(friendlyName, JSON.stringify(messagePayload), options);
}
startupLogVersion(callback) {
+44 -8
View File
@@ -1,5 +1,6 @@
const settings = require('../util/settings');
const zigbeeShepherdConverters = require('zigbee-shepherd-converters');
class NetworkMap {
constructor(zigbee, mqtt, state) {
@@ -23,7 +24,7 @@ class NetworkMap {
if (topic === this.topic && this.supportedFormats.hasOwnProperty(message)) {
this.zigbee.networkScan((result)=> {
const converted = this.supportedFormats[message](result);
const converted = this.supportedFormats[message](this.zigbee, result);
this.mqtt.publish(`bridge/networkmap/${message}`, converted, {});
});
@@ -31,20 +32,55 @@ class NetworkMap {
}
}
raw(topology) {
raw(zigbee, topology) {
return JSON.stringify(topology);
}
graphviz(topology) {
let text = 'digraph G {\n';
topology.forEach((item) => {
text += ` "${item.ieeeAddr}" [label="${item.ieeeAddr} (${item.status})"];\n`;
text += ` "${item.ieeeAddr}" -> "${item.parent}" [label="${item.lqi}"]\n`;
graphviz(zigbee, topology) {
let text = 'digraph G {\nnode[shape=record];\n';
const lqiDevices = new Map(topology.map((d) => [d.ieeeAddr, d]));
zigbee.getDevices().forEach((device) => {
const labels = [];
const friendlyDevice = settings.getDevice(device.ieeeAddr);
const friendlyName = friendlyDevice ? friendlyDevice.friendly_name : device.ieeeAddr;
// Add friendly name
labels.push(friendlyName);
// Add the device type
labels.push(device.type);
// Add the device model
const mappedModel = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
if (mappedModel) {
labels.push(`${mappedModel.vendor} ${mappedModel.description} (${mappedModel.model})`);
} else {
// This model is not supported by zigbee-shepherd-converters, add zigbee model information, if available
const zigbeeModel = [device.manufName, device.modelId].filter((a) => a).join(' ');
labels.push(zigbeeModel ? zigbeeModel : 'No model information available');
}
// Add the device status (online/offline)
labels.push(device.status);
// Add the device with its labels to the graph as a node.
text += ` "${device.ieeeAddr}" [label="{${labels.join('|')}}"];\n`;
/**
* Add an edge between the device and its parent to the graph
* NOTE: There are situations where a device is NOT in the topology, this can be e.g.
* due to not responded to the lqi scan. In that case we do not add an edge for this device.
*/
const lqiDevice = lqiDevices.get(device.ieeeAddr);
if (lqiDevice != undefined) {
text += ` "${device.ieeeAddr}" -> "${lqiDevice.parent}" [label="${lqiDevice.lqi}"]\n`;
}
});
text += '}';
return text;
return text.replace(/\0/g, '');
}
}
+40
View File
@@ -0,0 +1,40 @@
const utils = require('../util/utils');
const interval = utils.secondsToMilliseconds(60);
/**
* This extensions polls Xiaomi Zigbee routers to keep them awake.
*/
class RouterPollXiaomi {
constructor(zigbee, mqtt, state) {
this.zigbee = zigbee;
this.timer = null;
this.startTimer();
}
startTimer() {
this.clearTimer();
this.timer = setInterval(() => this.handleInterval(), interval);
}
clearTimer() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}
stop() {
this.clearTimer();
}
handleInterval() {
this.zigbee.getAllClients()
.filter((d) => utils.isXiaomiDevice(d)) // Filter Xiaomi devices
.filter((d) => d.type === 'Router') // Filter routers
.filter((d) => d.powerSource && d.powerSource !== 'Battery') // Remove battery powered devices
.forEach((d) => this.zigbee.ping(d.ieeeAddr)); // Ping devices.
}
}
module.exports = RouterPollXiaomi;
+66
View File
@@ -0,0 +1,66 @@
const settings = require('../util/settings');
const logger = require('../util/logger');
const utils = require('../util/utils');
/**
* This extensions soft resets the ZNP after a certain timeout.
*/
class SoftReset {
constructor(zigbee, mqtt, state) {
this.zigbee = zigbee;
this.timer = null;
this.timeout = utils.secondsToMilliseconds(settings.get().advanced.soft_reset_timeout);
if (this.timeout === 0) {
logger.debug(`Soft reset timeout disabled`);
} else {
logger.debug(`Soft reset timeout set to ${utils.millisecondsToSeconds(this.timeout)} seconds`);
}
this.resetTimer();
}
clearTimer() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}
resetTimer() {
if (this.timeout === 0) {
return;
}
this.clearTimer();
this.timer = setTimeout(() => this.handleTimeout(), this.timeout);
}
handleTimeout() {
logger.warn('Soft reset timeout triggered');
this.zigbee.softReset((error) => {
if (error) {
logger.warn('Soft reset failed, trying stop/start');
this.zigbee.stop((error) => {
logger.warn('Zigbee stopped');
this.zigbee.start((error) => {
if (error) {
logger.error('Failed to restart!');
}
});
});
} else {
logger.warn('Soft resetted ZNP due to timeout');
}
this.resetTimer();
});
}
handleZigbeeMessage(message) {
this.resetTimer();
}
}
module.exports = SoftReset;
+17 -5
View File
@@ -54,7 +54,7 @@ const configurations = {
payload_off: false,
value_template: '{{ value_json.gas }}',
device_class: 'gas',
json_attributes: [],
json_attributes: ['sensitivity'],
},
},
'binary_sensor_router': {
@@ -136,7 +136,10 @@ const configurations = {
discovery_payload: {
icon: 'mdi:gesture-double-tap',
value_template: '{{ value_json.action }}',
json_attributes: ['battery', 'voltage', 'angle', 'side', 'from_side', 'to_side', 'brightness'],
json_attributes: [
'battery', 'voltage', 'angle', 'side', 'from_side', 'to_side', 'brightness',
'angle_x_absolute', 'angle_y_absolute', 'angle_z', 'angle_y', 'angle_x', 'unknown_data',
],
force_update: true,
},
},
@@ -262,6 +265,7 @@ const mapping = {
'PLUG EDP RE:DY': [configurations.switch, configurations.sensor_power],
'CC2530.ROUTER': [configurations.binary_sensor_router],
'AA70155': [configurations.light_brightness_colortemp],
'4058075816718': [configurations.light_brightness_colortemp_xy],
'AA69697': [configurations.light_brightness_colortemp_xy],
'HALIGHTDIMWWE27': [configurations.light_brightness],
'AB3257001NJ': [configurations.switch],
@@ -315,7 +319,7 @@ const mapping = {
'GL-C-008': [configurations.light_brightness_colortemp_xy],
'STSS-MULT-001': [configurations.binary_sensor_contact],
'E11-G23': [configurations.light_brightness],
'AC03845': [configurations.light_brightness_colortemp_xy],
'AC03645': [configurations.light_brightness_colortemp_xy],
'AC03641': [configurations.light_brightness],
'FB56+ZSW05HG1.2': [configurations.switch],
'72922-A': [configurations.switch],
@@ -337,10 +341,18 @@ const mapping = {
'50045': [configurations.light_brightness],
'AV2010/22': [configurations.binary_sensor_occupancy],
'3210-L': [configurations.switch],
'7299355PH': [configurations.light_brightness_colortemp_xy],
'7299355PH': [configurations.light_brightness_xy],
'45857GE': [configurations.light_brightness],
'A6121': [configurations.sensor_lock],
'433714': [configurations.light_brightness],
'3261030P7': [configurations.light_brightness_colortemp],
'DJT11LM': [configurations.sensor_action],
'E1603': [configurations.switch],
'7199960PH': [configurations.light_brightness_xy],
'74696': [configurations.light_brightness],
'AB35996': [configurations.light_brightness_colortemp_xy],
'AB401130055': [configurations.light_brightness_colortemp],
'74282': [configurations.light_brightness_colortemp],
};
// A map of all discoverd devices
@@ -357,7 +369,7 @@ function discover(deviceID, model, mqtt, force) {
mapping[model].forEach((config) => {
const topic = `${config.type}/${deviceID}/${config.object_id}/config`;
const payload = config.discovery_payload;
const payload = {...config.discovery_payload};
payload.state_topic = `${settings.get().mqtt.base_topic}/${friendlyName}`;
payload.availability_topic = `${settings.get().mqtt.base_topic}/bridge/state`;
+2
View File
@@ -6,9 +6,11 @@ const objectAssignDeep = require(`object-assign-deep`);
const path = require('path');
const defaults = {
permit_join: false,
advanced: {
log_directory: path.join(data.getPath(), 'log', '%TIMESTAMP%'),
log_level: process.env.DEBUG ? 'debug' : 'info',
soft_reset_timeout: 0,
},
};
+8
View File
@@ -0,0 +1,8 @@
// Xiaomi uses 4151 and 4447 (lumi.plug) as manufacturer ID.
const xiaomiManufacturerID = [4151, 4447];
module.exports = {
millisecondsToSeconds: (milliseconds) => milliseconds / 1000,
secondsToMilliseconds: (seconds) => seconds * 1000,
isXiaomiDevice: (device) => xiaomiManufacturerID.includes(device.manufId),
};
+24 -17
View File
@@ -3,6 +3,7 @@ const logger = require('./util/logger');
const settings = require('./util/settings');
const data = require('./util/data');
const zclPacket = require('zcl-packet');
const utils = require('./util/utils');
const advancedSettings = settings.get().advanced;
@@ -21,13 +22,14 @@ const shepherdSettings = {
logger.debug(`Using zigbee-shepherd with settings: '${JSON.stringify(shepherdSettings)}'`);
class Zigbee {
constructor() {
constructor(onMessage) {
this.onMessage = onMessage;
this.handleReady = this.handleReady.bind(this);
this.handleMessage = this.handleMessage.bind(this);
this.handleError = this.handleError.bind(this);
}
start(onMessage, callback) {
start(callback) {
logger.info(`Starting zigbee-shepherd`);
this.shepherd = new ZShepherd(settings.get().serial.port, shepherdSettings);
@@ -62,8 +64,6 @@ class Zigbee {
this.shepherd.on('ready', this.handleReady);
this.shepherd.on('ind', this.handleMessage);
this.shepherd.on('error', this.handleError);
this.onMessage = onMessage;
}
_logStartupInfo() {
@@ -84,12 +84,11 @@ class Zigbee {
}
handleReady() {
// 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).
// Xiaomi lumi.plug has manufId === 4447 and can be in the sleep mode too
// Set all Xiaomi devices to be online, so shepherd won't try
// to query info from devices (which would fail because they go to sleep).
const devices = this.getAllClients();
devices.forEach((d) => {
if ((d.manufId === 4151) || (d.manufId === 4447)) {
if (utils.isXiaomiDevice(d)) {
const device = this.shepherd.find(d.ieeeAddr, 1);
if (device) {
device.getDevice().update({
@@ -100,7 +99,7 @@ class Zigbee {
}
});
// Check if we have to turn of the led
// Check if we have to turn off the led
if (settings.get().serial.disable_led) {
this.shepherd.controller.request('UTIL', 'ledControl', {ledid: 3, mode: 0});
}
@@ -128,7 +127,7 @@ class Zigbee {
}
getAllClients() {
return this.shepherd.list().filter((device) => device.type !== 'Coordinator');
return this.getDevices().filter((device) => device.type !== 'Coordinator');
}
removeDevice(deviceID, callback) {
@@ -174,28 +173,36 @@ class Zigbee {
}
}
getDevices() {
return this.shepherd.list();
}
getDevice(deviceID) {
return this.shepherd.list().find((d) => d.ieeeAddr === deviceID);
return this.getDevices().find((d) => d.ieeeAddr === deviceID);
}
getCoordinator() {
const device = this.shepherd.list().find((d) => d.type === 'Coordinator');
const device = this.getDevices().find((d) => d.type === 'Coordinator');
return this.shepherd.find(device.ieeeAddr, 1);
}
publish(deviceID, cid, cmd, zclData, ep, type, callback) {
publish(deviceID, cid, cmd, zclData, cfg, ep, type, callback) {
const device = this._findDevice(deviceID, ep);
if (!device) {
logger.error(`Zigbee cannot publish message to device because '${deviceID}' not known by zigbee-shepherd`);
return;
}
logger.info(`Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep}`);
logger.info(
`Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ` +
`${JSON.stringify(zclData)} - ${JSON.stringify(cfg)} - ${ep}`
);
const callback_ = (error) => {
if (error) {
logger.error(
`Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep} ` +
`Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} ` +
`- ${JSON.stringify(cfg)} - ${ep} ` +
`failed with error ${error}`);
}
@@ -203,9 +210,9 @@ class Zigbee {
};
if (type === 'functional') {
device.functional(cid, cmd, zclData, callback_);
device.functional(cid, cmd, zclData, cfg, callback_);
} else if (type === 'foundation') {
device.foundation(cid, cmd, [zclData], callback_);
device.foundation(cid, cmd, [zclData], cfg, callback_);
} else {
logger.error(`Unknown zigbee publish type ${type}`);
}
+56 -56
View File
@@ -1,6 +1,6 @@
{
"name": "zigbee2mqtt",
"version": "0.1.5",
"version": "0.1.7",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -249,9 +249,9 @@
}
},
"ajv": {
"version": "6.5.3",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.3.tgz",
"integrity": "sha512-LqZ9wY+fx3UMiiPd741yB2pj3hhil+hQc8taf4o2QGRFpWgZ2V5C8HA165DY9sS3fJwsk7uT7ZlFEyC3Ig3lLg==",
"version": "6.5.4",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.4.tgz",
"integrity": "sha512-4Wyjt8+t6YszqaXnLDfMmG/8AlO5Zbcsy3ATHncCzjW/NoPzAId8AK6749Ybjmdt+kUY1gP60fCu46oDxPv/mg==",
"dev": true,
"requires": {
"fast-deep-equal": "^2.0.1",
@@ -356,7 +356,7 @@
},
"ansi-colors": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-0.2.0.tgz",
"resolved": "http://registry.npmjs.org/ansi-colors/-/ansi-colors-0.2.0.tgz",
"integrity": "sha1-csMd4qDZoszQysMMyYI+6y9kNLU=",
"requires": {
"ansi-bgblack": "^0.1.1",
@@ -612,7 +612,7 @@
},
"async": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz",
"resolved": "http://registry.npmjs.org/async/-/async-1.0.0.tgz",
"integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k="
},
"async-limiter": {
@@ -640,7 +640,7 @@
},
"bl": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz",
"resolved": "http://registry.npmjs.org/bl/-/bl-1.2.2.tgz",
"integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==",
"requires": {
"readable-stream": "^2.3.5",
@@ -727,17 +727,17 @@
}
},
"chai": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chai/-/chai-4.1.2.tgz",
"integrity": "sha1-D2RYS6ZC8PKs4oBiefTwbKI61zw=",
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz",
"integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==",
"dev": true,
"requires": {
"assertion-error": "^1.0.1",
"check-error": "^1.0.1",
"deep-eql": "^3.0.0",
"assertion-error": "^1.1.0",
"check-error": "^1.0.2",
"deep-eql": "^3.0.1",
"get-func-name": "^2.0.0",
"pathval": "^1.0.0",
"type-detect": "^4.0.0"
"pathval": "^1.1.0",
"type-detect": "^4.0.5"
}
},
"chai-spies": {
@@ -858,9 +858,9 @@
"integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs="
},
"commander": {
"version": "2.18.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.18.0.tgz",
"integrity": "sha512-6CYPa+JP2ftfRU2qkDK+UTVeQYosOg/2GbcjIcKPHfinyOLPVGXu/ovN86RP49Re5ndJK1N0kuiidFFuepc4ZQ=="
"version": "2.19.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz",
"integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg=="
},
"commist": {
"version": "1.0.0",
@@ -1024,7 +1024,7 @@
"dependencies": {
"bl": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-0.7.0.tgz",
"resolved": "http://registry.npmjs.org/bl/-/bl-0.7.0.tgz",
"integrity": "sha1-P7BnBgKsKHjrdw3CA58YNr5irls=",
"requires": {
"readable-stream": "~1.0.2"
@@ -1176,16 +1176,16 @@
"dev": true
},
"eslint": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-5.6.0.tgz",
"integrity": "sha512-/eVYs9VVVboX286mBK7bbKnO1yamUy2UCRjiY6MryhQL2PaaXCExsCQ2aO83OeYRhU2eCU/FMFP+tVMoOrzNrA==",
"version": "5.6.1",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-5.6.1.tgz",
"integrity": "sha512-hgrDtGWz368b7Wqf+v1Z69O3ZebNR0+GA7PtDdbmuz4rInFVUV9uw7whjZEiWyLzCjVb5Rs5WRN1TAS6eo7AYA==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.0.0",
"ajv": "^6.5.3",
"chalk": "^2.1.0",
"cross-spawn": "^6.0.5",
"debug": "^3.1.0",
"debug": "^4.0.1",
"doctrine": "^2.1.0",
"eslint-scope": "^4.0.0",
"eslint-utils": "^1.3.1",
@@ -1228,9 +1228,9 @@
"dev": true
},
"debug": {
"version": "3.2.5",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.5.tgz",
"integrity": "sha512-D61LaDQPQkxJ5AUM2mbSJRbPkNs/TmdmOeLAi1hgDkpDfIfetSrjmWhccwtuResSwMbACjx/xXQofvM9CE/aeg==",
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.0.tgz",
"integrity": "sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==",
"dev": true,
"requires": {
"ms": "^2.1.1"
@@ -1537,9 +1537,9 @@
}
},
"globals": {
"version": "11.7.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-11.7.0.tgz",
"integrity": "sha512-K8BNSPySfeShBQXsahYB/AbbWruVOTyVpgoIDnl8odPpeSfP2J5QO2oLFFdl2j7GfDCtZj2bMKar2T49itTPCg==",
"version": "11.8.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-11.8.0.tgz",
"integrity": "sha512-io6LkyPVuzCHBSQV9fmOwxZkUk6nIaGmxheLDgmuFv89j0fm2aqDbIXKAGfzCMHqz3HLF2Zf8WSG6VqMh2qFmA==",
"dev": true
},
"globby": {
@@ -2250,9 +2250,9 @@
"integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s="
},
"nan": {
"version": "2.11.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.11.0.tgz",
"integrity": "sha512-F4miItu2rGnV2ySkXOQoA8FKz/SR2Q2sWP0sbTxNxz/tuokeC8WxOhPMcwi0qIyGtVn/rrSeLbvVkznqCdwYnw=="
"version": "2.11.1",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.11.1.tgz",
"integrity": "sha512-iji6k87OSXa0CcrLl9z+ZiYSuR2o+c0bGuNmXdrhTQTakxytAFsC56SArGYoiHlJlFoHSnvmhpceZJaXkVuOtA=="
},
"natural-compare": {
"version": "1.4.0",
@@ -2274,7 +2274,7 @@
"dependencies": {
"async": {
"version": "0.2.10",
"resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz",
"resolved": "http://registry.npmjs.org/async/-/async-0.2.10.tgz",
"integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E="
}
}
@@ -2291,9 +2291,9 @@
"dev": true
},
"node-abi": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.4.3.tgz",
"integrity": "sha512-b656V5C0628gOOA2kwcpNA/bxdlqYF9FvxJ+qqVX0ctdXNVZpS8J6xEUYir3WAKc7U0BH/NRlSpNbGsy+azjeg==",
"version": "2.4.5",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.4.5.tgz",
"integrity": "sha512-aa/UC6Nr3+tqhHGRsAuw/edz7/q9nnetBrKWxj6rpTtm+0X9T1qU7lIEHMS3yN9JwAbRiKUbRRFy1PLz/y3aaA==",
"requires": {
"semver": "^5.4.1"
}
@@ -4024,9 +4024,9 @@
}
},
"regexpp": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.0.tgz",
"integrity": "sha512-g2FAVtR8Uh8GO1Nv5wpxW7VFVwHcCEr4wyA8/MHiRkO8uHoR5ntAA8Uq3P1vvMTX/BeQiRVSpDGLd+Wn5HNOTA==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz",
"integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==",
"dev": true
},
"reinterval": {
@@ -4097,9 +4097,9 @@
}
},
"rxjs": {
"version": "6.3.2",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.3.2.tgz",
"integrity": "sha512-hV7criqbR0pe7EeL3O66UYVg92IR0XsA97+9y+BWTePK9SKmEI5Qd3Zj6uPnGkNzXsBywBQWTvujPl+1Kn9Zjw==",
"version": "6.3.3",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.3.3.tgz",
"integrity": "sha512-JTWmoY9tWCs7zvIk/CvRjhjGaOd+OVBM987mxFo+OW66cGpdKjZcpmc74ES1sB//7Kl/PAe8+wEakuhG4pcgOw==",
"dev": true,
"requires": {
"tslib": "^1.9.0"
@@ -4375,7 +4375,7 @@
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"requires": {
"ansi-regex": "^2.0.0"
@@ -4475,16 +4475,16 @@
}
},
"tar-stream": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-1.6.1.tgz",
"integrity": "sha512-IFLM5wp3QrJODQFPm6/to3LJZrONdBY/otxcvDIQzu217zKye6yVR3hhi9lAjrC2Z+m/j5oDxMPb1qcd8cIvpA==",
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-1.6.2.tgz",
"integrity": "sha512-rzS0heiNf8Xn7/mpdSVVSMAWAoy9bfb1WOTYC78Z0UQKeKa/CWS8FOq0lKGNa8DWKAn9gxjCvMLYc5PGXYlK2A==",
"requires": {
"bl": "^1.0.0",
"buffer-alloc": "^1.1.0",
"buffer-alloc": "^1.2.0",
"end-of-stream": "^1.0.0",
"fs-constants": "^1.0.0",
"readable-stream": "^2.3.0",
"to-buffer": "^1.1.0",
"to-buffer": "^1.1.1",
"xtend": "^4.0.0"
}
},
@@ -4782,8 +4782,8 @@
}
},
"zcl-packet": {
"version": "git+https://github.com/Koenkk/zcl-packet.git#8f17e5540946f9be198d737a879e334c24dbf20d",
"from": "git+https://github.com/Koenkk/zcl-packet.git#8f17e5540946f9be198d737a879e334c24dbf20d",
"version": "git+https://github.com/Koenkk/zcl-packet.git#fbd8c936bbd4be0597ad3e934be0ca722b0128a6",
"from": "git+https://github.com/Koenkk/zcl-packet.git#fbd8c936bbd4be0597ad3e934be0ca722b0128a6",
"requires": {
"concentrate": "^0.2.3",
"dissolve-chunks": "^1.3.0",
@@ -4801,8 +4801,8 @@
}
},
"zigbee-shepherd": {
"version": "git+https://github.com/Koenkk/zigbee-shepherd.git#c096ed6719a6c941217c560b4cdcc04e4dd34c3b",
"from": "git+https://github.com/Koenkk/zigbee-shepherd.git#c096ed6719a6c941217c560b4cdcc04e4dd34c3b",
"version": "git+https://github.com/Koenkk/zigbee-shepherd.git#c3fdef2c30267573aa5821a0f2c51f21a700eff2",
"from": "git+https://github.com/Koenkk/zigbee-shepherd.git#c3fdef2c30267573aa5821a0f2c51f21a700eff2",
"requires": {
"areq": "^0.2.0",
"busyman": "^0.3.0",
@@ -4812,7 +4812,7 @@
"proving": "^0.1.0",
"q": "^1.4.1",
"zcl-id": "^0.3.2",
"zcl-packet": "git+https://github.com/Koenkk/zcl-packet.git#8f17e5540946f9be198d737a879e334c24dbf20d",
"zcl-packet": "git+https://github.com/Koenkk/zcl-packet.git#fbd8c936bbd4be0597ad3e934be0ca722b0128a6",
"ziee": "^0.3.0",
"zive": "^0.2.2",
"zstack-constants": "^0.2.0"
@@ -4830,9 +4830,9 @@
}
},
"zigbee-shepherd-converters": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/zigbee-shepherd-converters/-/zigbee-shepherd-converters-3.0.5.tgz",
"integrity": "sha512-4jzcufFZKueuKEfRk5aGhKj1st8vbeY8098ciOS9IbAvTwF57XZ3lB1UDC4cd1mcuYmY2Zve3PggxSJAyYHOnQ==",
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/zigbee-shepherd-converters/-/zigbee-shepherd-converters-4.0.3.tgz",
"integrity": "sha512-+aH4cCXZCGjgmTqB9sWgELkuOgIskWv8T2bToonVH4/EGNVU0xX8gsrRBfwpKDAjGNU1JbOP27qhFRO4KIsY6Q==",
"requires": {
"debounce": "*"
},
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "zigbee2mqtt",
"version": "0.1.5",
"version": "0.1.7",
"description": "Zigbee to MQTT bridge using zigbee-shepherd",
"main": "index.js",
"repository": {
@@ -40,9 +40,9 @@
"object-assign-deep": "*",
"rimraf": "*",
"winston": "2.4.2",
"zcl-packet": "git+https://github.com/Koenkk/zcl-packet.git#8f17e5540946f9be198d737a879e334c24dbf20d",
"zigbee-shepherd": "git+https://github.com/Koenkk/zigbee-shepherd.git#c096ed6719a6c941217c560b4cdcc04e4dd34c3b",
"zigbee-shepherd-converters": "*"
"zcl-packet": "git+https://github.com/Koenkk/zcl-packet.git#fbd8c936bbd4be0597ad3e934be0ca722b0128a6",
"zigbee-shepherd": "git+https://github.com/Koenkk/zigbee-shepherd.git#c3fdef2c30267573aa5821a0f2c51f21a700eff2",
"zigbee-shepherd-converters": "4.0.3"
},
"devDependencies": {
"chai": "*",