Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setLightState sets bri to 1 [esmodules] #232

Open
tiptronic opened this issue Aug 30, 2023 · 1 comment
Open

setLightState sets bri to 1 [esmodules] #232

tiptronic opened this issue Aug 30, 2023 · 1 comment

Comments

@tiptronic
Copy link

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
Copy link
Author

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.',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant