Hacksore / bluelinky

An unofficial nodejs API wrapper for Hyundai bluelink and Kia UVO
https://bluelinky.readme.io
MIT License
345 stars 76 forks source link

Status fetch error SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse #276

Open carlosgamezvillegas opened 7 months ago

carlosgamezvillegas commented 7 months ago

Describe the bug A clear and concise description of what the bug is and how to reproduce it. Since yesterday I started getting this error after I tried to use Bluelinky:

Status fetch error SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at W. (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/bluelinky/dist/index.js:17:12462) at Generator.next () at s (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/bluelinky/dist/index.js:17:85) at processTicksAndRejections (node:internal/process/task_queues:96:5)

This happened out of nowhere because I have not made any changes

Usefull info(please complete the following information):

Additional context I am using node 16 since I cannot update it, if I use Node 20 I get the following error:

Client Error GotError [RequestError]: write EPROTO C07AE0ED01000000:error:0A000152:SSL routines:final_renegotiate:unsafe legacy renegotiation disabled:../deps/openssl/openssl/ssl/statem/extensions.c:922:

at ClientRequest.<anonymous> (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/got/source/request-as-event-emitter.js:178:14)
at Object.onceWrapper (node:events:633:26)
at ClientRequest.emit (node:events:530:35)
at ClientRequest.origin.emit (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/@szmarczak/http-timer/source/index.js:37:11)
at TLSSocket.socketErrorListener (node:_http_client:500:9)
at TLSSocket.emit (node:events:518:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21) {

code: 'EPROTO', host: 'api.telematics.hyundaiusa.com', hostname: 'api.telematics.hyundaiusa.com', method: 'POST', path: '/v2/ac/oauth/token', socketPath: undefined, protocol: 'https:', url: 'https://api.telematics.hyundaiusa.com/v2/ac/oauth/token', gotOptions: { path: '/v2/ac/oauth/token', protocol: 'https:', slashes: true, auth: null, host: 'api.telematics.hyundaiusa.com', port: null, hostname: 'api.telematics.hyundaiusa.com', hash: null, search: null, query: null, pathname: '/v2/ac/oauth/token', href: 'https://api.telematics.hyundaiusa.com/v2/ac/oauth/token', retry: { retries: [Function (anonymous)], methods: [Set], statusCodes: [Set], errorCodes: [Set] }, headers: { 'user-agent': 'PostmanRuntime/7.26.10', client_id: 'm66129Bb-em93-SPAHYN-bZ91-am4540zp19920', client_secret: 'v558o935-6nne-423i-baa8', accept: 'application/json', 'accept-encoding': 'gzip, deflate', 'content-type': 'application/json', 'content-length': 68 }, hooks: { beforeRequest: [], beforeRedirect: [], beforeRetry: [], afterResponse: [], beforeError: [], init: [] }, decompress: true, throwHttpErrors: true, followRedirect: true, stream: false, form: false, json: true, cache: false, useElectronNet: false, method: 'POST',

and if I use node 21 with bluelinky 8.3.1 I get the following error:

ReferenceError: ReadableStream is not defined at Object. (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/undici/lib/web/fetch/response.js:530:3) at Module._compile (node:internal/modules/cjs/loader:1198:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10) at Module.load (node:internal/modules/cjs/loader:1076:32) at Function.Module._load (node:internal/modules/cjs/loader:911:12) at Module.require (node:internal/modules/cjs/loader:1100:19) at require (node:internal/modules/cjs/helpers:119:18) at Object. (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/undici/lib/web/fetch/index.js:11:5) at Module._compile (node:internal/modules/cjs/loader:1198:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)

I would appreciate the help since I am out of workarounds.

Thanks

iProDeveloping commented 7 months ago

Also getting this error...

Following for updates

cmorozcogmailcom commented 7 months ago

i found a fix and a work around. I edited request-as-event-emitter.js. I added to the top const crypto = require('node:crypto'); const tls = require('tls');

then after const currentUrl = redirectString || requestUrl; I added the following. options.secureOptions=crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT;

then restart the plugin.

cmorozcogmailcom commented 7 months ago

on your system, it's different, you can see your error message points to /usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/got/source/request-as-event-emitter.js, give the change a try and let me know how you do.

at ClientRequest. (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/got/source/request-as-event-emitter.js:178:14) at Object.onceWrapper (node:events:633:26) at ClientRequest.emit (node:events:530:35) at ClientRequest.origin.emit (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/@szmarczak/http-timer/source/index.js:37:11) at TLSSocket.socketErrorListener (node:_http_client:500:9) at TLSSocket.emit (node:events:518:28) at emitErrorNT (node:internal/streams/destroy:169:8) at emitErrorCloseNT (node:internal/streams/destroy:128:3) at processTicksAndRejections (node:internal/process/task_queues:82:21) {

cmorozcogmailcom commented 7 months ago

this work around is in place of changing /etc/ssl/openssl.cnf since this code does not use the openssl config. the api site has changed their servers to not allow renegotiate as you can see from the EPROTO error message unsafe legacy renegotiation disabled

cmorozcogmailcom commented 7 months ago

request-as-event-emitter.js.zip here's the edited code.

carlosgamezvillegas commented 7 months ago

@cmorozcogmailcom,

Thank you for the fast response. Minutes after I send the message I was able to find the file. I applied the changes but unfortunately it did not work for me.

Let me give you a little bit of background on the issues people in the USA have. Months ago we started getting this error if we had node.js above node 16. Error: Client Error GotError [RequestError]: write EPROTO 00FAF1B6:error:0A000152:SSL routines:final_renegotiate:unsafe legacy renegotiation disabled:../deps/openssl/openssl/ssl/statem/extensions.c:922:

To avoid that issue I stayed at Node.js 16. But now we have this error:

Status fetch error SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at W. (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/bluelinky/dist/index.js:17:12462) at Generator.next () at s (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/bluelinky/dist/index.js:17:85) at processTicksAndRejections (node:internal/process/task_queues:96:5)

I applied your work around but I still have the an error using Node 16 and bluelinky 7.8 I get the following

Status fetch error SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at W. (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/bluelinky/dist/index.js:17:12462) at Generator.next () at s (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/bluelinky/dist/index.js:17:85) at processTicksAndRejections (node:internal/process/task_queues:96:5)

using node 21 and bluelinky 8.3.1 I get:

Client Error SyntaxError: Unexpected token '<', "

"... is not valid JSON at JSON.parse () at Z. (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/bluelinky/dist/index.cjs:2:20325) at Generator.next () at s (/usr/local/lib/node_modules/homebridge-hyundai-bluelink/node_modules/bluelinky/dist/index.cjs:2:607) at processTicksAndRejections (node:internal/process/task_queues:95:5)

what version of node.js and bluelinky are you using? are you in the USA?

Thank you for your time. I really appreciate you responding to this issue

cmorozcogmailcom commented 7 months ago

the error you get is because of a server change. I'm in the USA.

Error: Client Error GotError [RequestError]: write EPROTO 00FAF1B6:error:0A000152:SSL routines:final_renegotiate:unsafe legacy renegotiation disabled:../deps/openssl/openssl/ssl/statem/extensions.c:922:

unless you fix the error it will lead to Status fetch error SyntaxError: Unexpected token < in JSON at position 0 making this change allows you to move ahead from version Node 16. I'm using both version 16.14.0 and 16.20.2

can you share your versions of node and also the full error stack messages.

cmorozcogmailcom commented 7 months ago

did you try the debug test? npm run debug

bluelinky@8.3.0 debug ts-node debug.ts

? What Region are you in? US ? Which brand are you using? hyundai { region: 'US', brand: 'hyundai' } Logging in...

? What you wanna do? lock lock : "Lock successful"

? What you wanna do? exit carlosorozco@iMac bluelinky %

carlosgamezvillegas commented 7 months ago

Hello @cmorozcogmailcom,

I am using node 16.20.2 on a raspberry pi, bluelinky version is 7.6.6 (but I also get the error with 8.3.1). this are the logs:

Client Ready Fetching vehicle: KMxxxxxxxxxxxxxxxxxxxxxx Vehicle found { nickname: 'Guaxxxxxxxr', name: 'Guxxxxxxxx', vin: 'KMxxxxxxxxxxxxx', regDate: '20xxxxxxx', brandIndicator: 'H', regId: 'H00004xxxxxxxxxxxxxxx', generation: '2' Odometer fetch error SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at $. (/var/lib/homebridge/node_modules/homebridge-hyundai-bluelink/node_modules/bluelinky/dist/index.js:17:6615) at Generator.next () at s (/var/lib/homebridge/node_modules/homebridge-hyundai-bluelink/node_modules/bluelinky/dist/index.js:17:103) at processTicksAndRejections (node:internal/process/task_queues:96:5) Status fetch error SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at $. (/var/lib/homebridge/node_modules/homebridge-hyundai-bluelink/node_modules/bluelinky/dist/index.js:17:8560) at Generator.next () at s (/var/lib/homebridge/node_modules/homebridge-hyundai-bluelink/node_modules/bluelinky/dist/index.js:17:103)at processTicksAndRejections (node:internal/process/task_queues:96:5)

I am not sure how to run this: bluelinky@8.3.0 debug ts-node debug.ts since I am using bluelinky in a homebridge plugin

Thank you for the help and if you need anything else let me know

cmorozcogmailcom commented 7 months ago

follow https://github.com/Hacksore/bluelinky to run the debug.ts script with npm run debug, also you can read up on it here https://bluelinky.readme.io/reference/installation what version of Hyundai Bluelink Bridge plug-in are you running, I'm using 1.4.1

carlosgamezvillegas commented 7 months ago

@cmorozcogmailcom,

I run the commands and this is what I go but I don't know if I did it right : node 16.20.2.

guamis@Guamiss-Mac-Mini bluelinky % npm run debug

bluelinky@8.3.0 debug ts-node debug.ts

/Users/guamis/node_modules/bluelinky/node_modules/ts-node/src/index.ts:513 return new TSError(diagnosticText, diagnosticCodes) ^ TSError: ⨯ Unable to compile TypeScript: src/controllers/american.controller.ts:2:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

2 import got from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

at createTSError (/Users/guamis/node_modules/bluelinky/node_modules/ts-node/src/index.ts:513:12)
at reportTSError (/Users/guamis/node_modules/bluelinky/node_modules/ts-node/src/index.ts:517:19)
at getOutput (/Users/guamis/node_modules/bluelinky/node_modules/ts-node/src/index.ts:752:36)
at Object.compile (/Users/guamis/node_modules/bluelinky/node_modules/ts-node/src/index.ts:968:32)
at Module.m._compile (/Users/guamis/node_modules/bluelinky/node_modules/ts-node/src/index.ts:1056:42)
at Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
at Object.require.extensions.<computed> [as .ts] (/Users/guamis/node_modules/bluelinky/node_modules/ts-node/src/index.ts:1059:12)
at Module.load (node:internal/modules/cjs/loader:1076:32)
at Function.Module._load (node:internal/modules/cjs/loader:911:12)
at Module.require (node:internal/modules/cjs/loader:1100:19)

I am sugin version Hyundai Bluelink 1.4.1 but I did a lot of modifications to the plugin. I added a bunch of sensors and information in the form of TV inputs. When the plugin used to work all the of the information in the picture below was populated

Screenshot 2024-04-08 at 22 20 57

Do you think there is a path to make this work again? Unfortunately I am not experienced enough to solve my error so I would definitely appreciate all the help I can get

cmorozcogmailcom commented 7 months ago

it's likely you broke it with your mods, the data types you may have added may not be in the bluelinkly types. do you have typescript compiler installed? is see this error TSError: ⨯ Unable to compile TypeScript: src/controllers/american.controller.ts:2:8 - error TS1259: Module , you may need to install ts-node you should know also that the american.controller.ts: code does not have everything implemented the debug program will show you what is working and what is not.

for example: the odometer is not working What you wanna do? odometer SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at AmericanVehicle. (/Users/carlosorozco/bluelinky/src/vehicles/american.vehicle.ts:64:23) at Generator.next () at fulfilled (/Users/carlosorozco/bluelinky/src/vehicles/american.vehicle.ts:5:58) at processTicksAndRejections (node:internal/process/task_queues:95:5)

looks like bugs in bluelinky. to fix the odometer call you have to edit the american.vehicle.ts and look for the endpoint urls. some of them are wrong. if you change the odometer to look like this it will return the right data public async odometer(): Promise<VehicleOdometer | null> { const response = await this._request(ac/v2/enrollment/details/${this.userConfig.username}, { method: 'GET', headers: { ...this.getDefaultHeaders() },

bluelinky@8.3.0 debug

ts-node debug.ts

? What Region are you in? US ? Which brand are you using? hyundai { region: 'US', brand: 'hyundai' } Logging in...

? What you wanna do? stop stop : "Vehicle stopped"

? What you wanna do? odometer odometer { "value": "56112", "unit": 0 }

? What you wanna do? (Use arrow keys) ❯ exit

i also fixed the vehicle status stop status (on server cache) status (on server cache) unparsed ❯ status refresh (fetch from vehicle) full raw status (on server cache) -- not implemented full raw status refresh (fetch from vehicle) -- not implemented

? What you wanna do? status (on server cache) status : { "chassis": { "hoodOpen": false, "trunkOpen": false, "locked": true, "openDoors": { "frontRight": false, "frontLeft": false, "backLeft": false, "backRight": false }, "tirePressureWarningLamp": { "rearLeft": false, "frontLeft": false, "frontRight": false, "rearRight": false, "all": false } }, "climate": { "active": false, "steeringwheelHeat": false, "sideMirrorHeat": false, "rearWindowHeat": false, "defrost": false, "temperatureSetpoint": "01H", "temperatureUnit": 0 }, "engine": { "ignition": false, "accessory": false }, "lastupdate": "2024-04-09T10:46:45.000Z" }

What you wanna do? status (on server cache) unparsed status : { "dateTime": "2024-04-09T10:46:45Z", "acc": false, "trunkOpen": false, "doorLock": true, "defrostStatus": "false", "transCond": true, "doorLockStatus": "true", "doorOpen": { "frontRight": 0, "frontLeft": 0, "backLeft": 0, "backRight": 0 }, "airCtrlOn": false, "airTemp": { "unit": 0, "hvacTempType": 0, "value": "01H" }, "vehicleLocation": { "coord": { "alt": 18.52, "lon": -82.32112466666668, "type": 0, "lat": 27.89847966 } }, "ign3": false, "ignitionStatus": "false", "lowFuelLight": false, "sideBackWindowHeat": 0, "engine": false, "defrost": false, "hoodOpen": false, "airConditionStatus": "false", "steerWheelHeat": 0, "tirePressureLamp": { "tirePressureWarningLampRearLeft": 0, "tirePressureWarningLampFrontLeft": 0, "tirePressureWarningLampFrontRight": 0, "tirePressureWarningLampAll": 0, "tirePressureWarningLampRearRight": 0 }, "trunkOpenStatus": "false" }

What you wanna do? locate locate : { "latitude": 27.89847966, "longitude": -82.32112466666668, "altitude": 18.61, "speed": { "unit": 1, "value": 0 }, "heading": 182 }

cmorozcogmailcom commented 7 months ago

i'd like to ask how you added the controls and sensors to the plugin ?

carlosgamezvillegas commented 7 months ago

Hello @cmorozcogmailcom,

I am actually doing all the debug/testing in an unmodified version of bluelinky so my mods are not causing the problem. I will give ts-node.

About the plugin, I added a bunch of things to the Hyundai Bluelink homebridge plugin. Here is the file if you want to give it a try:

in dist/services/index.js you can add/remove any service you like by editing this line: homebridge-hyundai-bluelink.zip

const services = [new lock_1.Lock(va), new motor_1.Motor(va), new ignition_1.Ignition(va), new milage_1.Milage(va), new refill_1.Refill(va), new currentStatus_1.CurrentStatus(va), new odometer_1.Odometer(va), new oilSensor_1.OilSensor(va), new oil_1.Oil(va), new trunk_1.Trunk(va), new doors_1.Doors(va), new hood_1.Hood(va), new oilService_1.OilService(va), new palisade_1.Palisade(va), new palisade1_1.Palisade1(va), new palisade2_1.Palisade2(va), new palisade3_1.Palisade3(va), new palisade4_1.Palisade4(va), new palisade5_1.Palisade5(va), new palisade6_1.Palisade6(va), new palisade7_1.Palisade7(va), new palisade8_1.Palisade8(va), new palisade9_1.Palisade9(va), new palisade10_1.Palisade10(va), new palisade11_1.Palisade11(va), new palisade12_1.Palisade12(va), new palisade13_1.Palisade13(va), new palisade14_1.Palisade14(va), new palisade15_1.Palisade15(va)];

I also created a second homebridge plugin because for some reason the TV accessory in this one was not showing the inputs So I made this one: homebridge-palisade.zip

I would be happy to walk you through it if you are interested in the plugin.

carlosgamezvillegas commented 7 months ago

@cmorozcogmailcom,

I installed ts-node but I still have the same error, most likely I am not doing it right. However, I was able to run the debug.ts file and this is what I got.

guamis@Guamiss-Mac-Mini Bluelinky % tsc debug.ts
src/constants/stamps.ts:3:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

3 import got from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/controllers/american.controller.ts:2:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

2 import got from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/controllers/australia.controller.ts:1:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

1 import got, { GotInstance, GotJSONFn } from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/controllers/authStrategies/australia.authStrategy.ts:1:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

1 import got from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/controllers/authStrategies/australia.authStrategy.ts:4:8 - error TS2613: Module '"url"' has no default export. Did you mean to use 'import { Url } from "url"' instead?

4 import Url from 'url';


src/controllers/authStrategies/authStrategy.ts:1:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

1 import got from 'got';

node_modules/@types/got/index.d.ts:25:1 25 export = got;

    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/controllers/authStrategies/china.authStrategy.ts:1:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

1 import got from 'got';

node_modules/@types/got/index.d.ts:25:1 25 export = got;

    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/controllers/authStrategies/chinese.legacyAuth.strategy.ts:1:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

1 import got from 'got';

node_modules/@types/got/index.d.ts:25:1 25 export = got;

    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/controllers/authStrategies/chinese.legacyAuth.strategy.ts:5:8 - error TS2613: Module '"url"' has no default export. Did you mean to use 'import { Url } from "url"' instead?

5 import Url from 'url';

src/controllers/authStrategies/european.brandAuth.strategy.ts:1:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

1 import got from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/controllers/authStrategies/european.brandAuth.strategy.ts:5:8 - error TS2613: Module '"url"' has no default export. Did you mean to use 'import { Url } from "url"' instead?

5 import Url, { URLSearchParams } from 'url';


src/controllers/authStrategies/european.legacyAuth.strategy.ts:1:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

1 import got from 'got';

node_modules/@types/got/index.d.ts:25:1 25 export = got;

    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/controllers/authStrategies/european.legacyAuth.strategy.ts:5:8 - error TS2613: Module '"url"' has no default export. Did you mean to use 'import { Url } from "url"' instead?

5 import Url from 'url';

src/controllers/canadian.controller.ts:1:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

1 import got from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/controllers/chinese.controller.ts:7:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

7 import got, { GotInstance, GotJSONFn } from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/controllers/european.controller.ts:9:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

9 import got, { GotInstance, GotJSONFn } from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/vehicles/american.vehicle.ts:1:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

1 import got from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/vehicles/australia.vehicle.ts:26:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

26 import got from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/vehicles/canadian.vehicle.ts:1:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

1 import got from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/vehicles/chinese.vehicle.ts:36:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

36 import got from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

src/vehicles/european.vehicle.ts:36:8 - error TS1259: Module '"/Users/guamis/node_modules/bluelinky/node_modules/@types/got/index"' can only be default-imported using the 'esModuleInterop' flag

36 import got from 'got';


  node_modules/@types/got/index.d.ts:25:1
    25 export = got;
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

Found 21 errors in 17 files.

Errors Files 1 src/constants/stamps.ts:3 1 src/controllers/american.controller.ts:2 1 src/controllers/australia.controller.ts:1 2 src/controllers/authStrategies/australia.authStrategy.ts:1 1 src/controllers/authStrategies/authStrategy.ts:1 1 src/controllers/authStrategies/china.authStrategy.ts:1 2 src/controllers/authStrategies/chinese.legacyAuth.strategy.ts:1 2 src/controllers/authStrategies/european.brandAuth.strategy.ts:1 2 src/controllers/authStrategies/european.legacyAuth.strategy.ts:1 1 src/controllers/canadian.controller.ts:1 1 src/controllers/chinese.controller.ts:7 1 src/controllers/european.controller.ts:9 1 src/vehicles/american.vehicle.ts:1 1 src/vehicles/australia.vehicle.ts:26 1 src/vehicles/canadian.vehicle.ts:1 1 src/vehicles/chinese.vehicle.ts:36 1 src/vehicles/european.vehicle.ts:36

Any thoughts on how I can fix the Status fetch error SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse error?

cmorozcogmailcom commented 7 months ago

Hello @cmorozcogmailcom,

I am actually doing all the debug/testing in an unmodified version of bluelinky so my mods are not causing the problem. I will give ts-node.

  • you have to fix bluelinky or else your calls won't work.
  • for example
  • bugs in bluelinky. to fix the odometer call you have to edit the american.vehicle.ts and look for the endpoint urls. some of them are wrong. if you change the odometer to look like this it will return the right data public async odometer(): Promise<VehicleOdometer | null> { const response = await this._request(ac/v2/enrollment/details/${this.userConfig.username}, { method: 'GET', headers: { ...this.getDefaultHeaders() },

if you can't get a status from the debug test. your app will not work.

carlosgamezvillegas commented 7 months ago

@cmorozcogmailcom,

The odometer calls looks the way you mentioned and I wouldn't know how to start fixing bluelinky. @Hacksore do you think you can help us with this error: Status fetch error SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse

cmorozcogmailcom commented 7 months ago

I got my status to work in debug.ts and the plug-in. Just look at the endpoint in the error stack . If you see // then it's got a typo . It should be only one / . The only comment i can say is that there is not implementation of the raw status cases .

carlosgamezvillegas commented 7 months ago

@cmorozcogmailcom,

Would you share the Homebridge-Bluelink plugin folder and Bluelinky files with the edits you made?

Thank you!

cmorozcogmailcom commented 7 months ago

american.vehicle.ts.zip

carlosgamezvillegas commented 7 months ago

@cmorozcogmailcom,

I don't know where to put this file, Homebridge-bluelink does not use that file.

Screenshot 2024-04-10 at 07 20 23

If I install just Bluelinky on my Mac I get a dis folder and not scr folder, for that reason I asked for the whole Hombridge-Bluelink folder as well. So obviously I don't know what I am doing and probably I am doing a lot of things wrong. Please help this dumb dum make it work.

Thank you,

carlosgamezvillegas commented 7 months ago

@cmorozcogmailcom,

I realized that I was skipping a big important step (npm run build) and I want to thank you for being patient and provide a solution to our problem, I am truly grateful for all your help.

Kind regards,

cmorozcogmailcom commented 7 months ago

@carlosgamezvillegas any luck ?

carlosgamezvillegas commented 7 months ago

@cmorozcogmailcom,

yes, I don’t have the error anymore. I should have mentioned this in my last message. Everything is working again. Thank you!