Skip to content

Commit

Permalink
Saved state on boot
Browse files Browse the repository at this point in the history
Updated Screen Cap
Added Estimated Battery Range
Updated English, Spanish, and German translations
Packaged content
  • Loading branch information
f00d4tehg0dz committed May 18, 2024
1 parent 8777f01 commit ea3384e
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Please report any issues you see on the project's Github page. I welcome any fee

## Features

- **Customizable Display:** Choose which 5 fields to display on the Stream Deck from options including Car Name, Inside Temp, Battery Range, Charging State, Outside Temp, and Odometer.
- **Customizable Display:** Choose which 5 fields to display on the Stream Deck from options including Car Name, Inside Temp, Battery Range, Charging State, Outside Temp, Odometer, and Estimated Range.
- **Real-Time Updates:** Automatically refresh data every 20 minutes to keep your display current.
- **Unit Conversions:** Select temperature unit (Fahrenheit/Celsius) and distance unit (Miles/Kilometers) based on your preference.
- **Error Handling:** Displays an API limit error message when the majority of values return as `N/A`, indicating the need to wait for 5 minutes to clear the limit.
Expand All @@ -39,6 +39,7 @@ Make sure you have an active subscription with [TeslaFi](https://teslafi.com) an
4. **Charging State:** Display the current charging state.
5. **Outside Temp:** Display the current outside temperature.
6. **Odometer:** Display the current odometer.
7. **Estimated Range:** Display the estimated range.

## Localization

Expand Down
Binary file modified Release/com.f00d4tehg0dz.teslafi.streamDeckPlugin
Binary file not shown.
3 changes: 2 additions & 1 deletion com.f00d4tehg0dz.teslafi.sdPlugin/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"battery_range": "Batteriereichweite",
"charging_state": "Ladestatus",
"outside_temp": "Außentemperatur",
"odometer": "Kilometerzähler"
"odometer": "Kilometerzähler",
"est_battery_range": "Geschätzte Batteriereichweite"
},
"instructions_label": "Anweisungen",
"instructions_text": "Sie können mehr über dieses Plugin und wie Sie einen API-Schlüssel erhalten, auf der Github-Seite erfahren, indem Sie ",
Expand Down
4 changes: 3 additions & 1 deletion com.f00d4tehg0dz.teslafi.sdPlugin/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
"field_2_label": "Field 2",
"field_3_label": "Field 3",
"field_4_label": "Field 4",
"field_5_label": "Field 5",
"field_options": {
"display_name": "Car Name",
"inside_temp": "Inside Temp",
"battery_range": "Battery Range",
"charging_state": "Charging State",
"outside_temp": "Outside Temp",
"odometer": "Odometer"
"odometer": "Odometer",
"est_battery_range": "Est. Battery Range"
},
"instructions_label": "Instructions",
"instructions_text": "You can learn more about this plugin and how to obtain an API key by visiting its Github page by ",
Expand Down
3 changes: 2 additions & 1 deletion com.f00d4tehg0dz.teslafi.sdPlugin/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"battery_range": "Rango de Batería",
"charging_state": "Estado de Carga",
"outside_temp": "Temperatura Exterior",
"odometer": "Odómetro"
"odometer": "Odómetro",
"est_battery_range": "Rango de Batería Estimado"
},
"instructions_label": "Instrucciones",
"instructions_text": "Puede aprender más sobre este plugin y cómo obtener una clave API visitando su página de Github ",
Expand Down
35 changes: 26 additions & 9 deletions com.f00d4tehg0dz.teslafi.sdPlugin/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ if ($SD) {

$SD.on(`${actionName}.willAppear`, (jsonObj) => {
const settings = jsonObj.payload.settings;
loadLastState(jsonObj.context, settings);
if (settings.automaticRefresh && settings.apiKey && settings.distanceType && settings.degreeType) {
initiateTeslaFiStatus(jsonObj.context, settings);
}
Expand All @@ -25,14 +26,15 @@ if ($SD) {
clearInterval(intervals[context]);
updateTeslaFiStatus(context, settings);
if (settings.automaticRefresh) {
intervals[context] = setInterval(() => updateTeslaFiStatus(context, settings), moment.duration(60, 'minutes').asMilliseconds());
intervals[context] = setInterval(() => updateTeslaFiStatus(context, settings), moment.duration(20, 'minutes').asMilliseconds());
}
}

function updateTeslaFiStatus(context, settings) {
setTitle(context, "Updating");
getTeslaFiData(settings.apiKey, (result) => {
clearTitle(context);
saveLastState(context, result, settings);
updateCanvasWithStatus(result, context, settings);
});
}
Expand Down Expand Up @@ -97,7 +99,7 @@ if ($SD) {
lines.forEach(({ text, color, icon }, i) => {
ctx.fillStyle = color;
const iconElement = document.getElementById(icon);
ctx.drawImage(iconElement, 10, 24 * i + 10);
ctx.drawImage(iconElement, 10, 24 * i + 10);
ctx.fillText(text, 30, 24 * i + 15);
});
}
Expand All @@ -108,19 +110,22 @@ if ($SD) {
case 'display_name':
return { text: result.display_name || 'N/A', color: "white", icon: "car-icon" };
case 'inside_temp':
const insideTemp = settings.degreeType === 1 ? convertToCelsius(result.inside_temp) : result.inside_temp;
return { text: insideTemp ? `${insideTemp}°` : 'N/A', color: "#ff6b6b", icon: "temperature-icon" };
const insideTemp = settings.degreeType === 1 ? result.inside_temp : result.inside_tempF;
return { text: insideTemp !== null ? `${insideTemp}°` : 'N/A', color: "#ff6b6b", icon: "temperature-icon" };
case 'battery_range':
const batteryRange = settings.distanceType === 1 ? convertToKm(result.battery_range) : result.battery_range;
return { text: batteryRange ? `${batteryRange} ${settings.distanceType === 1 ? 'km' : 'mi'}` : 'N/A', color: "#45b6fe", icon: "distance-icon" };
return { text: batteryRange !== null ? `${batteryRange} ${settings.distanceType === 1 ? 'km' : 'mi'}` : 'N/A', color: "#45b6fe", icon: "distance-icon" };
case 'charging_state':
return { text: result.charging_state || 'N/A', color: "#c7f464", icon: "charging-icon" };
case 'outside_temp':
const outsideTemp = settings.degreeType === 1 ? convertToCelsius(result.outside_temp) : result.outside_temp;
return { text: outsideTemp ? `${outsideTemp}°` : 'N/A', color: "#ff6b6b", icon: "temperature-icon" };
const outsideTemp = settings.degreeType === 1 ? result.outside_temp : result.outside_tempF;
return { text: outsideTemp !== null ? `${outsideTemp}°` : 'N/A', color: "#ff6b6b", icon: "temperature-icon" };
case 'odometer':
const odometer = settings.distanceType === 1 ? convertToKm(result.odometer) : result.odometer;
return { text: odometer ? `${odometer} ${settings.distanceType === 1 ? 'km' : 'mi'}` : 'N/A', color: "white", icon: "car-icon" };
return { text: odometer !== null ? `${odometer} ${settings.distanceType === 1 ? 'km' : 'mi'}` : 'N/A', color: "white", icon: "car-icon" };
case 'est_battery_range':
const estBatteryRange = settings.distanceType === 1 ? convertToKm(result.est_battery_range) : result.est_battery_range;
return { text: estBatteryRange !== null ? `${estBatteryRange} ${settings.distanceType === 1 ? 'km' : 'mi'}` : 'N/A', color: "#45b6fe", icon: "distance-icon" };
default:
return { text: 'N/A', color: 'white', icon: 'car-icon' };
}
Expand All @@ -147,11 +152,23 @@ if ($SD) {
});
}

function saveLastState(context, result, settings) {
const state = { result, settings };
localStorage.setItem(context, JSON.stringify(state));
}

function loadLastState(context, settings) {
const state = JSON.parse(localStorage.getItem(context));
if (state) {
updateCanvasWithStatus(state.result, context, settings);
}
}

function convertToCelsius(fahrenheit) {
return Math.round((fahrenheit - 32) * (5 / 9));
}

function convertToKm(miles) {
return Math.round(miles * 1.609344);
}
}
}
5 changes: 5 additions & 0 deletions com.f00d4tehg0dz.teslafi.sdPlugin/teslafi.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<option value="charging_state">Charging State</option>
<option value="outside_temp">Outside Temp</option>
<option value="odometer">Odometer</option>
<option value="est_battery_range">Est. Battery Range</option>
</select>
</div>
<div class="sdpi-item">
Expand All @@ -59,6 +60,7 @@
<option value="charging_state">Charging State</option>
<option value="outside_temp">Outside Temp</option>
<option value="odometer">Odometer</option>
<option value="est_battery_range">Est. Battery Range</option>
</select>
</div>
<div class="sdpi-item">
Expand All @@ -70,6 +72,7 @@
<option value="charging_state">Charging State</option>
<option value="outside_temp">Outside Temp</option>
<option value="odometer">Odometer</option>
<option value="est_battery_range">Est. Battery Range</option>
</select>
</div>
<div class="sdpi-item">
Expand All @@ -81,6 +84,7 @@
<option value="charging_state">Charging State</option>
<option value="outside_temp">Outside Temp</option>
<option value="odometer">Odometer</option>
<option value="est_battery_range">Est. Battery Range</option>
</select>
</div>
<div class="sdpi-item">
Expand All @@ -92,6 +96,7 @@
<option value="charging_state">Charging State</option>
<option value="outside_temp">Outside Temp</option>
<option value="odometer">Odometer</option>
<option value="est_battery_range">Est. Battery Range</option>
</select>
</div>
<div class="sdpi-item">
Expand Down
Binary file modified doc/screencap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added teslafi_screencaps_and_marketing.psd
Binary file not shown.

0 comments on commit ea3384e

Please sign in to comment.