diff --git a/teslaCmds.go b/teslaCmds.go new file mode 100644 index 0000000..3f98d33 --- /dev/null +++ b/teslaCmds.go @@ -0,0 +1,132 @@ +package main + +import ( + "fmt" + "strconv" + "strings" + "time" + + "github.com/therecipe/qt/widgets" +) + +func enableClimate(i int) { + temp, err := strconv.ParseFloat(window.ClimateSettingSpinbox.Text(), 64) + if err != nil { + showDialogue(true, "Unable to parse temp setting\n%+v", err) + } + if guiSettings.GuiTemperatureUnits == "F" { + temp = (temp - 32) * 5 / 9 + } + if i == 0 { + vehicle.StopAirConditioning() + } else { + vehicle.SetTemperature(temp, temp) + vehicle.StartAirConditioning() + } + + go setValues() +} + +func lockDoors(b bool) { + if b { + vehicle.UnlockDoors() + } else { + vehicle.LockDoors() + } + go setValues() +} + +func enableCharging(b bool) { + if b { + vehicle.StopCharging() + } else { + vehicle.StartCharging() + } + go setValues() +} + +func honkHorn(c bool) { + err := vehicle.HonkHorn() + if err != nil { + showDialogue(true, "There was an error honking the horn\n%+v", err) + fmt.Printf("%+v\n", err) + } + go setValues() +} +func flash(c bool) { + err := vehicle.FlashLights() + if err != nil { + showDialogue(true, "There was an error flashing the lights\n%+v", err) + fmt.Printf("%+v\n", err) + } + go setValues() +} +func openTrunk(c bool) { + err := vehicle.OpenTrunk("rear") + if err != nil { + showDialogue(true, "There was an error opening your trunk\n%+v", err) + fmt.Printf("%+v\n", err) + } + go setValues() +} +func openFrunk(c bool) { + err := vehicle.OpenTrunk("front") + if err != nil { + showDialogue(true, "There was an error opening your frunk\n%+v", err) + fmt.Printf("%+v\n", err) + } + go setValues() +} + +func showDialogue(recover bool, msg string, a ...interface{}) { + popup = true + if !recover { + window.Close() + } + dialogue := widgets.NewQDialog(nil, 0) + centralWidget := widgets.NewQWidget(dialogue, 0) + actionHBox := widgets.NewQHBoxLayout() + formLayout := widgets.NewQFormLayout(nil) + contBtn := widgets.NewQPushButton(nil) + quitBtn := widgets.NewQPushButton(nil) + message := widgets.NewQLabel(nil, 0) + + dialogue.SetWindowTitle("TeslaGo Alert") + dialogue.SetMinimumWidth(255) + dialogue.SetMinimumHeight(50 + (20 * (1 + strings.Count(msg, "\n")))) + + contBtn.SetText("Continue") + quitBtn.SetText("Quit") + message.SetText(fmt.Sprintf(msg, a...)) + message.SetWordWrap(true) + + contBtn.ConnectClicked(func(checked bool) { + window.Show() + popup = false + dialogue.Close() + + go setValues() + }) + quitBtn.ConnectClicked(func(checked bool) { + mainApp.Quit() + }) + + if recover { + actionHBox.AddWidget(contBtn, 0, 0) + } + actionHBox.AddWidget(quitBtn, 0, 0) + + formLayout.AddRow5(message) + formLayout.AddRow6(actionHBox) + centralWidget.SetLayout(formLayout) + + dialogue.Show() +} + +func formatDuration(d time.Duration) string { + d = d.Round(time.Minute) + h := d / time.Hour + d -= h * time.Hour + m := d / time.Minute + return fmt.Sprintf("%02dh%02dm", h, m) +} diff --git a/ui/main.ui b/ui/main.ui new file mode 100644 index 0000000..821e8ee --- /dev/null +++ b/ui/main.ui @@ -0,0 +1,405 @@ + + + MainWindow + + + + 0 + 0 + 632 + 597 + + + + MainWindow + + + + + + + QLayout::SetDefaultConstraint + + + + + + + + + + Charge Percent + + + + + + + 100 + + + 90 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + + + + + 90% + + + + + + + + + + + + + + + Current Range + + + + + + + Value + + + + + + + + + + + Charging State + + + + + + + Value + + + + + + + + + + + Inside Temp + + + + + + + Value + + + + + + + + + + + Climate Setting + + + + + + + + + + F + + + + + + + + + + + Climate On + + + + + + + + + + + + + + + Current Charge + + + + + + + Value + + + + + + + + + + + Charge Port + + + + + + + Value + + + + + + + + + + + Outside Temp + + + + + + + Value + + + + + + + + + + + Sentry Mode + + + + + + + Value + + + + + + + + + + + TimeToCharge + + + + + + + Value + + + + + + + + + + + + + + + + + Frunk + + + + + + + Trunk + + + + + + + Flash + + + + + + + + + + + Lock + + + + + + + Honk + + + + + + + Start Charge + + + + + + + + + + + + + + + 0 + 0 + 632 + 29 + + + + + File + + + + Auto Refresh + + + + + + + + + + + + + + + Vehicles + + + + + + + + + Vehicles + + + + + Test + + + + + Refresh + + + Ctrl+R + + + + + Quit + + + Ctrl+Q + + + + + 2 Minutes + + + + + 5 Minutes + + + + + 10 Minutes + + + + + 15 Minutes + + + + + 30 Minutes + + + + + Hourly + + + + + + diff --git a/ui/uic_main.go b/ui/uic_main.go new file mode 100644 index 0000000..36ce0fc --- /dev/null +++ b/ui/uic_main.go @@ -0,0 +1,350 @@ +package ui + +import ( + "github.com/therecipe/qt/core" + "github.com/therecipe/qt/gui" + "github.com/therecipe/qt/widgets" +) + +type __mainwindow struct{} + +func (*__mainwindow) init() {} + +type MainWindow struct { + *__mainwindow + *widgets.QMainWindow + ActionVehicles *widgets.QAction + ActionTest *widgets.QAction + ActionRefresh *widgets.QAction + ActionQuit *widgets.QAction + Action2_Minutes *widgets.QAction + Action5_Minutes *widgets.QAction + Action10_Minutes *widgets.QAction + Action15_Minutes *widgets.QAction + Action30_Minutes *widgets.QAction + ActionHourly *widgets.QAction + Centralwidget *widgets.QWidget + GridLayout *widgets.QGridLayout + VerticalLayout_4 *widgets.QVBoxLayout + VehiclePreviewView *widgets.QGraphicsView + HorizontalLayout_13 *widgets.QHBoxLayout + Label_9 *widgets.QLabel + ChargePercentSlider *widgets.QSlider + ChargePercentageLabel *widgets.QLabel + HorizontalLayout *widgets.QHBoxLayout + VerticalLayout *widgets.QVBoxLayout + HorizontalLayout_5 *widgets.QHBoxLayout + Label_2 *widgets.QLabel + CurrentRangeValue *widgets.QLabel + HorizontalLayout_6 *widgets.QHBoxLayout + Label_3 *widgets.QLabel + ChargingStateValue *widgets.QLabel + HorizontalLayout_7 *widgets.QHBoxLayout + Label_5 *widgets.QLabel + InsideTempValue *widgets.QLabel + HorizontalLayout_2 *widgets.QHBoxLayout + Label_8 *widgets.QLabel + ClimateSettingSpinbox *widgets.QSpinBox + GuiOptionTempValue *widgets.QLabel + HorizontalLayout_8 *widgets.QHBoxLayout + ClimateOnCheckbox *widgets.QCheckBox + VerticalLayout_2 *widgets.QVBoxLayout + HorizontalLayout_9 *widgets.QHBoxLayout + Label *widgets.QLabel + CurrentChargeValue *widgets.QLabel + HorizontalLayout_10 *widgets.QHBoxLayout + Label_4 *widgets.QLabel + ChargePortValue *widgets.QLabel + HorizontalLayout_11 *widgets.QHBoxLayout + Label_6 *widgets.QLabel + OutsideTempValue *widgets.QLabel + HorizontalLayout_12 *widgets.QHBoxLayout + Label_10 *widgets.QLabel + SentryModeValue *widgets.QLabel + HorizontalLayout_14 *widgets.QHBoxLayout + TimeToChargeLabel *widgets.QLabel + TimeToChargeVal *widgets.QLabel + VerticalLayout_3 *widgets.QVBoxLayout + HorizontalLayout_3 *widgets.QHBoxLayout + FrunkPushButton *widgets.QPushButton + TrunkPushButton *widgets.QPushButton + FlashPushButton *widgets.QPushButton + HorizontalLayout_4 *widgets.QHBoxLayout + LockPushButton *widgets.QPushButton + HonkPushButton *widgets.QPushButton + ChargePushButton *widgets.QPushButton + Menubar *widgets.QMenuBar + MenuFile *widgets.QMenu + MenuAuto_Refresh *widgets.QMenu + MenuVehicles *widgets.QMenu + Statusbar *widgets.QStatusBar +} + +func NewMainWindow(p widgets.QWidget_ITF) *MainWindow { + var par *widgets.QWidget + if p != nil { + par = p.QWidget_PTR() + } + w := &MainWindow{QMainWindow: widgets.NewQMainWindow(par, 0)} + w.setupUI() + w.init() + return w +} +func (w *MainWindow) setupUI() { + if w.ObjectName() == "" { + w.SetObjectName("MainWindow") + } + w.Resize2(632, 597) + w.ActionVehicles = widgets.NewQAction(w) + w.ActionVehicles.SetObjectName("actionVehicles") + w.ActionTest = widgets.NewQAction(w) + w.ActionTest.SetObjectName("actionTest") + w.ActionRefresh = widgets.NewQAction(w) + w.ActionRefresh.SetObjectName("actionRefresh") + w.ActionQuit = widgets.NewQAction(w) + w.ActionQuit.SetObjectName("actionQuit") + w.Action2_Minutes = widgets.NewQAction(w) + w.Action2_Minutes.SetObjectName("action2_Minutes") + w.Action5_Minutes = widgets.NewQAction(w) + w.Action5_Minutes.SetObjectName("action5_Minutes") + w.Action10_Minutes = widgets.NewQAction(w) + w.Action10_Minutes.SetObjectName("action10_Minutes") + w.Action15_Minutes = widgets.NewQAction(w) + w.Action15_Minutes.SetObjectName("action15_Minutes") + w.Action30_Minutes = widgets.NewQAction(w) + w.Action30_Minutes.SetObjectName("action30_Minutes") + w.ActionHourly = widgets.NewQAction(w) + w.ActionHourly.SetObjectName("actionHourly") + w.Centralwidget = widgets.NewQWidget(w, 0) + w.Centralwidget.SetObjectName("centralwidget") + w.GridLayout = widgets.NewQGridLayout(w.Centralwidget) + w.GridLayout.SetObjectName("gridLayout") + w.VerticalLayout_4 = widgets.NewQVBoxLayout() + w.VerticalLayout_4.SetObjectName("verticalLayout_4") + w.VerticalLayout_4.SetSizeConstraint(widgets.QLayout__SetDefaultConstraint) + w.VehiclePreviewView = widgets.NewQGraphicsView(w.Centralwidget) + w.VehiclePreviewView.SetObjectName("vehiclePreviewView") + w.VerticalLayout_4.QLayout.AddWidget(w.VehiclePreviewView) + w.HorizontalLayout_13 = widgets.NewQHBoxLayout() + w.HorizontalLayout_13.SetObjectName("horizontalLayout_13") + w.Label_9 = widgets.NewQLabel(w.Centralwidget, 0) + w.Label_9.SetObjectName("label_9") + w.HorizontalLayout_13.QLayout.AddWidget(w.Label_9) + w.ChargePercentSlider = widgets.NewQSlider(w.Centralwidget) + w.ChargePercentSlider.SetObjectName("chargePercentSlider") + w.ChargePercentSlider.SetMaximum(100) + w.ChargePercentSlider.SetValue(90) + w.ChargePercentSlider.SetOrientation(core.Qt__Horizontal) + w.ChargePercentSlider.SetTickPosition(widgets.QSlider__TicksBelow) + w.ChargePercentSlider.SetTickInterval(10) + w.HorizontalLayout_13.QLayout.AddWidget(w.ChargePercentSlider) + w.ChargePercentageLabel = widgets.NewQLabel(w.Centralwidget, 0) + w.ChargePercentageLabel.SetObjectName("chargePercentageLabel") + w.HorizontalLayout_13.QLayout.AddWidget(w.ChargePercentageLabel) + w.VerticalLayout_4.AddLayout(w.HorizontalLayout_13, 0) + w.HorizontalLayout = widgets.NewQHBoxLayout() + w.HorizontalLayout.SetObjectName("horizontalLayout") + w.VerticalLayout = widgets.NewQVBoxLayout() + w.VerticalLayout.SetObjectName("verticalLayout") + w.HorizontalLayout_5 = widgets.NewQHBoxLayout() + w.HorizontalLayout_5.SetObjectName("horizontalLayout_5") + w.Label_2 = widgets.NewQLabel(w.Centralwidget, 0) + w.Label_2.SetObjectName("label_2") + w.HorizontalLayout_5.QLayout.AddWidget(w.Label_2) + w.CurrentRangeValue = widgets.NewQLabel(w.Centralwidget, 0) + w.CurrentRangeValue.SetObjectName("currentRangeValue") + w.HorizontalLayout_5.QLayout.AddWidget(w.CurrentRangeValue) + w.VerticalLayout.AddLayout(w.HorizontalLayout_5, 0) + w.HorizontalLayout_6 = widgets.NewQHBoxLayout() + w.HorizontalLayout_6.SetObjectName("horizontalLayout_6") + w.Label_3 = widgets.NewQLabel(w.Centralwidget, 0) + w.Label_3.SetObjectName("label_3") + w.HorizontalLayout_6.QLayout.AddWidget(w.Label_3) + w.ChargingStateValue = widgets.NewQLabel(w.Centralwidget, 0) + w.ChargingStateValue.SetObjectName("chargingStateValue") + w.HorizontalLayout_6.QLayout.AddWidget(w.ChargingStateValue) + w.VerticalLayout.AddLayout(w.HorizontalLayout_6, 0) + w.HorizontalLayout_7 = widgets.NewQHBoxLayout() + w.HorizontalLayout_7.SetObjectName("horizontalLayout_7") + w.Label_5 = widgets.NewQLabel(w.Centralwidget, 0) + w.Label_5.SetObjectName("label_5") + w.HorizontalLayout_7.QLayout.AddWidget(w.Label_5) + w.InsideTempValue = widgets.NewQLabel(w.Centralwidget, 0) + w.InsideTempValue.SetObjectName("insideTempValue") + w.HorizontalLayout_7.QLayout.AddWidget(w.InsideTempValue) + w.VerticalLayout.AddLayout(w.HorizontalLayout_7, 0) + w.HorizontalLayout_2 = widgets.NewQHBoxLayout() + w.HorizontalLayout_2.SetObjectName("horizontalLayout_2") + w.Label_8 = widgets.NewQLabel(w.Centralwidget, 0) + w.Label_8.SetObjectName("label_8") + w.HorizontalLayout_2.QLayout.AddWidget(w.Label_8) + w.ClimateSettingSpinbox = widgets.NewQSpinBox(w.Centralwidget) + w.ClimateSettingSpinbox.SetObjectName("climateSettingSpinbox") + w.HorizontalLayout_2.QLayout.AddWidget(w.ClimateSettingSpinbox) + w.GuiOptionTempValue = widgets.NewQLabel(w.Centralwidget, 0) + w.GuiOptionTempValue.SetObjectName("guiOptionTempValue") + w.HorizontalLayout_2.QLayout.AddWidget(w.GuiOptionTempValue) + w.VerticalLayout.AddLayout(w.HorizontalLayout_2, 0) + w.HorizontalLayout_8 = widgets.NewQHBoxLayout() + w.HorizontalLayout_8.SetObjectName("horizontalLayout_8") + w.ClimateOnCheckbox = widgets.NewQCheckBox(w.Centralwidget) + w.ClimateOnCheckbox.SetObjectName("climateOnCheckbox") + w.HorizontalLayout_8.QLayout.AddWidget(w.ClimateOnCheckbox) + w.VerticalLayout.AddLayout(w.HorizontalLayout_8, 0) + w.HorizontalLayout.AddLayout(w.VerticalLayout, 0) + w.VerticalLayout_2 = widgets.NewQVBoxLayout() + w.VerticalLayout_2.SetObjectName("verticalLayout_2") + w.HorizontalLayout_9 = widgets.NewQHBoxLayout() + w.HorizontalLayout_9.SetObjectName("horizontalLayout_9") + w.Label = widgets.NewQLabel(w.Centralwidget, 0) + w.Label.SetObjectName("label") + w.HorizontalLayout_9.QLayout.AddWidget(w.Label) + w.CurrentChargeValue = widgets.NewQLabel(w.Centralwidget, 0) + w.CurrentChargeValue.SetObjectName("currentChargeValue") + w.HorizontalLayout_9.QLayout.AddWidget(w.CurrentChargeValue) + w.VerticalLayout_2.AddLayout(w.HorizontalLayout_9, 0) + w.HorizontalLayout_10 = widgets.NewQHBoxLayout() + w.HorizontalLayout_10.SetObjectName("horizontalLayout_10") + w.Label_4 = widgets.NewQLabel(w.Centralwidget, 0) + w.Label_4.SetObjectName("label_4") + w.HorizontalLayout_10.QLayout.AddWidget(w.Label_4) + w.ChargePortValue = widgets.NewQLabel(w.Centralwidget, 0) + w.ChargePortValue.SetObjectName("chargePortValue") + w.HorizontalLayout_10.QLayout.AddWidget(w.ChargePortValue) + w.VerticalLayout_2.AddLayout(w.HorizontalLayout_10, 0) + w.HorizontalLayout_11 = widgets.NewQHBoxLayout() + w.HorizontalLayout_11.SetObjectName("horizontalLayout_11") + w.Label_6 = widgets.NewQLabel(w.Centralwidget, 0) + w.Label_6.SetObjectName("label_6") + w.HorizontalLayout_11.QLayout.AddWidget(w.Label_6) + w.OutsideTempValue = widgets.NewQLabel(w.Centralwidget, 0) + w.OutsideTempValue.SetObjectName("outsideTempValue") + w.HorizontalLayout_11.QLayout.AddWidget(w.OutsideTempValue) + w.VerticalLayout_2.AddLayout(w.HorizontalLayout_11, 0) + w.HorizontalLayout_12 = widgets.NewQHBoxLayout() + w.HorizontalLayout_12.SetObjectName("horizontalLayout_12") + w.Label_10 = widgets.NewQLabel(w.Centralwidget, 0) + w.Label_10.SetObjectName("label_10") + w.HorizontalLayout_12.QLayout.AddWidget(w.Label_10) + w.SentryModeValue = widgets.NewQLabel(w.Centralwidget, 0) + w.SentryModeValue.SetObjectName("sentryModeValue") + w.HorizontalLayout_12.QLayout.AddWidget(w.SentryModeValue) + w.VerticalLayout_2.AddLayout(w.HorizontalLayout_12, 0) + w.HorizontalLayout_14 = widgets.NewQHBoxLayout() + w.HorizontalLayout_14.SetObjectName("horizontalLayout_14") + w.TimeToChargeLabel = widgets.NewQLabel(w.Centralwidget, 0) + w.TimeToChargeLabel.SetObjectName("timeToChargeLabel") + w.HorizontalLayout_14.QLayout.AddWidget(w.TimeToChargeLabel) + w.TimeToChargeVal = widgets.NewQLabel(w.Centralwidget, 0) + w.TimeToChargeVal.SetObjectName("timeToChargeVal") + w.HorizontalLayout_14.QLayout.AddWidget(w.TimeToChargeVal) + w.VerticalLayout_2.AddLayout(w.HorizontalLayout_14, 0) + w.HorizontalLayout.AddLayout(w.VerticalLayout_2, 0) + w.VerticalLayout_4.AddLayout(w.HorizontalLayout, 0) + w.VerticalLayout_3 = widgets.NewQVBoxLayout() + w.VerticalLayout_3.SetObjectName("verticalLayout_3") + w.HorizontalLayout_3 = widgets.NewQHBoxLayout() + w.HorizontalLayout_3.SetObjectName("horizontalLayout_3") + w.FrunkPushButton = widgets.NewQPushButton(w.Centralwidget) + w.FrunkPushButton.SetObjectName("frunkPushButton") + w.HorizontalLayout_3.QLayout.AddWidget(w.FrunkPushButton) + w.TrunkPushButton = widgets.NewQPushButton(w.Centralwidget) + w.TrunkPushButton.SetObjectName("trunkPushButton") + w.HorizontalLayout_3.QLayout.AddWidget(w.TrunkPushButton) + w.FlashPushButton = widgets.NewQPushButton(w.Centralwidget) + w.FlashPushButton.SetObjectName("flashPushButton") + w.HorizontalLayout_3.QLayout.AddWidget(w.FlashPushButton) + w.VerticalLayout_3.AddLayout(w.HorizontalLayout_3, 0) + w.HorizontalLayout_4 = widgets.NewQHBoxLayout() + w.HorizontalLayout_4.SetObjectName("horizontalLayout_4") + w.LockPushButton = widgets.NewQPushButton(w.Centralwidget) + w.LockPushButton.SetObjectName("lockPushButton") + w.HorizontalLayout_4.QLayout.AddWidget(w.LockPushButton) + w.HonkPushButton = widgets.NewQPushButton(w.Centralwidget) + w.HonkPushButton.SetObjectName("honkPushButton") + w.HorizontalLayout_4.QLayout.AddWidget(w.HonkPushButton) + w.ChargePushButton = widgets.NewQPushButton(w.Centralwidget) + w.ChargePushButton.SetObjectName("chargePushButton") + w.HorizontalLayout_4.QLayout.AddWidget(w.ChargePushButton) + w.VerticalLayout_3.AddLayout(w.HorizontalLayout_4, 0) + w.VerticalLayout_4.AddLayout(w.VerticalLayout_3, 0) + w.GridLayout.AddLayout2(w.VerticalLayout_4, 0, 0, 1, 1, 0) + w.SetCentralWidget(w.Centralwidget) + w.Menubar = widgets.NewQMenuBar(w) + w.Menubar.SetObjectName("menubar") + w.Menubar.SetGeometry(core.NewQRect4(0, 0, 632, 29)) + w.MenuFile = widgets.NewQMenu(w.Menubar) + w.MenuFile.SetObjectName("menuFile") + w.MenuAuto_Refresh = widgets.NewQMenu(w.MenuFile) + w.MenuAuto_Refresh.SetObjectName("menuAuto_Refresh") + w.MenuVehicles = widgets.NewQMenu(w.Menubar) + w.MenuVehicles.SetObjectName("menuVehicles") + w.SetMenuBar(w.Menubar) + w.Statusbar = widgets.NewQStatusBar(w) + w.Statusbar.SetObjectName("statusbar") + w.SetStatusBar(w.Statusbar) + w.Menubar.AddActions([]*widgets.QAction{w.MenuFile.MenuAction()}) + w.Menubar.AddActions([]*widgets.QAction{w.MenuVehicles.MenuAction()}) + w.MenuFile.AddActions([]*widgets.QAction{w.ActionRefresh}) + w.MenuFile.AddActions([]*widgets.QAction{w.MenuAuto_Refresh.MenuAction()}) + w.MenuFile.AddActions([]*widgets.QAction{w.ActionQuit}) + w.MenuAuto_Refresh.AddActions([]*widgets.QAction{w.Action2_Minutes}) + w.MenuAuto_Refresh.AddActions([]*widgets.QAction{w.Action5_Minutes}) + w.MenuAuto_Refresh.AddActions([]*widgets.QAction{w.Action10_Minutes}) + w.MenuAuto_Refresh.AddActions([]*widgets.QAction{w.Action15_Minutes}) + w.MenuAuto_Refresh.AddActions([]*widgets.QAction{w.Action30_Minutes}) + w.MenuAuto_Refresh.AddActions([]*widgets.QAction{w.ActionHourly}) + w.retranslateUi() + core.QMetaObject_ConnectSlotsByName(w) + +} +func (w *MainWindow) retranslateUi() { + w.SetWindowTitle(core.QCoreApplication_Translate("MainWindow", "MainWindow", "", 0)) + w.ActionVehicles.SetText(core.QCoreApplication_Translate("MainWindow", "Vehicles", "", 0)) + w.ActionTest.SetText(core.QCoreApplication_Translate("MainWindow", "Test", "", 0)) + w.ActionRefresh.SetText(core.QCoreApplication_Translate("MainWindow", "Refresh", "", 0)) + if true { + w.ActionRefresh.SetShortcut(gui.NewQKeySequence2(core.QCoreApplication_Translate("MainWindow", "Ctrl+R", "", 0), 0)) + } + w.ActionQuit.SetText(core.QCoreApplication_Translate("MainWindow", "Quit", "", 0)) + if true { + w.ActionQuit.SetShortcut(gui.NewQKeySequence2(core.QCoreApplication_Translate("MainWindow", "Ctrl+Q", "", 0), 0)) + } + w.Action2_Minutes.SetText(core.QCoreApplication_Translate("MainWindow", "2 Minutes", "", 0)) + w.Action5_Minutes.SetText(core.QCoreApplication_Translate("MainWindow", "5 Minutes", "", 0)) + w.Action10_Minutes.SetText(core.QCoreApplication_Translate("MainWindow", "10 Minutes", "", 0)) + w.Action15_Minutes.SetText(core.QCoreApplication_Translate("MainWindow", "15 Minutes", "", 0)) + w.Action30_Minutes.SetText(core.QCoreApplication_Translate("MainWindow", "30 Minutes", "", 0)) + w.ActionHourly.SetText(core.QCoreApplication_Translate("MainWindow", "Hourly", "", 0)) + w.Label_9.SetText(core.QCoreApplication_Translate("MainWindow", "Charge Percent", "", 0)) + w.ChargePercentageLabel.SetText(core.QCoreApplication_Translate("MainWindow", "90%", "", 0)) + w.Label_2.SetText(core.QCoreApplication_Translate("MainWindow", "Current Range", "", 0)) + w.CurrentRangeValue.SetText(core.QCoreApplication_Translate("MainWindow", "Value", "", 0)) + w.Label_3.SetText(core.QCoreApplication_Translate("MainWindow", "Charging State", "", 0)) + w.ChargingStateValue.SetText(core.QCoreApplication_Translate("MainWindow", "Value", "", 0)) + w.Label_5.SetText(core.QCoreApplication_Translate("MainWindow", "Inside Temp", "", 0)) + w.InsideTempValue.SetText(core.QCoreApplication_Translate("MainWindow", "Value", "", 0)) + w.Label_8.SetText(core.QCoreApplication_Translate("MainWindow", "Climate Setting", "", 0)) + w.GuiOptionTempValue.SetText(core.QCoreApplication_Translate("MainWindow", "F", "", 0)) + w.ClimateOnCheckbox.SetText(core.QCoreApplication_Translate("MainWindow", "Climate On", "", 0)) + w.Label.SetText(core.QCoreApplication_Translate("MainWindow", "Current Charge", "", 0)) + w.CurrentChargeValue.SetText(core.QCoreApplication_Translate("MainWindow", "Value", "", 0)) + w.Label_4.SetText(core.QCoreApplication_Translate("MainWindow", "Charge Port", "", 0)) + w.ChargePortValue.SetText(core.QCoreApplication_Translate("MainWindow", "Value", "", 0)) + w.Label_6.SetText(core.QCoreApplication_Translate("MainWindow", "Outside Temp", "", 0)) + w.OutsideTempValue.SetText(core.QCoreApplication_Translate("MainWindow", "Value", "", 0)) + w.Label_10.SetText(core.QCoreApplication_Translate("MainWindow", "Sentry Mode", "", 0)) + w.SentryModeValue.SetText(core.QCoreApplication_Translate("MainWindow", "Value", "", 0)) + w.TimeToChargeLabel.SetText(core.QCoreApplication_Translate("MainWindow", "TimeToCharge", "", 0)) + w.TimeToChargeVal.SetText(core.QCoreApplication_Translate("MainWindow", "Value", "", 0)) + w.FrunkPushButton.SetText(core.QCoreApplication_Translate("MainWindow", "Frunk", "", 0)) + w.TrunkPushButton.SetText(core.QCoreApplication_Translate("MainWindow", "Trunk", "", 0)) + w.FlashPushButton.SetText(core.QCoreApplication_Translate("MainWindow", "Flash", "", 0)) + w.LockPushButton.SetText(core.QCoreApplication_Translate("MainWindow", "Lock", "", 0)) + w.HonkPushButton.SetText(core.QCoreApplication_Translate("MainWindow", "Honk", "", 0)) + w.ChargePushButton.SetText(core.QCoreApplication_Translate("MainWindow", "Start Charge", "", 0)) + w.MenuFile.SetTitle(core.QCoreApplication_Translate("MainWindow", "File", "", 0)) + w.MenuAuto_Refresh.SetTitle(core.QCoreApplication_Translate("MainWindow", "Auto Refresh", "", 0)) + w.MenuVehicles.SetTitle(core.QCoreApplication_Translate("MainWindow", "Vehicles", "", 0)) + +} diff --git a/updateValues.go b/updateValues.go new file mode 100644 index 0000000..4f8d49c --- /dev/null +++ b/updateValues.go @@ -0,0 +1,73 @@ +package main + +import ( + "fmt" + "strconv" + "strings" + "time" +) + +func setValues() { + vehicle = getVehicle(vehicleSearch) + if vehicle == nil { + showDialogue(false, "Unable to get vehicle") + return + } + test, err := vehicle.Data(vehicle.ID) + if err != nil { + showDialogue(false, "Unable to get Vehicle State") + } + vehicleState = test.Response.VehicleState + chargeStats = test.Response.ChargeState + climateState = test.Response.ClimateState + guiSettings = test.Response.GuiSettings + + window.SetWindowTitle(fmt.Sprintf("%+v: %+v", vehicle.DisplayName, vehicle.Vin)) + tempSettingVal := climateState.DriverTempSetting + insideTempVal := climateState.InsideTemp + outsideTempVal := climateState.OutsideTemp + if guiSettings.GuiTemperatureUnits == "F" { + tempSettingVal = (climateState.DriverTempSetting * 1.8) + 32 + insideTempVal = (climateState.InsideTemp * 1.8) + 32 + outsideTempVal = (climateState.OutsideTemp * 1.8) + 32 + } + window.CurrentChargeValue.SetText(fmt.Sprintf("%+v%%", chargeStats.BatteryLevel)) + window.CurrentRangeValue.SetText(fmt.Sprintf("%.2f%+v", chargeStats.BatteryRange, + strings.Replace(guiSettings.GuiDistanceUnits, "/hr", "", -1))) + window.CurrentRangeValue.SetFixedWidth(10 * len(window.CurrentRangeValue.Text())) + window.ChargingStateValue.SetText(chargeStats.ChargingState) + if chargeStats.ChargingState == "Charging" { + chargeTimer := time.Duration(chargeStats.MinutesToFullCharge) * time.Minute + window.TimeToChargeLabel.SetText("Charging Complete In") + window.TimeToChargeVal.SetText(fmt.Sprintf("%+v (%+v)", formatDuration(chargeTimer), time.Now().Add(chargeTimer).Format("15:04"))) + if chargeStats.FastChargerBrand == "Tesla" { + window.ChargingStateValue.SetText("Supercharging") + } + } else { + window.TimeToChargeLabel.SetText("") + window.TimeToChargeVal.SetText("") + } + + if chargeStats.ChargePortDoorOpen { + window.ChargePortValue.SetText("Open") + } else { + window.ChargePortValue.SetText("Closed") + } + window.ChargePercentSlider.SetValue(chargeStats.ChargeLimitSoc) + window.ChargePercentageLabel.SetText(strconv.Itoa(chargeStats.ChargeLimitSoc)) + + window.InsideTempValue.SetText(fmt.Sprintf("%.0f %+v", insideTempVal, guiSettings.GuiTemperatureUnits)) + window.OutsideTempValue.SetText(fmt.Sprintf("%.0f %+v", outsideTempVal, guiSettings.GuiTemperatureUnits)) + window.ClimateOnCheckbox.SetChecked(climateState.IsClimateOn) + window.ClimateSettingSpinbox.SetValue(int(tempSettingVal)) + window.GuiOptionTempValue.SetText(guiSettings.GuiTemperatureUnits) + + if vehicleState.SentryMode { + window.SentryModeValue.SetText("Engaged") + } else { + window.SentryModeValue.SetText("Disengaged") + } + window.ClimateOnCheckbox.SetCheckable(true) + window.ClimateSettingSpinbox.SetReadOnly(false) + fmt.Printf("%+v\n", vehicle.OptionCodes) +}