diff --git a/lib/controller.js b/lib/controller.js index 5118d9243..31110112b 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -5,6 +5,7 @@ const logger = require('./util/logger'); const settings = require('./util/settings'); const zigbeeShepherdConverters = require('zigbee-shepherd-converters'); const objectAssignDeep = require('object-assign-deep'); +const utils = require('./util/utils'); // Extensions const ExtensionNetworkMap = require('./extension/networkMap'); @@ -33,40 +34,40 @@ class Controller { this.onMQTTConnected = this.onMQTTConnected.bind(this); this.onZigbeeMessage = this.onZigbeeMessage.bind(this); this.onMQTTMessage = this.onMQTTMessage.bind(this); - this.publishDeviceState = this.publishDeviceState.bind(this); + this.publishEntityState = this.publishEntityState.bind(this); // Initialize extensions. this.extensions = [ - new ExtensionDeviceReceive(this.zigbee, this.mqtt, this.state, this.publishDeviceState), - new ExtensionDeviceConfigure(this.zigbee, this.mqtt, this.state, this.publishDeviceState), - new ExtensionDevicePublish(this.zigbee, this.mqtt, this.state, this.publishDeviceState), - new ExtensionNetworkMap(this.zigbee, this.mqtt, this.state, this.publishDeviceState), - new ExtensionRouterPollXiaomi(this.zigbee, this.mqtt, this.state, this.publishDeviceState), - new ExtensionMarkOnlineXiaomi(this.zigbee, this.mqtt, this.state, this.publishDeviceState), - new ExtensionBridgeConfig(this.zigbee, this.mqtt, this.state, this.publishDeviceState), - new ExtensionGroups(this.zigbee, this.mqtt, this.state, this.publishDeviceState), - new ExtensionBind(this.zigbee, this.mqtt, this.state, this.publishDeviceState), - new ExtensionCoordinatorGroup(this.zigbee, this.mqtt, this.state, this.publishDeviceState), - new ExtensionReporting(this.zigbee, this.mqtt, this.state, this.publishDeviceState), + new ExtensionDeviceReceive(this.zigbee, this.mqtt, this.state, this.publishEntityState), + new ExtensionDeviceConfigure(this.zigbee, this.mqtt, this.state, this.publishEntityState), + new ExtensionDevicePublish(this.zigbee, this.mqtt, this.state, this.publishEntityState), + new ExtensionNetworkMap(this.zigbee, this.mqtt, this.state, this.publishEntityState), + new ExtensionRouterPollXiaomi(this.zigbee, this.mqtt, this.state, this.publishEntityState), + new ExtensionMarkOnlineXiaomi(this.zigbee, this.mqtt, this.state, this.publishEntityState), + new ExtensionBridgeConfig(this.zigbee, this.mqtt, this.state, this.publishEntityState), + new ExtensionGroups(this.zigbee, this.mqtt, this.state, this.publishEntityState), + new ExtensionBind(this.zigbee, this.mqtt, this.state, this.publishEntityState), + new ExtensionCoordinatorGroup(this.zigbee, this.mqtt, this.state, this.publishEntityState), + new ExtensionReporting(this.zigbee, this.mqtt, this.state, this.publishEntityState), // https://github.com/Koenkk/zigbee2mqtt/issues/592 - // new ExtensionPollLivoloSwitch(this.zigbee, this.mqtt, this.state, this.publishDeviceState), + // new ExtensionPollLivoloSwitch(this.zigbee, this.mqtt, this.state, this.publishEntityState), ]; if (settings.get().homeassistant) { this.extensions.push(new ExtensionHomeAssistant( - this.zigbee, this.mqtt, this.state, this.publishDeviceState + this.zigbee, this.mqtt, this.state, this.publishEntityState )); } if (settings.get().advanced.soft_reset_timeout !== 0) { this.extensions.push(new ExtensionSoftReset( - this.zigbee, this.mqtt, this.state, this.publishDeviceState + this.zigbee, this.mqtt, this.state, this.publishEntityState )); } if (settings.get().advanced.availability_timeout) { this.extensions.push(new ExtensionAvailability( - this.zigbee, this.mqtt, this.state, this.publishDeviceState + this.zigbee, this.mqtt, this.state, this.publishEntityState )); } } @@ -215,44 +216,45 @@ class Controller { sendAllCachedStates() { this.zigbee.getAllClients().forEach((device) => { if (this.state.exists(device.ieeeAddr)) { - this.publishDeviceState(device, this.state.get(device.ieeeAddr), false); + this.publishEntityState(device.ieeeAddr, this.state.get(device.ieeeAddr), false); } }); } - publishDeviceState(device, payload, cache) { - const deviceID = device.ieeeAddr; + publishEntityState(entityID, payload, cache) { + const entity = utils.resolveEntity(entityID); const appSettings = settings.get(); let messagePayload = {...payload}; if (appSettings.advanced.cache_state) { // Add cached state to payload - if (this.state.exists(deviceID)) { - messagePayload = objectAssignDeep.noMutate(this.state.get(deviceID), payload); + if (this.state.exists(entityID)) { + messagePayload = objectAssignDeep.noMutate(this.state.get(entityID), payload); } // Update state cache with new state. if (cache) { - this.state.set(deviceID, messagePayload); + this.state.set(entityID, messagePayload); } } - const deviceSettings = settings.getDevice(deviceID); - const friendlyName = deviceSettings ? deviceSettings.friendly_name : deviceID; + const entitySettings = entity.type === 'device' ? settings.getDevice(entityID) : settings.getGroup(entityID); + const friendlyName = entitySettings ? entitySettings.friendly_name : entityID; const options = { - retain: deviceSettings ? deviceSettings.retain : false, - qos: deviceSettings && deviceSettings.qos ? deviceSettings.qos : 0, + retain: entitySettings ? entitySettings.retain : false, + qos: entitySettings && entitySettings.qos ? entitySettings.qos : 0, }; - if (appSettings.mqtt.include_device_information) { - messagePayload.device = this.getDeviceInfoForMqtt(device); + if (entity.type === 'device' && appSettings.mqtt.include_device_information) { + messagePayload.device = this.getDeviceInfoForMqtt(entityID); } this.mqtt.publish(friendlyName, JSON.stringify(messagePayload), options); } - getDeviceInfoForMqtt(device) { - const {type, ieeeAddr, nwkAddr, manufId, manufName, powerSource, modelId, status} = device; + getDeviceInfoForMqtt(ieeeAddr) { + const device = this.zigbee.getDevice(ieeeAddr); + const {type, nwkAddr, manufId, manufName, powerSource, modelId, status} = device; const deviceSettings = settings.getDevice(device.ieeeAddr); return { diff --git a/lib/extension/availability.js b/lib/extension/availability.js index d34cc584b..23a9f62c4 100644 --- a/lib/extension/availability.js +++ b/lib/extension/availability.js @@ -15,7 +15,7 @@ const toZigbeeCandidates = ['state']; * This extensions pings devices to check if they are online. */ class Availability { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.mqtt = mqtt; this.availability_timeout = settings.get().advanced.availability_timeout; diff --git a/lib/extension/bind.js b/lib/extension/bind.js index 12abd73bd..6e7937868 100644 --- a/lib/extension/bind.js +++ b/lib/extension/bind.js @@ -13,11 +13,11 @@ const allowedClusters = [ ]; class Bind { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.mqtt = mqtt; this.state = state; - this.publishDeviceState = publishDeviceState; + this.publishEntityState = publishEntityState; // Setup queue this.queue = new Queue(); diff --git a/lib/extension/bridgeConfig.js b/lib/extension/bridgeConfig.js index 1ccefa0d4..9aaec2f55 100644 --- a/lib/extension/bridgeConfig.js +++ b/lib/extension/bridgeConfig.js @@ -6,11 +6,11 @@ const configRegex = new RegExp(`${settings.get().mqtt.base_topic}/bridge/config/ const allowedLogLevels = ['error', 'warn', 'info', 'debug']; class BridgeConfig { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.mqtt = mqtt; this.state = state; - this.publishDeviceState = publishDeviceState; + this.publishEntityState = publishEntityState; // Bind functions this.permitJoin = this.permitJoin.bind(this); diff --git a/lib/extension/coordinatorGroup.js b/lib/extension/coordinatorGroup.js index 9e11d3c95..2c48e6f33 100644 --- a/lib/extension/coordinatorGroup.js +++ b/lib/extension/coordinatorGroup.js @@ -11,11 +11,11 @@ const devices = [E1524]; * This extensions adds the coordinator to a group which is required for some devices to work properly. */ class CoordinatorGroup { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.mqtt = mqtt; this.state = state; - this.publishDeviceState = publishDeviceState; + this.publishEntityState = publishEntityState; } onZigbeeStarted() { diff --git a/lib/extension/deviceConfigure.js b/lib/extension/deviceConfigure.js index 7e439ede5..51d02539c 100644 --- a/lib/extension/deviceConfigure.js +++ b/lib/extension/deviceConfigure.js @@ -7,7 +7,7 @@ const Queue = require('queue'); * This extensions handles configuration of devices. */ class DeviceConfigure { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.configured = []; this.attempts = {}; diff --git a/lib/extension/devicePublish.js b/lib/extension/devicePublish.js index eb414c24f..33e4c48f9 100644 --- a/lib/extension/devicePublish.js +++ b/lib/extension/devicePublish.js @@ -17,11 +17,11 @@ const groupConverters = [ ]; class DevicePublish { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.mqtt = mqtt; this.state = state; - this.publishDeviceState = publishDeviceState; + this.publishEntityState = publishEntityState; } onMQTTConnected() { @@ -151,7 +151,7 @@ class DevicePublish { const msg = {}; const _key = topic.postfix ? `state_${topic.postfix}` : 'state'; msg[_key] = key.startsWith('brightness') ? 'ON' : json['state']; - this.publishDeviceState(device, msg, true); + this.publishEntityState(device.ieeeAddr, msg, true); } } ); diff --git a/lib/extension/deviceReceive.js b/lib/extension/deviceReceive.js index 633292e10..58ee23bbf 100644 --- a/lib/extension/deviceReceive.js +++ b/lib/extension/deviceReceive.js @@ -7,11 +7,11 @@ const dontCacheProperties = ['action', 'button', 'button_left', 'button_right', * This extensions handles messages received from devices. */ class DeviceReceive { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.mqtt = mqtt; this.state = state; - this.publishDeviceState = publishDeviceState; + this.publishEntityState = publishEntityState; this.coordinator = null; this.elapsed = {}; } @@ -132,7 +132,7 @@ class DeviceReceive { this.elapsed[device.ieeeAddr] = now; } - this.publishDeviceState(device, payload, cache); + this.publishEntityState(device.ieeeAddr, payload, cache); }; let payload = {}; diff --git a/lib/extension/extensionTemplate.js b/lib/extension/extensionTemplate.js index b44f8114a..0214d38e4 100644 --- a/lib/extension/extensionTemplate.js +++ b/lib/extension/extensionTemplate.js @@ -9,13 +9,13 @@ class ExtensionTemplate { * @param {Zigbee} zigbee Zigbee controller * @param {MQTT} mqtt MQTT controller * @param {State} state State controller - * @param {Function} publishDeviceState Method to publish device state to MQTT. + * @param {Function} publishEntityState Method to publish device state to MQTT. */ - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.mqtt = mqtt; this.state = state; - this.publishDeviceState = publishDeviceState; + this.publishEntityState = publishEntityState; } /** diff --git a/lib/extension/groups.js b/lib/extension/groups.js index ac172f343..e7f510428 100644 --- a/lib/extension/groups.js +++ b/lib/extension/groups.js @@ -4,11 +4,11 @@ const logger = require('../util/logger'); const topicRegex = new RegExp(`^${settings.get().mqtt.base_topic}/bridge/group/.+/(remove|add|remove_all)$`); class Groups { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.mqtt = mqtt; this.state = state; - this.publishDeviceState = publishDeviceState; + this.publishEntityState = publishEntityState; } onMQTTConnected() { diff --git a/lib/extension/homeassistant.js b/lib/extension/homeassistant.js index cac078d52..b23d2b216 100644 --- a/lib/extension/homeassistant.js +++ b/lib/extension/homeassistant.js @@ -487,11 +487,11 @@ const mapping = { * This extensions handles integration with HomeAssistant */ class HomeAssistant { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.mqtt = mqtt; this.state = state; - this.publishDeviceState = publishDeviceState; + this.publishEntityState = publishEntityState; this.zigbee2mqttVersion = zigbee2mqttVersion; // A map of all discoverd devices @@ -593,7 +593,7 @@ class HomeAssistant { // Publish all device states. this.zigbee.getAllClients().forEach((device) => { if (this.state.exists(device.ieeeAddr)) { - this.publishDeviceState(device, this.state.get(device.ieeeAddr), false); + this.publishEntityState(device.ieeeAddr, this.state.get(device.ieeeAddr), false); } }); diff --git a/lib/extension/markOnlineXiaomi.js b/lib/extension/markOnlineXiaomi.js index 9f4a8e0df..f8f9514d8 100644 --- a/lib/extension/markOnlineXiaomi.js +++ b/lib/extension/markOnlineXiaomi.js @@ -4,7 +4,7 @@ const utils = require('../util/utils'); * This extensions marks Xiaomi devices as online. */ class MarkOnlineXiaomi { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; } diff --git a/lib/extension/networkMap.js b/lib/extension/networkMap.js index 51d57839d..583b93827 100644 --- a/lib/extension/networkMap.js +++ b/lib/extension/networkMap.js @@ -2,7 +2,7 @@ const settings = require('../util/settings'); const zigbeeShepherdConverters = require('zigbee-shepherd-converters'); class NetworkMap { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.mqtt = mqtt; this.state = state; diff --git a/lib/extension/pollLivoloSwitch.js b/lib/extension/pollLivoloSwitch.js index ec775d38f..f7ca1bf6e 100644 --- a/lib/extension/pollLivoloSwitch.js +++ b/lib/extension/pollLivoloSwitch.js @@ -8,7 +8,7 @@ const foundationCfg = {manufSpec: 0, disDefaultRsp: 0}; * Extension required for Livolo device support. */ class PollLivoloSwitch { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.timer = null; this.configured = {}; diff --git a/lib/extension/reporting.js b/lib/extension/reporting.js index 891b025d6..5b34d059c 100644 --- a/lib/extension/reporting.js +++ b/lib/extension/reporting.js @@ -15,11 +15,11 @@ const reportInterval = { const reportableChange = 0; class Reporting { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.mqtt = mqtt; this.state = state; - this.publishDeviceState = publishDeviceState; + this.publishEntityState = publishEntityState; } shouldReport(ieeeAddr) { diff --git a/lib/extension/routerPollXiaomi.js b/lib/extension/routerPollXiaomi.js index 158528ffc..7472f3156 100644 --- a/lib/extension/routerPollXiaomi.js +++ b/lib/extension/routerPollXiaomi.js @@ -5,7 +5,7 @@ const interval = utils.secondsToMilliseconds(60); * This extensions polls Xiaomi Zigbee routers to keep them awake. */ class RouterPollXiaomi { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.timer = null; } diff --git a/lib/extension/softReset.js b/lib/extension/softReset.js index 54005ce47..6ed78af92 100644 --- a/lib/extension/softReset.js +++ b/lib/extension/softReset.js @@ -6,7 +6,7 @@ const utils = require('../util/utils'); * This extensions soft resets the ZNP after a certain timeout. */ class SoftReset { - constructor(zigbee, mqtt, state, publishDeviceState) { + constructor(zigbee, mqtt, state, publishEntityState) { this.zigbee = zigbee; this.timer = null; this.timeout = utils.secondsToMilliseconds(settings.get().advanced.soft_reset_timeout); diff --git a/lib/util/settings.js b/lib/util/settings.js index d64fa2139..595352919 100644 --- a/lib/util/settings.js +++ b/lib/util/settings.js @@ -125,6 +125,7 @@ module.exports = { write: () => write(), getDevice: (ieeeAddr) => settings.devices ? settings.devices[ieeeAddr] : null, + getGroup: (ID) => settings.groups ? settings.groups[ID]: null, getDevices: () => settings.devices ? settings.devices : [], addDevice: (ieeeAddr) => addDevice(ieeeAddr), removeDevice: (ieeeAddr) => removeDevice(ieeeAddr), diff --git a/test/controller.test.js b/test/controller.test.js index 111159ad7..c5f2f1273 100644 --- a/test/controller.test.js +++ b/test/controller.test.js @@ -17,6 +17,14 @@ describe('Controller', () => { }); mqttPublish = sandbox.stub(mqtt.prototype, 'publish').callsFake(() => {}); controller = new Controller(); + controller.zigbee = { + getDevice: () => { + return { + modelId: 'TRADFRI bulb E27 CWS opal 600lm', + manufName: 'IKEA', + }; + }, + }; }); afterEach(() => { @@ -54,7 +62,7 @@ describe('Controller', () => { chai.assert.strictEqual( mqttPublish.getCall(0).args[1], `{"state":"ON","device":{"ieeeAddr":"0x12345678","friendlyName":"test",` + - `"modelId":"TRADFRI bulb E27 CWS opal 600lm"}}` + `"manufName":"IKEA","modelId":"TRADFRI bulb E27 CWS opal 600lm"}}` ); }); }); diff --git a/test/deviceReceive.test.js b/test/deviceReceive.test.js index 17bae682c..1d2e9ef8a 100644 --- a/test/deviceReceive.test.js +++ b/test/deviceReceive.test.js @@ -18,13 +18,13 @@ const mqtt = { describe('DeviceReceive', () => { let deviceReceive; - let publishDeviceState; + let publishEntityState; beforeEach(() => { utils.stubLogger(sandbox); sandbox.stub(settings, 'addDevice').callsFake(() => {}); - publishDeviceState = sinon.spy(); - deviceReceive = new DeviceReceive(null, mqtt, null, publishDeviceState); + publishEntityState = sinon.spy(); + deviceReceive = new DeviceReceive(null, mqtt, null, publishEntityState); }); afterEach(() => { @@ -36,24 +36,24 @@ describe('DeviceReceive', () => { const device = {ieeeAddr: '0x12345678'}; const message = utils.zigbeeMessage(device, 'genOnOff', 'attReport', {onOff: 1}, 1); deviceReceive.onZigbeeMessage(message, device, WXKG11LM); - chai.assert.isTrue(publishDeviceState.calledOnce); - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], {click: 'single'}); + chai.assert.isTrue(publishEntityState.calledOnce); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], {click: 'single'}); }); it('Should handle a zigbee message which uses ep (left)', () => { const device = {ieeeAddr: '0x12345678'}; const message = utils.zigbeeMessage(device, 'genOnOff', 'attReport', {onOff: 1}, 1); deviceReceive.onZigbeeMessage(message, device, WXKG02LM); - chai.assert.isTrue(publishDeviceState.calledOnce); - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], {click: 'left'}); + chai.assert.isTrue(publishEntityState.calledOnce); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], {click: 'left'}); }); it('Should handle a zigbee message which uses ep (right)', () => { const device = {ieeeAddr: '0x12345678'}; const message = utils.zigbeeMessage(device, 'genOnOff', 'attReport', {onOff: 1}, 2); deviceReceive.onZigbeeMessage(message, device, WXKG02LM); - chai.assert.isTrue(publishDeviceState.calledOnce); - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], {click: 'right'}); + chai.assert.isTrue(publishEntityState.calledOnce); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], {click: 'right'}); }); it('Should handle a zigbee message with default precision', () => { @@ -62,8 +62,8 @@ describe('DeviceReceive', () => { device, 'msTemperatureMeasurement', 'attReport', {measuredValue: -85}, 1 ); deviceReceive.onZigbeeMessage(message, device, WSDCGQ11LM); - chai.assert.isTrue(publishDeviceState.calledOnce); - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], {temperature: -0.85}); + chai.assert.isTrue(publishEntityState.calledOnce); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], {temperature: -0.85}); }); it('Should handle a zigbee message with 1 precision', () => { @@ -75,8 +75,8 @@ describe('DeviceReceive', () => { device, 'msTemperatureMeasurement', 'attReport', {measuredValue: -85}, 1 ); deviceReceive.onZigbeeMessage(message, device, WSDCGQ11LM); - chai.assert.isTrue(publishDeviceState.calledOnce); - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], {temperature: -0.8}); + chai.assert.isTrue(publishEntityState.calledOnce); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], {temperature: -0.8}); }); it('Should handle a zigbee message with 0 precision', () => { @@ -88,8 +88,8 @@ describe('DeviceReceive', () => { device, 'msTemperatureMeasurement', 'attReport', {measuredValue: -85}, 1 ); deviceReceive.onZigbeeMessage(message, device, WSDCGQ11LM); - chai.assert.isTrue(publishDeviceState.calledOnce); - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], {temperature: -1}); + chai.assert.isTrue(publishEntityState.calledOnce); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], {temperature: -1}); }); it('Should handle a zigbee message with 1 precision when set via device_options', () => { @@ -111,8 +111,8 @@ describe('DeviceReceive', () => { device, 'msTemperatureMeasurement', 'attReport', {measuredValue: -85}, 1 ); deviceReceive.onZigbeeMessage(message, device, WSDCGQ11LM); - chai.assert.isTrue(publishDeviceState.calledOnce); - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], {temperature: -0.8}); + chai.assert.isTrue(publishEntityState.calledOnce); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], {temperature: -0.8}); }); it('Should handle a zigbee message with 2 precision when overrides device_options', () => { @@ -136,44 +136,44 @@ describe('DeviceReceive', () => { device, 'msTemperatureMeasurement', 'attReport', {measuredValue: -85}, 1 ); deviceReceive.onZigbeeMessage(message, device, WSDCGQ11LM); - chai.assert.isTrue(publishDeviceState.calledOnce); - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], {temperature: -0.85}); + chai.assert.isTrue(publishEntityState.calledOnce); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], {temperature: -0.85}); }); it('Should handle a zigbee message with voltage 3010', () => { const device = {ieeeAddr: '0x12345678'}; const message = utils.zigbeeMessage(device, 'genBasic', 'attReport', {'65281': {'1': 3010}}, 1); deviceReceive.onZigbeeMessage(message, device, WXKG02LM); - chai.assert.isTrue(publishDeviceState.calledOnce); + chai.assert.isTrue(publishEntityState.calledOnce); const expected = {battery: 100, voltage: 3010}; - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], expected); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], expected); }); it('Should handle a zigbee message with voltage 2850', () => { const device = {ieeeAddr: '0x12345678'}; const message = utils.zigbeeMessage(device, 'genBasic', 'attReport', {'65281': {'1': 2850}}, 1); deviceReceive.onZigbeeMessage(message, device, WXKG02LM); - chai.assert.isTrue(publishDeviceState.calledOnce); + chai.assert.isTrue(publishEntityState.calledOnce); const expected = {battery: 35, voltage: 2850}; - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], expected); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], expected); }); it('Should handle a zigbee message with voltage 2650', () => { const device = {ieeeAddr: '0x12345678'}; const message = utils.zigbeeMessage(device, 'genBasic', 'attReport', {'65281': {'1': 2650}}, 1); deviceReceive.onZigbeeMessage(message, device, WXKG02LM); - chai.assert.isTrue(publishDeviceState.calledOnce); + chai.assert.isTrue(publishEntityState.calledOnce); const expected = {battery: 14, voltage: 2650}; - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], expected); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], expected); }); it('Should handle a zigbee message with voltage 2000', () => { const device = {ieeeAddr: '0x12345678'}; const message = utils.zigbeeMessage(device, 'genBasic', 'attReport', {'65281': {'1': 2000}}, 1); deviceReceive.onZigbeeMessage(message, device, WXKG02LM); - chai.assert.isTrue(publishDeviceState.calledOnce); + chai.assert.isTrue(publishEntityState.calledOnce); const expected = {battery: 0, voltage: 2000}; - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], expected); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], expected); }); it('Should publish 1 message when converted twice', () => { @@ -183,9 +183,9 @@ describe('DeviceReceive', () => { }; const message = utils.zigbeeMessage(device, 'genBasic', 'attReport', payload, 1); deviceReceive.onZigbeeMessage(message, device, RTCGQ11LM); - chai.assert.isTrue(publishDeviceState.calledOnce); + chai.assert.isTrue(publishEntityState.calledOnce); const expected = {'battery': 100, 'illuminance': 381, 'voltage': 3045}; - chai.assert.deepEqual(publishDeviceState.getCall(0).args[1], expected); + chai.assert.deepEqual(publishEntityState.getCall(0).args[1], expected); }); it('Should publish no message when converted without result', () => { @@ -193,7 +193,7 @@ describe('DeviceReceive', () => { const payload = {'9999': {'1': 3045}}; const message = utils.zigbeeMessage(device, 'genBasic', 'attReport', payload, 1); deviceReceive.onZigbeeMessage(message, device, RTCGQ11LM); - chai.assert.isTrue(publishDeviceState.notCalled); + chai.assert.isTrue(publishEntityState.notCalled); }); it('Should publish last_seen epoch', () => { @@ -207,8 +207,8 @@ describe('DeviceReceive', () => { }; }); deviceReceive.onZigbeeMessage(message, device, WXKG02LM); - chai.assert.isTrue(publishDeviceState.calledOnce); - chai.assert.equal(typeof publishDeviceState.getCall(0).args[1].last_seen, 'number'); + chai.assert.isTrue(publishEntityState.calledOnce); + chai.assert.equal(typeof publishEntityState.getCall(0).args[1].last_seen, 'number'); }); it('Should publish last_seen ISO_8601', () => { @@ -222,8 +222,8 @@ describe('DeviceReceive', () => { }; }); deviceReceive.onZigbeeMessage(message, device, WXKG02LM); - chai.assert.isTrue(publishDeviceState.calledOnce); - chai.assert.equal(typeof publishDeviceState.getCall(0).args[1].last_seen, 'string'); + chai.assert.isTrue(publishEntityState.calledOnce); + chai.assert.equal(typeof publishEntityState.getCall(0).args[1].last_seen, 'string'); }); }); });