forked from home-assistant/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter.ts
51 lines (45 loc) · 1003 Bytes
/
counter.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
import { HomeAssistant } from "../types";
export interface Counter {
id: string;
name: string;
icon?: string;
initial?: number;
restore?: boolean;
minimum?: number;
maximum?: number;
step?: number;
}
export interface CounterMutableParams {
name: string;
icon: string;
initial: number;
restore: boolean;
minimum: number;
maximum: number;
step: number;
}
export const fetchCounter = (hass: HomeAssistant) =>
hass.callWS<Counter[]>({ type: "counter/list" });
export const createCounter = (
hass: HomeAssistant,
values: CounterMutableParams
) =>
hass.callWS<Counter>({
type: "counter/create",
...values,
});
export const updateCounter = (
hass: HomeAssistant,
id: string,
updates: Partial<CounterMutableParams>
) =>
hass.callWS<Counter>({
type: "counter/update",
counter_id: id,
...updates,
});
export const deleteCounter = (hass: HomeAssistant, id: string) =>
hass.callWS({
type: "counter/delete",
counter_id: id,
});