//native
type Enode = {
token: string
}
export async function main(
auth: Enode,
scheduleId: string,
body:
| {
isEnabled?: false | true
defaultShouldCharge?: false | true
rules?: {
hourMinute?: { from: string; to: string }
fromTimestamp?: string
toTimestamp?: string
weekdays?: 0 | 1 | 2 | 3 | 4 | 5 | 6[]
} & { shouldCharge: false | true }[]
targetId?: string
targetType?: 'vehicle' | 'charger'
locationId?: string
}
| {
isEnabled?: false | true
targetId?: string
targetType?: 'hvac'
defaultTargetState?:
| ({ coolSetpoint: number; mode: 'COOL'; holdType: 'PERMANENT' } & {})
| ({ heatSetpoint: number; mode: 'HEAT'; holdType: 'PERMANENT' } & {})
| ({
coolSetpoint: number
heatSetpoint: number
mode: 'AUTO'
holdType: 'PERMANENT'
} & {})
| ({ mode: 'OFF'; holdType: 'PERMANENT' } & {})
| ({ holdType: 'SCHEDULED' } & {})
rules?: {
hourMinute?: { from: string; to: string }
fromTimestamp?: string
toTimestamp?: string
weekdays?: 0 | 1 | 2 | 3 | 4 | 5 | 6[]
} & {
targetState:
| ({
coolSetpoint: number
mode: 'COOL'
holdType: 'PERMANENT'
} & {})
| ({
heatSetpoint: number
mode: 'HEAT'
holdType: 'PERMANENT'
} & {})
| ({
coolSetpoint: number
heatSetpoint: number
mode: 'AUTO'
holdType: 'PERMANENT'
} & {})
| ({ mode: 'OFF'; holdType: 'PERMANENT' } & {})
| ({ holdType: 'SCHEDULED' } & {})
}[]
}
) {
const url = new URL(`https://enode-api.production.enode.io/schedules/${scheduleId}`)
const response = await fetch(url, {
method: 'PUT',
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