|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/therecipe/qt/core"
|
|
|
|
"github.com/therecipe/qt/gui"
|
|
|
|
"github.com/therecipe/qt/widgets"
|
|
|
|
)
|
|
|
|
|
|
|
|
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")
|
|
|
|
if guiSettings.Gui24HourTime {
|
|
|
|
window.TimeToChargeVal.SetText(fmt.Sprintf("%+v (%+v)", formatDuration(chargeTimer), time.Now().Add(chargeTimer).Format("15:04")))
|
|
|
|
} else {
|
|
|
|
window.TimeToChargeVal.SetText(fmt.Sprintf("%+v (%+v)", formatDuration(chargeTimer), time.Now().Add(chargeTimer).Format(time.Kitchen)))
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
go func() {
|
|
|
|
client := getTeslaClient()
|
|
|
|
vehicles, _ := client.Vehicles()
|
|
|
|
for _, v := range vehicles {
|
|
|
|
a := window.MenuVehicles.AddAction(v.DisplayName)
|
|
|
|
a.ConnectTriggered(func(checked bool) {
|
|
|
|
vehicleSearch = v.Vin
|
|
|
|
go setValues()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateVehicleImgURL() {
|
|
|
|
var model string = "m3"
|
|
|
|
var color string = "PMNG"
|
|
|
|
var wheels string = "W38B"
|
|
|
|
window.VehiclePreviewView.Hide()
|
|
|
|
url := fmt.Sprintf("https://static-assets.tesla.com/configurator/compositor/?model=%+v&options=%+v,%+v&bkba_opt=1&view=STUD_3QTR&size=1318", model, color, wheels)
|
|
|
|
response, e := http.Get(url)
|
|
|
|
if e != nil {
|
|
|
|
window.VehiclePreviewView.Hide()
|
|
|
|
}
|
|
|
|
defer response.Body.Close()
|
|
|
|
img := response.Body
|
|
|
|
file, err := os.Create("vehicle.png")
|
|
|
|
if err != nil {
|
|
|
|
window.VehiclePreviewView.Hide()
|
|
|
|
}
|
|
|
|
_, err = io.Copy(file, img)
|
|
|
|
if err != nil {
|
|
|
|
window.VehiclePreviewView.Hide()
|
|
|
|
}
|
|
|
|
window.VehiclePreviewView.SetMinimumWidth(window.Width())
|
|
|
|
window.VehiclePreviewView.VerticalScrollBar().Hide()
|
|
|
|
scene := widgets.NewQGraphicsScene(nil)
|
|
|
|
image := widgets.NewQGraphicsPixmapItem2(gui.NewQPixmap3("vehicle.png", "", core.Qt__AutoColor).Scaled2(window.Width(), int(float32(window.Height())*0.5), core.Qt__KeepAspectRatio, core.Qt__FastTransformation), nil)
|
|
|
|
scene.AddItem(image)
|
|
|
|
window.VehiclePreviewView.SetScene(scene)
|
|
|
|
window.VehiclePreviewView.Show()
|
|
|
|
}
|