|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/bogosj/tesla"
|
|
|
|
"github.com/therecipe/qt/widgets"
|
|
|
|
|
|
|
|
"git.nightmare.haus/rudi/TeslaGo/ui"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
vehicle *tesla.Vehicle
|
|
|
|
vehicleState *tesla.VehicleState
|
|
|
|
chargeStats *tesla.ChargeState
|
|
|
|
climateState *tesla.ClimateState
|
|
|
|
guiSettings *tesla.GuiSettings
|
|
|
|
|
|
|
|
window *ui.MainWindow
|
|
|
|
mainApp *widgets.QApplication
|
|
|
|
vehicleSearch string
|
|
|
|
refresh int
|
|
|
|
popup bool
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.StringVar(&vehicleSearch, "v", "", "Vehicle Identifier")
|
|
|
|
flag.IntVar(&refresh, "r", -1, "Auto-refresh (every \"r\" minutes) WARNING: Vehicle can not sleep while refreshing.")
|
|
|
|
flag.Parse()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
mainApp = widgets.NewQApplication(len(os.Args), os.Args)
|
|
|
|
|
|
|
|
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.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !popup {
|
|
|
|
NewMainWindow().Show()
|
|
|
|
}
|
|
|
|
widgets.QApplication_Exec()
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMainWindow() *ui.MainWindow {
|
|
|
|
window = ui.NewMainWindow(nil)
|
|
|
|
|
|
|
|
window.SetWindowTitle("Tesla Go!")
|
|
|
|
window.HonkPushButton.ConnectClicked(honkHorn)
|
|
|
|
window.TimeToChargeLabel.SetText("")
|
|
|
|
window.TimeToChargeVal.SetText("")
|
|
|
|
window.FlashPushButton.ConnectClicked(flash)
|
|
|
|
window.FrunkPushButton.ConnectClicked(openFrunk)
|
|
|
|
window.TrunkPushButton.ConnectClicked(openTrunk)
|
|
|
|
window.LockPushButton.ConnectClicked(lockDoors)
|
|
|
|
window.ChargePushButton.ConnectClicked(enableCharging)
|
|
|
|
window.VehiclePreviewView.SetFixedWidth(50)
|
|
|
|
window.ClimateOnCheckbox.ConnectStateChanged(enableClimate)
|
|
|
|
window.ActionRefresh.ConnectTriggered(setVal2)
|
|
|
|
go setValues()
|
|
|
|
return window
|
|
|
|
}
|
|
|
|
|
|
|
|
func setVal2(check bool) {
|
|
|
|
go setValues()
|
|
|
|
}
|