homebridge-lib 6.3.7 → 6.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -6
- package/cli/hap.js +2 -2
- package/cli/json.js +2 -2
- package/cli/sysinfo.js +2 -2
- package/cli/upnp.js +2 -2
- package/index.js +41 -105
- package/lib/AccessoryDelegate.js +1 -1
- package/lib/AdaptiveLighting.js +3 -3
- package/lib/Delegate.js +2 -1
- package/lib/EveHomeKitTypes.js +2 -2
- package/lib/MyHomeKitTypes.js +2 -2
- package/lib/Platform.js +7 -5
- package/lib/ServiceDelegate/AccessoryInformation.js +1 -3
- package/lib/ServiceDelegate/Battery.js +1 -3
- package/lib/ServiceDelegate/Dummy.js +1 -3
- package/lib/ServiceDelegate/History.js +6 -11
- package/lib/ServiceDelegate/ServiceLabel.js +1 -3
- package/lib/UiServer.js +1 -2
- package/package.json +4 -6
- package/lib/Colour.js +0 -323
- package/lib/CommandLineParser.js +0 -311
- package/lib/CommandLineTool.js +0 -328
- package/lib/HapTool.js +0 -92
- package/lib/HttpClient.js +0 -478
- package/lib/JsonFormatter.js +0 -200
- package/lib/JsonTool.js +0 -166
- package/lib/OptionParser.js +0 -886
- package/lib/SysinfoTool.js +0 -79
- package/lib/SystemInfo.js +0 -522
- package/lib/UpnpClient.js +0 -217
- package/lib/UpnpTool.js +0 -148
package/lib/JsonTool.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// homebridge-lib/lib/JsonTool.js
|
|
4
|
-
//
|
|
5
|
-
// Library for Homebridge plugins.
|
|
6
|
-
// Copyright © 2018-2023 Erik Baauw. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
// JSON formatter.
|
|
9
|
-
|
|
10
|
-
'use strict'
|
|
11
|
-
|
|
12
|
-
const homebridgeLib = require('../index')
|
|
13
|
-
|
|
14
|
-
const fs = require('fs')
|
|
15
|
-
const util = require('util')
|
|
16
|
-
const zlib = require('zlib')
|
|
17
|
-
|
|
18
|
-
const gunzip = util.promisify(zlib.unzip)
|
|
19
|
-
|
|
20
|
-
const { b, u } = homebridgeLib.CommandLineTool
|
|
21
|
-
|
|
22
|
-
const usage = `${b('json')} [${b('-hVsnjuatlkv')}] [${b('-p')} path] [${b('-d')} depth] [${b('-c')} ${u('string')}]... [${u('file')}]...`
|
|
23
|
-
const help = `JSON formatter.
|
|
24
|
-
|
|
25
|
-
Usage: ${usage}
|
|
26
|
-
|
|
27
|
-
By default, ${b('json')} reads JSON from stdin, formats it, and prints it to stdout.
|
|
28
|
-
|
|
29
|
-
Parameters:
|
|
30
|
-
${b('-h')}, ${b('--help')}
|
|
31
|
-
Print this help and exit.
|
|
32
|
-
|
|
33
|
-
${b('-V')}, ${b('--version')}
|
|
34
|
-
Print version and exit.
|
|
35
|
-
|
|
36
|
-
${b('-s')}, ${b('--sortKeys')}
|
|
37
|
-
Sort object key/value pairs alphabetically on key.
|
|
38
|
-
|
|
39
|
-
${b('-n')}, ${b('--noWhiteSpace')}
|
|
40
|
-
Do not include spaces nor newlines in output.
|
|
41
|
-
|
|
42
|
-
${b('-j')}, ${b('--jsonArray')}
|
|
43
|
-
Output JSON array of objects for each key/value pair.
|
|
44
|
-
Each object contains two key/value pairs:
|
|
45
|
-
- key ${b('keys')} with an array of keys as value;
|
|
46
|
-
- key ${b('value')} with the value as value.
|
|
47
|
-
|
|
48
|
-
${b('-u')}, ${b('--joinKeys')}
|
|
49
|
-
Output JSON array of objects for each key/value pair.
|
|
50
|
-
Each object contains one key/value pair:
|
|
51
|
-
the path (concatenated keys separated by ${b('/')} as key and the value as value.
|
|
52
|
-
|
|
53
|
-
${b('-a')}, ${b('--ascii')}
|
|
54
|
-
Output ${u('path')}${b(':')}${u('value')} in plain text instead of JSON.
|
|
55
|
-
|
|
56
|
-
${b('-t')}, ${b('--topOnly')}
|
|
57
|
-
Limit output to top-level key/values.
|
|
58
|
-
|
|
59
|
-
${b('-p')} ${u('path')}, ${b('--fromPath=')}${u('path')}
|
|
60
|
-
Limit output to key/values under ${u('path')}. Set top level below ${u('path')}.
|
|
61
|
-
|
|
62
|
-
${b('-d')} ${u('depth')}, ${b('--maxDepth=')}${u('depth')}
|
|
63
|
-
Limit output to levels above ${u('depth')}.
|
|
64
|
-
|
|
65
|
-
${b('-l')}, ${b('--leavesOnly')}
|
|
66
|
-
Limit output to leaf (non-array, non-object) key/values.
|
|
67
|
-
|
|
68
|
-
${b('-k')}, ${b('--keysOnly')}
|
|
69
|
-
Limit output to keys. With ${b('-u')} output JSON array of paths.
|
|
70
|
-
|
|
71
|
-
${b('-v')}, ${b('--valuesOnly')}
|
|
72
|
-
Limit output to values. With ${b('-u')} output JSON array of values.
|
|
73
|
-
|
|
74
|
-
${b('-c')} ${u('string')}, ${b('--string=')}${u('string')}
|
|
75
|
-
Read JSON from ${u('string')} instead of from stdin.
|
|
76
|
-
|
|
77
|
-
${u('file')}
|
|
78
|
-
Read JSON from ${u('file')} instead of from stdin.
|
|
79
|
-
When the file name ends in ${b('.gz')}, it is assumed to be a gzip file and
|
|
80
|
-
uncompressed automatically.`
|
|
81
|
-
|
|
82
|
-
class JsonTool extends homebridgeLib.CommandLineTool {
|
|
83
|
-
constructor () {
|
|
84
|
-
super()
|
|
85
|
-
this.usage = usage
|
|
86
|
-
this.options = {}
|
|
87
|
-
this.stringList = []
|
|
88
|
-
this.fileList = []
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
parseArguments () {
|
|
92
|
-
const parser = new homebridgeLib.CommandLineParser()
|
|
93
|
-
parser
|
|
94
|
-
.help('h', 'help', help)
|
|
95
|
-
.version('V', 'version')
|
|
96
|
-
.flag('s', 'sortKeys', () => { this.options.sortKeys = true })
|
|
97
|
-
.flag('n', 'noWhiteSpace', () => { this.options.noWhiteSpace = true })
|
|
98
|
-
.flag('j', 'jsonArray', () => { this.options.jsonArray = true })
|
|
99
|
-
.flag('u', 'joinKeys', () => { this.options.joinKeys = true })
|
|
100
|
-
.flag('a', 'ascii', () => { this.options.ascii = true })
|
|
101
|
-
.flag('t', 'topOnly', () => { this.options.topOnly = true })
|
|
102
|
-
.option('d', 'maxDepth', (value, option) => {
|
|
103
|
-
this.options.maxDepth = homebridgeLib.OptionParser.toInt(
|
|
104
|
-
'maxDepth', value, 0, undefined, true)
|
|
105
|
-
})
|
|
106
|
-
.option('p', 'fromPath', (value, option) => {
|
|
107
|
-
this.options.fromPath = homebridgeLib.OptionParser.toPath(
|
|
108
|
-
'fromPath', value, true
|
|
109
|
-
)
|
|
110
|
-
})
|
|
111
|
-
.flag('l', 'leavesOnly', () => { this.options.leavesOnly = true })
|
|
112
|
-
.flag('k', 'keysOnly', () => { this.options.keysOnly = true })
|
|
113
|
-
.flag('v', 'valuesOnly', () => { this.options.valuesOnly = true })
|
|
114
|
-
.option('c', 'string', (value) => { this.stringList.push(value) })
|
|
115
|
-
.remaining((list) => { this.fileList = list })
|
|
116
|
-
.parse()
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
processString (s) {
|
|
120
|
-
let value
|
|
121
|
-
try {
|
|
122
|
-
value = JSON.parse(s)
|
|
123
|
-
} catch (error) {
|
|
124
|
-
throw new Error(error.message) // Convert SyntaxError to Error.
|
|
125
|
-
}
|
|
126
|
-
const output = this.jsonFormatter.stringify(value)
|
|
127
|
-
if (this.n++ > 0) {
|
|
128
|
-
this.print('------')
|
|
129
|
-
}
|
|
130
|
-
if (output !== '') {
|
|
131
|
-
this.print(output)
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async main () {
|
|
136
|
-
try {
|
|
137
|
-
this.parseArguments()
|
|
138
|
-
this.jsonFormatter = new homebridgeLib.JsonFormatter(this.options)
|
|
139
|
-
if (this.fileList.length === 0 && this.stringList.length === 0) {
|
|
140
|
-
this.fileList = ['-']
|
|
141
|
-
}
|
|
142
|
-
this.n = 0
|
|
143
|
-
this.stringList.forEach((s) => {
|
|
144
|
-
try {
|
|
145
|
-
this.processString(s)
|
|
146
|
-
} catch (error) {
|
|
147
|
-
this.error(error)
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
this.fileList.forEach(async (file) => {
|
|
151
|
-
try {
|
|
152
|
-
const s = file.endsWith('.gz')
|
|
153
|
-
? await gunzip(fs.readFileSync(file))
|
|
154
|
-
: fs.readFileSync(file === '-' ? 0 : file, 'utf8')
|
|
155
|
-
this.processString(s)
|
|
156
|
-
} catch (error) {
|
|
157
|
-
this.error(error)
|
|
158
|
-
}
|
|
159
|
-
})
|
|
160
|
-
} catch (error) {
|
|
161
|
-
await this.fatal(error)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
module.exports = JsonTool
|