//native
type Enode = {
token: string
}
export async function main(
auth: Enode,
batteryId: string,
body: {
operationMode: 'IMPORT_FOCUS' | 'EXPORT_FOCUS' | 'TIME_OF_USE' | 'SELF_RELIANCE'
}
) {
const url = new URL(`https://enode-api.production.enode.io/batteries/${batteryId}/operation-mode`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.token
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 581 days ago