Skip to content

Commit

Permalink
🔇 Ignore GenericUnusedResponse logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bdsoha committed Nov 11, 2024
1 parent 1817796 commit 6642290
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 29 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ npm install vitrea-client
The section below outlines the different configuration values available and their
corresponding default settings.

| Config | Description | Default |
| ------------------------------- | ------------------------------------------ | -------------------- |
| `VBoxConfigs.host` | Host address to connect to the vBox | `192.168.1.23` |
| `VBoxConfigs.port` | Port used to connect to the vBox | `11501` |
| `VBoxConfigs.username` | Username used to connect to the vBox | `null` |
| `VBoxConfigs.password` | Password used to connect to the vBox | `null` |
| `VBoxConfigs.version` | Protocol version of vBox | `ProtocolVersion.V2` |
| `SocketConfigs.log` | Logger to print values | `null` |
| `SocketConfigs.ignoreAckLogs` | Ignore `Acknowledgement` logs | `false` |
| `SocketConfigs.requestBuffer` | Buffer time between requests | `250` |
| `SocketConfigs.requestTimeout` | Max timeout for requests | `1000` |
| `SocketConfigs.shouldReconnect` | Automatically reconnect on lost connection | `true` |
| `SocketConfigs.socketSupplier` | Provide a prebuilt `Net.Socket` object | `null` |
| Config | Description | Default |
| ------------------------------- | --------------------------------------------------------- | -------------------- |
| `VBoxConfigs.host` | Host address to connect to the vBox | `192.168.1.23` |
| `VBoxConfigs.port` | Port used to connect to the vBox | `11501` |
| `VBoxConfigs.username` | Username used to connect to the vBox | `null` |
| `VBoxConfigs.password` | Password used to connect to the vBox | `null` |
| `VBoxConfigs.version` | Protocol version of vBox | `ProtocolVersion.V2` |
| `SocketConfigs.log` | Logger to print values | `null` |
| `SocketConfigs.ignoreAckLogs` | Ignore `Acknowledgement` and `GenericUnusedResponse` logs | `false` |
| `SocketConfigs.requestBuffer` | Buffer time between requests | `250` |
| `SocketConfigs.requestTimeout` | Max timeout for requests | `1000` |
| `SocketConfigs.shouldReconnect` | Automatically reconnect on lost connection | `true` |
| `SocketConfigs.socketSupplier` | Provide a prebuilt `Net.Socket` object | `null` |

### Environment Variables

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vitrea-client",
"version": "0.0.7",
"version": "0.0.8",
"description": "Vitrea Smart Home API Client",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
9 changes: 9 additions & 0 deletions src/VitreaClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ describe('VitreaClient', () => {
0x56, 0x54, 0x55, 0x3C, 0x00, 0x00, 0x03, 0x00, 0x00, 0x3E
]

const generic = [
0x56, 0x54, 0x55, 0x3C, 0xC8, 0x00, 0x0E, 0x64, 0x03, 0xFF,
0x00, 0x0D, 0x6F, 0x00, 0x16, 0x17, 0x09, 0x54, 0x7D
]

const notAck = [
0x56, 0x54, 0x55, 0x3C, 0x1A, 0x00, 0x15, 0x1F, 0x00, 0x00, 0x10,
0x45, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x72, 0x00, 0x61, 0x00, 0x6E,
Expand All @@ -171,6 +176,10 @@ describe('VitreaClient', () => {

expect(mock.info).toHaveBeenCalledTimes(0)

socket.emit('data', Buffer.from(generic))

expect(mock.info).toHaveBeenCalledTimes(0)

socket.emit('data', Buffer.from(notAck))

expect(mock.info).toHaveBeenCalledTimes(1)
Expand Down
36 changes: 21 additions & 15 deletions src/VitreaClient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Mutex } from 'async-mutex'
import { Events } from './utilities/Events'
import { Timeout } from './socket/Timeout'
import { Acknowledgement, KeyStatus } from './responses'
import { AbstractSocket } from './socket/AbstractSocket'
import { ResponseFactory } from './responses/helpers'
import { SplitMultipleBuffers } from './utilities/SplitMultipleBuffers'
import { Login, ToggleHeartbeat } from './requests'
import { VitreaHeartbeatHandler } from './socket/VitreaHeartbeatHandler'
import * as Core from './core'
import { Mutex } from 'async-mutex'
import { Events } from './utilities/Events'
import { Timeout } from './socket/Timeout'
import { AbstractSocket } from './socket/AbstractSocket'
import { ResponseFactory } from './responses/helpers'
import { SplitMultipleBuffers } from './utilities/SplitMultipleBuffers'
import { Login, ToggleHeartbeat } from './requests'
import { VitreaHeartbeatHandler } from './socket/VitreaHeartbeatHandler'
import * as Core from './core'
import {
Acknowledgement,
GenericUnusedResponse,
KeyStatus

} from './responses'
import {
ConnectionConfigs,
ConnectionConfigParser,
Expand Down Expand Up @@ -74,10 +79,9 @@ export class VitreaClient extends AbstractSocket {
})
}

protected logResponseData(response: Core.BaseResponse) {
if (!(this.socketConfigs.ignoreAckLogs && response instanceof Acknowledgement)) {
this.log.info('Data Received', response.logData)
}
protected shouldLogResponse(response: Core.BaseResponse): boolean {
return !this.socketConfigs.ignoreAckLogs
|| !(response instanceof Acknowledgement || response instanceof GenericUnusedResponse)
}

protected async handleConnect() {
Expand Down Expand Up @@ -105,7 +109,9 @@ export class VitreaClient extends AbstractSocket {
return
}

this.logResponseData(response)
if (this.shouldLogResponse(response)) {
this.log.info('Data Received', response.logData)
}

this.emit(response.eventName, response)
}
Expand Down

0 comments on commit 6642290

Please sign in to comment.