diff --git a/front/src/components/boxs/device-in-room/device-features/BinaryDeviceFeature.jsx b/front/src/components/boxs/device-in-room/device-features/BinaryDeviceFeature.jsx index 1c477e9b5e..3a0cc416dc 100644 --- a/front/src/components/boxs/device-in-room/device-features/BinaryDeviceFeature.jsx +++ b/front/src/components/boxs/device-in-room/device-features/BinaryDeviceFeature.jsx @@ -7,7 +7,7 @@ const BinaryDeviceType = ({ children, ...props }) => { props.deviceFeature, props.deviceIndex, props.deviceFeatureIndex, - props.deviceFeature.last_value === 1 ? 0 : 1 + !props.deviceFeature.last_value ); } diff --git a/package-lock.json b/package-lock.json index 07fd9952d2..c2e7e1409e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "gladys", - "version": "4.0.0", + "version": "4.0.0-beta", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/server/lib/device/device.setValue.js b/server/lib/device/device.setValue.js index 7c0c83bef4..b3069b5c60 100644 --- a/server/lib/device/device.setValue.js +++ b/server/lib/device/device.setValue.js @@ -19,7 +19,7 @@ async function setValue(device, deviceFeature, value) { throw new NotFoundError(`Function device.setValue in service ${device.service.name} does not exist.`); } await service.device.setValue(device, deviceFeature, value); - if (!deviceFeature.has_state_feedback) { + if (!deviceFeature.has_feedback) { await this.saveState(deviceFeature, value); } } diff --git a/server/lib/gateway/gateway.forwardWebsockets.js b/server/lib/gateway/gateway.forwardWebsockets.js index a55e8c31a4..2139196e3c 100644 --- a/server/lib/gateway/gateway.forwardWebsockets.js +++ b/server/lib/gateway/gateway.forwardWebsockets.js @@ -10,6 +10,12 @@ const logger = require('../../utils/logger'); * }); */ async function forwardWebsockets(event) { + if (!this.connected) { + logger.debug('Gateway: not connected. Prevent forwarding event.'); + + return; + } + logger.debug(`Gateway : Forward websocket message : ${event.type}`); try { if (event.userId) { diff --git a/server/services/zwave/index.js b/server/services/zwave/index.js index 78010f35f4..137cb8a4e7 100644 --- a/server/services/zwave/index.js +++ b/server/services/zwave/index.js @@ -35,6 +35,7 @@ module.exports = function ZwaveService(gladys, serviceId) { return Object.freeze({ start, stop, + device: zwaveManager, controllers: ZwaveController(gladys, zwaveManager, serviceId), }); }; diff --git a/server/services/zwave/lib/index.js b/server/services/zwave/lib/index.js index da02da2c63..2ccc021cf2 100644 --- a/server/services/zwave/lib/index.js +++ b/server/services/zwave/lib/index.js @@ -24,6 +24,7 @@ const { getInfos } = require('./commands/zwave.getInfos'); const { getNodes } = require('./commands/zwave.getNodes'); const { getNodeNeighbors } = require('./commands/zwave.getNodeNeighbors'); const { removeNode } = require('./commands/zwave.removeNode'); +const { setValue } = require('./commands/zwave.setValue'); const DEFAULT_ZWAVE_OPTIONS = { Logging: false, @@ -81,5 +82,6 @@ ZwaveManager.prototype.getInfos = getInfos; ZwaveManager.prototype.getNodes = getNodes; ZwaveManager.prototype.getNodeNeighbors = getNodeNeighbors; ZwaveManager.prototype.removeNode = removeNode; +ZwaveManager.prototype.setValue = setValue; module.exports = ZwaveManager; diff --git a/server/test/lib/gateway/GladysGatewayClientMock.test.js b/server/test/lib/gateway/GladysGatewayClientMock.test.js index 990908353b..8932437d8a 100644 --- a/server/test/lib/gateway/GladysGatewayClientMock.test.js +++ b/server/test/lib/gateway/GladysGatewayClientMock.test.js @@ -1,60 +1,53 @@ const fs = require('fs'); const { fake } = require('sinon'); -class GladysGatewayClientMock {} - -GladysGatewayClientMock.prototype.login = fake.resolves({ - two_factor_token: 'token', -}); - -// AUTHENTICATION -GladysGatewayClientMock.prototype.loginInstance = fake.resolves({}); -GladysGatewayClientMock.prototype.createInstance = fake.resolves({ - instance: { - id: '25239392-debf-40c9-9363-fc8d3b9ebbbe', - refresh_token: 'token', - }, - rsaPrivateKeyJwk: {}, - ecdsaPrivateKeyJwk: {}, - rsaPublicKeyJwk: {}, - ecdsaPublicKeyJwk: {}, -}); -GladysGatewayClientMock.prototype.instanceConnect = fake.resolves({}); - -// BACKUPS -GladysGatewayClientMock.prototype.uploadBackup = fake.resolves({ - success: true, -}); - -GladysGatewayClientMock.prototype.getBackups = fake.resolves([ - { - id: '74dc8d58-3997-484a-a791-53e5b07279d7', - account_id: 'b2d23f66-487d-493f-8acb-9c8adb400def', - path: 'http://backup-url', - size: 1000, - created_at: '2018-10-16T02:21:25.901Z', - updated_at: '2018-10-16T02:21:25.901Z', - is_deleted: false, - }, -]); - -GladysGatewayClientMock.prototype.downloadBackup = (backupUrl, writeStream) => { - const readStream = fs.createReadStream(backupUrl); - readStream.pipe(writeStream); - return new Promise((resolve, reject) => { - writeStream.on('finish', resolve); - writeStream.on('error', reject); - }); +const GladysGatewayClientMock = function() { + return { + login: fake.resolves({ + two_factor_token: 'token', + }), + loginInstance: fake.resolves({}), + createInstance: fake.resolves({ + instance: { + id: '25239392-debf-40c9-9363-fc8d3b9ebbbe', + refresh_token: 'token', + }, + rsaPrivateKeyJwk: {}, + ecdsaPrivateKeyJwk: {}, + rsaPublicKeyJwk: {}, + ecdsaPublicKeyJwk: {}, + }), + instanceConnect: fake.resolves({}), + uploadBackup: fake.resolves({ + success: true, + }), + getBackups: fake.resolves([ + { + id: '74dc8d58-3997-484a-a791-53e5b07279d7', + account_id: 'b2d23f66-487d-493f-8acb-9c8adb400def', + path: 'http://backup-url', + size: 1000, + created_at: '2018-10-16T02:21:25.901Z', + updated_at: '2018-10-16T02:21:25.901Z', + is_deleted: false, + }, + ]), + downloadBackup: (backupUrl, writeStream) => { + const readStream = fs.createReadStream(backupUrl); + readStream.pipe(writeStream); + return new Promise((resolve, reject) => { + writeStream.on('finish', resolve); + writeStream.on('error', reject); + }); + }, + getLatestGladysVersion: fake.resolves({ + name: 'v4.0.0-alpha', + created_at: '2018-10-16T02:21:25.901Z', + }), + disconnect: fake.returns(null), + newEventInstance: fake.returns(null), + generateFingerprint: fake.resolves('fingerprint'), + }; }; -GladysGatewayClientMock.prototype.getLatestGladysVersion = fake.resolves({ - name: 'v4.0.0-alpha', - created_at: '2018-10-16T02:21:25.901Z', -}); - -GladysGatewayClientMock.prototype.disconnect = fake.returns(null); - -GladysGatewayClientMock.prototype.newEventInstance = fake.returns(null); -GladysGatewayClientMock.prototype.generateFingerprint = fake.resolves('fingerprint'); - module.exports = GladysGatewayClientMock; diff --git a/server/test/lib/gateway/gateway.test.js b/server/test/lib/gateway/gateway.test.js index a472c507f5..5ca5736e19 100644 --- a/server/test/lib/gateway/gateway.test.js +++ b/server/test/lib/gateway/gateway.test.js @@ -136,9 +136,10 @@ describe('gateway', () => { }); }); describe('gateway.forwardWebsockets', () => { - it('should forward a websocket message', async () => { + it('should forward a websocket message when connected', () => { const gateway = new Gateway({}, event, system, sequelize, config); - await gateway.login('tony.stark@gladysassistant.com', 'warmachine123'); + gateway.connected = true; + const websocketMessage = { type: 'zwave.new-node', payload: {}, @@ -146,6 +147,16 @@ describe('gateway', () => { gateway.forwardWebsockets(websocketMessage); assert.calledWith(gateway.gladysGatewayClient.newEventInstance, websocketMessage.type, websocketMessage.payload); }); + it('should prevent forwarding a websocket message when not connected', () => { + const gateway = new Gateway({}, event, system, sequelize, config); + + const websocketMessage = { + type: 'zwave.new-node', + payload: {}, + }; + gateway.forwardWebsockets(websocketMessage); + assert.notCalled(gateway.gladysGatewayClient.newEventInstance); + }); }); describe('gateway.handleNewMessage', () => {