iobroker.teslafi 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,601 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TeslaFiAPICaller = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const teslafiHelper_1 = require("./teslafiHelper");
9
+ //import { IHomeInfo, TeslaFiHelper } from "./teslafiHelper";
10
+ function resolveAfterXSeconds(x) {
11
+ return new Promise((resolve) => {
12
+ setTimeout(() => {
13
+ resolve(x);
14
+ }, x * 1000);
15
+ });
16
+ }
17
+ class TeslaFiAPICaller extends teslafiHelper_1.TeslaFiHelper {
18
+ queryUrl = "";
19
+ constructor(adapter) {
20
+ super(adapter);
21
+ this.queryUrl = "https://www.teslafi.com/feed.php?token=";
22
+ }
23
+ /****************************************************************************************
24
+ * ReadTeslaFi **************************************************************************/
25
+ async ReadTeslaFi() {
26
+ await axios_1.default
27
+ .get(`${this.queryUrl}${this.adapter.config.TeslaFiAPIToken}&command=`, { transformResponse: (r) => r })
28
+ .then((response) => {
29
+ if (!response.data) {
30
+ throw new Error(`Empty answer from TeslaFi.`);
31
+ }
32
+ // this.adapter.log.debug(`TeslaFI data read - response data: ${response.data}`);
33
+ const result = JSON.parse(response.data);
34
+ // Check if the response indicates an unauthorized access {"response":{"reason":"","result":"unauthorized"}}
35
+ if (result.response?.result === "unauthorized") {
36
+ this.adapter.log.warn(`TeslaFI data read - unauthorized access detected - please verify your API-TOKEN`);
37
+ return false;
38
+ }
39
+ else {
40
+ // Iterate over each key-value pair in the result object and log non-null values
41
+ for (const [key, value] of Object.entries(result)) {
42
+ if (value !== null) {
43
+ switch (key) {
44
+ case "Date": //"2024-10-25 20:43:33"
45
+ this.checkAndSetValue(`vehicle-data.${key}`, value, `Last connection to your Tesla`);
46
+ break;
47
+ case "display_name": //"Red Elephant"
48
+ this.checkAndSetValue(`vehicle-data.${key}`, value, `Name of your Tesla`);
49
+ break;
50
+ case "vin": //"LRWYGCEKXNC44xxxx"
51
+ this.checkAndSetValue(`vehicle-data.${key}`, value, `VIN of your Tesla`);
52
+ break;
53
+ case "state": //"online"
54
+ this.checkAndSetValue(`vehicle-data.${key}`, value, `State of your Tesla`);
55
+ break;
56
+ case "time_to_full_charge": //"0.0"
57
+ this.checkAndSetValue(`vehicle-data.${key}`, value, `Time to full charge`);
58
+ break;
59
+ case "charge_current_request": //"16"
60
+ this.checkAndSetValueNumber(`vehicle-data.${key}`, parseFloat(value), `requested charge current by your car`, "A");
61
+ break;
62
+ case "charger_power": //"0"
63
+ this.checkAndSetValueNumber(`vehicle-data.${key}`, parseFloat(value), `current charge power`, "kW");
64
+ break;
65
+ case "charge_limit_soc": //"80"
66
+ this.checkAndSetValueNumber(`vehicle-data.${key}`, parseFloat(value), `charge limit defined in your Tesla`, "%");
67
+ break;
68
+ case "usable_battery_level": //"75"
69
+ this.checkAndSetValueNumber(`vehicle-data.${key}`, parseFloat(value), `usable battery SoC at this temperature conditions`, "%");
70
+ break;
71
+ case "battery_level": //"76"
72
+ this.checkAndSetValueNumber(`vehicle-data.${key}`, parseFloat(value), `battery SoC of your Tesla`, "%");
73
+ break;
74
+ case "est_battery_range": //"208.25"
75
+ this.checkAndSetValueNumber(`vehicle-data.${key}`, parseFloat(value), `estimated battery range`, "mi");
76
+ this.checkAndSetValueNumber(`vehicle-data.${key}_km`, parseFloat((value * 1.60934).toFixed(2)), `estimated battery range`, "km");
77
+ break;
78
+ case "inside_temp": //"15.8"
79
+ this.checkAndSetValueNumber(`vehicle-data.${key}`, parseFloat(value), `inside temperature in your Tesla`, "°C");
80
+ break;
81
+ case "longitude": //"9.899749"
82
+ this.checkAndSetValue(`vehicle-data.${key}`, value, `Current position longitude of your Tesla`);
83
+ break;
84
+ case "latitude": //"49.873095"
85
+ this.checkAndSetValue(`vehicle-data.${key}`, value, `Current position latitude of your Tesla`);
86
+ break;
87
+ case "speed": //null
88
+ this.checkAndSetValueNumber(`vehicle-data.${key}`, parseFloat(value.toFixed(2)), `current speed of your Tesla`, "km/h");
89
+ break;
90
+ case "outside_temp": //"14.0"
91
+ this.checkAndSetValueNumber(`vehicle-data.${key}`, parseFloat(value), `outside temperature near your Tesla`, "°C");
92
+ break;
93
+ case "odometer": // "16434.079511"
94
+ this.checkAndSetValueNumber(`vehicle-data.${key}`, parseFloat(value.toFixed(2)), `current odometer level of your Tesla`, "mi");
95
+ this.checkAndSetValueNumber(`vehicle-data.${key}_km`, parseFloat((value * 1.60934).toFixed(2)), `current odometer level of your Tesla`, "km");
96
+ break;
97
+ case "car_version": //"2024.32.7 3f0d0fff88"
98
+ this.checkAndSetValue(`vehicle-data.${key}`, value, `Current software version`);
99
+ break;
100
+ case "carState": //"Idling"
101
+ this.checkAndSetValue(`vehicle-data.${key}`, value, `Sleep-state of your Tesla`);
102
+ break;
103
+ case "location": //"Home"
104
+ this.checkAndSetValue(`vehicle-data.${key}`, value, `Location of your Tesla`);
105
+ break;
106
+ case "newVersion": //" "
107
+ this.checkAndSetValue(`vehicle-data.${key}`, value, `Next software version if available`);
108
+ break;
109
+ default:
110
+ // this.adapter.log.debug(`Unhandled field with data - ${key}: ${value}`);
111
+ break;
112
+ }
113
+ }
114
+ }
115
+ }
116
+ })
117
+ .catch((error) => {
118
+ this.HandleConnectionError(error, `TeslaFi API call`, `FI0`);
119
+ return false;
120
+ });
121
+ //#region *** DEMO DATA ***
122
+ /*
123
+ DemoERGTeslaFiSLEEP = {
124
+ data_id: 2307428,
125
+ Date: "2024-10-25 12:20:33",
126
+ calendar_enabled: "169",
127
+ remote_start_enabled: "1",
128
+ vehicle_id: "739 0 0 0 0 0 0",
129
+ display_name: null,
130
+ color: null,
131
+ fast_charger_brand: null,
132
+ notifications_enabled: null,
133
+ vin: null,
134
+ conn_charge_cable: null,
135
+ id: null,
136
+ charge_port_cold_weather_mode: null,
137
+ id_s: null,
138
+ state: "offline",
139
+ option_codes: null,
140
+ user_charge_enable_request: null,
141
+ time_to_full_charge: null,
142
+ charge_current_request: null,
143
+ charge_enable_request: null,
144
+ charge_to_max_range: null,
145
+ charger_phases: null,
146
+ battery_heater_on: null,
147
+ managed_charging_start_time: null,
148
+ battery_range: null,
149
+ charger_power: null,
150
+ charge_limit_soc: null,
151
+ charger_pilot_current: null,
152
+ charge_port_latch: null,
153
+ battery_current: null,
154
+ charger_actual_current: null,
155
+ scheduled_charging_pending: null,
156
+ fast_charger_type: null,
157
+ usable_battery_level: null,
158
+ motorized_charge_port: null,
159
+ charge_limit_soc_std: null,
160
+ not_enough_power_to_heat: null,
161
+ battery_level: null,
162
+ charge_energy_added: null,
163
+ charge_port_door_open: null,
164
+ max_range_charge_counter: null,
165
+ charge_limit_soc_max: null,
166
+ ideal_battery_range: null,
167
+ managed_charging_active: null,
168
+ charging_state: null,
169
+ fast_charger_present: null,
170
+ trip_charging: null,
171
+ managed_charging_user_canceled: null,
172
+ scheduled_charging_start_time: null,
173
+ est_battery_range: null,
174
+ charge_rate: null,
175
+ charger_voltage: null,
176
+ charge_current_request_max: null,
177
+ eu_vehicle: null,
178
+ charge_miles_added_ideal: null,
179
+ charge_limit_soc_min: null,
180
+ charge_miles_added_rated: null,
181
+ inside_temp: null,
182
+ longitude: null,
183
+ heading: null,
184
+ gps_as_of: null,
185
+ latitude: null,
186
+ speed: null,
187
+ shift_state: null,
188
+ seat_heater_rear_right: null,
189
+ seat_heater_rear_left_back: null,
190
+ seat_heater_left: null,
191
+ passenger_temp_setting: null,
192
+ is_auto_conditioning_on: null,
193
+ driver_temp_setting: null,
194
+ outside_temp: null,
195
+ seat_heater_rear_center: null,
196
+ is_rear_defroster_on: null,
197
+ seat_heater_rear_right_back: null,
198
+ smart_preconditioning: null,
199
+ seat_heater_right: null,
200
+ fan_status: null,
201
+ is_front_defroster_on: null,
202
+ seat_heater_rear_left: null,
203
+ gui_charge_rate_units: null,
204
+ gui_24_hour_time: null,
205
+ gui_temperature_units: null,
206
+ gui_range_display: null,
207
+ gui_distance_units: null,
208
+ sun_roof_installed: null,
209
+ rhd: null,
210
+ remote_start_supported: null,
211
+ homelink_nearby: null,
212
+ parsed_calendar_supported: null,
213
+ spoiler_type: null,
214
+ ft: null,
215
+ odometer: null,
216
+ remote_start: null,
217
+ pr: null,
218
+ climate_keeper_mode: null,
219
+ roof_color: null,
220
+ perf_config: null,
221
+ valet_mode: null,
222
+ calendar_supported: null,
223
+ pf: null,
224
+ sun_roof_percent_open: null,
225
+ third_row_seats: null,
226
+ seat_type: null,
227
+ api_version: null,
228
+ rear_seat_heaters: null,
229
+ rt: null,
230
+ exterior_color: null,
231
+ df: null,
232
+ autopark_state: null,
233
+ sun_roof_state: null,
234
+ notifications_supported: null,
235
+ vehicle_name: null,
236
+ dr: null,
237
+ autopark_style: null,
238
+ car_type: null,
239
+ wheel_type: null,
240
+ locked: null,
241
+ center_display_state: null,
242
+ last_autopark_error: null,
243
+ car_version: null,
244
+ defrost_mode: null,
245
+ autopark_state_v2: null,
246
+ is_preconditioning: "",
247
+ inside_tempF: "",
248
+ driver_temp_settingF: "",
249
+ outside_tempF: "",
250
+ battery_heater: "",
251
+ Notes: "Offline Asleep",
252
+ odometerF: "",
253
+ idleNumber: 0,
254
+ sleepNumber: 6750,
255
+ driveNumber: 0,
256
+ chargeNumber: 0,
257
+ polling: "",
258
+ idleTime: 0,
259
+ maxRange: "314.14",
260
+ left_temp_direction: null,
261
+ max_avail_temp: null,
262
+ is_climate_on: null,
263
+ right_temp_direction: null,
264
+ min_avail_temp: null,
265
+ is_user_present: null,
266
+ in_service: null,
267
+ valet_pin_needed: null,
268
+ charge_port_led_color: null,
269
+ timestamp: null,
270
+ power: null,
271
+ side_mirror_heaters: null,
272
+ wiper_blade_heater: null,
273
+ steering_wheel_heater: null,
274
+ elevation: "",
275
+ sentry_mode: "",
276
+ fd_window: "",
277
+ fp_window: "",
278
+ rd_window: "",
279
+ rp_window: "",
280
+ measure: "metric",
281
+ temperature: "C",
282
+ currency: "€",
283
+ carState: "Sleeping",
284
+ location: "Home",
285
+ rangeDisplay: "rated",
286
+ newVersion: " ",
287
+ newVersionStatus: "",
288
+ allow_cabin_overheat_protection: "",
289
+ cabin_overheat_protection: null,
290
+ cabin_overheat_protection_actively_cooling: null,
291
+ cop_activation_temperature: null,
292
+ pressure: null,
293
+ tpms_front_left: "39.5",
294
+ tpms_front_right: "39.2",
295
+ tpms_rear_left: "39.5",
296
+ tpms_rear_right: "39.2",
297
+ };
298
+
299
+ DemoERGTeslaFiAWAKE = {
300
+ data_id: 2307502,
301
+ Date: "2024-10-25 20:43:33",
302
+ calendar_enabled: null,
303
+ remote_start_enabled: "1",
304
+ vehicle_id: "1241 70 45 0 0 0 0",
305
+ display_name: "Red Elephant",
306
+ color: "1 FanOnly ",
307
+ fast_charger_brand: "",
308
+ notifications_enabled: null,
309
+ vin: "LRWYGCEKXNC446038",
310
+ conn_charge_cable: "IEC",
311
+ id: "NULL",
312
+ charge_port_cold_weather_mode: "0",
313
+ id_s: "",
314
+ state: "online",
315
+ option_codes: null,
316
+ user_charge_enable_request: null,
317
+ time_to_full_charge: "0.0",
318
+ charge_current_request: "16",
319
+ charge_enable_request: "1",
320
+ charge_to_max_range: "",
321
+ charger_phases: null,
322
+ battery_heater_on: "0",
323
+ managed_charging_start_time: "",
324
+ battery_range: "237.17",
325
+ charger_power: "0",
326
+ charge_limit_soc: "80",
327
+ charger_pilot_current: "16",
328
+ charge_port_latch: "Engaged",
329
+ battery_current: "",
330
+ charger_actual_current: "0",
331
+ scheduled_charging_pending: "0",
332
+ fast_charger_type: "",
333
+ usable_battery_level: "75",
334
+ motorized_charge_port: null,
335
+ charge_limit_soc_std: null,
336
+ not_enough_power_to_heat: null,
337
+ battery_level: "76",
338
+ charge_energy_added: "0.0",
339
+ charge_port_door_open: "1",
340
+ max_range_charge_counter: null,
341
+ charge_limit_soc_max: null,
342
+ ideal_battery_range: "237.17",
343
+ managed_charging_active: "",
344
+ charging_state: "NoPower",
345
+ fast_charger_present: "0",
346
+ trip_charging: "1",
347
+ managed_charging_user_canceled: null,
348
+ scheduled_charging_start_time: null,
349
+ est_battery_range: "208.25",
350
+ charge_rate: "0.0",
351
+ charger_voltage: "1",
352
+ charge_current_request_max: "16",
353
+ eu_vehicle: "1",
354
+ charge_miles_added_ideal: "0.0",
355
+ charge_limit_soc_min: null,
356
+ charge_miles_added_rated: "0.0",
357
+ inside_temp: "15.8",
358
+ longitude: "9.899749",
359
+ heading: "",
360
+ gps_as_of: null,
361
+ latitude: "49.873095",
362
+ speed: null,
363
+ shift_state: null,
364
+ seat_heater_rear_right: "0",
365
+ seat_heater_rear_left_back: "",
366
+ seat_heater_left: "0",
367
+ passenger_temp_setting: "20.5",
368
+ is_auto_conditioning_on: "0",
369
+ driver_temp_setting: "20.5",
370
+ outside_temp: "14.0",
371
+ seat_heater_rear_center: "0",
372
+ is_rear_defroster_on: "0",
373
+ seat_heater_rear_right_back: "",
374
+ smart_preconditioning: "",
375
+ seat_heater_right: "0",
376
+ fan_status: "0",
377
+ is_front_defroster_on: "0",
378
+ seat_heater_rear_left: "0",
379
+ gui_charge_rate_units: null,
380
+ gui_24_hour_time: null,
381
+ gui_temperature_units: null,
382
+ gui_range_display: null,
383
+ gui_distance_units: null,
384
+ sun_roof_installed: null,
385
+ rhd: "0",
386
+ remote_start_supported: null,
387
+ homelink_nearby: "0",
388
+ parsed_calendar_supported: null,
389
+ spoiler_type: null,
390
+ ft: "0",
391
+ odometer: "16434.079511",
392
+ remote_start: null,
393
+ pr: "0",
394
+ climate_keeper_mode: "off",
395
+ roof_color: null,
396
+ perf_config: null,
397
+ valet_mode: "0",
398
+ calendar_supported: null,
399
+ pf: "0",
400
+ sun_roof_percent_open: null,
401
+ third_row_seats: null,
402
+ seat_type: null,
403
+ api_version: null,
404
+ rear_seat_heaters: null,
405
+ rt: "0",
406
+ exterior_color: null,
407
+ df: "0",
408
+ autopark_state: "NULL",
409
+ sun_roof_state: null,
410
+ notifications_supported: null,
411
+ vehicle_name: null,
412
+ dr: "0",
413
+ autopark_style: null,
414
+ car_type: null,
415
+ wheel_type: "Apollo19MetallicShad",
416
+ locked: "1",
417
+ center_display_state: null,
418
+ last_autopark_error: null,
419
+ car_version: "2024.32.7 3f0d0fff88",
420
+ defrost_mode: "0",
421
+ autopark_state_v2: null,
422
+ is_preconditioning: "0",
423
+ inside_tempF: "60",
424
+ driver_temp_settingF: "",
425
+ outside_tempF: "57",
426
+ battery_heater: "0",
427
+ Notes: "",
428
+ odometerF: "",
429
+ idleNumber: 14780,
430
+ sleepNumber: 0,
431
+ driveNumber: 0,
432
+ chargeNumber: 0,
433
+ polling: "",
434
+ idleTime: 1,
435
+ maxRange: "314.14",
436
+ left_temp_direction: null,
437
+ max_avail_temp: null,
438
+ is_climate_on: "0",
439
+ right_temp_direction: null,
440
+ min_avail_temp: null,
441
+ is_user_present: "0",
442
+ in_service: "0",
443
+ valet_pin_needed: null,
444
+ charge_port_led_color: null,
445
+ timestamp: null,
446
+ power: "0",
447
+ side_mirror_heaters: "0",
448
+ wiper_blade_heater: "0",
449
+ steering_wheel_heater: "0",
450
+ elevation: "",
451
+ sentry_mode: "0",
452
+ fd_window: "0",
453
+ fp_window: "0",
454
+ rd_window: "0",
455
+ rp_window: "0",
456
+ measure: "metric",
457
+ temperature: "C",
458
+ currency: "€",
459
+ carState: "Idling",
460
+ location: "Home",
461
+ rangeDisplay: "rated",
462
+ newVersion: " ",
463
+ newVersionStatus: "",
464
+ allow_cabin_overheat_protection: "1",
465
+ cabin_overheat_protection: "FanOnly",
466
+ cabin_overheat_protection_actively_cooling: "",
467
+ cop_activation_temperature: null,
468
+ pressure: null,
469
+ tpms_front_left: "41.7",
470
+ tpms_front_right: "41.0",
471
+ tpms_rear_left: "41.7",
472
+ tpms_rear_right: "41.0",
473
+ };
474
+ */
475
+ //#endregion
476
+ await resolveAfterXSeconds(2);
477
+ return true;
478
+ } // END ReadTeslaFi
479
+ /**
480
+ * updates list of tomorrows prices of one home
481
+ *
482
+ * @param homeId - homeId string
483
+ * @param forceUpdate - OPTIONAL: force mode, without verification if existing data is fitting to current date, default: false
484
+ * @returns okprice - got new data
485
+ */
486
+ /*
487
+ private async updatePricesTomorrow(homeId: string, forceUpdate = false): Promise<boolean> {
488
+ try {
489
+ let exDate: Date | null = null;
490
+ let exPricesTomorrow: IPrice[] = [];
491
+ if (!forceUpdate) {
492
+ exPricesTomorrow = JSON.parse(await this.getStateValue(`Homes.${homeId}.PricesTomorrow.json`));
493
+ }
494
+ if (Array.isArray(exPricesTomorrow) && exPricesTomorrow[2] && exPricesTomorrow[2].startsAt) {
495
+ exDate = new Date(exPricesTomorrow[2].startsAt);
496
+ }
497
+ const morgen = new Date();
498
+ morgen.setDate(morgen.getDate() + 1);
499
+ morgen.setHours(0, 0, 0, 0); // sets clock to 0:00
500
+ if (!exDate || exDate < morgen || forceUpdate) {
501
+ const pricesTomorrow = await this.tibberQuery.getTomorrowsEnergyPrices(homeId);
502
+ this.adapter.log.debug(`Got prices tomorrow from tibber api: ${JSON.stringify(pricesTomorrow)} Force: ${forceUpdate}`);
503
+ this.checkAndSetValue(this.getStatePrefix(homeId, "PricesTomorrow", "json"), JSON.stringify(pricesTomorrow), "The prices tomorrow as json"); // write also it might be empty
504
+ if (pricesTomorrow.length === 0) {
505
+ // pricing not known, before about 13:00 - delete all the states
506
+ this.adapter.log.debug(`Emptying prices tomorrow and average cause existing ones are obsolete...`);
507
+ this.emptyingPriceAverage(homeId, `PricesTomorrow.average`);
508
+ this.checkAndSetValue(
509
+ this.getStatePrefix(homeId, "PricesTomorrow", "jsonBYpriceASC"),
510
+ JSON.stringify(pricesTomorrow),
511
+ "prices sorted by cost ascending as json",
512
+ );
513
+ return false;
514
+ } else if (Array.isArray(pricesTomorrow)) {
515
+ // pricing known, after about 13:00 - write the states
516
+ this.checkAndSetValue(
517
+ this.getStatePrefix(homeId, "PricesTomorrow", "jsonBYpriceASC"),
518
+ JSON.stringify(pricesTomorrow.sort((a, b) => a.total - b.total)),
519
+ "prices sorted by cost ascending as json",
520
+ );
521
+ exDate = new Date(pricesTomorrow[2].startsAt);
522
+ if (exDate && exDate >= morgen) {
523
+ return true;
524
+ } else {
525
+ return false;
526
+ }
527
+ }
528
+ } else if (exDate && exDate >= morgen) {
529
+ this.adapter.log.debug(`Existing date (${exDate}) of price info is already the tomorrow date, polling of prices tomorrow from Tibber skipped`);
530
+ return true;
531
+ }
532
+ return false;
533
+ } catch (error: any) {
534
+ if (forceUpdate) this.adapter.log.error(this.generateErrorMessage(error, `force pull of prices tomorrow`));
535
+ else this.adapter.log.warn(this.generateErrorMessage(error, `pull of prices tomorrow`));
536
+ return false;
537
+ }
538
+ }
539
+ */
540
+ /*****************************************************************************************/
541
+ async HandleConnectionError(stError, sOccasion, sErrorOccInt) {
542
+ if (stError.response) {
543
+ //get HTTP error code
544
+ switch (stError.response.status) {
545
+ case 401:
546
+ //this.SendSentryError(stError.Message);
547
+ this.adapter.log.error(`The TeslaFi API request has not been completed because it lacks valid authentication credentials.`);
548
+ this.adapter.log.error(`HTTP error 401 when calling ${sOccasion}!! (e${sErrorOccInt}.0)`);
549
+ this.adapter.log.error(`Adapter is shutting down`);
550
+ void this.adapter.stop;
551
+ break;
552
+ default:
553
+ this.adapter.log.error(`HTTP error ${stError.response.status} when polling ${sOccasion}!! (e${sErrorOccInt}.1)`);
554
+ }
555
+ }
556
+ else if (stError.code) {
557
+ //get error code
558
+ switch (stError.code) {
559
+ case "ETIMEDOUT":
560
+ this.adapter.log.warn(`Connection timeout error when calling ${sOccasion}`);
561
+ this.adapter.log.warn(`Please verify the API Token or adapt yout poll interval, (e${sErrorOccInt}.2)`);
562
+ break;
563
+ case "EHOSTUNREACH":
564
+ this.adapter.log.warn(`TeslaFi not reachable error when calling ${sOccasion}`);
565
+ this.adapter.log.warn(`Please verify yout network environment, (e${sErrorOccInt}.2)`);
566
+ break;
567
+ case "ENETUNREACH":
568
+ this.adapter.log.warn(`Inverter network not reachable error when calling ${sOccasion}`);
569
+ this.adapter.log.warn(`Please verify yout network environment, (e${sErrorOccInt}.2)`);
570
+ break;
571
+ }
572
+ // errors: 'Unexpected end of JSON input' 'read ECONNRESET' 'connect ECONNREFUSED 192.168.0.1:80'
573
+ }
574
+ else {
575
+ this.adapter.log.error(`Unknown error when calling ${sOccasion}: ${stError.message}`);
576
+ this.adapter.log.error(`Please verify the API Token or adapt yout poll interval, (e${sErrorOccInt}.3)`);
577
+ if (this.adapter.supportsFeature && this.adapter.supportsFeature("PLUGINS")) {
578
+ // send Sentry error
579
+ const sentryInstance = this.adapter.getPluginInstance("sentry");
580
+ if (sentryInstance) {
581
+ const oldError = await this.adapter.getStateAsync("LastSentryLoggedError");
582
+ if (oldError?.val != stError.message) {
583
+ // if new error
584
+ const Sentry = sentryInstance.getSentryObject();
585
+ const date = new Date();
586
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
587
+ Sentry &&
588
+ Sentry.withScope((scope) => {
589
+ scope.setLevel("info");
590
+ scope.setTag("Hour of event", date.getHours());
591
+ Sentry.captureMessage(`Catched error: ${stError.message}`, "info");
592
+ });
593
+ this.adapter.setState("LastSentryLoggedError", { val: stError.message, ack: true });
594
+ }
595
+ }
596
+ }
597
+ }
598
+ }
599
+ }
600
+ exports.TeslaFiAPICaller = TeslaFiAPICaller;
601
+ //# sourceMappingURL=teslafiAPICaller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"teslafiAPICaller.js","sourceRoot":"","sources":["../../src/lib/teslafiAPICaller.ts"],"names":[],"mappings":";;;;;;AACA,kDAA0C;AAC1C,mDAAgD;AAChD,6DAA6D;AAE7D,SAAS,oBAAoB,CAAC,CAAS;IACtC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC9B,UAAU,CAAC,GAAG,EAAE;YACf,OAAO,CAAC,CAAC,CAAC,CAAC;QACZ,CA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