33 BluelinkTokens ,
44 BluelinkCar ,
55 BluelinkStatus ,
6- // ClimateRequest,
6+ ClimateRequest ,
77 DEFAULT_STATUS_CHECK_INTERVAL ,
88} from './base'
99import { Config } from '../../config'
@@ -248,15 +248,15 @@ export class BluelinkUSA extends Bluelink {
248248 return await this . lockUnlock ( id , false )
249249 }
250250
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 } > {
252252 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 )
256253 const resp = await this . request ( {
257254 url : this . apiDomain + api ,
258255 method : 'POST' ,
259- data : params . toString ( ) ,
256+ data : JSON . stringify ( {
257+ userName : this . config . auth . username ,
258+ vin : this . cache . car . vin ,
259+ } ) ,
260260 headers : {
261261 ...this . carHeaders ( ) ,
262262 bluelinkservicepin : this . config . auth . pin ,
@@ -280,17 +280,17 @@ export class BluelinkUSA extends Bluelink {
280280 }
281281
282282 protected async chargeStopCharge (
283- id : string ,
283+ _id : string ,
284284 shouldCharge : boolean ,
285285 ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
286286 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 )
290287 const resp = await this . request ( {
291288 url : this . apiDomain + api ,
292289 method : 'POST' ,
293- data : params . toString ( ) ,
290+ data : JSON . stringify ( {
291+ userName : this . config . auth . username ,
292+ vin : this . cache . car . vin ,
293+ } ) ,
294294 headers : {
295295 ...this . carHeaders ( ) ,
296296 bluelinkservicepin : this . config . auth . pin ,
@@ -304,4 +304,66 @@ export class BluelinkUSA extends Bluelink {
304304 if ( this . config . debugLogging ) await this . logger . log ( error )
305305 throw Error ( error )
306306 }
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+ }
307369}
0 commit comments