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

setLightState sets bri to 1 [esmodules] #232

Open tiptronic opened 11 months ago

tiptronic commented 11 months ago

I am using the esmodules branch (or the default branch with this patch applied, so it can import discovery)

Everything works fine, but if I switch a light off (or toggle it), it sets its bri state to 1...

I tried to debug it, but the library's flow is really hard to follow...

However, I can reproduce it with a simple example (mostly from the examples directory):

let xAPI; // just use this as cache for now
v3.api.createLocal(host).connect(USERNAME)
    .then(api => {
        xAPI = api;
        return api.lights.getLightState(LIGHT_ID);
    })
    .then((state) => {
        // Display the state of the light
        console.log(state);
        return xAPI.lights.setLightState(LIGHT_ID, { on: !state.on, transitiontime: 2 });
    })
    .then(api => {
        return xAPI.lights.getLightState(LIGHT_ID);
    })
    .then((state) => {
        // Display the state of the light
        console.log(JSON.stringify(state, null, 2));
    });

or a bit less 'then':

const toggle = async ( id ) => {
    try {
        const state = await hueApi.lights.getLightState(id);
        console.log('getLightState1', state);
        const success = await hueApi.lights.setLightState(id, { on: !state.on, transitiontime: 2 });
        console.log('setLightState', success);
        hueApi.lights.getLightState(id).then((lightState) => {
            console.log('getLightState2', lightState);
        });
    } catch (e) {
        console.log('error', e);
    }
}

Anyone out there seeing the same problem? (Or any hint what else the problem could be?)

tiptronic commented 11 months ago

Quick info: it has something to do with the transitiontime setting...

If I change:

return xAPI.lights.setLightState(LIGHT_ID, { on: !state.on, transitiontime: 2 });

to

return xAPI.lights.setLightState(LIGHT_ID, { on: !state.on });

everything works fine.

The light I checked here is an Extended color light, but it happens with other lights as well....

type: 'Extended color light',
  name: 'Luminare 1',
  modelid: 'LCT001',
  manufacturername: 'Signify Netherlands B.V.',