DouweM / homebridge-unifi-occupancy

Homebridge plugin that adds HomeKit occupancy sensors for selected devices (and people) on your UniFi network to the iOS Home app: quickly see who's where and automate accordingly.
Apache License 2.0
41 stars 1 forks source link

Show UnifiOS option in UI #22

Closed bc2297 closed 1 year ago

bc2297 commented 1 year ago

Describe The Bug: I migrated my unifi setup from an OSX based network application with a USG, to a UDM-SE and I think the plugin has cached the sites that were used previously and now the plug isn't working. I'm going to try to clear the cache and see if that fixes it, but wanted to file in case this was worth fixing or it was something else

To Reproduce: change from computer hosted network application to UDM based application

Expected behavior: to work

Logs:

[4/24/2023, 2:03:40 PM] [homebridge-unifi-occupancy] Loaded homebridge-unifi-occupancy v1.2.7 child bridge successfully
[4/24/2023, 2:03:40 PM] Loaded 11 cached accessories from cachedAccessories.0E78E28DF387.
[4/24/2023, 2:03:40 PM] Homebridge v1.6.0 (HAP v0.11.0) (homebridge-unifi-occupancy) is running on port 31973.
[4/24/2023, 2:03:41 PM] [homebridge-unifi-occupancy] ERROR: Failed to load device fingerprints StatusCodeError: 404 - "Not Found"
    at new StatusCodeError (/usr/local/lib/node_modules/homebridge-unifi-occupancy/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (/usr/local/lib/node_modules/homebridge-unifi-occupancy/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (/usr/local/lib/node_modules/homebridge-unifi-occupancy/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (/usr/local/lib/node_modules/homebridge-unifi-occupancy/node_modules/request/request.js:185:22)
    at Request.emit (node:events:512:28)
    at Request.<anonymous> (/usr/local/lib/node_modules/homebridge-unifi-occupancy/node_modules/request/request.js:1154:10)
    at Request.emit (node:events:512:28)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/homebridge-unifi-occupancy/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (node:events:626:28)
    at IncomingMessage.emit (node:events:524:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  statusCode: 404,
  error: 'Not Found',
  options: {
    rejectUnauthorized: false,
    jar: RequestJar { _jar: [CookieJar] },
    headers: { 'User-Agent': 'node.js unifi-events UniFi Events' },
    json: true,
    uri: 'https://192.168.1.1:443//v2/api/fingerprint_devices/0',
    method: 'GET',
    callback: [Function: RP$callback],
    transform: undefined,
    simple: true,
    resolveWithFullResponse: false,
    transform2xxOnly: false
  },
  response: <ref *1> IncomingMessage {
    _readableState: ReadableState {
      objectMode: false,
      highWaterMark: 16384,
      buffer: BufferList { head: null, tail: null, length: 0 },
      length: 0,
      pipes: [],
      flowing: true,
      ended: true,
      endEmitted: true,
      reading: false,
      constructed: true,
      sync: true,
      needReadable: false,
      emittedReadable: false,
      readableListening: false,
      resumeScheduled: false,
      errorEmitted: false,
      emitClose: true,
      autoDestroy: true,
      destroyed: true,
      errored: null,
      closed: true,
      closeEmitted: true,
      defaultEncoding: 'utf8',
      awaitDrainWriters: null,
      multiAwaitDrain: false,
      readingMore: true,
      dataEmitted: true,
      decoder: null,
      encoding: null,
      [Symbol(kPaused)]: false
    },
    _events: [Object: null prototype] {
      end: [Array],
      close: [Array],
      data: [Function (anonymous)],
      error: [Function (anonymous)]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    socket: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: false,
      alpnProtocol: false,
      authorized: false,
      authorizationError: 'DEPTH_ZERO_SELF_SIGNED_CERT',
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 9,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: null,
      _closeAfterHandlingError: false,
      _readableState: [ReadableState],
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: null,
      _requestCert: true,
      _rejectUnauthorized: false,
      parser: null,
      _httpMessage: [ClientRequest],
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(async_id_symbol)]: 153,
      [Symbol(kHandle)]: null,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(kSetKeepAlive)]: false,
      [Symbol(kSetKeepAliveInitialDelay)]: 0,
      [Symbol(kBytesRead)]: 425,
      [Symbol(kBytesWritten)]: 158,
      [Symbol(connect-options)]: [Object]
    },
    httpVersionMajor: 1,
    httpVersionMinor: 1,
    httpVersion: '1.1',
    complete: true,
    rawHeaders: [
      'Vary',
      'Origin',
      'X-DNS-Prefetch-Control',
      'off',
      'X-Frame-Options',
      'SAMEORIGIN',
      'Strict-Transport-Security',
      'max-age=15552000; includeSubDomains',
      'X-Download-Options',
      'noopen',
      'X-Content-Type-Options',
      'nosniff',
      'X-XSS-Protection',
      '1; mode=block',
      'Accept-Ranges',
      'bytes',
      'X-Response-Time',
      '3ms',
      'Content-Type',
      'text/plain; charset=utf-8',
      'Content-Length',
      '9',
      'Date',
      'Mon, 24 Apr 2023 21:03:41 GMT',
      'Connection',
      'close'
    ],
    rawTrailers: [],
    joinDuplicateHeaders: undefined,
    aborted: false,
    upgrade: false,
    url: '',
    method: null,
    statusCode: 404,
    statusMessage: 'Not Found',
    client: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: false,
      alpnProtocol: false,
      authorized: false,
      authorizationError: 'DEPTH_ZERO_SELF_SIGNED_CERT',
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 9,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: null,
      _closeAfterHandlingError: false,
      _readableState: [ReadableState],
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: null,
      _requestCert: true,
      _rejectUnauthorized: false,
      parser: null,
      _httpMessage: [ClientRequest],
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(async_id_symbol)]: 153,
      [Symbol(kHandle)]: null,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(kSetKeepAlive)]: false,
      [Symbol(kSetKeepAliveInitialDelay)]: 0,
      [Symbol(kBytesRead)]: 425,
      [Symbol(kBytesWritten)]: 158,
      [Symbol(connect-options)]: [Object]
    },
    _consuming: false,
    _dumped: false,
    req: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'GET //v2/api/fingerprint_devices/0 HTTP/1.1\r\n' +
        'User-Agent: node.js unifi-events UniFi Events\r\n' +
        'host: 192.168.1.1\r\n' +
        'accept: application/json\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      joinDuplicateHeaders: undefined,
      path: '//v2/api/fingerprint_devices/0',
      _ended: true,
      res: [Circular *1],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: '192.168.1.1',
      protocol: 'https:',
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype],
      [Symbol(errored)]: null,
      [Symbol(kUniqueHeaders)]: null
    },
    request: Request {
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      rejectUnauthorized: false,
      headers: [Object],
      uri: [Url],
      method: 'GET',
      readable: true,
      writable: true,
      explicitMethod: true,
      _qs: [Querystring],
      _auth: [Auth],
      _oauth: [OAuth],
      _multipart: [Multipart],
      _redirect: [Redirect],
      _tunnel: [Tunnel],
      _rp_resolve: [Function (anonymous)],
      _rp_reject: [Function (anonymous)],
      _rp_promise: [Promise [Object]],
      _rp_callbackOrig: undefined,
      callback: [Function (anonymous)],
      _rp_options: [Object],
      setHeader: [Function (anonymous)],
      hasHeader: [Function (anonymous)],
      getHeader: [Function (anonymous)],
      removeHeader: [Function (anonymous)],
      localAddress: undefined,
      pool: [Object],
      dests: [],
      __isRequestRequest: true,
      _callback: [Function: RP$callback],
      proxy: null,
      tunnel: true,
      setHost: true,
      originalCookieHeader: undefined,
      _jar: [RequestJar],
      port: '443',
      host: '192.168.1.1',
      path: '//v2/api/fingerprint_devices/0',
      _json: true,
      httpModule: [Object],
      agentClass: [Function: Agent],
      agent: [Agent],
      _started: true,
      href: 'https://192.168.1.1:443//v2/api/fingerprint_devices/0',
      req: [ClientRequest],
      ntick: true,
      response: [Circular *1],
      originalHost: '192.168.1.1',
      originalHostHeaderName: 'host',
      responseContent: [Circular *1],
      _destdata: true,
      _ended: true,
      _callbackCalled: true,
      [Symbol(kCapture)]: false
    },
    toJSON: [Function: responseToJSON],
    caseless: Caseless { dict: [Object] },
    body: 'Not Found',
    [Symbol(kCapture)]: false,
    [Symbol(kHeaders)]: {
      vary: 'Origin',
      'x-dns-prefetch-control': 'off',
      'x-frame-options': 'SAMEORIGIN',
      'strict-transport-security': 'max-age=15552000; includeSubDomains',
      'x-download-options': 'noopen',
      'x-content-type-options': 'nosniff',
      'x-xss-protection': '1; mode=block',
      'accept-ranges': 'bytes',
      'x-response-time': '3ms',
      'content-type': 'text/plain; charset=utf-8',
      'content-length': '9',
      date: 'Mon, 24 Apr 2023 21:03:41 GMT',
      connection: 'close'
    },
    [Symbol(kHeadersCount)]: 26,
    [Symbol(kTrailers)]: null,
    [Symbol(kTrailersCount)]: 0
  }
}
Unhandled rejection StatusCodeError: 404 - "Not Found"
    at new StatusCodeError (/usr/local/lib/node_modules/homebridge-unifi-occupancy/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (/usr/local/lib/node_modules/homebridge-unifi-occupancy/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (/usr/local/lib/node_modules/homebridge-unifi-occupancy/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (/usr/local/lib/node_modules/homebridge-unifi-occupancy/node_modules/request/request.js:185:22)
    at Request.emit (node:events:512:28)
    at Request.<anonymous> (/usr/local/lib/node_modules/homebridge-unifi-occupancy/node_modules/request/request.js:1154:10)
    at Request.emit (node:events:512:28)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/homebridge-unifi-occupancy/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (node:events:626:28)
    at IncomingMessage.emit (node:events:524:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)

Plugin Config:

Show your Homebridge config.json here, remove any sensitive information.

Screenshots:

Environment:

bc2297 commented 1 year ago

Yeah this was solved by changing the plugin config, which totally makes sense. I'd say maybe consider making the unifios option show up in the home bridge UI config as it currently isn't.

DouweM commented 1 year ago

@bc2297 Good call, that was an oversight! Option added to the UI.