iobroker.teslafi 3.0.0 → 3.0.2
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.
- package/README.md +16 -18
- package/build/lib/projectUtils.js +77 -120
- package/build/lib/projectUtils.js.map +1 -1
- package/build/lib/teslafiAPICaller.js +47 -206
- package/build/lib/teslafiAPICaller.js.map +1 -1
- package/build/main.js +1 -31
- package/build/main.js.map +1 -1
- package/io-package.json +27 -27
- package/package.json +16 -17
|
@@ -7,206 +7,166 @@ exports.TeslaFiAPICaller = void 0;
|
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const date_fns_1 = require("date-fns");
|
|
9
9
|
const projectUtils_1 = require("./projectUtils");
|
|
10
|
-
const axiosInstance = axios_1.default.create({
|
|
11
|
-
//timeout: 5000, //by default
|
|
12
|
-
});
|
|
13
|
-
// structure of vehicle data
|
|
10
|
+
const axiosInstance = axios_1.default.create({});
|
|
14
11
|
const stVD = {
|
|
15
|
-
Date: { key: `Date`, desc: `Last connection to your Tesla`, value:
|
|
16
|
-
// calendar_enabled: null, remote_start_enabled: "1"
|
|
12
|
+
Date: { key: `Date`, desc: `Last connection to your Tesla`, value: "" },
|
|
17
13
|
display_name: {
|
|
18
14
|
key: `display_name`,
|
|
19
15
|
desc: `Name of your Tesla`,
|
|
20
|
-
value:
|
|
16
|
+
value: "",
|
|
21
17
|
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// conn_charge_cable: "IEC", id: "NULL", charge_port_cold_weather_mode: "0", id_s: ""
|
|
25
|
-
state: { key: `state`, desc: `State of your Tesla`, value: null },
|
|
26
|
-
// option_codes: null, user_charge_enable_request: null
|
|
18
|
+
vin: { key: `vin`, desc: `VIN of your Tesla`, value: "" },
|
|
19
|
+
state: { key: `state`, desc: `State of your Tesla`, value: "" },
|
|
27
20
|
time_to_full_charge: {
|
|
28
21
|
key: `time_to_full_charge`,
|
|
29
22
|
desc: `Time to full charge`,
|
|
30
|
-
value:
|
|
23
|
+
value: "",
|
|
31
24
|
},
|
|
32
25
|
charge_current_request: {
|
|
33
26
|
key: `charge_current_request`,
|
|
34
27
|
desc: `requested charge current by your car`,
|
|
35
|
-
value:
|
|
28
|
+
value: "",
|
|
36
29
|
},
|
|
37
|
-
// charge_enable_request: "1", charge_to_max_range: ""
|
|
38
30
|
charger_phases: {
|
|
39
31
|
key: `charger_phases`,
|
|
40
32
|
desc: `current number of charge phases`,
|
|
41
|
-
value:
|
|
33
|
+
value: "",
|
|
42
34
|
},
|
|
43
|
-
// battery_heater_on: "0"
|
|
44
|
-
// managed_charging_start_time: { key: `managed_charging_start_time`, desc: `planned managed charging time`, value: null },
|
|
45
35
|
battery_range: {
|
|
46
36
|
key: `battery_range`,
|
|
47
37
|
desc: `current battery range`,
|
|
48
|
-
value:
|
|
38
|
+
value: "",
|
|
49
39
|
},
|
|
50
40
|
charger_power: {
|
|
51
41
|
key: `charger_power`,
|
|
52
42
|
desc: `current charge power`,
|
|
53
|
-
value:
|
|
43
|
+
value: "",
|
|
54
44
|
},
|
|
55
45
|
charge_limit_soc: {
|
|
56
46
|
key: `charge_limit_soc`,
|
|
57
47
|
desc: `charge limit defined in your Tesla`,
|
|
58
|
-
value:
|
|
48
|
+
value: "",
|
|
59
49
|
},
|
|
60
|
-
// charger_pilot_current: "16", charge_port_latch: "Engaged", battery_current: "", charger_actual_current: "0", scheduled_charging_pending: "0", fast_charger_type: ""
|
|
61
50
|
usable_battery_level: {
|
|
62
51
|
key: `usable_battery_level`,
|
|
63
52
|
desc: `usable battery SoC at this temperature conditions`,
|
|
64
|
-
value:
|
|
53
|
+
value: "",
|
|
65
54
|
},
|
|
66
|
-
// motorized_charge_port: null, charge_limit_soc_std: null, not_enough_power_to_heat: null
|
|
67
55
|
battery_level: {
|
|
68
56
|
key: `battery_level`,
|
|
69
57
|
desc: `battery SoC of your Tesla`,
|
|
70
|
-
value:
|
|
58
|
+
value: "",
|
|
71
59
|
},
|
|
72
|
-
// charge_energy_added: "0.0", charge_port_door_open: "1", max_range_charge_counter: null, charge_limit_soc_max: null, ideal_battery_range: "237.17"
|
|
73
|
-
// managed_charging_active: { key: `managed_charging_active`, desc: `managed charging planned`, value: null },
|
|
74
60
|
charging_state: {
|
|
75
61
|
key: `charging_state`,
|
|
76
62
|
desc: `charging state of the car`,
|
|
77
|
-
value:
|
|
63
|
+
value: "",
|
|
78
64
|
},
|
|
79
|
-
// fast_charger_present: "0", trip_charging: "1", managed_charging_user_canceled: null
|
|
80
65
|
scheduled_charging_start_time: {
|
|
81
66
|
key: `scheduled_charging_start_time`,
|
|
82
67
|
desc: `scheduled charging start time`,
|
|
83
|
-
value:
|
|
68
|
+
value: "",
|
|
84
69
|
},
|
|
85
70
|
est_battery_range: {
|
|
86
71
|
key: `est_battery_range`,
|
|
87
72
|
desc: `estimated battery range`,
|
|
88
|
-
value:
|
|
73
|
+
value: "",
|
|
89
74
|
},
|
|
90
|
-
// charge_rate: "0.0", charger_voltage: "1", charge_current_request_max: "16", eu_vehicle: "1", charge_miles_added_ideal: "0.0", charge_limit_soc_min: null, charge_miles_added_rated: "0.0"
|
|
91
75
|
inside_temp: {
|
|
92
76
|
key: `inside_temp`,
|
|
93
77
|
desc: `inside temperature in your Tesla`,
|
|
94
|
-
value:
|
|
78
|
+
value: "",
|
|
95
79
|
},
|
|
96
80
|
longitude: {
|
|
97
81
|
key: `longitude`,
|
|
98
82
|
desc: `current positional longitude of your Tesla`,
|
|
99
|
-
value:
|
|
83
|
+
value: "",
|
|
100
84
|
},
|
|
101
|
-
// heading: "", gps_as_of: null
|
|
102
85
|
latitude: {
|
|
103
86
|
key: `latitude`,
|
|
104
87
|
desc: `current positional latitude of your Tesla`,
|
|
105
|
-
value:
|
|
88
|
+
value: "",
|
|
106
89
|
},
|
|
107
|
-
speed: { key: `speed`, desc: `current driving speed`, value:
|
|
108
|
-
// shift_state: null
|
|
90
|
+
speed: { key: `speed`, desc: `current driving speed`, value: "" },
|
|
109
91
|
seat_heater_rear_right: {
|
|
110
92
|
key: `seat_heater_rear_right`,
|
|
111
93
|
desc: `level of the right second row seat heater`,
|
|
112
|
-
value:
|
|
94
|
+
value: "",
|
|
113
95
|
},
|
|
114
96
|
seat_heater_rear_left_back: {
|
|
115
97
|
key: `seat_heater_rear_left_back`,
|
|
116
98
|
desc: `level of the left third row seat heater`,
|
|
117
|
-
value:
|
|
99
|
+
value: "",
|
|
118
100
|
},
|
|
119
101
|
seat_heater_left: {
|
|
120
102
|
key: `seat_heater_left`,
|
|
121
103
|
desc: `level of the left first row seat heater`,
|
|
122
|
-
value:
|
|
104
|
+
value: "",
|
|
123
105
|
},
|
|
124
|
-
// passenger_temp_setting: "20.5", is_auto_conditioning_on: "0"
|
|
125
106
|
driver_temp_setting: {
|
|
126
107
|
key: `driver_temp_setting`,
|
|
127
108
|
desc: `inside temperature setting of your Tesla`,
|
|
128
|
-
value:
|
|
109
|
+
value: "",
|
|
129
110
|
},
|
|
130
111
|
outside_temp: {
|
|
131
112
|
key: `outside_temp`,
|
|
132
113
|
desc: `outside temperature near your Tesla`,
|
|
133
|
-
value:
|
|
114
|
+
value: "",
|
|
134
115
|
},
|
|
135
116
|
seat_heater_rear_center: {
|
|
136
117
|
key: `seat_heater_rear_center`,
|
|
137
118
|
desc: `level of the second row center seat heater`,
|
|
138
|
-
value:
|
|
119
|
+
value: "",
|
|
139
120
|
},
|
|
140
|
-
// is_rear_defroster_on: "0"
|
|
141
121
|
seat_heater_rear_right_back: {
|
|
142
122
|
key: `seat_heater_rear_right_back`,
|
|
143
123
|
desc: `level of the right third row seat heater`,
|
|
144
|
-
value:
|
|
124
|
+
value: "",
|
|
145
125
|
},
|
|
146
|
-
// smart_preconditioning: ""
|
|
147
126
|
seat_heater_right: {
|
|
148
127
|
key: `seat_heater_right`,
|
|
149
128
|
desc: `level of the right seat heater`,
|
|
150
|
-
value:
|
|
129
|
+
value: "",
|
|
151
130
|
},
|
|
152
|
-
// fan_status: "0", is_front_defroster_on: "0"
|
|
153
131
|
seat_heater_rear_left: {
|
|
154
132
|
key: `seat_heater_rear_left`,
|
|
155
133
|
desc: `level of the left second row seat heater`,
|
|
156
|
-
value:
|
|
134
|
+
value: "",
|
|
157
135
|
},
|
|
158
|
-
|
|
159
|
-
// rhd: "0", remote_start_supported: null, homelink_nearby: "0", parsed_calendar_supported: null, spoiler_type: null, ft: "0"
|
|
160
|
-
odometer: { key: `odometer`, desc: `current odometer level`, value: null },
|
|
161
|
-
// remote_start: null, pr: "0", climate_keeper_mode: "off", roof_color: null, perf_config: null, valet_mode: "0", calendar_supported: null, pf: "0", sun_roof_percent_open: null,
|
|
136
|
+
odometer: { key: `odometer`, desc: `current odometer level`, value: "" },
|
|
162
137
|
third_row_seats: {
|
|
163
138
|
key: `third_row_seats`,
|
|
164
139
|
desc: `third seating row present`,
|
|
165
|
-
value:
|
|
140
|
+
value: "",
|
|
166
141
|
},
|
|
167
|
-
// seat_type: null, api_version: null, rear_seat_heaters: null, rt: "0", exterior_color: null, df: "0", autopark_state: "NULL", sun_roof_state: null, notifications_supported: null, vehicle_name: null,
|
|
168
|
-
// dr: "0", autopark_style: null, car_type: null, wheel_type: "Apollo19MetallicShad", locked: "1", center_display_state: null, last_autopark_error: null
|
|
169
142
|
car_version: {
|
|
170
143
|
key: `car_version`,
|
|
171
144
|
desc: `Current software version`,
|
|
172
|
-
value:
|
|
145
|
+
value: "",
|
|
173
146
|
},
|
|
174
|
-
// defrost_mode: "0", autopark_state_v2: null, is_preconditioning: "0", inside_tempF: "60", driver_temp_settingF: "", outside_tempF: "57", battery_heater: "0", Notes: "", odometerF: "", idleNumber: 14780,
|
|
175
|
-
// sleepNumber: 0, driveNumber: 0, chargeNumber: 0, polling: "", idleTime: 1, maxRange: "314.14", left_temp_direction: null, max_avail_temp: null, is_climate_on: "0", right_temp_direction: null,
|
|
176
|
-
// min_avail_temp: null, is_user_present: "0", in_service: "0", valet_pin_needed: null, charge_port_led_color: null, timestamp: null, power: "0", side_mirror_heaters: "0", wiper_blade_heater: "0",
|
|
177
147
|
steering_wheel_heater: {
|
|
178
148
|
key: `steering_wheel_heater`,
|
|
179
149
|
desc: `level of the steering wheel heater`,
|
|
180
|
-
value:
|
|
150
|
+
value: "",
|
|
181
151
|
},
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
location: { key: `location`, desc: `Location of your Tesla`, value: null },
|
|
185
|
-
// rangeDisplay: "rated",
|
|
152
|
+
carState: { key: `carState`, desc: `Sleep-state of your Tesla`, value: "" },
|
|
153
|
+
location: { key: `location`, desc: `Location of your Tesla`, value: "" },
|
|
186
154
|
newVersion: {
|
|
187
155
|
key: `newVersion`,
|
|
188
156
|
desc: `Next software version if available`,
|
|
189
|
-
value:
|
|
157
|
+
value: "",
|
|
190
158
|
},
|
|
191
|
-
newVersionStatus: { key: `newVersionStatus`, desc: ``, value: `` },
|
|
192
|
-
// allow_cabin_overheat_protection: "1", cabin_overheat_protection: "FanOnly", cabin_overheat_protection_actively_cooling: "", cop_activation_temperature: null, pressure: null,
|
|
193
|
-
// tpms_front_left: "41.7", tpms_front_right: "41.0", tpms_rear_left: "41.7", tpms_rear_right: "41.0"
|
|
159
|
+
newVersionStatus: { key: `newVersionStatus`, desc: ``, value: `` },
|
|
194
160
|
};
|
|
195
|
-
// structure of vehicle commands
|
|
196
161
|
const stVCom = {
|
|
197
162
|
auto_conditioning_start: { key: `Start-HVAC`, desc: `Start HVAC of your Tesla`, command: `auto_conditioning_start` },
|
|
198
163
|
auto_conditioning_stop: { key: `Stop-HVAC`, desc: `Stop HVAC of your Tesla`, command: `auto_conditioning_stop` },
|
|
199
164
|
set_HVAC_temp: { key: `Set-Temp`, desc: `Set Temp for HVAC`, command: `set_temps&temp` },
|
|
200
|
-
// `set_temps&temp=XX` - temp is entered in your default TeslaFi measurement Celcius and can include one decimal point
|
|
201
|
-
// WiP NEW:
|
|
202
165
|
set_seat_heat_left: {
|
|
203
166
|
key: `Set-Seat-Heater-Left`,
|
|
204
167
|
desc: `Set left seat heater level`,
|
|
205
168
|
command: `seat_heater&heater=0&level`,
|
|
206
169
|
},
|
|
207
|
-
// `seat_heater&heater=X&level=X`
|
|
208
|
-
// Heater: 0-Driver, 1-Passenger, 2-Rear Left, 4-Rear Center, 5-Rear Right - Level: 0-3 (0 is off)
|
|
209
|
-
// Conditioning must be on before sending.
|
|
210
170
|
set_seat_heat_right: {
|
|
211
171
|
key: `Set-Seat-Heater-Right`,
|
|
212
172
|
desc: `Set right seat heater level`,
|
|
@@ -230,9 +190,7 @@ const stVCom = {
|
|
|
230
190
|
start_charging: { key: `Start-Charging`, desc: `Start charging your Tesla`, command: `charge_start` },
|
|
231
191
|
stop_charging: { key: `Stop-Charging`, desc: `Stop charging your Tesla`, command: `charge_stop` },
|
|
232
192
|
set_charge_limit: { key: `Set-Charge-Limit`, desc: `set charging SoC limit`, command: `set_charge_limit&charge_limit_soc` },
|
|
233
|
-
// `set_charge_limit&charge_limit_soc=XX`
|
|
234
193
|
set_charge_amps: { key: `Set-Charge-Amps`, desc: `set charging ampere limit`, command: `set_charging_amps&charging_amps` },
|
|
235
|
-
// `set_charging_amps&charging_amps=XX`
|
|
236
194
|
};
|
|
237
195
|
function convertUnixToLocalTime(unixTimestamp, dateFormat = "dd.MM.yyyy HH:mm:ss") {
|
|
238
196
|
const date = (0, date_fns_1.fromUnixTime)(unixTimestamp);
|
|
@@ -243,23 +201,12 @@ function calculateEndTimeFromNow(hours, dateFormat = "dd.MM.yyyy HH:mm:ss") {
|
|
|
243
201
|
const endTime = (0, date_fns_1.add)(new Date(), { seconds: totalSeconds });
|
|
244
202
|
return (0, date_fns_1.format)(endTime, dateFormat);
|
|
245
203
|
}
|
|
246
|
-
/**
|
|
247
|
-
* TeslaFiAPICaller
|
|
248
|
-
*/
|
|
249
204
|
class TeslaFiAPICaller extends projectUtils_1.ProjectUtils {
|
|
250
205
|
queryUrl = "";
|
|
251
|
-
/**
|
|
252
|
-
* constructor
|
|
253
|
-
*
|
|
254
|
-
* @param adapter - ioBroker adapter instance
|
|
255
|
-
*/
|
|
256
206
|
constructor(adapter) {
|
|
257
207
|
super(adapter);
|
|
258
208
|
this.queryUrl = "https://www.teslafi.com/feed.php?token=";
|
|
259
209
|
}
|
|
260
|
-
/**
|
|
261
|
-
* SetupCommandStates
|
|
262
|
-
*/
|
|
263
210
|
SetupCommandStates() {
|
|
264
211
|
if (this.adapter.config.UseCarCommands) {
|
|
265
212
|
void this.checkAndSetValueNumber(`commands.command_counter`, 0, `Used commands counter`, "", `value`, false, true);
|
|
@@ -267,21 +214,6 @@ class TeslaFiAPICaller extends projectUtils_1.ProjectUtils {
|
|
|
267
214
|
void this.checkAndSetValueNumber(`commands.${stVCom.set_seat_heat_left.key}`, 0, stVCom.set_seat_heat_left.desc, "", `level.temperature`, true, true, false, 0, 3, 1);
|
|
268
215
|
void this.checkAndSetValueNumber(`commands.${stVCom.set_seat_heat_right.key}`, 0, stVCom.set_seat_heat_right.desc, "", `level.temperature`, true, true, false, 0, 3, 1);
|
|
269
216
|
void this.checkAndSetValueNumber(`commands.${stVCom.set_seat_heat_rear_left.key}`, 0, stVCom.set_seat_heat_rear_left.desc, "", `level.temperature`, true, true, false, 0, 3, 1);
|
|
270
|
-
/*
|
|
271
|
-
void this.checkAndSetValueNumber(
|
|
272
|
-
`commands.${stVCom.set_seat_heat_rear_center.key}`,
|
|
273
|
-
0,
|
|
274
|
-
stVCom.set_seat_heat_rear_center.desc,
|
|
275
|
-
"",
|
|
276
|
-
`level.temperature`,
|
|
277
|
-
true,
|
|
278
|
-
true,
|
|
279
|
-
false,
|
|
280
|
-
0,
|
|
281
|
-
3,
|
|
282
|
-
1,
|
|
283
|
-
);
|
|
284
|
-
*/
|
|
285
217
|
void this.checkAndSetValueNumber(`commands.${stVCom.set_seat_heat_rear_right.key}`, 0, stVCom.set_seat_heat_rear_right.desc, "", `level.temperature`, true, true, false, 0, 3, 1);
|
|
286
218
|
void this.checkAndSetValueBoolean(`commands.${stVCom.auto_conditioning_start.key}`, false, stVCom.auto_conditioning_start.desc, `button.start`, true);
|
|
287
219
|
void this.checkAndSetValueBoolean(`commands.${stVCom.auto_conditioning_stop.key}`, false, stVCom.auto_conditioning_stop.desc, `button.start`, true);
|
|
@@ -293,19 +225,7 @@ class TeslaFiAPICaller extends projectUtils_1.ProjectUtils {
|
|
|
293
225
|
this.adapter.subscribeStates(`commands.*`);
|
|
294
226
|
}
|
|
295
227
|
}
|
|
296
|
-
/**
|
|
297
|
-
* HandleCarCommand
|
|
298
|
-
*
|
|
299
|
-
* @param command - command to be send to TeslaFi
|
|
300
|
-
* @param value - optional number value for command
|
|
301
|
-
*/
|
|
302
228
|
async HandleCarCommand(command, value) {
|
|
303
|
-
// Usage Details
|
|
304
|
-
// If the vehicle is awake: The command will be sent, and one usage will be deducted from your command count.
|
|
305
|
-
// If the vehicle is asleep: TeslaFi will send a wake command and pause for 15 seconds before sending the command.
|
|
306
|
-
// One usage will be deducted from both the command count and the wake count.
|
|
307
|
-
// The pause duration can be customized by adding &wake=X to the command, where X specifies the number
|
|
308
|
-
// of seconds to pause (up to 60 seconds).
|
|
309
229
|
this.adapter.log.info(`TeslaFI adapter got command ${command} and sends this to the vehicle`);
|
|
310
230
|
let clampedValue;
|
|
311
231
|
switch (command) {
|
|
@@ -318,27 +238,27 @@ class TeslaFiAPICaller extends projectUtils_1.ProjectUtils {
|
|
|
318
238
|
void this.adapter.setState(`commands.${stVCom.auto_conditioning_stop.key}`, false, true);
|
|
319
239
|
break;
|
|
320
240
|
case stVCom.set_HVAC_temp.key:
|
|
321
|
-
clampedValue = Math.min(28, Math.max(15, value));
|
|
241
|
+
clampedValue = Math.min(28, Math.max(15, Number(value)));
|
|
322
242
|
await this.ReadTeslaFi(`${stVCom.set_HVAC_temp.command}=${clampedValue ?? 20}`);
|
|
323
243
|
break;
|
|
324
244
|
case stVCom.set_seat_heat_left.key:
|
|
325
|
-
clampedValue = Math.min(3, Math.max(0, Math.round(value)));
|
|
245
|
+
clampedValue = Math.min(3, Math.max(0, Math.round(Number(value))));
|
|
326
246
|
await this.ReadTeslaFi(`${stVCom.set_seat_heat_left.command}=${clampedValue ?? 0}`);
|
|
327
247
|
break;
|
|
328
248
|
case stVCom.set_seat_heat_right.key:
|
|
329
|
-
clampedValue = Math.min(3, Math.max(0, Math.round(value)));
|
|
249
|
+
clampedValue = Math.min(3, Math.max(0, Math.round(Number(value))));
|
|
330
250
|
await this.ReadTeslaFi(`${stVCom.set_seat_heat_right.command}=${clampedValue ?? 0}`);
|
|
331
251
|
break;
|
|
332
252
|
case stVCom.set_seat_heat_rear_left.key:
|
|
333
|
-
clampedValue = Math.min(3, Math.max(0, Math.round(value)));
|
|
253
|
+
clampedValue = Math.min(3, Math.max(0, Math.round(Number(value))));
|
|
334
254
|
await this.ReadTeslaFi(`${stVCom.set_seat_heat_rear_left.command}=${clampedValue ?? 0}`);
|
|
335
255
|
break;
|
|
336
256
|
case stVCom.set_seat_heat_rear_center.key:
|
|
337
|
-
clampedValue = Math.min(3, Math.max(0, Math.round(value)));
|
|
257
|
+
clampedValue = Math.min(3, Math.max(0, Math.round(Number(value))));
|
|
338
258
|
await this.ReadTeslaFi(`${stVCom.set_seat_heat_rear_center.command}=${clampedValue ?? 0}`);
|
|
339
259
|
break;
|
|
340
260
|
case stVCom.set_seat_heat_rear_right.key:
|
|
341
|
-
clampedValue = Math.min(3, Math.max(0, Math.round(value)));
|
|
261
|
+
clampedValue = Math.min(3, Math.max(0, Math.round(Number(value))));
|
|
342
262
|
await this.ReadTeslaFi(`${stVCom.set_seat_heat_rear_right.command}=${clampedValue ?? 0}`);
|
|
343
263
|
break;
|
|
344
264
|
case stVCom.start_charging.key:
|
|
@@ -348,59 +268,37 @@ class TeslaFiAPICaller extends projectUtils_1.ProjectUtils {
|
|
|
348
268
|
await this.ReadTeslaFi(stVCom.stop_charging.command);
|
|
349
269
|
break;
|
|
350
270
|
case stVCom.set_charge_limit.key:
|
|
351
|
-
clampedValue = Math.min(100, Math.max(50, Math.round(value)));
|
|
271
|
+
clampedValue = Math.min(100, Math.max(50, Math.round(Number(value))));
|
|
352
272
|
await this.ReadTeslaFi(`${stVCom.set_charge_limit.command}=${clampedValue ?? 80}`);
|
|
353
273
|
break;
|
|
354
274
|
case stVCom.set_charge_amps.key:
|
|
355
|
-
clampedValue = Math.min(32, Math.max(5, Math.round(value)));
|
|
275
|
+
clampedValue = Math.min(32, Math.max(5, Math.round(Number(value))));
|
|
356
276
|
await this.ReadTeslaFi(`${stVCom.set_charge_amps.command}=${clampedValue ?? 10}`);
|
|
357
277
|
break;
|
|
358
278
|
default:
|
|
359
279
|
}
|
|
360
280
|
}
|
|
361
|
-
/**
|
|
362
|
-
* ReadTeslaFi
|
|
363
|
-
*
|
|
364
|
-
* @param command - optional command to be send to TeslaFi - default ""
|
|
365
|
-
*/
|
|
366
281
|
async ReadTeslaFi(command = "") {
|
|
367
282
|
try {
|
|
368
283
|
const getString = `${this.queryUrl}${this.adapter.config.TeslaFiAPIToken}&command=${command}`;
|
|
369
284
|
this.adapter.log.debug(`sending command/request to TeslaFi: ${getString}`);
|
|
370
285
|
const response = await axiosInstance.get(getString, {
|
|
371
286
|
transformResponse: r => r,
|
|
372
|
-
timeout: this.adapter.config.UpdateTimeout,
|
|
287
|
+
timeout: this.adapter.config.UpdateTimeout,
|
|
373
288
|
});
|
|
374
289
|
if (!response.data) {
|
|
375
290
|
throw new Error(`Empty answer from TeslaFi.`);
|
|
376
291
|
}
|
|
377
292
|
const result = JSON.parse(response.data);
|
|
378
|
-
// debug
|
|
379
|
-
// this.adapter.log.debug(`TeslaFi full response: ${JSON.stringify(result, null, 2)}`);
|
|
380
|
-
// verify authorized access
|
|
381
293
|
if (result.response?.result === "unauthorized") {
|
|
382
294
|
this.adapter.log.warn(`TeslaFI data read - unauthorized access detected - please verify your API Token`);
|
|
383
295
|
return false;
|
|
384
296
|
}
|
|
385
|
-
//#region *** "commands" properties ***
|
|
386
|
-
/* Response in case of sent command
|
|
387
|
-
{
|
|
388
|
-
"response": {
|
|
389
|
-
"result": true,
|
|
390
|
-
"reason": ""
|
|
391
|
-
},
|
|
392
|
-
"tesla_request_counter": {
|
|
393
|
-
"commands": 8,
|
|
394
|
-
"wakes": 3
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
*/
|
|
398
297
|
if (result.response?.result === true) {
|
|
399
298
|
this.adapter.log.debug(`TeslaFI command received with response TRUE`);
|
|
400
299
|
}
|
|
401
300
|
if (result.tesla_request_counter && typeof result.tesla_request_counter === "object") {
|
|
402
301
|
if (result.tesla_request_counter.commands != null) {
|
|
403
|
-
// await this.adapter.setState(`commands.command_counter`, { val: result.tesla_request_counter.commands, ack: true });
|
|
404
302
|
void this.checkAndSetValueNumber(`commands.command_counter`, result.tesla_request_counter.commands, `Used commands counter`, "", `value`, false);
|
|
405
303
|
}
|
|
406
304
|
if (result.tesla_request_counter.wakes != null) {
|
|
@@ -408,139 +306,104 @@ class TeslaFiAPICaller extends projectUtils_1.ProjectUtils {
|
|
|
408
306
|
}
|
|
409
307
|
}
|
|
410
308
|
else {
|
|
411
|
-
// debug
|
|
412
|
-
// this.adapter.log.debug(`tesla_request_counter is missing or not an object`);
|
|
413
|
-
// debug
|
|
414
309
|
}
|
|
415
|
-
//#endregion
|
|
416
|
-
// save raw JSON
|
|
417
310
|
void this.checkAndSetValue(`vehicle-data.rawJSON`, response.data, `JSON raw data from TeslaFi`, `json`);
|
|
418
|
-
// fill values into predefined structur
|
|
419
311
|
for (const [key, value] of Object.entries(result)) {
|
|
420
312
|
if (key in stVD) {
|
|
421
|
-
stVD[key].value = value;
|
|
313
|
+
stVD[key].value = value;
|
|
422
314
|
}
|
|
423
315
|
}
|
|
424
|
-
// now process property structure
|
|
425
|
-
//#region *** "vehicle-data" properties ***
|
|
426
316
|
if (stVD.Date.value !== null) {
|
|
427
|
-
//"2024-10-25 20:43:33"
|
|
428
317
|
void this.checkAndSetValue(`vehicle-data.${stVD.Date.key}`, stVD.Date.value, stVD.Date.desc, `date`);
|
|
429
318
|
}
|
|
430
319
|
if (stVD.vin.value !== null) {
|
|
431
|
-
//"LRWYGCEKXNC44xxxx"
|
|
432
320
|
void this.checkAndSetValue(`vehicle-data.${stVD.vin.key}`, stVD.vin.value, stVD.vin.desc);
|
|
433
321
|
}
|
|
434
322
|
if (stVD.display_name.value !== null) {
|
|
435
|
-
//"Red Elephant"
|
|
436
323
|
void this.checkAndSetValue(`vehicle-data.${stVD.display_name.key}`, stVD.display_name.value, stVD.display_name.desc);
|
|
437
324
|
}
|
|
438
|
-
//#endregion
|
|
439
|
-
//#region *** "vehicle-state" properties ***
|
|
440
325
|
if (stVD.carState.value !== null) {
|
|
441
|
-
//"Idling"
|
|
442
326
|
void this.checkAndSetValue(`vehicle-state.${stVD.carState.key}`, stVD.carState.value, stVD.carState.desc);
|
|
443
327
|
}
|
|
444
328
|
if (stVD.state.value !== null) {
|
|
445
|
-
//"online"
|
|
446
329
|
void this.checkAndSetValue(`vehicle-state.${stVD.state.key}`, stVD.state.value, stVD.state.desc);
|
|
447
330
|
}
|
|
448
331
|
if (stVD.charging_state.value !== null) {
|
|
449
|
-
//"NoPower", "Charging", null
|
|
450
332
|
void this.checkAndSetValue(`vehicle-state.${stVD.charging_state.key}`, stVD.charging_state.value, stVD.charging_state.desc);
|
|
451
333
|
}
|
|
452
334
|
else {
|
|
453
335
|
void this.checkAndSetValue(`vehicle-state.${stVD.charging_state.key}`, "---", stVD.charging_state.desc);
|
|
454
336
|
}
|
|
455
337
|
if (stVD.car_version.value !== null) {
|
|
456
|
-
//"2024.32.7 3f0d0fff88"
|
|
457
338
|
void this.checkAndSetValue(`vehicle-state.${stVD.car_version.key}`, stVD.car_version.value, stVD.car_version.desc);
|
|
458
339
|
}
|
|
459
340
|
if (stVD.newVersion.value && stVD.newVersion.value.trim() !== "") {
|
|
460
|
-
//" "
|
|
461
341
|
void this.checkAndSetValue(`vehicle-state.${stVD.newVersion.key}`, stVD.newVersion.value, stVD.newVersion.desc);
|
|
462
342
|
}
|
|
463
343
|
else {
|
|
464
344
|
void this.checkAndSetValue(`vehicle-state.${stVD.newVersion.key}`, "---", stVD.newVersion.desc);
|
|
465
345
|
}
|
|
466
346
|
if (stVD.newVersionStatus.value && stVD.newVersionStatus.value.trim() !== "") {
|
|
467
|
-
//"installing"
|
|
468
347
|
void this.checkAndSetValue(`vehicle-state.${stVD.newVersionStatus.key}`, stVD.newVersionStatus.value, stVD.newVersionStatus.desc);
|
|
469
348
|
}
|
|
470
349
|
else {
|
|
471
350
|
void this.checkAndSetValue(`vehicle-state.${stVD.newVersionStatus.key}`, "---", stVD.newVersionStatus.desc);
|
|
472
351
|
}
|
|
473
352
|
if (stVD.location.value !== null) {
|
|
474
|
-
//"Home"
|
|
475
353
|
void this.checkAndSetValue(`vehicle-state.${stVD.location.key}`, stVD.location.value, stVD.location.desc);
|
|
476
354
|
}
|
|
477
355
|
if (stVD.longitude.value !== null) {
|
|
478
|
-
//"9.899749"
|
|
479
356
|
void this.checkAndSetValue(`vehicle-state.${stVD.longitude.key}`, stVD.longitude.value, stVD.longitude.desc, `value.gps.longitude`);
|
|
480
357
|
}
|
|
481
358
|
if (stVD.latitude.value !== null) {
|
|
482
|
-
//"49.873095"
|
|
483
359
|
void this.checkAndSetValue(`vehicle-state.${stVD.latitude.key}`, stVD.latitude.value, stVD.latitude.desc, `value.gps.latitude`);
|
|
484
360
|
}
|
|
485
361
|
if (stVD.odometer.value !== null) {
|
|
486
|
-
//"16434.079511"
|
|
487
362
|
void this.checkAndSetValueNumber(`vehicle-state.${stVD.odometer.key}`, Math.round(parseFloat(stVD.odometer.value) * 100) / 100, stVD.odometer.desc, "mi");
|
|
488
363
|
void this.checkAndSetValueNumber(`vehicle-state.${stVD.odometer.key}_km`, Math.round(parseFloat(stVD.odometer.value) * 160.934) / 100, stVD.odometer.desc, "km");
|
|
489
364
|
}
|
|
490
365
|
if (stVD.speed.value !== null) {
|
|
491
|
-
//"28"
|
|
492
366
|
void this.checkAndSetValueNumber(`vehicle-state.${stVD.speed.key}`, Math.round(parseFloat(stVD.speed.value) * 100) / 100, stVD.speed.desc, "km/h");
|
|
493
367
|
}
|
|
494
368
|
else {
|
|
495
369
|
void this.checkAndSetValueNumber(`vehicle-state.${stVD.speed.key}`, 0, stVD.speed.desc, "km/h");
|
|
496
370
|
}
|
|
497
|
-
//#endregion
|
|
498
|
-
//#region *** "battery-state" properties ***
|
|
499
371
|
if (stVD.battery_level.value !== null) {
|
|
500
|
-
//"76"
|
|
501
372
|
void this.checkAndSetValueNumber(`battery-state.${stVD.battery_level.key}`, parseFloat(stVD.battery_level.value), stVD.battery_level.desc, "%", `value.battery`);
|
|
502
373
|
}
|
|
503
374
|
if (stVD.usable_battery_level.value !== null) {
|
|
504
|
-
//"75"
|
|
505
375
|
void this.checkAndSetValueNumber(`battery-state.${stVD.usable_battery_level.key}`, parseFloat(stVD.usable_battery_level.value), stVD.usable_battery_level.desc, "%", `value.battery`);
|
|
506
376
|
}
|
|
507
377
|
if (stVD.battery_range.value !== null) {
|
|
508
|
-
//"237.17"
|
|
509
378
|
void this.checkAndSetValueNumber(`battery-state.${stVD.battery_range.key}`, parseFloat(stVD.battery_range.value), stVD.battery_range.desc, "mi");
|
|
510
379
|
void this.checkAndSetValueNumber(`battery-state.${stVD.battery_range.key}_km`, Math.round(parseFloat(stVD.battery_range.value) * 160.934) / 100, stVD.battery_range.desc, "km");
|
|
511
380
|
}
|
|
512
381
|
if (stVD.est_battery_range.value !== null) {
|
|
513
|
-
//"208.25"
|
|
514
382
|
void this.checkAndSetValueNumber(`battery-state.${stVD.est_battery_range.key}`, parseFloat(stVD.est_battery_range.value), stVD.est_battery_range.desc, "mi");
|
|
515
383
|
void this.checkAndSetValueNumber(`battery-state.${stVD.est_battery_range.key}_km`, Math.round(parseFloat(stVD.est_battery_range.value) * 160.934) / 100, stVD.est_battery_range.desc, "km");
|
|
516
384
|
}
|
|
517
385
|
if (stVD.charge_current_request.value !== null) {
|
|
518
|
-
//"16"
|
|
519
386
|
void this.checkAndSetValueNumber(`battery-state.${stVD.charge_current_request.key}`, parseFloat(stVD.charge_current_request.value), stVD.charge_current_request.desc, "A", `value.current`);
|
|
520
387
|
}
|
|
521
388
|
else {
|
|
522
389
|
void this.checkAndSetValueNumber(`battery-state.${stVD.charge_current_request.key}`, 0, stVD.charge_current_request.desc, "A", `value.current`);
|
|
523
390
|
}
|
|
524
391
|
if (stVD.charge_limit_soc.value !== null) {
|
|
525
|
-
//"80"
|
|
526
392
|
void this.checkAndSetValueNumber(`battery-state.${stVD.charge_limit_soc.key}`, parseFloat(stVD.charge_limit_soc.value), stVD.charge_limit_soc.desc, "%", `value.battery`);
|
|
527
393
|
}
|
|
528
394
|
if (stVD.charger_phases.value !== null) {
|
|
529
|
-
//"3"
|
|
530
395
|
void this.checkAndSetValueNumber(`battery-state.${stVD.charger_phases.key}`, parseFloat(stVD.charger_phases.value), stVD.charger_phases.desc);
|
|
531
396
|
}
|
|
532
397
|
else {
|
|
533
398
|
void this.checkAndSetValueNumber(`battery-state.${stVD.charger_phases.key}`, 0, stVD.charger_phases.desc);
|
|
534
399
|
}
|
|
535
400
|
if (stVD.charger_power.value !== null) {
|
|
536
|
-
//"0"
|
|
537
401
|
void this.checkAndSetValueNumber(`battery-state.${stVD.charger_power.key}`, parseFloat(stVD.charger_power.value), stVD.charger_power.desc, "kW", `value.power`);
|
|
538
402
|
}
|
|
539
403
|
else {
|
|
540
404
|
void this.checkAndSetValueNumber(`battery-state.${stVD.charger_power.key}`, 0, stVD.charger_power.desc, "kW", `value.power`);
|
|
541
405
|
}
|
|
542
406
|
if (stVD.time_to_full_charge.value !== null) {
|
|
543
|
-
//"0.0"
|
|
544
407
|
void this.checkAndSetValueNumber(`battery-state.${stVD.time_to_full_charge.key}`, parseFloat(stVD.time_to_full_charge.value), stVD.time_to_full_charge.desc, "h");
|
|
545
408
|
if (parseFloat(stVD.time_to_full_charge.value) != 0) {
|
|
546
409
|
void this.checkAndSetValue(`battery-state.time_to_finish_charge`, calculateEndTimeFromNow(parseFloat(stVD.time_to_full_charge.value)), stVD.time_to_full_charge.desc);
|
|
@@ -554,7 +417,6 @@ class TeslaFiAPICaller extends projectUtils_1.ProjectUtils {
|
|
|
554
417
|
void this.checkAndSetValue(`battery-state.time_to_finish_charge`, `---`, stVD.time_to_full_charge.desc);
|
|
555
418
|
}
|
|
556
419
|
if (stVD.scheduled_charging_start_time.value !== null && stVD.scheduled_charging_start_time.value !== "") {
|
|
557
|
-
// ""; "1731031200"; "1731193200",
|
|
558
420
|
void this.checkAndSetValue(`battery-state.${stVD.scheduled_charging_start_time.key}`, convertUnixToLocalTime(parseFloat(stVD.scheduled_charging_start_time.value)), stVD.scheduled_charging_start_time.desc);
|
|
559
421
|
}
|
|
560
422
|
else {
|
|
@@ -562,55 +424,41 @@ class TeslaFiAPICaller extends projectUtils_1.ProjectUtils {
|
|
|
562
424
|
void this.checkAndSetValue(`battery-state.${stVD.scheduled_charging_start_time.key}`, `---`, stVD.scheduled_charging_start_time.desc);
|
|
563
425
|
}
|
|
564
426
|
}
|
|
565
|
-
//#endregion
|
|
566
|
-
//#region *** "thermal-state" properties ***
|
|
567
427
|
if (stVD.inside_temp.value !== null) {
|
|
568
|
-
//"15.8"
|
|
569
428
|
void this.checkAndSetValueNumber(`thermal-state.${stVD.inside_temp.key}`, parseFloat(stVD.inside_temp.value), stVD.inside_temp.desc, "°C", `value.temperature`);
|
|
570
429
|
}
|
|
571
430
|
if (stVD.outside_temp.value !== null) {
|
|
572
|
-
//"14.0"
|
|
573
431
|
void this.checkAndSetValueNumber(`thermal-state.${stVD.outside_temp.key}`, parseFloat(stVD.outside_temp.value), stVD.outside_temp.desc, "°C", `value.temperature`);
|
|
574
432
|
}
|
|
575
433
|
if (stVD.driver_temp_setting.value !== null) {
|
|
576
|
-
//"20.5"
|
|
577
434
|
void this.checkAndSetValueNumber(`thermal-state.${stVD.driver_temp_setting.key}`, parseFloat(stVD.driver_temp_setting.value), stVD.driver_temp_setting.desc, "°C", `value.temperature`);
|
|
578
435
|
}
|
|
579
436
|
if (stVD.seat_heater_left.value !== null) {
|
|
580
|
-
//"2"
|
|
581
437
|
void this.checkAndSetValueNumber(`thermal-state.${stVD.seat_heater_left.key}`, parseFloat(stVD.seat_heater_left.value), stVD.seat_heater_left.desc);
|
|
582
438
|
}
|
|
583
439
|
if (stVD.seat_heater_right.value !== null) {
|
|
584
|
-
//"0"
|
|
585
440
|
void this.checkAndSetValueNumber(`thermal-state.${stVD.seat_heater_right.key}`, parseFloat(stVD.seat_heater_right.value), stVD.seat_heater_right.desc);
|
|
586
441
|
}
|
|
587
442
|
if (stVD.seat_heater_rear_left.value !== null) {
|
|
588
|
-
//"2"
|
|
589
443
|
void this.checkAndSetValueNumber(`thermal-state.${stVD.seat_heater_rear_left.key}`, parseFloat(stVD.seat_heater_rear_left.value), stVD.seat_heater_rear_left.desc);
|
|
590
444
|
}
|
|
591
445
|
if (stVD.seat_heater_rear_center.value !== null) {
|
|
592
|
-
//"0"
|
|
593
446
|
void this.checkAndSetValueNumber(`thermal-state.${stVD.seat_heater_rear_center.key}`, parseFloat(stVD.seat_heater_rear_center.value), stVD.seat_heater_rear_center.desc);
|
|
594
447
|
}
|
|
595
448
|
if (stVD.seat_heater_rear_right.value !== null) {
|
|
596
|
-
//"3"
|
|
597
449
|
void this.checkAndSetValueNumber(`thermal-state.${stVD.seat_heater_rear_right.key}`, parseFloat(stVD.seat_heater_rear_right.value), stVD.seat_heater_rear_right.desc);
|
|
598
450
|
}
|
|
599
451
|
if (stVD.third_row_seats.value !== null) {
|
|
600
452
|
if (stVD.seat_heater_rear_left_back.value !== null) {
|
|
601
|
-
//"3"
|
|
602
453
|
void this.checkAndSetValueNumber(`thermal-state.${stVD.seat_heater_rear_left_back.key}`, parseFloat(stVD.seat_heater_rear_left_back.value), stVD.seat_heater_rear_left_back.desc);
|
|
603
454
|
}
|
|
604
455
|
if (stVD.seat_heater_rear_right_back.value !== null) {
|
|
605
|
-
//"2"
|
|
606
456
|
void this.checkAndSetValueNumber(`thermal-state.${stVD.seat_heater_rear_right_back.key}`, parseFloat(stVD.seat_heater_rear_right_back.value), stVD.seat_heater_rear_right_back.desc);
|
|
607
457
|
}
|
|
608
458
|
}
|
|
609
459
|
if (stVD.steering_wheel_heater.value !== null) {
|
|
610
|
-
//"0"
|
|
611
460
|
void this.checkAndSetValueNumber(`thermal-state.${stVD.steering_wheel_heater.key}`, parseFloat(stVD.steering_wheel_heater.value), stVD.steering_wheel_heater.desc);
|
|
612
461
|
}
|
|
613
|
-
//#endregion
|
|
614
462
|
return true;
|
|
615
463
|
}
|
|
616
464
|
catch (error) {
|
|
@@ -618,13 +466,10 @@ class TeslaFiAPICaller extends projectUtils_1.ProjectUtils {
|
|
|
618
466
|
return false;
|
|
619
467
|
}
|
|
620
468
|
}
|
|
621
|
-
/*****************************************************************************************/
|
|
622
469
|
async HandleConnectionError(stError, sOccasion, sErrorOccInt) {
|
|
623
470
|
if (stError.response) {
|
|
624
|
-
//get HTTP error code
|
|
625
471
|
switch (stError.response.status) {
|
|
626
472
|
case 401:
|
|
627
|
-
//this.SendSentryError(stError.Message);
|
|
628
473
|
this.adapter.log.error(`The TeslaFi API request has not been completed because it lacks valid authentication credentials.`);
|
|
629
474
|
this.adapter.log.error(`HTTP error 401 when calling ${sOccasion}!! (e${sErrorOccInt}.0)`);
|
|
630
475
|
this.adapter.log.error(`Adapter is shutting down`);
|
|
@@ -635,7 +480,6 @@ class TeslaFiAPICaller extends projectUtils_1.ProjectUtils {
|
|
|
635
480
|
}
|
|
636
481
|
}
|
|
637
482
|
else if (stError.code) {
|
|
638
|
-
//get error code
|
|
639
483
|
switch (stError.code) {
|
|
640
484
|
case "ETIMEDOUT":
|
|
641
485
|
this.adapter.log.warn(`Connection timeout error when calling ${sOccasion}`);
|
|
@@ -650,18 +494,15 @@ class TeslaFiAPICaller extends projectUtils_1.ProjectUtils {
|
|
|
650
494
|
this.adapter.log.warn(`Please verify your network environment, (e${sErrorOccInt}.2)`);
|
|
651
495
|
break;
|
|
652
496
|
}
|
|
653
|
-
// errors: 'Unexpected end of JSON input' 'read ECONNRESET' 'connect ECONNREFUSED 192.168.0.1:80'
|
|
654
497
|
}
|
|
655
498
|
else {
|
|
656
499
|
this.adapter.log.error(`Unknown error when calling ${sOccasion}: ${stError.message}`);
|
|
657
500
|
this.adapter.log.error(`Please verify the API Token or adapt your poll interval, (e${sErrorOccInt}.3)`);
|
|
658
501
|
if (this.adapter.supportsFeature && this.adapter.supportsFeature("PLUGINS")) {
|
|
659
|
-
// send Sentry error
|
|
660
502
|
const sentryInstance = this.adapter.getPluginInstance("sentry");
|
|
661
503
|
if (sentryInstance) {
|
|
662
504
|
const oldError = await this.adapter.getStateAsync("LastSentryLoggedError");
|
|
663
505
|
if (oldError?.val != stError.message) {
|
|
664
|
-
// if new error
|
|
665
506
|
const Sentry = sentryInstance.getSentryObject();
|
|
666
507
|
const date = new Date();
|
|
667
508
|
Sentry &&
|