-
Notifications
You must be signed in to change notification settings - Fork 53
/
rooms.ts
90 lines (79 loc) · 2.66 KB
/
rooms.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { Endpoint } from '../endpoint'
import { EndpointClient, EndpointClientConfig } from '../endpoint-client'
import { Status, SuccessStatusValue } from '../types'
import { Device } from './devices'
export class RoomRequest {
/**
* A name given for the room (eg. Living Room)
*/
name?: string
}
export class Room extends RoomRequest {
/**
* The ID of the parent location.
*/
locationId?: string
/**
* The ID of the room.
*/
roomId?: string
}
export class RoomsEndpoint extends Endpoint {
constructor(config: EndpointClientConfig) {
super(new EndpointClient('locations', config))
}
/**
* List the rooms in a location
* @param locationId UUID of the location
*/
public list(locationId?: string): Promise<Room[]>{
return this.client.getPagedItems<Room>(`${this.locationId(locationId)}/rooms`)
}
/**
* Get a specific room in a location
* @param id UUID of the room
* @param locationId UUID of the location. If the client is configured with a location ID this parameter
* can be omitted
*/
public get(id: string, locationId?: string): Promise<Room>{
return this.client.get<Room>(`${this.locationId(locationId)}/rooms/${id}`)
}
/**
* Create a room in a location
* @param data request containing the room name
* @param locationId UUID of the location. If the client is configured with a location ID this parameter
* can be omitted
*/
public create(data: RoomRequest, locationId?: string): Promise<Room> {
return this.client.post(`${this.locationId(locationId)}/rooms`, data)
}
/**
* Update a room
* @param id UUID of the room
* @param data request containing the name of the room
* @param locationId UUID of the location. If the client is configured with a location ID this parameter
* can be omitted
*/
public update(id: string, data: RoomRequest, locationId?: string): Promise<Room> {
return this.client.put(`${this.locationId(locationId)}/rooms/${id}`, data)
}
/**
* Delete a room from a location
* @param id UUID of the room
* @param locationId UUID of the location. If the client is configured with a location ID this parameter
* can be omitted
*/
public async delete(id: string, locationId?: string): Promise<Status> {
await this.client.delete(`${this.locationId(locationId)}/rooms/${id}`)
return SuccessStatusValue
}
/**
* Returns a list of all the devices in a room
* @param id UUID of the room
* @param locationId UUID of the location. If the client is configured with a location ID this parameter
* can be omitted
*/
public listDevices(id: string, locationId?: string): Promise<Device[]> {
return this.client.getPagedItems<Device>(`${this.locationId(locationId)}/rooms/${id}/devices`)
}
}