Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit 01f4e0d

Browse files
authored
feat: add create noise threshold method (#186)
1 parent 776edcc commit 01f4e0d

6 files changed

Lines changed: 125 additions & 11 deletions

File tree

docs/classes/Seam.md

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/modules.md

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli/commands/noise-thresholds.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,61 @@ const command: CommandModule<GlobalOptions> = {
3131
)
3232
}
3333
)
34+
.command(
35+
"create",
36+
"create a noise threshold",
37+
(yargs) => {
38+
return yargs
39+
.option("device_id", {
40+
describe: "the device ID",
41+
type: "string",
42+
demandOption: true,
43+
})
44+
.option("name", {
45+
describe: "the name of the noise threshold",
46+
type: "string",
47+
demandOption: false,
48+
})
49+
.option("starts_daily_at", {
50+
describe: "the time the noise threshold starts",
51+
type: "string",
52+
demandOption: true,
53+
})
54+
.option("ends_daily_at", {
55+
describe: "the time the noise threshold ends",
56+
type: "string",
57+
demandOption: true,
58+
})
59+
.option("noise_threshold_decibels", {
60+
describe: "the noise threshold in decibels",
61+
type: "number",
62+
demandOption: false,
63+
conflicts: "noise_threshold_nrs",
64+
})
65+
.option("noise_threshold_nrs", {
66+
describe: "the noise threshold in NRS",
67+
type: "number",
68+
demandOption: false,
69+
conflicts: "noise_threshold_decibels",
70+
})
71+
},
72+
async (argv) => {
73+
await executeCommand(
74+
"noiseThresholds.create",
75+
[
76+
{
77+
device_id: argv.device_id,
78+
name: argv.name,
79+
starts_daily_at: argv.starts_daily_at,
80+
ends_daily_at: argv.ends_daily_at,
81+
noise_threshold_decibels: argv.noise_threshold_decibels,
82+
noise_threshold_nrs: argv.noise_threshold_nrs,
83+
},
84+
],
85+
argv
86+
)
87+
}
88+
)
3489
.command(
3590
"delete",
3691
"delete a noise threshold",

src/seam-connect/routes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
WebhookGetRequest,
3737
NoiseThresholdsListRequest,
3838
NoiseThresholdsDeleteRequest,
39+
NoiseThresholdsCreateRequest,
3940
} from "../types/route-requests"
4041
import {
4142
AccessCodeCreateMultipleResponse,
@@ -406,6 +407,12 @@ export abstract class Routes {
406407
},
407408
}
408409
),
410+
create: (params: NoiseThresholdsCreateRequest) =>
411+
this.makeRequest({
412+
url: "/noise_sensors/noise_thresholds/create",
413+
method: "POST",
414+
data: params,
415+
}),
409416
delete: (params: NoiseThresholdsDeleteRequest) =>
410417
this.makeRequest({
411418
url: "/noise_sensors/noise_thresholds/delete",

src/types/route-requests.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ export type NoiseThresholdsListRequest = {
157157
device_id: string
158158
}
159159

160+
export type NoiseThresholdsCreateRequest = {
161+
device_id: string
162+
name?: string
163+
starts_daily_at: string
164+
ends_daily_at: string
165+
noise_threshold_decibels?: number
166+
/**
167+
* only available for NoiseAware devices
168+
*/
169+
noise_threshold_nrs?: number
170+
}
171+
160172
export type NoiseThresholdsDeleteRequest = {
161173
device_id: string
162174
noise_threshold_id: string

tests/routes.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ test(
1616
"NoiseThresholds[]"
1717
)
1818

19+
test(
20+
testAPIMethod("noiseThresholds.create"),
21+
{
22+
args: (seed) => [
23+
{
24+
device_id: seed.devices.minut.device_without_quiet_hours.device_id,
25+
starts_daily_at: "13:00:00[America/Los_Angeles]",
26+
ends_daily_at: "13:00:00[America/Los_Angeles]",
27+
noise_threshold_decibels: 80,
28+
},
29+
],
30+
modifiesState: true,
31+
load_devices_from: ["minut"],
32+
},
33+
"{}"
34+
)
35+
1936
test(
2037
testAPIMethod("noiseThresholds.delete"),
2138
{

0 commit comments

Comments
 (0)