forked from home-assistant/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.ts
74 lines (62 loc) · 1.84 KB
/
scene.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
import {
HassEntityAttributeBase,
HassEntityBase,
} from "home-assistant-js-websocket";
import { navigate } from "../common/navigate";
import { HomeAssistant, ServiceCallResponse } from "../types";
export const SCENE_IGNORED_DOMAINS = [
"sensor",
"binary_sensor",
"device_tracker",
"person",
"persistent_notification",
"configuration",
"image_processing",
"sun",
"weather",
"zone",
];
let inititialSceneEditorData: Partial<SceneConfig> | undefined;
export const showSceneEditor = (data?: Partial<SceneConfig>) => {
inititialSceneEditorData = data;
navigate("/config/scene/edit/new");
};
export const getSceneEditorInitData = () => {
const data = inititialSceneEditorData;
inititialSceneEditorData = undefined;
return data;
};
export interface SceneEntity extends HassEntityBase {
attributes: HassEntityAttributeBase & { id?: string };
}
export interface SceneConfig {
id?: string;
name: string;
icon?: string;
entities: SceneEntities;
}
export interface SceneEntities {
[entityId: string]: string | { state: string; [key: string]: any };
}
export const activateScene = (
hass: HomeAssistant,
entityId: string
): Promise<ServiceCallResponse> =>
hass.callService("scene", "turn_on", { entity_id: entityId });
export const applyScene = (
hass: HomeAssistant,
entities: SceneEntities
): Promise<ServiceCallResponse> =>
hass.callService("scene", "apply", { entities });
export const getSceneConfig = (
hass: HomeAssistant,
sceneId: string
): Promise<SceneConfig> =>
hass.callApi<SceneConfig>("GET", `config/scene/config/${sceneId}`);
export const saveScene = (
hass: HomeAssistant,
sceneId: string,
config: SceneConfig
) => hass.callApi("POST", `config/scene/config/${sceneId}`, config);
export const deleteScene = (hass: HomeAssistant, id: string) =>
hass.callApi("DELETE", `config/scene/config/${id}`);