From b99c531d62bcc636395bb6059ab6ba1fed62c4a0 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 25 Apr 2025 13:50:47 -0400 Subject: [PATCH 1/2] new components --- .../actions/activate-scene/activate-scene.mjs | 41 ++++ .../set-light-color/set-light-color.mjs | 92 ++++++++ .../actions/turn-light-on/turn-light-on.mjs | 75 ++++++ components/philips_hue/package.json | 4 +- components/philips_hue/philips_hue.app.mjs | 217 +++++++++++++++++- .../philips_hue/sources/common/base.mjs | 44 ++++ .../new-light-state/new-light-state.mjs | 92 ++++++++ .../sources/new-light-state/test-event.mjs | 169 ++++++++++++++ .../new-scene-activated.mjs | 54 +++++ .../new-scene-activated/test-event.mjs | 92 ++++++++ .../new-sensor-update/new-sensor-update.mjs | 105 +++++++++ 11 files changed, 979 insertions(+), 6 deletions(-) create mode 100644 components/philips_hue/actions/activate-scene/activate-scene.mjs create mode 100644 components/philips_hue/actions/set-light-color/set-light-color.mjs create mode 100644 components/philips_hue/actions/turn-light-on/turn-light-on.mjs create mode 100644 components/philips_hue/sources/common/base.mjs create mode 100644 components/philips_hue/sources/new-light-state/new-light-state.mjs create mode 100644 components/philips_hue/sources/new-light-state/test-event.mjs create mode 100644 components/philips_hue/sources/new-scene-activated/new-scene-activated.mjs create mode 100644 components/philips_hue/sources/new-scene-activated/test-event.mjs create mode 100644 components/philips_hue/sources/new-sensor-update/new-sensor-update.mjs diff --git a/components/philips_hue/actions/activate-scene/activate-scene.mjs b/components/philips_hue/actions/activate-scene/activate-scene.mjs new file mode 100644 index 0000000000000..62db9a64b359c --- /dev/null +++ b/components/philips_hue/actions/activate-scene/activate-scene.mjs @@ -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; + }, +}; diff --git a/components/philips_hue/actions/set-light-color/set-light-color.mjs b/components/philips_hue/actions/set-light-color/set-light-color.mjs new file mode 100644 index 0000000000000..3c095b95ab241 --- /dev/null +++ b/components/philips_hue/actions/set-light-color/set-light-color.mjs @@ -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; + }, +}; diff --git a/components/philips_hue/actions/turn-light-on/turn-light-on.mjs b/components/philips_hue/actions/turn-light-on/turn-light-on.mjs new file mode 100644 index 0000000000000..3a4a0b2ad8c39 --- /dev/null +++ b/components/philips_hue/actions/turn-light-on/turn-light-on.mjs @@ -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; + }, +}; diff --git a/components/philips_hue/package.json b/components/philips_hue/package.json index f5e455c19a54b..1fbabf972523f 100644 --- a/components/philips_hue/package.json +++ b/components/philips_hue/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/philips_hue", - "version": "0.6.0", + "version": "0.7.0", "description": "Pipedream philips_hue Components", "main": "philips_hue.app.mjs", "keywords": [ @@ -13,6 +13,6 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^3.0.0" + "@pipedream/platform": "^3.0.3" } } diff --git a/components/philips_hue/philips_hue.app.mjs b/components/philips_hue/philips_hue.app.mjs index 162f80ed4dbfa..e5ab7580641f8 100644 --- a/components/philips_hue/philips_hue.app.mjs +++ b/components/philips_hue/philips_hue.app.mjs @@ -1,11 +1,220 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "philips_hue", - propDefinitions: {}, + propDefinitions: { + username: { + type: "string", + label: "Username", + description: "The username to use. [See the documentation](https://developers.meethue.com/develop/hue-api-v2/getting-started/) for information on how to create an authorized username", + }, + lightId: { + type: "string", + label: "Light ID", + description: "The identifier of a hue light", + async options({ username }) { + const { data } = await this.listLights({ + username, + }); + return data?.map(({ + id: value, metadata, + }) => ({ + label: metadata.name, + value, + })) || []; + }, + }, + groupId: { + type: "string", + label: "Group ID", + description: "The identifier of a hue light group", + async options({ username }) { + const { data } = await this.listGroups({ + username, + }); + return data?.map(({ id }) => id ) || []; + }, + }, + sceneId: { + type: "string", + label: "Scene ID", + description: "The identifier of a scene", + async options({ username }) { + const { data } = await this.listScenes({ + username, + }); + return data?.map(({ + id: value, metadata, + }) => ({ + label: metadata.name, + value, + })) || []; + }, + }, + motionId: { + type: "string", + label: "Motion Sensor ID", + description: "The identifier of a hue motion sensor", + async options({ username }) { + const { data } = await this.listMotionSensors({ + username, + }); + return data?.map(({ id }) => id ) || []; + }, + }, + temperatureId: { + type: "string", + label: "Temperature Sensor ID", + description: "The identifier of a hue temperature sensor", + async options({ username }) { + const { data } = await this.listTemperatureSensors({ + username, + }); + return data?.map(({ id }) => id ) || []; + }, + }, + lightLevelId: { + type: "string", + label: "Light Level Sensor ID", + description: "The identifier of a hue light level sensor", + async options({ username }) { + const { data } = await this.listLightSensors({ + username, + }); + return data?.map(({ id }) => id ) || []; + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.meethue.com/route/clip/v2"; + }, + _makeRequest({ + $ = this, + path, + username, + ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + "hue-application-key": username, + }, + ...opts, + }); + }, + getLight({ + lightId, ...opts + }) { + return this._makeRequest({ + path: `/resource/light/${lightId}`, + ...opts, + }); + }, + getGroup({ + groupId, ...opts + }) { + return this._makeRequest({ + path: `/resource/grouped_light/${groupId}`, + ...opts, + }); + }, + getScene({ + sceneId, ...opts + }) { + return this._makeRequest({ + path: `/resource/scene/${sceneId}`, + ...opts, + }); + }, + getMotionSensor({ + motionId, ...opts + }) { + return this._makeRequest({ + path: `/resource/motion/${motionId}`, + ...opts, + }); + }, + getTemperatureSensor({ + temperatureId, ...opts + }) { + return this._makeRequest({ + path: `/resource/temperature/${temperatureId}`, + ...opts, + }); + }, + getLightSensor({ + lightLevelId, ...opts + }) { + return this._makeRequest({ + path: `/resource/light_level/${lightLevelId}`, + ...opts, + }); + }, + listLights(opts = {}) { + return this._makeRequest({ + path: "/resource/light", + ...opts, + }); + }, + listGroups(opts = {}) { + return this._makeRequest({ + path: "/resource/grouped_light", + ...opts, + }); + }, + listScenes(opts = {}) { + return this._makeRequest({ + path: "/resource/scene", + ...opts, + }); + }, + listMotionSensors(opts = {}) { + return this._makeRequest({ + path: "/resource/motion", + ...opts, + }); + }, + listTemperatureSensors(opts = {}) { + return this._makeRequest({ + path: "/resource/temperature", + ...opts, + }); + }, + listLightSensors(opts = {}) { + return this._makeRequest({ + path: "/resource/light_level", + ...opts, + }); + }, + updateLight({ + lightId, ...opts + }) { + return this._makeRequest({ + method: "PUT", + path: `/resource/light/${lightId}`, + ...opts, + }); + }, + updateGroup({ + groupId, ...opts + }) { + return this._makeRequest({ + method: "PUT", + path: `/resource/grouped_light/${groupId}`, + ...opts, + }); + }, + updateScene({ + sceneId, ...opts + }) { + return this._makeRequest({ + method: "PUT", + path: `/resource/scene/${sceneId}`, + ...opts, + }); }, }, }; diff --git a/components/philips_hue/sources/common/base.mjs b/components/philips_hue/sources/common/base.mjs new file mode 100644 index 0000000000000..93b171ea0b37c --- /dev/null +++ b/components/philips_hue/sources/common/base.mjs @@ -0,0 +1,44 @@ +import philipsHue from "../../philips_hue.app.mjs"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; + +export default { + props: { + philipsHue, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + username: { + propDefinition: [ + philipsHue, + "username", + ], + }, + }, + methods: { + _getPreviousData() { + return this.db.get("previousData") || {}; + }, + _setPreviousData(data) { + this.db.set("previousData", data); + }, + emitEvent(item) { + const meta = this.generateMeta(item); + this.$emit(item, meta); + }, + generateMeta(item) { + const ts = Date.now(); + return { + id: `${item.id}${ts}`, + summary: this.getSummary(item), + ts, + }; + }, + getSummary() { + throw new Error("getSummary is not implemented"); + }, + }, +}; diff --git a/components/philips_hue/sources/new-light-state/new-light-state.mjs b/components/philips_hue/sources/new-light-state/new-light-state.mjs new file mode 100644 index 0000000000000..9c39280a76093 --- /dev/null +++ b/components/philips_hue/sources/new-light-state/new-light-state.mjs @@ -0,0 +1,92 @@ +import common from "../common/base.mjs"; +import { ConfigurationError } from "@pipedream/platform"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "philips_hue-new-light-state", + name: "New Light State", + description: "Emit new event when the state of a light changes (e.g., turned on/off, brightness adjusted, color changed). [See the documentation](https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_light__id__put)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...common.props, + lightId: { + propDefinition: [ + common.props.philipsHue, + "lightId", + (c) => ({ + username: c.username, + }), + ], + optional: true, + }, + groupId: { + propDefinition: [ + common.props.philipsHue, + "groupId", + (c) => ({ + username: c.username, + }), + ], + optional: true, + }, + }, + hooks: { + deploy() { + if ((!this.lightId && !this.groupId) || (this.lightId && this.groupId)) { + throw new ConfigurationError("Must specify exactly one of Light ID or Group ID"); + } + }, + }, + methods: { + ...common.methods, + getSummary(item) { + return `${this.lightId + ? "Light" + : "Group"} with ID ${item.id} changed ${item.propertyChanged} state`; + }, + }, + async run() { + const previousData = this._getPreviousData(); + const args = { + username: this.username, + }; + const { data } = this.lightId + ? await this.philipsHue.getLight({ + ...args, + lightId: this.lightId, + }) + : await this.philipsHue.getGroup({ + ...args, + groupId: this.groupId, + }); + + for (const item of data) { + const itemData = { + on: item?.on, + brightness: item?.dimming?.brightness, + color: item?.color?.xy, + }; + if ( + previousData[item.id] + && JSON.stringify(previousData[item.id]) === JSON.stringify(itemData) + ) { + continue; + } + item.propertyChanged = !previousData[item.id] || previousData[item.id].on !== itemData.on + ? "on/off" + : previousData[item.id].brightness !== itemData.brightness + ? "brightness" + : "color"; + + this.emitEvent(item); + + previousData[item.id] = itemData; + } + + this._setPreviousData(previousData); + }, + sampleEmit, +}; diff --git a/components/philips_hue/sources/new-light-state/test-event.mjs b/components/philips_hue/sources/new-light-state/test-event.mjs new file mode 100644 index 0000000000000..e903c1b064f6a --- /dev/null +++ b/components/philips_hue/sources/new-light-state/test-event.mjs @@ -0,0 +1,169 @@ +export default { + "id": "2792ce43-36b5-4e83-b28a-c05f5d35b6ef", + "id_v1": "/lights/4", + "owner": { + "rid": "d40b7e02-7b27-4d7b-aae8-4753d7ba5485", + "rtype": "device" + }, + "metadata": { + "name": "Michelle’s Den 1", + "archetype": "sultan_bulb", + "function": "mixed" + }, + "product_data": { + "function": "mixed" + }, + "identify": {}, + "service_id": 0, + "on": { + "on": false + }, + "dimming": { + "brightness": 100, + "min_dim_level": 0.2 + }, + "dimming_delta": {}, + "color_temperature": { + "mirek": null, + "mirek_valid": false, + "mirek_schema": { + "mirek_minimum": 153, + "mirek_maximum": 500 + } + }, + "color_temperature_delta": {}, + "color": { + "xy": { + "x": 0.325, + "y": 0.15 + }, + "gamut": { + "red": { + "x": 0.6915, + "y": 0.3083 + }, + "green": { + "x": 0.17, + "y": 0.7 + }, + "blue": { + "x": 0.1532, + "y": 0.0475 + } + }, + "gamut_type": "C" + }, + "dynamics": { + "status": "none", + "status_values": [ + "none", + "dynamic_palette" + ], + "speed": 0, + "speed_valid": false + }, + "alert": { + "action_values": [ + "breathe" + ] + }, + "signaling": { + "signal_values": [ + "no_signal", + "on_off", + "on_off_color", + "alternating" + ] + }, + "mode": "normal", + "effects": { + "status_values": [ + "no_effect", + "candle", + "fire", + "prism", + "sparkle", + "opal", + "glisten", + "underwater", + "cosmos", + "sunbeam", + "enchant" + ], + "status": "no_effect", + "effect_values": [ + "no_effect", + "candle", + "fire", + "prism", + "sparkle", + "opal", + "glisten", + "underwater", + "cosmos", + "sunbeam", + "enchant" + ] + }, + "effects_v2": { + "action": { + "effect_values": [ + "no_effect", + "candle", + "fire", + "prism", + "sparkle", + "opal", + "glisten", + "underwater", + "cosmos", + "sunbeam", + "enchant" + ] + }, + "status": { + "effect": "no_effect", + "effect_values": [ + "no_effect", + "candle", + "fire", + "prism", + "sparkle", + "opal", + "glisten", + "underwater", + "cosmos", + "sunbeam", + "enchant" + ] + } + }, + "timed_effects": { + "status_values": [ + "no_effect", + "sunrise", + "sunset" + ], + "status": "no_effect", + "effect_values": [ + "no_effect", + "sunrise", + "sunset" + ] + }, + "powerup": { + "preset": "powerfail", + "configured": true, + "on": { + "mode": "previous" + }, + "dimming": { + "mode": "previous" + }, + "color": { + "mode": "previous" + } + }, + "type": "light", + "propertyChanged": "on/off" +} \ No newline at end of file diff --git a/components/philips_hue/sources/new-scene-activated/new-scene-activated.mjs b/components/philips_hue/sources/new-scene-activated/new-scene-activated.mjs new file mode 100644 index 0000000000000..75bd1c8f0ee59 --- /dev/null +++ b/components/philips_hue/sources/new-scene-activated/new-scene-activated.mjs @@ -0,0 +1,54 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "philips_hue-new-scene-activated", + name: "New Scene Activated", + description: "Emit new event when a specific scene is activated. [See the documentation](https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_light__id__put)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...common.props, + sceneId: { + propDefinition: [ + common.props.philipsHue, + "sceneId", + (c) => ({ + username: c.username, + }), + ], + }, + }, + methods: { + ...common.methods, + getSummary(item) { + return `Scene Activated with ID: ${item.id}`; + }, + }, + async run() { + const previousData = this._getPreviousData(); + + const { data } = await this.philipsHue.getScene({ + username: this.username, + sceneId: this.sceneId, + }); + + for (const item of data) { + const state = item.status.active; + if (previousData[item.id] && previousData[item.id] === state) { + continue; + } + + if (state === "static") { + this.emitEvent(item); + } + + previousData[item.id] = state; + } + + this._setPreviousData(previousData); + }, + sampleEmit, +}; diff --git a/components/philips_hue/sources/new-scene-activated/test-event.mjs b/components/philips_hue/sources/new-scene-activated/test-event.mjs new file mode 100644 index 0000000000000..61b8da836b7e4 --- /dev/null +++ b/components/philips_hue/sources/new-scene-activated/test-event.mjs @@ -0,0 +1,92 @@ +export default { + "id": "05f0693a-63a2-482d-9a49-3ec6aa582228", + "id_v1": "/scenes/NLojEidXQitRkxdQ", + "actions": [ + { + "target": { + "rid": "19216997-0bac-474e-a830-fe18b452d43a", + "rtype": "light" + }, + "action": { + "on": { + "on": true + }, + "dimming": { + "brightness": 100 + }, + "color_temperature": { + "mirek": 233 + } + } + }, + { + "target": { + "rid": "f4a7e1f8-10e2-47a9-8816-8788527d3cde", + "rtype": "light" + }, + "action": { + "on": { + "on": true + }, + "dimming": { + "brightness": 100 + }, + "color_temperature": { + "mirek": 233 + } + } + }, + { + "target": { + "rid": "15da328d-faa9-4296-b5b4-c48b9b3cbc30", + "rtype": "light" + }, + "action": { + "on": { + "on": true + }, + "dimming": { + "brightness": 100 + }, + "color_temperature": { + "mirek": 233 + } + } + } + ], + "palette": { + "color": [], + "dimming": [], + "color_temperature": [ + { + "color_temperature": { + "mirek": 233 + }, + "dimming": { + "brightness": 100 + } + } + ], + "effects": [], + "effects_v2": [] + }, + "recall": {}, + "metadata": { + "name": "Concentrate", + "image": { + "rid": "b90c8900-a6b7-422c-a5d3-e170187dbf8c", + "rtype": "public_image" + } + }, + "group": { + "rid": "206361d0-d999-498e-a8b1-3a0b101cca9b", + "rtype": "room" + }, + "speed": 0.603, + "auto_dynamic": false, + "status": { + "active": "static", + "last_recall": "2025-04-25T17:06:00.896Z" + }, + "type": "scene" +} \ No newline at end of file diff --git a/components/philips_hue/sources/new-sensor-update/new-sensor-update.mjs b/components/philips_hue/sources/new-sensor-update/new-sensor-update.mjs new file mode 100644 index 0000000000000..f05386af2413a --- /dev/null +++ b/components/philips_hue/sources/new-sensor-update/new-sensor-update.mjs @@ -0,0 +1,105 @@ +import common from "../common/base.mjs"; +import { ConfigurationError } from "@pipedream/platform"; + +export default { + ...common, + key: "philips_hue-new-sensor-update", + name: "New Sensor Update", + description: "Emit new event when a linked Hue sensor (e.g., motion, temperature, or ambient light) sends an update. [See the documentation](https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_light__id__put)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...common.props, + motionId: { + propDefinition: [ + common.props.philipsHue, + "motionId", + (c) => ({ + username: c.username, + }), + ], + optional: true, + }, + temperatureId: { + propDefinition: [ + common.props.philipsHue, + "temperatureId", + (c) => ({ + username: c.username, + }), + ], + optional: true, + }, + lightLevelId: { + propDefinition: [ + common.props.philipsHue, + "lightLevelId", + (c) => ({ + username: c.username, + }), + ], + optional: true, + }, + }, + hooks: { + deploy() { + const definedCount = [ + this.motionId, + this.temperatureId, + this.lightLevelId, + ].filter((x) => x !== undefined).length; + if (definedCount !== 1) { + throw new ConfigurationError("Must specify exactly one of Motion Sensor ID, Temperature Sensor ID or Light Level Sensor ID"); + } + }, + }, + methods: { + ...common.methods, + getSummary(item) { + const sensorType = this.motionId + ? "Motion" + : this.temperatureId + ? "Temperature" + : "Light level"; + return `${sensorType} Sensor Updated with ID: ${item.id}`; + }, + }, + async run() { + const previousData = this._getPreviousData(); + const args = { + username: this.username, + }; + const { data } = this.motionId + ? await this.philipsHue.getMotionSensor({ + ...args, + motionId: this.motionId, + }) + : this.temperatureId + ? await this.philipsHue.getTemperatureSensor({ + ...args, + temperatureId: this.temperatureId, + }) + : await this.philipsHue.getLightLevelSensor({ + ...args, + lightLevelId: this.lightLevelId, + }); + + for (const item of data) { + const changed = this.motionId + ? item.motion.motion_report.changed + : this.temperatureId + ? item.temperature.temperature_report.changed + : item.light.light_level_report.changed; + if (previousData[item.id] && previousData[item.id] <= Date.parse(changed)) { + continue; + } + + this.emitEvent(item); + + previousData[item.id] = Date.parse(changed); + } + + this._setPreviousData(previousData); + }, +}; From 4ea3a4d91f751e0c2afea66364b73e92e96dd09f Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 25 Apr 2025 13:52:34 -0400 Subject: [PATCH 2/2] pnpm-lock.yaml --- pnpm-lock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7917c4e2f33a9..27bb1e2c15143 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9567,7 +9567,7 @@ importers: components/philips_hue: dependencies: '@pipedream/platform': - specifier: ^3.0.0 + specifier: ^3.0.3 version: 3.0.3 components/phone_com: {}