3
3
BluelinkTokens ,
4
4
BluelinkCar ,
5
5
BluelinkStatus ,
6
- // ClimateRequest,
6
+ ClimateRequest ,
7
7
DEFAULT_STATUS_CHECK_INTERVAL ,
8
8
} from './base'
9
9
import { Config } from '../../config'
@@ -248,15 +248,15 @@ export class BluelinkUSA extends Bluelink {
248
248
return await this . lockUnlock ( id , false )
249
249
}
250
250
251
- protected async lockUnlock ( id : string , shouldLock : boolean ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
251
+ protected async lockUnlock ( _id : string , shouldLock : boolean ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
252
252
const api = shouldLock ? '/ac/v2/rcs/rdo/off' : '/ac/v2/rcs/rdo/on'
253
- const params = new URLSearchParams ( )
254
- params . append ( 'userName' , this . config . auth . username )
255
- params . append ( 'vin' , this . cache . car . vin )
256
253
const resp = await this . request ( {
257
254
url : this . apiDomain + api ,
258
255
method : 'POST' ,
259
- data : params . toString ( ) ,
256
+ data : JSON . stringify ( {
257
+ userName : this . config . auth . username ,
258
+ vin : this . cache . car . vin ,
259
+ } ) ,
260
260
headers : {
261
261
...this . carHeaders ( ) ,
262
262
bluelinkservicepin : this . config . auth . pin ,
@@ -280,17 +280,17 @@ export class BluelinkUSA extends Bluelink {
280
280
}
281
281
282
282
protected async chargeStopCharge (
283
- id : string ,
283
+ _id : string ,
284
284
shouldCharge : boolean ,
285
285
) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
286
286
const api = shouldCharge ? '/ac/v2/evc/charge/start' : '/ac/v2/evc/charge/stop'
287
- const params = new URLSearchParams ( )
288
- params . append ( 'userName' , this . config . auth . username )
289
- params . append ( 'vin' , this . cache . car . vin )
290
287
const resp = await this . request ( {
291
288
url : this . apiDomain + api ,
292
289
method : 'POST' ,
293
- data : params . toString ( ) ,
290
+ data : JSON . stringify ( {
291
+ userName : this . config . auth . username ,
292
+ vin : this . cache . car . vin ,
293
+ } ) ,
294
294
headers : {
295
295
...this . carHeaders ( ) ,
296
296
bluelinkservicepin : this . config . auth . pin ,
@@ -304,4 +304,66 @@ export class BluelinkUSA extends Bluelink {
304
304
if ( this . config . debugLogging ) await this . logger . log ( error )
305
305
throw Error ( error )
306
306
}
307
+
308
+ protected async climateOn (
309
+ _id : string ,
310
+ config : ClimateRequest ,
311
+ ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
312
+ if ( ! this . tempLookup ) {
313
+ throw Error ( `Mis-Configured sub-class - no temp lookup defined` )
314
+ }
315
+ const configTempIndex = this . config . tempType
316
+ const tempIndex = this . tempLookup [ configTempIndex ] . indexOf ( config . temp )
317
+
318
+ if ( ! tempIndex || tempIndex == - 1 ) {
319
+ throw Error ( `Failed to convert temp ${ config . temp } in climateOn command` )
320
+ }
321
+
322
+ const api = '/ac/v2/evc/fatc/start'
323
+ const resp = await this . request ( {
324
+ url : this . apiDomain + api ,
325
+ method : 'POST' ,
326
+ data : JSON . stringify ( {
327
+ airCtrl : 1 ,
328
+ defrost : config . defrost ,
329
+ airTemp : {
330
+ value : this . tempLookup . H [ tempIndex ] ,
331
+ unit : 0 ,
332
+ hvacTempType : 1 ,
333
+ } ,
334
+ igniOnDuration : config . durationMinutes ,
335
+ heating1 : config . steering ? 4 : 0 ,
336
+ } ) ,
337
+ headers : {
338
+ ...this . carHeaders ( ) ,
339
+ bluelinkservicepin : this . config . auth . pin ,
340
+ } ,
341
+ validResponseFunction : this . requestResponseValid ,
342
+ } )
343
+ if ( this . requestResponseValid ( resp . resp , resp . json ) . valid ) {
344
+ return await this . pollForCommandCompletion ( resp )
345
+ }
346
+ const error = `Failed to send climateOff command: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
347
+ if ( this . config . debugLogging ) await this . logger . log ( error )
348
+ throw Error ( error )
349
+ }
350
+
351
+ protected async climateOff ( _id : string ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
352
+ const api = '/ac/v2/evc/fatc/stop'
353
+ const resp = await this . request ( {
354
+ url : this . apiDomain + api ,
355
+ method : 'POST' ,
356
+ headers : {
357
+ ...this . carHeaders ( ) ,
358
+ bluelinkservicepin : this . config . auth . pin ,
359
+ } ,
360
+ validResponseFunction : this . requestResponseValid ,
361
+ } )
362
+ if ( this . requestResponseValid ( resp . resp , resp . json ) . valid ) {
363
+ return await this . pollForCommandCompletion ( resp )
364
+ }
365
+ const error = `Failed to send climateOff command: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
366
+ if ( this . config . debugLogging ) await this . logger . log ( error )
367
+ throw Error ( error )
368
+ }
307
369
}
0 commit comments