From 5619cb3edef8c5e46b36f5b75fe62130bfea90d7 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Mon, 7 Dec 2020 15:19:38 +0100 Subject: [PATCH] fix: socket events constants --- lib/SocketManager.js | 1 + src/App.vue | 18 -------------- src/components/ControlPanel.vue | 43 ++++++++++++++++----------------- src/components/Mesh.vue | 24 +++++++++--------- src/plugins/socket.js | 21 ++++++++++++++++ 5 files changed, 55 insertions(+), 52 deletions(-) create mode 100644 src/plugins/socket.js diff --git a/lib/SocketManager.js b/lib/SocketManager.js index d76d6a13f92..a97051a1d2d 100644 --- a/lib/SocketManager.js +++ b/lib/SocketManager.js @@ -7,6 +7,7 @@ const debug = reqlib('/lib/debug')('Socket') debug.color = 3 +// FIXME: this constants are duplicated on /src/plugins/socket.js. When converting this to ES6 module that can be removed // events from server ---> client const socketEvents = { init: 'INIT', // automatically sent when a new client connects to the socket diff --git a/src/App.vue b/src/App.vue index 728e050ef10..f3cd2d9d9f5 100644 --- a/src/App.vue +++ b/src/App.vue @@ -70,8 +70,6 @@ @showSnackbar="showSnackbar" @showConfirm="confirm" :socket="socket" - :socketEvents="socketEvents" - :socketActions="socketActions" /> @@ -222,22 +220,6 @@ export default { { icon: 'settings', title: 'Settings', path: '/settings' }, { icon: 'share', title: 'Network graph', path: '/mesh' } ], - socketEvents: { - init: 'INIT', - controller: 'CONTROLLER_CMD', - connected: 'CONNECTED', - nodeRemoved: 'NODE_REMOVED', - nodeUpdated: 'NODE_UPDATED', - valueUpdated: 'VALUE_UPDATED', - valueRemoved: 'VALUE_REMOVED', - api: 'API_RETURN', - debug: 'DEBUG' - }, - socketActions: { - init: 'INITED', - hass: 'HASS_API', - zwave: 'ZWAVE_API' - }, status: '', statusColor: '', drawer: false, diff --git a/src/components/ControlPanel.vue b/src/components/ControlPanel.vue index dd108a40933..710947ac21f 100644 --- a/src/components/ControlPanel.vue +++ b/src/components/ControlPanel.vue @@ -660,6 +660,7 @@ import ValueID from '@/components/ValueId' import AnsiUp from 'ansi_up' import DialogSceneValue from '@/components/dialogs/DialogSceneValue' +import { socketEvents, inboundEvents as socketActions } from '@/plugins/socket' const ansiUp = new AnsiUp() @@ -668,9 +669,7 @@ const MAX_DEBUG_LINES = 300 export default { name: 'ControlPanel', props: { - socket: Object, - socketActions: Object, - socketEvents: Object + socket: Object }, components: { ValueID, @@ -997,7 +996,7 @@ export default { api: apiName, args: args } - this.socket.emit(this.socketActions.zwave, data) + this.socket.emit(socketActions.zwave, data) } else { this.showSnackbar('Socket disconnected') } @@ -1074,7 +1073,7 @@ export default { 'alert' )) ) { - this.socket.emit(this.socketActions.hass, { + this.socket.emit(socketActions.hass, { apiName: 'delete', device: device, nodeId: this.selectedNode.id @@ -1090,7 +1089,7 @@ export default { 'Are you sure you want to re-discover all node values?' )) ) { - this.socket.emit(this.socketActions.hass, { + this.socket.emit(socketActions.hass, { apiName: 'rediscoverNode', nodeId: this.selectedNode.id }) @@ -1105,7 +1104,7 @@ export default { 'Are you sure you want to disable discovery of all values? In order to make this persistent remember to click on Store' )) ) { - this.socket.emit(this.socketActions.hass, { + this.socket.emit(socketActions.hass, { apiName: 'disableDiscovery', nodeId: this.selectedNode.id }) @@ -1120,7 +1119,7 @@ export default { 'Are you sure you want to re-discover selected device?' )) ) { - this.socket.emit(this.socketActions.hass, { + this.socket.emit(socketActions.hass, { apiName: 'discover', device: device, nodeId: this.selectedNode.id @@ -1135,7 +1134,7 @@ export default { this.selectedDevice.id, updated ) - this.socket.emit(this.socketActions.hass, { + this.socket.emit(socketActions.hass, { apiName: 'update', device: updated, nodeId: this.selectedNode.id @@ -1145,7 +1144,7 @@ export default { addDevice () { if (!this.errorDevice) { var newDevice = JSON.parse(this.deviceJSON) - this.socket.emit(this.socketActions.hass, { + this.socket.emit(socketActions.hass, { apiName: 'add', device: newDevice, nodeId: this.selectedNode.id @@ -1153,7 +1152,7 @@ export default { } }, storeDevices (remove) { - this.socket.emit(this.socketActions.hass, { + this.socket.emit(socketActions.hass, { apiName: 'store', devices: this.selectedNode.hassDevices, nodeId: this.selectedNode.id, @@ -1404,24 +1403,24 @@ export default { this.nodeTableItems = !isNaN(itemsPerPage) ? itemsPerPage : 10 - this.socket.on(this.socketEvents.controller, data => { + this.socket.on(socketEvents.controller, data => { self.cnt_status = data }) - this.socket.on(this.socketEvents.connected, info => { + this.socket.on(socketEvents.connected, info => { self.homeid = info.homeid self.homeHex = info.name self.ozwVersion = info.version }) - this.socket.on(this.socketEvents.nodeRemoved, node => { + this.socket.on(socketEvents.nodeRemoved, node => { if (self.selectedNode && self.selectedNode.id === node.id) { self.selectedNode = null } self.$set(self.nodes, node.id, node) }) - this.socket.on(this.socketEvents.debug, data => { + this.socket.on(socketEvents.debug, data => { if (self.debugActive) { data = ansiUp.ansi_to_html(data) data = data.replace(/\n/g, '
') @@ -1438,7 +1437,7 @@ export default { } }) - this.socket.on(this.socketEvents.init, data => { + this.socket.on(socketEvents.init, data => { // convert node values in array var nodes = data.nodes for (var i = 0; i < nodes.length; i++) { @@ -1451,7 +1450,7 @@ export default { self.ozwVersion = data.info.version }) - this.socket.on(this.socketEvents.nodeUpdated, data => { + this.socket.on(socketEvents.nodeUpdated, data => { self.initNode(data) if (!self.nodes[data.id] || self.nodes[data.id].failed) { // add missing nodes @@ -1470,7 +1469,7 @@ export default { } }) - this.socket.on(this.socketEvents.valueRemoved, data => { + this.socket.on(socketEvents.valueRemoved, data => { const valueId = self.getValue(data) if (valueId) { @@ -1483,7 +1482,7 @@ export default { } }) - this.socket.on(this.socketEvents.valueUpdated, data => { + this.socket.on(socketEvents.valueUpdated, data => { const valueId = self.getValue(data) if (valueId) { @@ -1504,7 +1503,7 @@ export default { } }) - this.socket.on(this.socketEvents.api, async data => { + this.socket.on(socketEvents.api, async data => { if (data.success) { switch (data.api) { case 'getAssociations': @@ -1542,12 +1541,12 @@ export default { } }) - this.socket.emit(this.socketActions.init, true) + this.socket.emit(socketActions.init, true) }, beforeDestroy () { if (this.socket) { // unbind events - for (const event in this.socketEvents) { + for (const event in socketEvents) { this.socket.off(event) } } diff --git a/src/components/Mesh.vue b/src/components/Mesh.vue index 76399b7c627..4db9c16cec8 100644 --- a/src/components/Mesh.vue +++ b/src/components/Mesh.vue @@ -120,12 +120,12 @@