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

Commit 179508e

Browse files
authored
feat: add delete noise threshold method (#182)
1 parent 58d39bc commit 179508e

8 files changed

Lines changed: 139 additions & 33 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: 18 additions & 0 deletions
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: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,61 @@ const command: CommandModule<GlobalOptions> = {
77
aliases: ["noise-thresholds", "nt"],
88
describe: "interact with noise thresholds",
99
builder: (yargs) => {
10-
return yargs.demandCommand().command(
11-
"list",
12-
"list noise thresholds",
13-
(yargs) => {
14-
return yargs.option("device-id", {
15-
describe: "filter by device ID",
16-
demandOption: true,
17-
type: "string",
18-
})
19-
},
20-
async (argv) => {
21-
await executeCommand(
22-
"noiseThresholds.list",
23-
[
24-
{
25-
device_id: argv.deviceId,
26-
},
27-
],
28-
argv
29-
)
30-
}
31-
)
10+
return yargs
11+
.demandCommand()
12+
.command(
13+
"list",
14+
"list noise thresholds",
15+
(yargs) => {
16+
return yargs.option("device-id", {
17+
describe: "filter by device ID",
18+
demandOption: true,
19+
type: "string",
20+
})
21+
},
22+
async (argv) => {
23+
await executeCommand(
24+
"noiseThresholds.list",
25+
[
26+
{
27+
device_id: argv.deviceId,
28+
},
29+
],
30+
argv
31+
)
32+
}
33+
)
34+
.command(
35+
"delete",
36+
"delete 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("noise_threshold_id", {
45+
describe: "the noise threshold ID",
46+
type: "string",
47+
demandOption: true,
48+
})
49+
},
50+
async (argv) => {
51+
await executeCommand(
52+
"noiseThresholds.delete",
53+
[
54+
{
55+
device_id: argv.device_id,
56+
noise_threshold_id: argv.noise_threshold_id,
57+
},
58+
],
59+
argv
60+
)
61+
}
62+
)
3263
},
64+
3365
handler: () => {},
3466
}
3567

src/seam-connect/routes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
WebhookCreateRequest,
3636
WebhookGetRequest,
3737
NoiseThresholdsListRequest,
38+
NoiseThresholdsDeleteRequest,
3839
} from "../types/route-requests"
3940
import {
4041
AccessCodeCreateMultipleResponse,
@@ -405,6 +406,12 @@ export abstract class Routes {
405406
},
406407
}
407408
),
409+
delete: (params: NoiseThresholdsDeleteRequest) =>
410+
this.makeRequest({
411+
url: "/noise_sensors/noise_thresholds/delete",
412+
method: "DELETE",
413+
data: params,
414+
}),
408415
}
409416

410417
public readonly webhooks = {

src/types/route-requests.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,8 @@ export interface EventsListRequest {
156156
export type NoiseThresholdsListRequest = {
157157
device_id: string
158158
}
159+
160+
export type NoiseThresholdsDeleteRequest = {
161+
device_id: string
162+
noise_threshold_id: string
163+
}

tests/fixtures/plugins/get-server-plugin.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ type SeedLock = {
1515
type SeedNoiseSensors = {
1616
device_with_quiet_hours: Device<any, "minut">
1717
device_without_quiet_hours: Device<any, "minut">
18+
noise_threshold_quiet_hours: {
19+
noise_threshold_id: string
20+
}
21+
noise_threshold_normal_hours: {
22+
noise_threshold_id: string
23+
}
1824
}
1925

2026
export type WorkerPublishedMessage = {

tests/fixtures/workers/helpers/add-fake-minut-devices.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Axios, AxiosResponse } from "axios"
22
import getDeviceType from "./get-device-type"
3+
import { Device } from "../../../../src"
34

45
const addFakeMinutDevices = async (axios: Axios) => {
56
const defaultConfig = {
@@ -35,12 +36,32 @@ const addFakeMinutDevices = async (axios: Axios) => {
3536
sync: true,
3637
})
3738

38-
const devices = await getDeviceType(axios, "minut_sensor")
39+
const devices: Device<any, "minut">[] = await getDeviceType(
40+
axios,
41+
"minut_sensor"
42+
)
3943
const [device_with_quiet_hours, device_without_quiet_hours] = devices
44+
const device_id = device_with_quiet_hours.device_id
45+
const {
46+
data: { noise_thresholds },
47+
} = await axios.post("/noise_sensors/noise_thresholds/list", {
48+
device_id,
49+
sync: true,
50+
})
51+
52+
const noise_threshold_normal_hours = (noise_thresholds as any[]).find(
53+
(noise_threshold) => noise_threshold.name === "builtin_normal_hours"
54+
)
55+
56+
const noise_threshold_quiet_hours = (noise_thresholds as any[]).find(
57+
(noise_threshold) => noise_threshold.name === "builtin_quiet_hours"
58+
)
4059

4160
return {
4261
device_with_quiet_hours,
4362
device_without_quiet_hours,
63+
noise_threshold_normal_hours,
64+
noise_threshold_quiet_hours,
4465
}
4566
}
4667

tests/routes.test.ts

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

19+
test(
20+
testAPIMethod("noiseThresholds.delete"),
21+
{
22+
args: (seed) => [
23+
{
24+
noise_threshold_id:
25+
seed.devices.minut.noise_threshold_quiet_hours.noise_threshold_id,
26+
device_id: seed.devices.minut.device_with_quiet_hours.device_id,
27+
},
28+
],
29+
modifiesState: true,
30+
load_devices_from: ["minut"],
31+
},
32+
"{}"
33+
)
34+
1935
// Workspaces
2036
test(testAPIMethod("workspaces.list"), {}, "Workspace[]")
2137
test(testAPIMethod("workspaces.get"), {}, "Workspace")

0 commit comments

Comments
 (0)