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

Commit 2da3689

Browse files
authored
feat: add update noise threshold method (#187)
* feat: add update noise threshold method * fix issue in create noise sensor test
1 parent 7bb5a49 commit 2da3689

File tree

6 files changed

+136
-12
lines changed

6 files changed

+136
-12
lines changed

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: 24 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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,67 @@ const command: CommandModule<GlobalOptions> = {
8686
)
8787
}
8888
)
89+
.command(
90+
"update",
91+
"update a noise threshold",
92+
(yargs) => {
93+
return yargs
94+
.option("device_id", {
95+
describe: "the device ID",
96+
type: "string",
97+
demandOption: true,
98+
})
99+
.option("noise_threshold_id", {
100+
describe: "the noise threshold ID",
101+
type: "string",
102+
demandOption: true,
103+
})
104+
.option("name", {
105+
describe: "the name of the noise threshold",
106+
type: "string",
107+
demandOption: false,
108+
})
109+
.option("starts_daily_at", {
110+
describe: "the time the noise threshold starts",
111+
type: "string",
112+
demandOption: false,
113+
})
114+
.option("ends_daily_at", {
115+
describe: "the time the noise threshold ends",
116+
type: "string",
117+
demandOption: false,
118+
})
119+
.option("noise_threshold_decibels", {
120+
describe: "the noise threshold in decibels",
121+
type: "number",
122+
demandOption: false,
123+
conflicts: "noise_threshold_nrs",
124+
})
125+
.option("noise_threshold_nrs", {
126+
describe: "the noise threshold in NRS",
127+
type: "number",
128+
demandOption: false,
129+
conflicts: "noise_threshold_decibels",
130+
})
131+
},
132+
async (argv) => {
133+
await executeCommand(
134+
"noiseThresholds.update",
135+
[
136+
{
137+
device_id: argv.device_id,
138+
noise_threshold_id: argv.noise_threshold_id,
139+
name: argv.name,
140+
starts_daily_at: argv.starts_daily_at,
141+
ends_daily_at: argv.ends_daily_at,
142+
noise_threshold_decibels: argv.noise_threshold_decibels,
143+
noise_threshold_nrs: argv.noise_threshold_nrs,
144+
},
145+
],
146+
argv
147+
)
148+
}
149+
)
89150
.command(
90151
"delete",
91152
"delete a noise threshold",

src/seam-connect/routes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
NoiseThresholdsListRequest,
3838
NoiseThresholdsDeleteRequest,
3939
NoiseThresholdsCreateRequest,
40+
NoiseThresholdsUpdateRequest,
4041
} from "../types/route-requests"
4142
import {
4243
AccessCodeCreateMultipleResponse,
@@ -413,6 +414,12 @@ export abstract class Routes {
413414
method: "POST",
414415
data: params,
415416
}),
417+
update: (params: NoiseThresholdsUpdateRequest) =>
418+
this.makeRequest({
419+
url: "/noise_sensors/noise_thresholds/update",
420+
method: "POST",
421+
data: params,
422+
}),
416423
delete: (params: NoiseThresholdsDeleteRequest) =>
417424
this.makeRequest({
418425
url: "/noise_sensors/noise_thresholds/delete",

src/types/route-requests.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ export type NoiseThresholdsCreateRequest = {
169169
noise_threshold_nrs?: number
170170
}
171171

172+
export type NoiseThresholdsUpdateRequest = {
173+
device_id: string
174+
noise_threshold_id: string
175+
name?: string
176+
starts_daily_at?: string
177+
ends_daily_at?: string
178+
noise_threshold_decibels?: number
179+
/**
180+
* only available for NoiseAware devices
181+
*/
182+
noise_threshold_nrs?: number
183+
}
184+
172185
export type NoiseThresholdsDeleteRequest = {
173186
device_id: string
174187
noise_threshold_id: string

tests/routes.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,26 @@ test(
2323
{
2424
device_id: seed.devices.minut.device_without_quiet_hours.device_id,
2525
starts_daily_at: "13:00:00[America/Los_Angeles]",
26-
ends_daily_at: "13:00:00[America/Los_Angeles]",
26+
ends_daily_at: "14:00:00[America/Los_Angeles]",
27+
noise_threshold_decibels: 80,
28+
},
29+
],
30+
modifiesState: true,
31+
load_devices_from: ["minut"],
32+
},
33+
"{}"
34+
)
35+
36+
test(
37+
testAPIMethod("noiseThresholds.update"),
38+
{
39+
args: (seed) => [
40+
{
41+
noise_threshold_id:
42+
seed.devices.minut.noise_threshold_quiet_hours.noise_threshold_id,
43+
device_id: seed.devices.minut.device_with_quiet_hours.device_id,
44+
starts_daily_at: "19:00:00[America/Los_Angeles]",
45+
ends_daily_at: "21:00:00[America/Los_Angeles]",
2746
noise_threshold_decibels: 80,
2847
},
2948
],

0 commit comments

Comments
 (0)