diff --git a/src/frontend/components/points-component.jsx b/src/frontend/components/points-component.jsx index 9758d4992d..11b4714aaf 100644 --- a/src/frontend/components/points-component.jsx +++ b/src/frontend/components/points-component.jsx @@ -2,7 +2,6 @@ import React, { useEffect } from 'react' import { Button, Input } from 'reactstrap' import PropTypes from 'prop-types' -import objectPath from 'object-path' import { nanoid } from 'nanoid' import Table from './table/table.jsx' import TablePagination from './table/table-pagination.jsx' @@ -53,11 +52,10 @@ const PointsComponent = ({ * @returns {void} */ const handleAddPoint = () => { - const newPoint = Object.entries(schema.points).map(([name]) => name).reduce((previousValue, currentValue) => { - objectPath.set(previousValue, currentValue, '') - return previousValue - }, {}) - newPoint.id = nanoid() + const newPoint = { id: nanoid() } + Object.entries(schema.points).forEach(([key, value]) => { + newPoint[key] = value.defaultValue + }) const newAllPoints = [...allPoints] newAllPoints.unshift(newPoint) setAllPoints(newAllPoints) @@ -71,6 +69,7 @@ const PointsComponent = ({ const pointToUpdate = newAllPoints.find((point) => point.id === id) pointToUpdate[name] = value setAllPoints(newAllPoints) + onChange(prefix, newAllPoints) } /** @@ -167,7 +166,7 @@ const PointsComponent = ({ onPagePressed={(page) => setSelectedPage(page)} /> )} -
+
diff --git a/src/south/south-modbus/south-modbus.js b/src/south/south-modbus/south-modbus.js index db40ef8c75..b6949e1d19 100644 --- a/src/south/south-modbus/south-modbus.js +++ b/src/south/south-modbus/south-modbus.js @@ -1,6 +1,6 @@ import net from 'node:net' -import modbus from 'jsmodbus' +import { client } from 'jsmodbus' import SouthConnector from '../south-connector.js' import getNumberOfWords from './utils.js' @@ -209,16 +209,18 @@ export default class SouthModbus extends SouthConnector { clearTimeout(this.reconnectTimeout) } this.socket = new net.Socket() - this.client = new modbus.client.TCP(this.socket, this.slaveId) + this.client = new client.TCP(this.socket, this.slaveId) + this.logger.debug(`Connecting Modbus socket into ${this.host}:${this.port}`) this.socket.connect( { host: this.host, port: this.port }, async () => { + this.logger.info(`Modbus socket connected to ${this.host}:${this.port}`) await super.connect() resolve() }, ) this.socket.on('error', async (error) => { - this.logger.error(error) + this.logger.error(`Modbus socket error: ${error}`) await this.disconnect() this.reconnectTimeout = setTimeout(this.connect.bind(this), this.retryInterval) }) diff --git a/src/south/south-modbus/south-modbus.spec.js b/src/south/south-modbus/south-modbus.spec.js index 1f17bc0590..790cb19b24 100644 --- a/src/south/south-modbus/south-modbus.spec.js +++ b/src/south/south-modbus/south-modbus.spec.js @@ -145,7 +145,7 @@ describe('SouthModbus', () => { mockedEmitter.emit('error', 'connect error') await flushPromises() expect(south.disconnect).toHaveBeenCalledTimes(1) - expect(south.logger.error).toHaveBeenCalledWith('connect error') + expect(south.logger.error).toHaveBeenCalledWith('Modbus socket error: connect error') jest.advanceTimersByTime(configuration.settings.retryInterval) expect(net.Socket).toHaveBeenCalledTimes(2)