diff --git a/components/home_connect/actions/get-appliances/get-appliances.mjs b/components/home_connect/actions/get-appliances/get-appliances.mjs new file mode 100644 index 0000000000000..a217acf53c265 --- /dev/null +++ b/components/home_connect/actions/get-appliances/get-appliances.mjs @@ -0,0 +1,19 @@ +import app from "../../home_connect.app.mjs"; + +export default { + key: "home_connect-get-appliances", + name: "Get Home Appliances", + description: "Retrieves a list of paired home appliances. [See the documentation](https://apiclient.home-connect.com/#/appliances/get_home_appliances)", + version: "0.0.1", + type: "action", + props: { + app, + }, + async run({ $ }) { + const response = await this.app.getAppliances($); + + $.export("$summary", "Successfully retrieved paired home appliances"); + + return response; + }, +}; diff --git a/components/home_connect/actions/get-programs/get-programs.mjs b/components/home_connect/actions/get-programs/get-programs.mjs new file mode 100644 index 0000000000000..0c276c9e41ca0 --- /dev/null +++ b/components/home_connect/actions/get-programs/get-programs.mjs @@ -0,0 +1,28 @@ +import app from "../../home_connect.app.mjs"; + +export default { + key: "home_connect-get-programs", + name: "Get Available Programs", + description: "Get a list of available programs of a home appliance. [See the documentation](https://api-docs.home-connect.com/programs-and-options/#cleaning-robot_cleaning-mode-option)", + version: "0.0.1", + type: "action", + props: { + app, + haId: { + propDefinition: [ + app, + "haId", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getAvailablePrograms({ + $, + haId: this.haId, + }); + + $.export("$summary", `Successfully retrieved available programs for appliance ${this.haId}`); + + return response; + }, +}; diff --git a/components/home_connect/actions/get-status/get-status.mjs b/components/home_connect/actions/get-status/get-status.mjs new file mode 100644 index 0000000000000..11176f38a22ef --- /dev/null +++ b/components/home_connect/actions/get-status/get-status.mjs @@ -0,0 +1,28 @@ +import app from "../../home_connect.app.mjs"; + +export default { + key: "home_connect-get-status", + name: "Get Home Appliance Status", + description: "Gets the status information of a home appliance. [See the documentation](https://api-docs.home-connect.com/general/#best-practices)", + version: "0.0.1", + type: "action", + props: { + app, + haId: { + propDefinition: [ + app, + "haId", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getApplianceStatus({ + $, + haId: this.haId, + }); + + $.export("$summary", `Successfully retrieved the status of the home appliance with ID ${this.haId}`); + + return response; + }, +}; diff --git a/components/home_connect/home_connect.app.mjs b/components/home_connect/home_connect.app.mjs index 9e27374f3127b..27790bf0c9c3c 100644 --- a/components/home_connect/home_connect.app.mjs +++ b/components/home_connect/home_connect.app.mjs @@ -1,11 +1,66 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "home_connect", - propDefinitions: {}, + propDefinitions: { + haId: { + type: "string", + label: "Home Appliance ID", + description: "The unique identifier of the home appliance.", + async options() { + const { data: { homeappliances: resources } } = await this.getAppliances(); + + return resources.map(({ + haId, name, + }) => ({ + value: haId, + label: name, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `https://${this.$auth.host_environment}/api`; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + }, + }); + }, + async getAppliances(args = {}) { + return this._makeRequest({ + path: "/homeappliances", + ...args, + }); + }, + async getApplianceStatus({ + haId, ...args + }) { + return this._makeRequest({ + path: `/homeappliances/${haId}/status`, + ...args, + }); + }, + async getAvailablePrograms({ + haId, ...args + }) { + return this._makeRequest({ + path: `/homeappliances/${haId}/programs/available`, + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/home_connect/package.json b/components/home_connect/package.json index f7011f5862f8a..e6ab2edf42e8f 100644 --- a/components/home_connect/package.json +++ b/components/home_connect/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/home_connect", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Home Connect Components", "main": "home_connect.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^1.6.0" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aec2588a1a422..cb1555fced4bd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3443,7 +3443,10 @@ importers: '@pipedream/platform': 1.5.1 components/home_connect: - specifiers: {} + specifiers: + '@pipedream/platform': ^1.6.0 + dependencies: + '@pipedream/platform': 1.6.0 components/hookdeck: specifiers: