Skip to content

Commit

Permalink
feat: improve debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
plasticrake committed Nov 9, 2023
1 parent 1febedb commit 69920e0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ See more [examples](https://github.com/plasticrake/tplink-smarthome-simulator/tr
To see everything:

```console
DEBUG=* node examples/multi-device.js
DEBUG=tplink-simulator:* node examples/multi-device.js
```

To see most:

```console
DEBUG=*,-device:udp,*:error node examples/multi-device.js
DEBUG=tplink-simulator:*,-device:udp,*:error node examples/multi-device.js
```

```javascript
'use strict';

const Device = require('..').Device;
const UdpServer = require('..').UdpServer;

Expand All @@ -44,55 +42,55 @@ devices.push(
address: '10.0.0.200',
model: 'hs100',
data: { alias: 'Mock HS100', mac: '50:c7:bf:8f:58:18', deviceId: 'A100' },
})
}),
);
devices.push(
new Device({
port: 9999,
address: '10.0.0.201',
model: 'hs105',
data: { alias: 'Mock HS105', mac: '50:c7:bf:d8:bf:d4', deviceId: 'A105' },
})
}),
);
devices.push(
new Device({
port: 9999,
address: '10.0.0.202',
model: 'hs110',
data: { alias: 'Mock HS110', mac: '50:c7:bf:0d:91:8c', deviceId: 'A110' },
})
}),
);
devices.push(
new Device({
port: 9999,
address: '10.0.0.203',
model: 'hs200',
data: { alias: 'Mock HS200', mac: '50:c7:bf:46:b4:24', deviceId: 'A200' },
})
}),
);
devices.push(
new Device({
port: 9999,
address: '10.0.0.204',
model: 'lb100',
data: { alias: 'Mock LB100', mac: '50:c7:bf:49:ca:42', deviceId: 'BB100' },
})
}),
);
devices.push(
new Device({
port: 9999,
address: '10.0.0.205',
model: 'lb120',
data: { alias: 'Mock LB120', mac: '50:c7:bf:90:9b:da', deviceId: 'BB120' },
})
}),
);
devices.push(
new Device({
port: 9999,
address: '10.0.0.206',
model: 'lb130',
data: { alias: 'Mock LB130', mac: '50:c7:bf:b1:04:d3', deviceId: 'BB130' },
})
}),
);

devices.forEach((d) => {
Expand Down
10 changes: 5 additions & 5 deletions src/device-networking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { decrypt, decryptWithHeader } from 'tplink-smarthome-crypto';
import type { Device } from './device';
import UdpServer from './udp-server';

const log = debug('device');
const logUdp = debug('device:udp');
const logUdpErr = debug('device:udp:error');
const logTcp = debug('device:tcp');
const logTcpErr = debug('device:tcp:error');
const log = debug('tplink-simulator:device');
const logUdp = debug('tplink-simulator:device:udp');
const logUdpErr = debug('tplink-simulator:device:udp:error');
const logTcp = debug('tplink-simulator:device:tcp');
const logTcpErr = debug('tplink-simulator:device:tcp:error');

const delay = (t: number) =>
new Promise((resolve) => {
Expand Down
2 changes: 1 addition & 1 deletion src/devices/hs300.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Hs = require('./hs');

const defaultData = require('./data/hs300');

const logDebug = debug('DEBUG');
const logDebug = debug('tplink-simulator:DEBUG');

class Hs300 extends Hs {
constructor(data) {
Expand Down
4 changes: 2 additions & 2 deletions src/udp-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import EventEmitter from 'events';
import dgram from 'dgram';
import debug from 'debug';

const log = debug('udp-server');
const logErr = debug('udp-server:error');
const log = debug('tplink-simulator:udp-server');
const logErr = debug('tplink-simulator:udp-server:error');

interface UdpServerType extends EventEmitter {
start: () => Promise<UdpServerType>;
Expand Down

0 comments on commit 69920e0

Please sign in to comment.