Skip to content

Commit

Permalink
fix(south): reinitialize properly south currently on scan after error
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerni10 authored and Nicolas Burger committed Oct 19, 2022
1 parent 239dbd4 commit 637dcc5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/south/Modbus/Modbus.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ class Modbus extends SouthConnector {
async () => this.modbusFunction(point),
), Promise.resolve())
} catch (error) {
if (error?.err === 'Offline') {
if (error.err === 'Offline') {
this.logger.error('Modbus server offline.')
await this.disconnect()
this.reconnectTimeout = setTimeout(this.connect.bind(this), this.retryInterval)
} else {
throw error
throw new Error(error.err)
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/south/Modbus/Modbus.class.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ describe('South Modbus', () => {
it('should throw error if modbus function throws an error', async () => {
await south.connect()
south.client.readHoldingRegisters = jest.fn().mockImplementation(() => {
throw new Error('modbus error')
const rejectError = new Error()
rejectError.err = 'modbus error'
throw rejectError
})
let modbusError
try {
Expand Down
4 changes: 4 additions & 0 deletions src/south/SouthConnector.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ class SouthConnector {
async disconnect() {
this.connected = false
const { name, id } = this.settings
Object.keys(this.currentlyOnScan).forEach((scanMode) => {
this.currentlyOnScan[scanMode] = 0
this.queryParts[scanMode] = 0
})
this.statusService.updateStatusDataStream({ 'Connected at': 'Not connected' })
this.logger.info(`South connector "${name}" (${id}) disconnected.`)
}
Expand Down

0 comments on commit 637dcc5

Please sign in to comment.