Skip to content

setLightState sets bri to 1 [esmodules] #232

@tiptronic

Description

@tiptronic

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?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions