0

Link Tariff to Location

by
Published Nov 5, 2024

Link a tariff to a Location using a daily schedule. Each new schedule overwrites any previous requests. Devices positioned at this location will use the schedule to calculate electricity costs. The schedule must ensure that there are no overlapping intervals, although gaps are permissible. In case of gaps, the system will default to market prices.

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
	locationId: string,
9
	body: {
10
		tariffId: string
11
		tariffIntervals: {
12
			name: string
13
			weekdays?: 0 | 1 | 2 | 3 | 4 | 5 | 6[]
14
			from: string
15
			to: string
16
		}[]
17
	}
18
) {
19
	const url = new URL(`https://enode-api.production.enode.io/locations/${locationId}/tariff`)
20

21
	const response = await fetch(url, {
22
		method: 'PUT',
23
		headers: {
24
			'Content-Type': 'application/json',
25
			Authorization: 'Bearer ' + auth.token
26
		},
27
		body: JSON.stringify(body)
28
	})
29

30
	if (!response.ok) {
31
		const text = await response.text()
32
		throw new Error(`${response.status} ${text}`)
33
	}
34

35
	return await response.text()
36
}
37