Skip to content

Commit

Permalink
use simplified group API
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Nov 7, 2017
1 parent 62c5649 commit 3073ae9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
14 changes: 3 additions & 11 deletions build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,14 @@ let adapter = utils_1.default.adapter({
// if the change was acknowledged, update the state later
let wasAcked;
if (id.endsWith(".state")) {
wasAcked = !(yield session_1.session.tradfri.operateGroup(group, {
onOff: val,
}));
wasAcked = !(yield group.toggle(val));
}
else if (id.endsWith(".brightness")) {
wasAcked = !(yield session_1.session.tradfri.operateGroup(group, {
dimmer: val,
transitionTime: yield getTransitionDuration(group),
}));
wasAcked = !(yield group.setBrightness(val, yield getTransitionDuration(group)));
}
else if (id.endsWith(".activeScene")) {
// turn on and activate a scene
wasAcked = !(yield session_1.session.tradfri.operateGroup(group, {
onOff: true,
sceneId: val,
}));
wasAcked = !(yield group.activateScene(val));
}
else if (id.endsWith(".color")) {
val = colors_1.normalizeHexColor(val);
Expand Down
17 changes: 6 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,15 @@ let adapter: ExtendedAdapter = utils.adapter({
let wasAcked: boolean;

if (id.endsWith(".state")) {
wasAcked = !await $.tradfri.operateGroup(group, {
onOff: val,
});
wasAcked = !await group.toggle(val);
} else if (id.endsWith(".brightness")) {
wasAcked = !await $.tradfri.operateGroup(group, {
dimmer: val,
transitionTime: await getTransitionDuration(group),
});
wasAcked = !await group.setBrightness(
val,
await getTransitionDuration(group),
);
} else if (id.endsWith(".activeScene")) {
// turn on and activate a scene
wasAcked = !await $.tradfri.operateGroup(group, {
onOff: true,
sceneId: val,
});
wasAcked = !await group.activateScene(val);
} else if (id.endsWith(".color")) {
val = normalizeHexColor(val);
if (val != null) {
Expand Down

0 comments on commit 3073ae9

Please sign in to comment.