How to use the homebridge-lib.JsonFormatter function in homebridge-lib

To help you get started, we’ve selected a few homebridge-lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ebaauw / homebridge-hue / cli / ph.js View on Github external
parser.remaining((list) => {
      if (list.length > 1) {
        throw new Error('too many paramters')
      }
      if (list.length === 1) {
        try {
          clargs.body = JSON.parse(list[0])
        } catch (err) {
          throw new Error(err.message)
        }
      }
    })
    parser.parse(...args)
    const response = await this.hueClient[command](clargs.resource, clargs.body)
    if (response != null) {
      const jsonFormatter = new homebridgeLib.JsonFormatter()
      if (clargs.options.verbose) {
        const json = jsonFormatter.stringify(response)
        this.print(json)
      } else if (command === 'post') {
        const key = Object.keys(response)[0]
        const json = jsonFormatter.stringify(response[key])
        this.print(json)
      }
    }
  }
github ebaauw / homebridge-hue / cli / ph.js View on Github external
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)
  }
github ebaauw / homebridge-hue / cli / ph.js View on Github external
async simpleCommand (command, ...args) {
    const parser = new homebridgeLib.CommandLineParser(packageJson)
    parser.help('h', 'help', help[command])
    parser.parse(...args)
    const response = await this.hueClient[command]()
    const jsonFormatter = new homebridgeLib.JsonFormatter()
    const json = jsonFormatter.stringify(response)
    this.print(json)
  }
github ebaauw / homebridge-hue / cli / ph.js View on Github external
_writeBridges () {
    const jsonFormatter = new homebridgeLib.JsonFormatter(
      { noWhiteSpace: true, sortKeys: true }
    )
    const text = jsonFormatter.stringify(this.bridges)
    fs.writeFileSync(process.env.HOME + '/.ph', text, { mode: 0o600 })
  }
github ebaauw / homebridge-hue / cli / ph.js View on Github external
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) => {
      if (list.length > 1) {
        throw new UsageError('too many paramters')
      }
      clargs.resource = list.length === 1 ? list[0] : '/'
      if (clargs.resource[0] !== '/') {
        throw new UsageError(`${clargs.resource}: invalid resource`)
      }
    })
    parser.parse(...args)
    const jsonFormatter = new homebridgeLib.JsonFormatter(clargs.options)
    const response = await this.hueClient.get(clargs.resource)
    const json = jsonFormatter.stringify(response)
    this.print(json)
  }
github ebaauw / homebridge-hue / cli / ph.js View on Github external
async discover (...args) {
    const parser = new homebridgeLib.CommandLineParser(packageJson)
    const clargs = {}
    parser.help('h', 'help', help.discover)
    parser.option('t', 'timeout', (value, key) => {
      clargs.timeout = homebridgeLib.OptionParser.toInt(
        'timeout', value, 1, 60, true
      )
    })
    parser.flag('v', 'verbose', () => { clargs.verbose = true })
    parser.parse(...args)
    const hueDiscovery = new HueDiscovery(clargs)
    const jsonFormatter = new homebridgeLib.JsonFormatter({ sortKeys: true })
    const bridges = await hueDiscovery.discover()
    this.print(jsonFormatter.stringify(bridges))
  }
github ebaauw / homebridge-hue / cli / ph.js View on Github external
async description (...args) {
    const parser = new homebridgeLib.CommandLineParser(packageJson)
    const options = {}
    parser.help('h', 'help', help.description)
    parser.flag('s', 'sortKeys', () => { options.sortKeys = true })
    parser.parse(...args)
    const response = await this.hueClient.description()
    const jsonFormatter = new homebridgeLib.JsonFormatter(options)
    const json = jsonFormatter.stringify(response)
    this.print(json)
  }