-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - philips_hue #16456
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
Merged
Merged
New Components - philips_hue #16456
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
components/philips_hue/actions/activate-scene/activate-scene.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import philipsHue from "../../philips_hue.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "philips_hue-activate-scene", | ||
| name: "Activate Scene", | ||
| description: "Activates a Philips Hue light scene. [See the documentation](https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_light__id__put)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| philipsHue, | ||
| username: { | ||
| propDefinition: [ | ||
| philipsHue, | ||
| "username", | ||
| ], | ||
| }, | ||
| sceneId: { | ||
| propDefinition: [ | ||
| philipsHue, | ||
| "sceneId", | ||
| (c) => ({ | ||
| username: c.username, | ||
| }), | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.philipsHue.updateScene({ | ||
| $, | ||
| username: this.username, | ||
| sceneId: this.sceneId, | ||
| data: { | ||
| recall: { | ||
| action: "active", | ||
| }, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully activated scene with ID: ${this.sceneId}`); | ||
| return response; | ||
| }, | ||
| }; | ||
92 changes: 92 additions & 0 deletions
92
components/philips_hue/actions/set-light-color/set-light-color.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import philipsHue from "../../philips_hue.app.mjs"; | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import convert from "color-convert"; | ||
|
|
||
| export default { | ||
| key: "philips_hue-set-light-color", | ||
| name: "Set Light Color", | ||
| 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)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| philipsHue, | ||
| username: { | ||
| propDefinition: [ | ||
| philipsHue, | ||
| "username", | ||
| ], | ||
| }, | ||
| lightId: { | ||
| propDefinition: [ | ||
| philipsHue, | ||
| "lightId", | ||
| (c) => ({ | ||
| username: c.username, | ||
| }), | ||
| ], | ||
| optional: true, | ||
| }, | ||
| groupId: { | ||
| propDefinition: [ | ||
| philipsHue, | ||
| "groupId", | ||
| (c) => ({ | ||
| username: c.username, | ||
| }), | ||
| ], | ||
| optional: true, | ||
| }, | ||
| color: { | ||
| type: "string", | ||
| label: "Color", | ||
| description: "A hexidecimal color value to set the light(s) to. E.g. `#800080`", | ||
| }, | ||
| }, | ||
| methods: { | ||
| hexToCIE(hex) { | ||
| const rgb = convert.hex.rgb(hex); | ||
| const xyz = convert.rgb.xyz(rgb); | ||
| const x = xyz[0] / (xyz[0] + xyz[1] + xyz[2]); | ||
| const y = xyz[1] / (xyz[0] + xyz[1] + xyz[2]); | ||
| return { | ||
| x, | ||
| y, | ||
| }; | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| if ((!this.lightId && !this.groupId) || (this.lightId && this.groupId)) { | ||
| throw new ConfigurationError("Must specify exactly one of Light ID or GroupID"); | ||
| } | ||
|
|
||
| const { | ||
| x, y, | ||
| } = this.hexToCIE(this.color); | ||
|
|
||
| const opts = { | ||
| $, | ||
| username: this.username, | ||
| data: { | ||
| color: { | ||
| xy: { | ||
| x, | ||
| y, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const response = this.lightId | ||
| ? await this.philipsHue.updateLight({ | ||
| lightId: this.lightId, | ||
| ...opts, | ||
| }) | ||
| : await this.philipsHue.updateGroup({ | ||
| groupId: this.groupId, | ||
| ...opts, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully set light color to ${this.color}`); | ||
| return response; | ||
| }, | ||
| }; |
75 changes: 75 additions & 0 deletions
75
components/philips_hue/actions/turn-light-on/turn-light-on.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import philipsHue from "../../philips_hue.app.mjs"; | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| key: "philips_hue-turn-light-on", | ||
| name: "Turn Light On", | ||
| 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)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| philipsHue, | ||
| username: { | ||
| propDefinition: [ | ||
| philipsHue, | ||
| "username", | ||
| ], | ||
| }, | ||
| lightId: { | ||
| propDefinition: [ | ||
| philipsHue, | ||
| "lightId", | ||
| (c) => ({ | ||
| username: c.username, | ||
| }), | ||
| ], | ||
| optional: true, | ||
| }, | ||
| groupId: { | ||
| propDefinition: [ | ||
| philipsHue, | ||
| "groupId", | ||
| (c) => ({ | ||
| username: c.username, | ||
| }), | ||
| ], | ||
| optional: true, | ||
| }, | ||
| turnLightOff: { | ||
| type: "boolean", | ||
| label: "Turn Light(s) Off", | ||
| description: "Set to `true` to turn the light(s) off instead of on", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| if ((!this.lightId && !this.groupId) || (this.lightId && this.groupId)) { | ||
| throw new ConfigurationError("Must specify exactly one of Light ID or GroupID"); | ||
| } | ||
|
|
||
| const opts = { | ||
| $, | ||
| username: this.username, | ||
| data: { | ||
| on: { | ||
| on: !this.turnLightOff, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const response = this.lightId | ||
| ? await this.philipsHue.updateLight({ | ||
| lightId: this.lightId, | ||
| ...opts, | ||
| }) | ||
| : await this.philipsHue.updateGroup({ | ||
| groupId: this.groupId, | ||
| ...opts, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully turned ${this.turnLightOff | ||
| ? "off" | ||
| : "on"} light(s)`); | ||
| return response; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.