Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async resourceCommand (command, ...args) {
const parser = new homebridgeLib.CommandLineParser(packageJson)
const clargs = {
options: {}
}
parser.help('h', 'help', help[command])
parser.flag('v', 'verbose', () => { clargs.options.verbose = true })
parser.parameter('resource', (value) => {
clargs.resource = value
if (
clargs.resource.length === 0 || clargs.resource[0] !== '/' ||
clargs.resource === '/'
) {
throw new Error(`${clargs.resource}: invalid resource`)
}
})
parser.remaining((list) => {
if (list.length > 1) {
parseArguments () {
const parser = new homebridgeLib.CommandLineParser(packageJson)
const clargs = {
options: {
host: process.env.PH_HOST || 'localhost'
}
}
parser.help('h', 'help', help.ph)
parser.version('V', 'version')
parser.option('H', 'host', (value) => {
homebridgeLib.OptionParser.toHost('host', value, true)
clargs.options.host = value
})
parser.flag('p', 'phoscon', () => {
clargs.options.phoscon = true
})
parser.flag('s', 'https', () => {
clargs.options.https = true
async config (...args) {
const parser = new homebridgeLib.CommandLineParser(packageJson)
const options = {}
parser.help('h', 'help', help.config)
parser.flag('s', 'sortKeys', () => { options.sortKeys = true })
parser.parse(...args)
const jsonFormatter = new homebridgeLib.JsonFormatter(options)
const json = jsonFormatter.stringify(await this.hueClient.config())
this.print(json)
}
async probe (...args) {
const parser = new homebridgeLib.CommandLineParser(packageJson)
const clargs = {
maxCount: 60
}
parser.help('h', 'help', help.probe)
parser.flag('v', 'verbose', () => { clargs.verbose = true })
parser.option('t', 'timeout', (value, key) => {
homebridgeLib.OptionParser.toInt(
'timeout', value, 1, 10, true
)
clargs.maxCount = value * 12
})
parser.parameter('light', (value) => {
if (value.substring(0, 8) !== '/lights/') {
throw new UsageError(`${value}: invalid light`)
}
clargs.light = value
async get (...args) {
const parser = new homebridgeLib.CommandLineParser(packageJson)
const clargs = {
options: {}
}
parser.help('h', 'help', help.get)
parser.flag('s', 'sortKeys', () => { clargs.options.sortKeys = true })
parser.flag('n', 'noWhiteSpace', () => {
clargs.options.noWhiteSpace = true
})
parser.flag('j', 'jsonArray', () => { clargs.options.noWhiteSpace = true })
parser.flag('u', 'joinKeys', () => { clargs.options.joinKeys = true })
parser.flag('a', 'ascii', () => { clargs.options.ascii = true })
parser.flag('t', 'topOnly', () => { clargs.options.topOnly = true })
parser.flag('l', 'leavesOnly', () => { clargs.options.leavesOnly = true })
parser.flag('k', 'keysOnly', () => { clargs.options.keysOnly = true })
parser.flag('v', 'valuesOnly', () => { clargs.options.valuesOnly = true })
parser.remaining((list) => {
async restart (...args) {
const parser = new homebridgeLib.CommandLineParser(packageJson)
const clargs = {}
parser.help('h', 'help', help.restart)
parser.flag('v', 'verbose', () => { clargs.verbose = true })
parser.parse(...args)
if (!this.hueClient.isDeconz) {
this.fatal('restart: only supported for deCONZ gateway')
}
const response = await this.hueClient.post('/config/restartapp')
if (!response['/config/restartapp']) {
return Promise.resolve(false)
}
clargs.verbose && this.log('restarting ...\\c')
return new Promise((resolve, reject) => {
let busy = false
const interval = setInterval(async () => {
try {
async outlet (...args) {
const parser = new homebridgeLib.CommandLineParser(packageJson)
const clargs = {}
parser.help('h', 'help', help.outlet)
parser.flag('v', 'verbose', () => { clargs.verbose = true })
parser.parse(...args)
let outlet
const lights = await this.hueClient.get('/lights')
const resourcelinks = await this.hueClient.get('/resourcelinks')
for (const id in resourcelinks) {
const link = resourcelinks[id]
if (link.name === 'homebridge-hue' && link.description === 'outlet') {
outlet = id
}
}
if (outlet == null) {
const body = {
name: 'homebridge-hue',
async createuser (...args) {
const parser = new homebridgeLib.CommandLineParser(packageJson)
const jsonFormatter = new homebridgeLib.JsonFormatter(
{ noWhiteSpace: true, sortKeys: true }
)
parser.help('h', 'help', help.createuser)
parser.parse(...args)
const username = await this.hueClient.createuser('ph')
this.print(jsonFormatter.stringify(username))
this.bridges[this.bridgeid] = { username: username }
if (this.hueClient.fingerprint != null) {
this.bridges[this.bridgeid].fingerprint = this.hueClient.fingerprint
}
this._writeBridges()
}