This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
79 lines (57 loc) · 1.95 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const { authorize } = require('./src/authorize')
const { createClient } = require('./src/client')
const { discover, ipv6, ipv4 } = require('./src/discover')
const WebSocket = require('ws')
const { agent } = require('./src/machinery/fetch')
run(async () => {
// const x = await discover({ interface: 'enp0s31f6' })
// const info = await discover({ ipVersion: ipv6 })
// console.log(info)
// const { ip, port } = info
// const authorization = await authorize({ ip, port, name: 'test' })
// console.log(authorization)
// const { accessToken } = authorization
// const {ip, port} = { ip: '192.168.0.100', port: 8443 }
// const accessToken = '...'
// const client = createClient({ ip, port, accessToken })
// const devices = await client.listDevices()
// console.log(devices)
// return
// const red = [
// { colorTemperature: 2702, },
// { colorHue: 0, colorSaturation: 1, },
// ]
// const blue = [
// { colorTemperature: 4000, },
// { colorHue: 239.996337890625, colorSaturation: 1, },
// ]
// const on = [{ isOn: true }]
// const off = [{ isOn: false }]
// const light = devices.find(x => x.attributes.customName === 'light6')
// const x = await client.patchDeviceAttributes(light.id, red)
// console.log(x)
// const button = devices.find(x => x.attributes.customName === 'remote1')
// console.log(button)
// console.log(devices.map(x => x.attributes.customName))
// const ws = new WebSocket(
// `wss://${ip}:${port}/v1`, {
// agent,
// headers: { 'Authorization': `Bearer ${accessToken}` }
// }
// )
// ws.on('open', () => {
// console.log('socket open')
// })
// ws.on('error', e => {
// console.error(e)
// })
// ws.on('message', data => {
// console.log(JSON.parse(data, null, 2))
// })
// await new Promise(_ => {})
})
function run(f) {
f()
.then(_ => { console.log('Done'); process.exit(0) })
.catch(e => { console.error(e); process.exit(1) })
}