From 62c56494085e7651200f932e08bb377ca5e79bd0 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Sat, 4 Nov 2017 18:06:18 +0100 Subject: [PATCH] use the new simplified API --- build/main.js | 20 +++++--------------- src/main.ts | 29 ++++++++++++++--------------- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/build/main.js b/build/main.js index 86b491ed..71874c23 100644 --- a/build/main.js +++ b/build/main.js @@ -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 @@ -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), diff --git a/src/main.ts b/src/main.ts index a38fef6e..54e0e5da 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 @@ -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),