-
Notifications
You must be signed in to change notification settings - Fork 1
/
Room.ts
54 lines (41 loc) · 1.61 KB
/
Room.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
import { ResourceType } from '../api/ResourceType';
import { ArcheTypeResource, ArcheTypeResourceEditOptions } from './ArcheTypeResource';
import { RoomManager } from '../managers/RoomManager';
import { ZoneEditOptions } from './Zone';
import { SceneCreateOptions } from './Scene';
export interface RoomEditOptions extends ArcheTypeResourceEditOptions {
children?: string[];
}
export type RoomCreateOptions = Required<RoomEditOptions>;
export class Room extends ArcheTypeResource<ResourceType.Room> {
type = ResourceType.Room;
get manager(): RoomManager {
return this.hue.rooms;
}
get childIds(): string[] {
return this.data.children.map((child) => child.rid);
}
get serviceIds(): string[] {
return this.data.services.map((service) => service.rid);
}
public async createScene(options: SceneCreateOptions): Promise<string | undefined> {
return await this.hue.scenes.create(this.id, options);
}
public async addChildren(children: Required<ZoneEditOptions>['children']): Promise<void> {
const newChildren = [...this.childIds, ...children];
await this.setChildren(newChildren);
}
public async removeChildren(children: Required<ZoneEditOptions>['children']): Promise<void> {
const newChildren = this.childIds.filter((id) => !children.includes(id));
await this.setChildren(newChildren);
}
public async setChildren(children: Required<ZoneEditOptions>['children']): Promise<void> {
await this.edit({ children });
}
public async edit(options: RoomEditOptions): Promise<void> {
await this.manager.edit(this.id, options);
}
public async delete(): Promise<void> {
await this.manager.delete(this.id);
}
}