0

Set Operation Mode for Battery

by
Published Nov 5, 2024

Request an `operationMode` change for a battery.

Script enode Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Enode = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Enode,
8
	batteryId: string,
9
	body: {
10
		operationMode: 'IMPORT_FOCUS' | 'EXPORT_FOCUS' | 'TIME_OF_USE' | 'SELF_RELIANCE'
11
	}
12
) {
13
	const url = new URL(`https://enode-api.production.enode.io/batteries/${batteryId}/operation-mode`)
14

15
	const response = await fetch(url, {
16
		method: 'POST',
17
		headers: {
18
			'Content-Type': 'application/json',
19
			Authorization: 'Bearer ' + auth.token
20
		},
21
		body: JSON.stringify(body)
22
	})
23

24
	if (!response.ok) {
25
		const text = await response.text()
26
		throw new Error(`${response.status} ${text}`)
27
	}
28

29
	return await response.json()
30
}
31