Skip to content

Commit

Permalink
[package] use debug for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhyde committed Jun 9, 2024
1 parent c7d2e7e commit 7ad5ec8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@2bad/tsconfig": "3.0.1",
"@swc/cli": "0.3.12",
"@swc/core": "1.5.24",
"@types/debug": "4.1.12",
"@types/node": "20.12.13",
"@vitest/coverage-v8": "1.6.0",
"eslint-config-love": "52.0.0",
Expand Down
6 changes: 4 additions & 2 deletions source/decorators/measure.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import debug from 'debug'
import { performance } from 'node:perf_hooks'
import { Roarr as log } from 'roarr'

const log = debug('tvt:perf')

/**
* A method decorator that measures the execution time of the decorated method.
Expand All @@ -24,7 +26,7 @@ export const measure = <This, Args extends any[], Return>(
const start = performance.now()
const result = target.call(this, ...args)
const finish = performance.now()
log(`[${methodName}] Execution time: ${finish - start} milliseconds`)
log(`[${methodName}] execution time: ${finish - start} ms`)
return result
}
return trackPerf
Expand Down
28 changes: 4 additions & 24 deletions source/device.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import debug from 'debug'
import { randomUUID } from 'node:crypto'
import { existsSync, mkdirSync } from 'node:fs'
import { dirname } from 'node:path'
Expand All @@ -7,30 +8,8 @@ import { validateIp, validatePort } from './helpers/validators.ts'
import { sdk } from './lib/sdk.ts'
import { NET_SDK_ERROR, type DeviceInfo } from './lib/types.ts'
import type { Settings, VersionInfo } from './types.ts'
export type Settings = {
uuid?: `${string}-${string}-${string}-${string}-${string}`
connectionTimeoutMs?: number
maxRetries?: number
reconnectIntervalMs?: number
isReconnectEnabled?: boolean
}

export type VersionInfo = {
sdk: {
version: string
build: string
}
device: {
name: string
model: string
SN: string
firmware: string
kernel: string
hardware: string
MCU: string
software: number
}
}
const log = debug('tvt:device')

/**
* Represents a generic TVT Device.
Expand Down Expand Up @@ -76,7 +55,7 @@ export class Device {
}

if (this.init()) {
console.log('Device initialized successfully!')
log(`${this.uuid} device initialized successfully!`)

const sdkVersion = sdk.getSDKVersion()
const buildVersion = sdk.getSDKBuildVersion()
Expand Down Expand Up @@ -196,6 +175,7 @@ export class Device {
*/
@auth
triggerAlarm(value: boolean): boolean {
// @TODO: get alarm channels from device info
const alarmChannels = [0]
const alarmValues = [value ? 1 : 0]
return sdk.triggerAlarm(this.userId, alarmChannels, alarmValues, alarmChannels.length, this.#isAlarmOpen)
Expand Down

0 comments on commit 7ad5ec8

Please sign in to comment.