peter-murray / node-hue-api

Node.js Library for interacting with the Philips Hue Bridge and Lights
Apache License 2.0
1.18k stars 144 forks source link

getUser and getUserByName do not seem to work at all #215

Closed lexicalunit closed 2 years ago

lexicalunit commented 2 years ago

I was able to get things to work after creating a user via createUser(). But now I can not jump back into things using the user that I created. Do I have to do createUser() every time the app starts?

const { discovery, v3 } = require('node-hue-api');
const api = v3.api;
const results = await discovery.nupnpSearch();
const host = results[0].ipaddress;
const app = "myapp";
const device = "mydevice";
const local = await api.createLocal(host).connect();
await local.users.getUser('a previously created user name created via createUser()')
Uncaught TypeError: No value provided and 'username' is not optional
    at StringType.getValue (/Users/me/source/myapp/node_modules/@peter-murray/hue-bridge-model/dist/cjs/types/BaseType.js:40:27)
    at StringType.getValue (/Users/me/source/myapp/node_modules/@peter-murray/hue-bridge-model/dist/cjs/types/StringType.js:17:36)
    at UsernamePlaceholder.getValue (/Users/me/source/myapp/node_modules/node-hue-api/dist/cjs/api/placeholders/Placeholder.js:33:31)
    at UsernamePlaceholder.inject (/Users/me/source/myapp/node_modules/node-hue-api/dist/cjs/api/placeholders/Placeholder.js:22:54)
    at /Users/me/source/myapp/node_modules/node-hue-api/dist/cjs/api/http/endpoints/ApiEndpoint.js:145:34
    at Array.forEach (<anonymous>)
    at replacePlaceholders (/Users/me/source/myapp/node_modules/node-hue-api/dist/cjs/api/http/endpoints/ApiEndpoint.js:144:22)
    at ApiEndpoint.getRequest (/Users/me/source/myapp/node_modules/node-hue-api/dist/cjs/api/http/endpoints/ApiEndpoint.js:74:18)
    at Job.task (/Users/me/source/myapp/node_modules/node-hue-api/dist/cjs/api/http/Transport.js:30:39)
    at /Users/me/source/myapp/node_modules/bottleneck/lib/Job.js:141:109 {
  _hueError: undefined
}
lexicalunit commented 2 years ago

Ah, I see. You have to connect with the username you got from createUser().

const secure = await api.createLocal(host).connect('the username');
const bridgeConfig = await secure.configuration.getConfiguration();
[...]