Skip to content

Commit

Permalink
use the new simplified API
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Nov 4, 2017
1 parent b79f0d1 commit 62c5649
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
20 changes: 5 additions & 15 deletions build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,10 @@ let adapter = utils_1.default.adapter({
// operate the lights depending on the set state
// if no request was sent, we can ack the state immediately
if (id.endsWith(".state")) {
wasAcked = !(yield session_1.session.tradfri.operateLight(accessory, {
onOff: val,
}));
wasAcked = !(yield light.toggle(val));
}
else if (id.endsWith(".brightness")) {
wasAcked = !(yield session_1.session.tradfri.operateLight(accessory, {
dimmer: val,
transitionTime: yield getTransitionDuration(accessory),
}));
wasAcked = !(yield light.setBrightness(val, yield getTransitionDuration(accessory)));
}
else if (id.endsWith(".color")) {
// we need to differentiate here, because some ppl
Expand All @@ -325,20 +320,15 @@ let adapter = utils_1.default.adapter({
val = colors_1.normalizeHexColor(val);
if (val != null) {
state.val = val;
wasAcked = !(yield session_1.session.tradfri.operateLight(accessory, {
color: val,
transitionTime: yield getTransitionDuration(accessory),
}));
wasAcked = !(yield light.setColor(val, yield getTransitionDuration(accessory)));
}
}
else if (light.spectrum === "white") {
wasAcked = !(yield session_1.session.tradfri.operateLight(accessory, {
colorTemperature: val,
transitionTime: yield getTransitionDuration(accessory),
}));
wasAcked = !(yield light.setColorTemperature(val, yield getTransitionDuration(accessory)));
}
}
else if (/\.(colorTemperature|hue|saturation)$/.test(id)) {
// we're not using the simplified API here, since that means we have to repeat the if-clause 3 times.
wasAcked = !(yield session_1.session.tradfri.operateLight(accessory, {
[id.substr(id.lastIndexOf(".") + 1)]: val,
transitionTime: yield getTransitionDuration(accessory),
Expand Down
29 changes: 14 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,12 @@ let adapter: ExtendedAdapter = utils.adapter({
// operate the lights depending on the set state
// if no request was sent, we can ack the state immediately
if (id.endsWith(".state")) {
wasAcked = !await $.tradfri.operateLight(accessory, {
onOff: val,
});
wasAcked = !await light.toggle(val);
} else if (id.endsWith(".brightness")) {
wasAcked = !await $.tradfri.operateLight(accessory, {
dimmer: val,
transitionTime: await getTransitionDuration(accessory),
});
wasAcked = !await light.setBrightness(
val,
await getTransitionDuration(accessory),
);
} else if (id.endsWith(".color")) {
// we need to differentiate here, because some ppl
// might already have "color" states for white spectrum bulbs
Expand All @@ -348,18 +346,19 @@ let adapter: ExtendedAdapter = utils.adapter({
val = normalizeHexColor(val);
if (val != null) {
state.val = val;
wasAcked = !await $.tradfri.operateLight(accessory, {
color: val,
transitionTime: await getTransitionDuration(accessory),
});
wasAcked = !await light.setColor(
val,
await getTransitionDuration(accessory),
);
}
} else if (light.spectrum === "white") {
wasAcked = !await $.tradfri.operateLight(accessory, {
colorTemperature: val,
transitionTime: await getTransitionDuration(accessory),
});
wasAcked = !await light.setColorTemperature(
val,
await getTransitionDuration(accessory),
);
}
} else if (/\.(colorTemperature|hue|saturation)$/.test(id)) {
// we're not using the simplified API here, since that means we have to repeat the if-clause 3 times.
wasAcked = !await $.tradfri.operateLight(accessory, {
[id.substr(id.lastIndexOf(".") + 1)]: val,
transitionTime: await getTransitionDuration(accessory),
Expand Down

0 comments on commit 62c5649

Please sign in to comment.