|
|
|
@ -1,10 +1,12 @@
@@ -1,10 +1,12 @@
|
|
|
|
|
package main |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"flag" |
|
|
|
|
"fmt" |
|
|
|
|
"os" |
|
|
|
|
"strconv" |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/bogosj/tesla" |
|
|
|
|
"github.com/therecipe/qt/widgets" |
|
|
|
@ -43,14 +45,36 @@ var (
@@ -43,14 +45,36 @@ var (
|
|
|
|
|
|
|
|
|
|
window *widgets.QMainWindow |
|
|
|
|
mainApp *widgets.QApplication |
|
|
|
|
vehicleSearch string |
|
|
|
|
refresh bool |
|
|
|
|
popup = false |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
flag.StringVar(&vehicleSearch, "v", "", "Vehicle Identifier") |
|
|
|
|
flag.BoolVar(&refresh, "r", false, "Auto-refresh (every minute)") |
|
|
|
|
flag.Parse() |
|
|
|
|
} |
|
|
|
|
func main() { |
|
|
|
|
mainApp = widgets.NewQApplication(len(os.Args), os.Args) |
|
|
|
|
window = widgets.NewQMainWindow(nil, 0) |
|
|
|
|
|
|
|
|
|
c := getTeslaClient() |
|
|
|
|
vehicles, err := c.Vehicles() |
|
|
|
|
if err != nil { |
|
|
|
|
showDialogue(false, "Unable to get vehicles.\n%+v", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if len(vehicles) == 0 { |
|
|
|
|
showDialogue(false, "No vehicles to show.") |
|
|
|
|
return |
|
|
|
|
} else if len(vehicles) > 1 && vehicleSearch == "" { |
|
|
|
|
showDialogue(false, "Unable to determine vehicle.") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Setup all UI Elements
|
|
|
|
|
window.SetWindowTitle("Loading, please wait!") |
|
|
|
|
|
|
|
|
|
batteryLevel = widgets.NewQLabel(nil, 0) |
|
|
|
|
batteryRange = widgets.NewQLabel(nil, 0) |
|
|
|
|
chargingState = widgets.NewQLabel(nil, 0) |
|
|
|
@ -93,10 +117,19 @@ func main() {
@@ -93,10 +117,19 @@ func main() {
|
|
|
|
|
centralWidget := widgets.NewQWidget(window, 0) |
|
|
|
|
|
|
|
|
|
// Set Values for everything
|
|
|
|
|
go setValues() |
|
|
|
|
if refresh { |
|
|
|
|
go func() { |
|
|
|
|
time.Sleep(1 * time.Minute) |
|
|
|
|
setValues() |
|
|
|
|
}() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Some adjustments
|
|
|
|
|
window.SetWindowTitle(fmt.Sprintf("%+v: %+v", vehicle.DisplayName, vehicle.Vin)) |
|
|
|
|
|
|
|
|
|
lockedDoors.SetCheckable(false) |
|
|
|
|
climateOn.SetCheckable(false) |
|
|
|
|
tempSetting.SetReadOnly(true) |
|
|
|
|
|
|
|
|
|
batteryLevel.SetFixedWidth(30) |
|
|
|
|
insideTemp.SetFixedWidth(25) |
|
|
|
@ -134,7 +167,7 @@ func main() {
@@ -134,7 +167,7 @@ func main() {
|
|
|
|
|
chargeHbox.AddWidget(batteryRange, 0, 0) |
|
|
|
|
|
|
|
|
|
// Charging State has its own section and is handled differently based on if it is present or not
|
|
|
|
|
if chargeStats.ChargingState != "Disconnected" { |
|
|
|
|
if chargeStats != nil && chargeStats.ChargingState != "Disconnected" { |
|
|
|
|
statusLayout.AddRow3("Minutes to Full:", minutesToFull) |
|
|
|
|
if chargeStats.FastChargerPresent { |
|
|
|
|
statusLayout.AddRow3("Fast Charger:", fastChargerInd) |
|
|
|
@ -163,7 +196,7 @@ func main() {
@@ -163,7 +196,7 @@ func main() {
|
|
|
|
|
securityHbox.AddItem(widgets.NewQSpacerItem(10, 10, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed)) |
|
|
|
|
securityHbox.AddWidget(sentryModeLabel, 0, 0) |
|
|
|
|
securityHbox.AddWidget(sentryMode, 0, 0) |
|
|
|
|
if chargeStats.ChargingState != "Disconnected" { |
|
|
|
|
if chargeStats != nil && chargeStats.ChargingState != "Disconnected" { |
|
|
|
|
securityHbox.AddItem(widgets.NewQSpacerItem(10, 10, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed)) |
|
|
|
|
securityHbox.AddWidget(chargingStateLabel, 0, 0) |
|
|
|
|
securityHbox.AddWidget(startStopCharge, 0, 0) |
|
|
|
@ -200,7 +233,7 @@ func main() {
@@ -200,7 +233,7 @@ func main() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func setValues() { |
|
|
|
|
vehicle = getVehicle("") |
|
|
|
|
vehicle = getVehicle(vehicleSearch) |
|
|
|
|
var err error |
|
|
|
|
if vehicle == nil { |
|
|
|
|
showDialogue(false, "Unable to get vehicle") |
|
|
|
@ -221,9 +254,9 @@ func setValues() {
@@ -221,9 +254,9 @@ func setValues() {
|
|
|
|
|
} |
|
|
|
|
guiSettings, err = vehicle.GuiSettings() |
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
|
|
showDialogue(false, "Unable to get Gui Settings") |
|
|
|
|
} |
|
|
|
|
window.SetWindowTitle(fmt.Sprintf("%+v: %+v", vehicle.DisplayName, vehicle.Vin)) |
|
|
|
|
tempSettingVal := climateState.DriverTempSetting |
|
|
|
|
insideTempVal := climateState.InsideTemp |
|
|
|
|
outsideTempVal := climateState.OutsideTemp |
|
|
|
@ -260,6 +293,9 @@ func setValues() {
@@ -260,6 +293,9 @@ func setValues() {
|
|
|
|
|
lockedDoors.SetChecked(vehicleState.Locked) |
|
|
|
|
sentryMode.SetChecked(vehicleState.SentryMode) |
|
|
|
|
sentryMode.SetCheckable(!vehicleState.SentryMode) |
|
|
|
|
lockedDoors.SetCheckable(true) |
|
|
|
|
climateOn.SetCheckable(true) |
|
|
|
|
tempSetting.SetReadOnly(false) |
|
|
|
|
|
|
|
|
|
startStopCharge.SetChecked(chargeStats.ChargingState == "Charging") |
|
|
|
|
if chargeStats.ChargingState == "Disconnected" { |
|
|
|
@ -344,7 +380,7 @@ func openFrunk(c bool) {
@@ -344,7 +380,7 @@ func openFrunk(c bool) {
|
|
|
|
|
|
|
|
|
|
func showDialogue(recover bool, msg string, a ...interface{}) { |
|
|
|
|
popup = true |
|
|
|
|
if (!recover) { |
|
|
|
|
if !recover { |
|
|
|
|
window.Close() |
|
|
|
|
} |
|
|
|
|
dialogue := widgets.NewQDialog(nil, 0) |
|
|
|
|