mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-16 10:28:33 -07:00
5d3461c4c6
* Add timestamp on receiving message from Zigbee Add last_message to the payload * Discovery on HASS restart and last_message attribute added - On restarting Home Assistant, resending device discovery information - Add timestamp on receiving message from Zigbee * Add option: add_timestamp in settings * Add option: add_timestamp in settings * Add option: add_timestamp in settings * typo * Update homeassistant.js * Update homeassistant.js * Update homeassistant.js * Update deviceReceive.js * Update deviceReceive.js * Update homeassistant.js * Update settings.js * Update deviceReceive.js * Update deviceReceive.js * Update deviceReceive.js * Update deviceReceive.js * Fix tests * Fix lint * Fix lint
62 lines
2.3 KiB
JavaScript
62 lines
2.3 KiB
JavaScript
const chai = require('chai');
|
|
const sinon = require('sinon');
|
|
const Controller = require('../lib/controller');
|
|
const settings = require('../lib/util/settings');
|
|
const mqtt = require('../lib/mqtt');
|
|
const utils = require('./utils');
|
|
const sandbox = sinon.createSandbox();
|
|
|
|
describe('Controller', () => {
|
|
let controller;
|
|
let mqttPublish;
|
|
|
|
beforeEach(() => {
|
|
utils.stubLogger(sandbox);
|
|
sandbox.stub(settings, 'getDevice').callsFake((ieeeAddr) => {
|
|
return {friendly_name: 'test'};
|
|
});
|
|
mqttPublish = sandbox.stub(mqtt.prototype, 'publish').callsFake(() => {});
|
|
controller = new Controller();
|
|
});
|
|
|
|
afterEach(() => {
|
|
sandbox.restore();
|
|
});
|
|
|
|
describe('Handling zigbee messages', () => {
|
|
it('Should handle a zigbee message', () => {
|
|
const device = {ieeeAddr: '0x12345678', modelId: 'TRADFRI bulb E27 CWS opal 600lm'};
|
|
const message = utils.zigbeeMessage(device, 'genOnOff', 'devChange', {onOff: 1}, 1);
|
|
controller.onZigbeeMessage(message);
|
|
chai.assert.isTrue(mqttPublish.calledOnce);
|
|
chai.assert.strictEqual(
|
|
utils.withoutLastSeen(mqttPublish.getCall(0).args[1]),
|
|
JSON.stringify({state: 'ON'})
|
|
);
|
|
});
|
|
|
|
it('Should handle a zigbee message when include_device_information is set', () => {
|
|
sandbox.stub(settings, 'get').callsFake(() => {
|
|
return {
|
|
mqtt: {
|
|
include_device_information: true,
|
|
},
|
|
advanced: {
|
|
cache_state: false,
|
|
},
|
|
};
|
|
});
|
|
|
|
const device = {ieeeAddr: '0x12345678', modelId: 'TRADFRI bulb E27 CWS opal 600lm'};
|
|
const message = utils.zigbeeMessage(device, 'genOnOff', 'devChange', {onOff: 1}, 1);
|
|
controller.onZigbeeMessage(message);
|
|
chai.assert.isTrue(mqttPublish.calledOnce);
|
|
chai.assert.strictEqual(
|
|
utils.withoutLastSeen(mqttPublish.getCall(0).args[1]),
|
|
`{"state":"ON","device":{"ieeeAddr":"0x12345678","friendlyName":"test",` +
|
|
`"modelId":"TRADFRI bulb E27 CWS opal 600lm"}}`
|
|
);
|
|
});
|
|
});
|
|
});
|