forked from home-assistant/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.ts
57 lines (49 loc) · 1.11 KB
/
tag.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
import { HomeAssistant } from "../types";
import { HassEventBase } from "home-assistant-js-websocket";
export const EVENT_TAG_SCANNED = "tag_scanned";
export interface TagScannedEvent extends HassEventBase {
event_type: "tag_scanned";
data: {
tag_id: string;
device_id?: string;
};
}
export interface Tag {
id: string;
name?: string;
description?: string;
last_scanned?: string;
}
export interface UpdateTagParams {
name?: Tag["name"];
description?: Tag["description"];
}
export const fetchTags = async (hass: HomeAssistant) =>
hass.callWS<Tag[]>({
type: "tag/list",
});
export const createTag = async (
hass: HomeAssistant,
params: UpdateTagParams,
tagId?: string
) =>
hass.callWS<Tag>({
type: "tag/create",
tag_id: tagId,
...params,
});
export const updateTag = async (
hass: HomeAssistant,
tagId: string,
params: UpdateTagParams
) =>
hass.callWS<Tag>({
...params,
type: "tag/update",
tag_id: tagId,
});
export const deleteTag = async (hass: HomeAssistant, tagId: string) =>
hass.callWS<void>({
type: "tag/delete",
tag_id: tagId,
});