-
Notifications
You must be signed in to change notification settings - Fork 54
/
scenes.ts
99 lines (92 loc) · 2.48 KB
/
scenes.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
91
92
93
94
95
96
97
98
99
import { Endpoint } from '../endpoint'
import { EndpointClient, EndpointClientConfig, HttpClientParams } from '../endpoint-client'
import { Status } from '../types'
export interface SceneSummary {
/**
* The unique identifier of the Scene
*/
sceneId?: string
/**
* The user-defined name of the Scene
*/
sceneName?: string
/**
* The name of the icon
*/
sceneIcon?: string
/**
* The color of the icon
*/
sceneColor?: string
/**
* Location of the Scene
*/
locationId?: string
/**
* The unique identifier of the user that created the scene
*/
createdBy?: string
/**
* The date the scene was created
*/
createdDate?: Date
/**
* The date the scene was last updated
*/
lastUpdatedDate?: Date
/**
* The date the scene was last executed
*/
lastExecutedDate?: Date
/**
* Whether or not this scene can be edited by the logged in user using the version of the app that made the request
*/
editable?: boolean
apiVersion?: string
}
export interface SceneListOptions {
locationId?: string[]
max?: number
page?: number
}
export class ScenesEndpoint extends Endpoint {
constructor(config: EndpointClientConfig) {
super(new EndpointClient('scenes', config))
}
/**
* Returns a list of scenes filterd by the specified options. If a location ID is included in the options or the
* client has been configured with a location ID, then only the scenes in that location are returned. If there is
* no locationId configured or specified, then the scenes in all locations accessible to the principal are returned.
* @param options optional filtering options accepting the location Id
*/
public list(options: SceneListOptions = {}): Promise<SceneSummary[]> {
const params: HttpClientParams = {}
if ('locationId' in options && options.locationId) {
params.locationId = options.locationId
} else if (this.client.config.locationId) {
params.locationId = this.client.config.locationId
}
return this.client.getPagedItems<SceneSummary>(undefined, params)
}
/**
* Get a specific scene
* @param id UUID of the scene
*/
public async get(id: string): Promise<SceneSummary> {
const list: SceneSummary[] = await this.client.getPagedItems<SceneSummary>()
if (list) {
const item = list.find(it => it.sceneId === id)
if (item) {
return item
}
}
throw Error(`Scene ${id} not found`)
}
/**
* Execute the actions specified in a scene
* @param id
*/
public execute(id: string): Promise<Status> {
return this.client.post(`${id}/execute`)
}
}