@@ -109,7 +109,7 @@ export class BluelinkUSA extends Bluelink {
109
109
return {
110
110
accessToken : resp . json . access_token ,
111
111
refreshToken : resp . json . refresh_token ,
112
- expiry : Math . floor ( Date . now ( ) / 1000 ) + resp . json . expires_in , // we only get a expireIn not a actual date
112
+ expiry : Math . floor ( Date . now ( ) / 1000 ) + Number ( resp . json . expires_in ) , // we only get a expireIn not a actual date
113
113
authCookie : undefined ,
114
114
}
115
115
}
@@ -227,4 +227,81 @@ export class BluelinkUSA extends Bluelink {
227
227
if ( this . config . debugLogging ) await this . logger . log ( error )
228
228
throw Error ( error )
229
229
}
230
+
231
+ // US implementation does not seem to have a mechanism to check for succesful commands or not
232
+ // for now do nothing but return success until we get some logs and can work out what to do
233
+ protected async pollForCommandCompletion ( resp : {
234
+ resp : Record < string , any >
235
+ json : any
236
+ } ) : Promise < { isSuccess : boolean ; data : any } > {
237
+ return {
238
+ isSuccess : true ,
239
+ data : resp . json ,
240
+ }
241
+ }
242
+
243
+ protected async lock ( id : string ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
244
+ return await this . lockUnlock ( id , true )
245
+ }
246
+
247
+ protected async unlock ( id : string ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
248
+ return await this . lockUnlock ( id , false )
249
+ }
250
+
251
+ protected async lockUnlock ( id : string , shouldLock : boolean ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
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
+ const resp = await this . request ( {
257
+ url : this . apiDomain + api ,
258
+ method : 'POST' ,
259
+ data : params . toString ( ) ,
260
+ headers : {
261
+ ...this . carHeaders ( ) ,
262
+ bluelinkservicepin : this . config . auth . pin ,
263
+ } ,
264
+ validResponseFunction : this . requestResponseValid ,
265
+ } )
266
+ if ( this . requestResponseValid ( resp . resp , resp . json ) . valid ) {
267
+ return await this . pollForCommandCompletion ( resp )
268
+ }
269
+ const error = `Failed to send lockUnlock command: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
270
+ if ( this . config . debugLogging ) await this . logger . log ( error )
271
+ throw Error ( error )
272
+ }
273
+
274
+ protected async startCharge ( id : string ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
275
+ return await this . chargeStopCharge ( id , true )
276
+ }
277
+
278
+ protected async stopCharge ( id : string ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
279
+ return await this . chargeStopCharge ( id , false )
280
+ }
281
+
282
+ protected async chargeStopCharge (
283
+ id : string ,
284
+ shouldCharge : boolean ,
285
+ ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
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
+ const resp = await this . request ( {
291
+ url : this . apiDomain + api ,
292
+ method : 'POST' ,
293
+ data : params . toString ( ) ,
294
+ headers : {
295
+ ...this . carHeaders ( ) ,
296
+ bluelinkservicepin : this . config . auth . pin ,
297
+ } ,
298
+ validResponseFunction : this . requestResponseValid ,
299
+ } )
300
+ if ( this . requestResponseValid ( resp . resp , resp . json ) . valid ) {
301
+ return await this . pollForCommandCompletion ( resp )
302
+ }
303
+ const error = `Failed to send charge command: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
304
+ if ( this . config . debugLogging ) await this . logger . log ( error )
305
+ throw Error ( error )
306
+ }
230
307
}
0 commit comments