Skip to content

Commit 582ff70

Browse files
authored
New Components - philips_hue (#16456)
* new components * pnpm-lock.yaml
1 parent 7f240b2 commit 582ff70

File tree

12 files changed

+980
-7
lines changed

12 files changed

+980
-7
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import philipsHue from "../../philips_hue.app.mjs";
2+
3+
export default {
4+
key: "philips_hue-activate-scene",
5+
name: "Activate Scene",
6+
description: "Activates a Philips Hue light scene. [See the documentation](https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_light__id__put)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
philipsHue,
11+
username: {
12+
propDefinition: [
13+
philipsHue,
14+
"username",
15+
],
16+
},
17+
sceneId: {
18+
propDefinition: [
19+
philipsHue,
20+
"sceneId",
21+
(c) => ({
22+
username: c.username,
23+
}),
24+
],
25+
},
26+
},
27+
async run({ $ }) {
28+
const response = await this.philipsHue.updateScene({
29+
$,
30+
username: this.username,
31+
sceneId: this.sceneId,
32+
data: {
33+
recall: {
34+
action: "active",
35+
},
36+
},
37+
});
38+
$.export("$summary", `Successfully activated scene with ID: ${this.sceneId}`);
39+
return response;
40+
},
41+
};
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import philipsHue from "../../philips_hue.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
import convert from "color-convert";
4+
5+
export default {
6+
key: "philips_hue-set-light-color",
7+
name: "Set Light Color",
8+
description: "Sets the light color of a Philips Hue light. [See the documentation](https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_light__id__put)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
philipsHue,
13+
username: {
14+
propDefinition: [
15+
philipsHue,
16+
"username",
17+
],
18+
},
19+
lightId: {
20+
propDefinition: [
21+
philipsHue,
22+
"lightId",
23+
(c) => ({
24+
username: c.username,
25+
}),
26+
],
27+
optional: true,
28+
},
29+
groupId: {
30+
propDefinition: [
31+
philipsHue,
32+
"groupId",
33+
(c) => ({
34+
username: c.username,
35+
}),
36+
],
37+
optional: true,
38+
},
39+
color: {
40+
type: "string",
41+
label: "Color",
42+
description: "A hexidecimal color value to set the light(s) to. E.g. `#800080`",
43+
},
44+
},
45+
methods: {
46+
hexToCIE(hex) {
47+
const rgb = convert.hex.rgb(hex);
48+
const xyz = convert.rgb.xyz(rgb);
49+
const x = xyz[0] / (xyz[0] + xyz[1] + xyz[2]);
50+
const y = xyz[1] / (xyz[0] + xyz[1] + xyz[2]);
51+
return {
52+
x,
53+
y,
54+
};
55+
},
56+
},
57+
async run({ $ }) {
58+
if ((!this.lightId && !this.groupId) || (this.lightId && this.groupId)) {
59+
throw new ConfigurationError("Must specify exactly one of Light ID or GroupID");
60+
}
61+
62+
const {
63+
x, y,
64+
} = this.hexToCIE(this.color);
65+
66+
const opts = {
67+
$,
68+
username: this.username,
69+
data: {
70+
color: {
71+
xy: {
72+
x,
73+
y,
74+
},
75+
},
76+
},
77+
};
78+
79+
const response = this.lightId
80+
? await this.philipsHue.updateLight({
81+
lightId: this.lightId,
82+
...opts,
83+
})
84+
: await this.philipsHue.updateGroup({
85+
groupId: this.groupId,
86+
...opts,
87+
});
88+
89+
$.export("$summary", `Successfully set light color to ${this.color}`);
90+
return response;
91+
},
92+
};
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import philipsHue from "../../philips_hue.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "philips_hue-turn-light-on",
6+
name: "Turn Light On",
7+
description: "Turns on or off a Philips Hue light or group of lights. [See the documentation](https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_light__id__put)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
philipsHue,
12+
username: {
13+
propDefinition: [
14+
philipsHue,
15+
"username",
16+
],
17+
},
18+
lightId: {
19+
propDefinition: [
20+
philipsHue,
21+
"lightId",
22+
(c) => ({
23+
username: c.username,
24+
}),
25+
],
26+
optional: true,
27+
},
28+
groupId: {
29+
propDefinition: [
30+
philipsHue,
31+
"groupId",
32+
(c) => ({
33+
username: c.username,
34+
}),
35+
],
36+
optional: true,
37+
},
38+
turnLightOff: {
39+
type: "boolean",
40+
label: "Turn Light(s) Off",
41+
description: "Set to `true` to turn the light(s) off instead of on",
42+
optional: true,
43+
},
44+
},
45+
async run({ $ }) {
46+
if ((!this.lightId && !this.groupId) || (this.lightId && this.groupId)) {
47+
throw new ConfigurationError("Must specify exactly one of Light ID or GroupID");
48+
}
49+
50+
const opts = {
51+
$,
52+
username: this.username,
53+
data: {
54+
on: {
55+
on: !this.turnLightOff,
56+
},
57+
},
58+
};
59+
60+
const response = this.lightId
61+
? await this.philipsHue.updateLight({
62+
lightId: this.lightId,
63+
...opts,
64+
})
65+
: await this.philipsHue.updateGroup({
66+
groupId: this.groupId,
67+
...opts,
68+
});
69+
70+
$.export("$summary", `Successfully turned ${this.turnLightOff
71+
? "off"
72+
: "on"} light(s)`);
73+
return response;
74+
},
75+
};

components/philips_hue/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/philips_hue",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"description": "Pipedream philips_hue Components",
55
"main": "philips_hue.app.mjs",
66
"keywords": [
@@ -13,6 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^3.0.0"
16+
"@pipedream/platform": "^3.0.3"
1717
}
1818
}

0 commit comments

Comments
 (0)