How to use homebridge-lib - 10 common examples

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
${b('-v')}          Verbose.
  ${b('-t')} ${u('timeout')}  Timeout after ${u('timeout')} minutes (default: 5).
  ${u('light')}       Light resource to probe.`,
  restart: `${description.ph}

Usage: ${b('ph')} ${usage.restart}

${description.restart}
Note: this command is not supported on a Hue bridge.

Parameters:
  ${b('-h')}          Print this help and exit.
  ${b('-v')}          Verbose.`
}

class Main extends homebridgeLib.CommandLineTool {
  constructor () {
    super({ mode: 'command', debug: false })
    this.usage = usage.ph
    try {
      this._readBridges()
    } catch (err) {
      if (err.code !== 'ENOENT') {
        this.error(err)
      }
      this.bridges = {}
    }
  }

  // ===========================================================================

  _readBridges () {
github ebaauw / homebridge-hue / lib / HueDiscovery.js View on Github external
return new Promise((resolve, reject) => {
      const upnpClient = new homebridgeLib.UpnpClient({
        filter: (message) => {
          return /^[0-9A-F]{16}$/.test(message['hue-bridgeid'])
        },
        timeout: this._options.timeout
      })
      upnpClient.on('deviceFound', (address, obj, message) => {
        const id = obj['hue-bridgeid']
        const location = obj.location
        let host
        const a = location.split('/')
        if (a.length > 3 && a[2] != null) {
          host = a[2]
          const b = host.split(':')
          const port = parseInt(b[1])
          if (port === 80) {
            host = b[0]
github ebaauw / homebridge-hue / cli / ph.js View on Github external
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) {
github ebaauw / homebridge-hue / cli / ph.js View on Github external
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
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 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
github ebaauw / homebridge-hue / cli / ph.js View on Github external
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) => {
github ebaauw / homebridge-hue / cli / ph.js View on Github external
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 {
github ebaauw / homebridge-hue / cli / ph.js View on Github external
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',
github ebaauw / homebridge-hue / cli / ph.js View on Github external
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()
  }