-
Notifications
You must be signed in to change notification settings - Fork 0
/
plug.ts
45 lines (41 loc) · 1.38 KB
/
plug.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
import DigestClient from "digest-fetch";
export async function turnPlugOn(ip: string, username: string, password: string) {
const client = new DigestClient(username, password, { algorithm: "SHA-256" });
try {
const res = await client.fetch(`http://${ip}/rpc/Switch.Set?id=0&on=true`);
return await res.json();
} catch (err) {
console.log(err);
return {};
}
}
export async function turnPlugOff(ip: string, username: string, password: string) {
const client = new DigestClient(username, password, { algorithm: "SHA-256" });
try {
const res = await client.fetch(`http://${ip}/rpc/Switch.Set?id=0&on=false`);
return await res.json();
} catch (err) {
console.log(err);
return {};
}
}
export async function togglePlug(ip: string, username: string, password: string) {
const client = new DigestClient(username, password, { algorithm: "SHA-256" });
try {
const res = await client.fetch(`http://${ip}/rpc/Switch.Toggle?id=0`);
return await res.json();
} catch (err) {
console.log(err);
return {};
}
}
export async function getPlugStatus(ip: string, username: string, password: string) {
const client = new DigestClient(username, password, { algorithm: "SHA-256" });
try {
const res = await client.fetch(`http://${ip}/rpc/Switch.GetStatus?id=0`);
return await res.json();
} catch (err) {
console.log(err);
return {};
}
}