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

colorTemperatureRange is function returns promise #189

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions lib/devices/yeelight.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@ module.exports.ColorTemperature = Thing.mixin(Parent => class extends Parent
}

changeColor(color, options) {
const range = this.colorTemperatureRange;
const temperature = Math.min(Math.max(color.temperature.kelvins, range.min), range.max);
return this.colorTemperatureRange().then(range => {
const temperature = Math.min(Math.max(color.temperature.kelvins, range.min), range.max);

return this.call('set_ct_abx', Yeelight.withEffect(temperature, options.duration), {
refresh: [ 'colorTemperature' ]
}).then(MiioApi.checkOk);
return this.call('set_ct_abx', Yeelight.withEffect(temperature, options.duration), {
refresh: [ 'colorTemperature' ]
}).then(MiioApi.checkOk);
});
}
});

Expand Down Expand Up @@ -258,12 +259,12 @@ module.exports.ColorFull = Thing.mixin(Parent => class extends Parent
if(color.is('temperature')) {
// The user has request a color via temperature

const range = this.colorTemperatureRange;
const temperature = Math.min(Math.max(color.temperature.kelvins, range.min), range.max);

return this.call('set_ct_abx', Yeelight.withEffect(temperature, options.duration), {
refresh: [ 'colorTemperature', 'colorMode' ]
}).then(MiioApi.checkOk);
this.colorTemperatureRange().then(range => {
const temperature = Math.min(Math.max(color.temperature.kelvins, range.min), range.max);
return this.call('set_ct_abx', Yeelight.withEffect(temperature, options.duration), {
refresh: [ 'colorTemperature', 'colorMode' ]
}).then(MiioApi.checkOk);
});
} else if(color.is('hsl')) {
/*
* User has requested hue and saturation
Expand Down