Go/Qt desktop application for Tesla vehicles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.8 KiB

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()
}
generateVehicleImgURL()
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()
}