Skip to content

Commit 77d0982

Browse files
authored
Merge branch 'master' into issue-15670
2 parents df9ecb4 + 492fbe1 commit 77d0982

File tree

23 files changed

+545
-42
lines changed

23 files changed

+545
-42
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default {
2+
type: "app",
3+
app: "autotask_psa",
4+
propDefinitions: {},
5+
methods: {
6+
// this.$auth contains connected account data
7+
authKeys() {
8+
console.log(Object.keys(this.$auth));
9+
},
10+
},
11+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@pipedream/autotask_psa",
3+
"version": "0.0.1",
4+
"description": "Pipedream Autotask PSA Components",
5+
"main": "autotask_psa.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"autotask_psa"
9+
],
10+
"homepage": "https://pipedream.com/apps/autotask_psa",
11+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default {
2+
type: "app",
3+
app: "cloudflare_browser_rendering",
4+
propDefinitions: {},
5+
methods: {
6+
// this.$auth contains connected account data
7+
authKeys() {
8+
console.log(Object.keys(this.$auth));
9+
},
10+
},
11+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@pipedream/cloudflare_browser_rendering",
3+
"version": "0.0.1",
4+
"description": "Pipedream Cloudflare Browser Rendering Components",
5+
"main": "cloudflare_browser_rendering.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"cloudflare_browser_rendering"
9+
],
10+
"homepage": "https://pipedream.com/apps/cloudflare_browser_rendering",
11+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
}
15+
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import { v4 as uuid } from "uuid";
2+
import app from "../../govee.app.mjs";
3+
4+
export default {
5+
key: "govee-control-device",
6+
name: "Control Device",
7+
description: "Send a command to control a Govee device, such as turning it on/off, changing its brightness, or adjusting its color. [See the documentation](https://developer.govee.com/reference/control-you-devices).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
deviceId: {
13+
propDefinition: [
14+
app,
15+
"deviceId",
16+
],
17+
},
18+
commandType: {
19+
reloadProps: true,
20+
propDefinition: [
21+
app,
22+
"commandType",
23+
({ deviceId }) => ({
24+
deviceId,
25+
}),
26+
],
27+
},
28+
},
29+
async additionalProps() {
30+
const {
31+
deviceId,
32+
commandType,
33+
} = this;
34+
35+
const { data: devices } = await this.app.listDevices();
36+
const device = devices.find(({ device }) => device === deviceId);
37+
const capability = device?.capabilities?.find(({ type }) => type === commandType);
38+
const { parameters } = capability ?? {};
39+
40+
if (parameters.dataType === "ENUM") {
41+
return {
42+
value: {
43+
type: "string",
44+
label: "Value",
45+
description: "The value of the command.",
46+
options: parameters?.options.map(({
47+
name: label,
48+
value,
49+
}) => ({
50+
label,
51+
value: String(value),
52+
})),
53+
},
54+
};
55+
}
56+
57+
if (parameters.dataType === "INTEGER") {
58+
return {
59+
value: {
60+
type: "integer",
61+
label: "Value",
62+
description: `The value of the command. Min value: \`${parameters.range.min}\`, Max value: \`${parameters.range.max}\`.`,
63+
min: parameters.range.min,
64+
max: parameters.range.max,
65+
},
66+
};
67+
}
68+
69+
if (parameters.dataType === "STRUCT") {
70+
return parameters.fields.reduce((acc, {
71+
fieldName,
72+
dataType,
73+
range,
74+
required,
75+
options,
76+
}) => {
77+
if (dataType === "INTEGER") {
78+
acc[fieldName] = {
79+
type: "integer",
80+
label: fieldName,
81+
description: `The value of the ${fieldName} field. Min value: \`${range.min}\`, Max value: \`${range.max}\`.`,
82+
min: range.min,
83+
max: range.max,
84+
optional: !required,
85+
};
86+
} else if (dataType === "ENUM") {
87+
acc[fieldName] = {
88+
type: "string",
89+
label: fieldName,
90+
description: `The value of the ${fieldName} field.`,
91+
optional: !required,
92+
options: options.reduce((acc, {
93+
name: label,
94+
value,
95+
defaultValue,
96+
options: nestedOptions,
97+
}) => {
98+
if (nestedOptions) {
99+
return acc.concat(nestedOptions.map(({
100+
name: label,
101+
value,
102+
}) => ({
103+
label,
104+
value: String(value),
105+
})));
106+
}
107+
return acc.concat({
108+
label,
109+
value: value !== undefined && String(value) || String(defaultValue),
110+
});
111+
}, []),
112+
};
113+
} else if (dataType === "Array") {
114+
acc[fieldName] = {
115+
type: "string[]",
116+
label: fieldName,
117+
description: `The value of the ${fieldName} field.`,
118+
optional: !required,
119+
options: options.map(({ value }) => String(value)),
120+
};
121+
} else {
122+
acc[fieldName] = {
123+
type: "string",
124+
label: fieldName,
125+
description: `The value of the ${fieldName} field.`,
126+
optional: !required,
127+
};
128+
}
129+
return acc;
130+
}, {});
131+
}
132+
},
133+
methods: {
134+
controlDevice(args = {}) {
135+
return this.app.post({
136+
path: "/device/control",
137+
...args,
138+
});
139+
},
140+
},
141+
async run({ $ }) {
142+
const {
143+
app,
144+
controlDevice,
145+
deviceId,
146+
commandType,
147+
value,
148+
...fields
149+
} = this;
150+
151+
const { data: devices } = await app.listDevices();
152+
const device = devices.find(({ device }) => device === deviceId);
153+
154+
const response = await controlDevice({
155+
$,
156+
data: {
157+
requestId: uuid(),
158+
payload: {
159+
sku: device.sku,
160+
device: deviceId,
161+
capability: {
162+
type: commandType,
163+
parameters: {
164+
value: value ?? fields,
165+
},
166+
},
167+
},
168+
},
169+
});
170+
171+
$.export("$summary", "Successfully sent command to device.");
172+
return response;
173+
},
174+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { v4 as uuid } from "uuid";
2+
import app from "../../govee.app.mjs";
3+
4+
export default {
5+
key: "govee-retrieve-device-info",
6+
name: "Retrieve Device Info",
7+
description: "Retrieve the current status and metadata of a specific Govee device, such as its power state, color, mode, and health. [See the documentation](https://developer.govee.com/reference/get-devices-status).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
deviceId: {
13+
propDefinition: [
14+
app,
15+
"deviceId",
16+
],
17+
},
18+
},
19+
methods: {
20+
getDeviceStatus(args = {}) {
21+
return this.app.post({
22+
path: "/device/state",
23+
...args,
24+
});
25+
},
26+
},
27+
async run({ $ }) {
28+
const {
29+
app,
30+
getDeviceStatus,
31+
deviceId,
32+
} = this;
33+
34+
const { data: devices } = await app.listDevices();
35+
const device = devices.find(({ device }) => device === deviceId);
36+
37+
const response = await getDeviceStatus({
38+
$,
39+
data: {
40+
requestId: uuid(),
41+
payload: {
42+
sku: device.sku,
43+
device: deviceId,
44+
},
45+
},
46+
});
47+
$.export("$summary", "Successfully retrieved device info");
48+
return response;
49+
},
50+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const BASE_URL = "https://openapi.api.govee.com";
2+
const VERSION_PATH = "/router/api/v1";
3+
4+
export default {
5+
BASE_URL,
6+
VERSION_PATH,
7+
};

components/govee/govee.app.mjs

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,72 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "govee",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
deviceId: {
9+
type: "string",
10+
label: "Device ID",
11+
description: "The device ID",
12+
async options() {
13+
const { data: devices } = await this.listDevices();
14+
return devices.map(({
15+
device: value,
16+
sku: label,
17+
}) => ({
18+
label,
19+
value,
20+
}));
21+
},
22+
},
23+
commandType: {
24+
type: "string",
25+
label: "Command Type",
26+
description: "The type of command, e.g., power, brightness change, color change.",
27+
async options({ deviceId }) {
28+
const { data: devices } = await this.listDevices();
29+
const device = devices.find(({ device }) => device === deviceId);
30+
return device?.capabilities?.map(({
31+
type: value,
32+
instance: label,
33+
}) => ({
34+
label,
35+
value,
36+
}));
37+
},
38+
},
39+
},
540
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
41+
getUrl(path) {
42+
return `${constants.BASE_URL}${constants.VERSION_PATH}${path}`;
43+
},
44+
getHeaders(headers) {
45+
return {
46+
"Content-Type": "application/json",
47+
"Govee-API-Key": this.$auth.api_key,
48+
...headers,
49+
};
50+
},
51+
_makeRequest({
52+
$ = this, path, headers, ...args
53+
} = {}) {
54+
return axios($, {
55+
...args,
56+
url: this.getUrl(path),
57+
headers: this.getHeaders(headers),
58+
});
59+
},
60+
post(args = {}) {
61+
return this._makeRequest({
62+
method: "POST",
63+
...args,
64+
});
65+
},
66+
listDevices() {
67+
return this._makeRequest({
68+
path: "/user/devices",
69+
});
970
},
1071
},
11-
};
72+
};

components/govee/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/govee",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Govee Components",
55
"main": "govee.app.mjs",
66
"keywords": [
@@ -11,5 +11,9 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3",
17+
"uuid": "^11.1.0"
1418
}
1519
}

0 commit comments

Comments
 (0)