Updated MySubaru example script

This commit is contained in:
2025-05-27 23:28:13 -04:00
parent d2f8cfb4a6
commit 84501efa56
3 changed files with 15 additions and 158 deletions

View File

@ -2,60 +2,29 @@ package main
import (
"fmt"
"log/slog"
"log"
"os"
"git.savin.nyc/alex/mysubaru"
"git.savin.nyc/alex/mysubaru/config"
)
// var log = *slog.Logger
var cfg = &config.Config{}
const (
LoggingOutputJson = "JSON"
LoggingOutputText = "TEXT"
)
func configureLogging(config *config.Logging) *slog.Logger { //nolint:unparam
if config == nil {
return nil
}
var level slog.Level
if err := level.UnmarshalText([]byte(config.Level)); err != nil {
slog.Warn(err.Error())
slog.Warn(fmt.Sprintf("logging level not recognized, defaulting to level %s", slog.LevelInfo.String()))
level = slog.LevelInfo
}
var handler slog.Handler
switch config.Output {
case LoggingOutputJson:
handler = slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{AddSource: cfg.Logging.Source, Level: level})
case LoggingOutputText:
handler = slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{AddSource: cfg.Logging.Source, Level: level})
default:
handler = slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{AddSource: cfg.Logging.Source, Level: level})
}
return slog.New(handler)
}
func main() {
var err error
cfg, err = config.New()
if err != nil { // Handle errors reading the config file
slog.Error("Fatal error config file", "error", err.Error())
os.Exit(1)
configFile, err := os.ReadFile("config.yaml")
if err != nil {
log.Fatal(err)
}
logger := configureLogging(cfg.Logging)
cfg, err := config.FromBytes(configFile)
if err != nil {
log.Fatal(err)
}
cfg.Logger.Debug("printting config", "config", cfg)
logger.Debug("printting config", "config", cfg)
ms, _ := mysubaru.New(logger, &cfg.MySubaru)
ms, _ := mysubaru.New(cfg)
// mysubaru.selectVehicle("4S4BTGPD0P3199198")
// 11.6MMAN ABS_MIL ACCS AHBL_MIL ATF_MIL AWD_MIL BSD BSDRCT_MIL CEL_MIL EBD_MIL EOL_MIL EPAS_MIL EPB_MIL ESS_MIL EYESIGHT ISS_MIL NAV_TOMTOM OPL_MIL RAB_MIL RCC REARBRK RES RESCC RHSF RPOI RPOIA SRS_MIL TEL_MIL TIF_35 TIR_33 TPMS_MIL VDC_MIL WASH_MIL g2
@ -98,7 +67,6 @@ func main() {
// subaru.GetVehicleStatus()
// subaru.GetVehicleCondition()
// fmt.Printf("SUBARU: %+v\n", subaru)
// subaru.GetClimateQuickPresets()
// subaru.GetClimatePresets()
@ -127,4 +95,5 @@ func main() {
// subaru.LightsStop()
// subaru.GetLocation()
fmt.Printf("SUBARU: %+v\n", subaru)
}

View File

@ -2,24 +2,13 @@ module example
go 1.24
require git.savin.nyc/alex/mysubaru v0.0.0-20250522033415-67b9d218a741
require git.savin.nyc/alex/mysubaru v0.0.0-20250528030529-0fb499633428
require (
github.com/Jeffail/gabs/v2 v2.7.0 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/sagikazarmark/locafero v0.9.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.14.0 // indirect
github.com/spf13/cast v1.8.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/spf13/viper v1.20.1 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.25.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
resty.dev/v3 v3.0.0-beta.3 // indirect
)