first commit
This commit is contained in:
15
example/config.sample.yaml
Normal file
15
example/config.sample.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
credentials:
|
||||
username: user@email.com
|
||||
password: "Secr#TPassW0rd"
|
||||
pin: "PIN"
|
||||
deviceId: GENERATE-DEVICE-ID
|
||||
deviceName: Golang Integration
|
||||
mysubaru:
|
||||
region: USA
|
||||
mqtt:
|
||||
client_id: mysubaru
|
||||
username: mysubaru
|
||||
password:
|
||||
host: mqtt.hostname.com
|
||||
port: 1883
|
||||
log: info
|
129
example/example.go
Normal file
129
example/example.go
Normal file
@ -0,0 +1,129 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
mysubaru "github.com/alex-savin/go-mysubaru"
|
||||
"github.com/alex-savin/go-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)
|
||||
}
|
||||
|
||||
logger := configureLogging(cfg.Logging)
|
||||
|
||||
logger.Debug("printting config", "config", cfg)
|
||||
|
||||
ms, _ := mysubaru.New(logger, &cfg.MySubaru)
|
||||
// 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
|
||||
// subaru1 := mysubaru.GetVehicleByVIN("4S4BTGND8L3137058")
|
||||
// fmt.Printf("SUBARU #2 (Vehicle Status):\n")
|
||||
// subaru1.GetVehicleStatus()
|
||||
// fmt.Printf("SUBARU #2 (Vehicle Condition):\n")
|
||||
// subaru1.GetVehicleCondition()
|
||||
// fmt.Printf("SUBARU #1: %+v\n", subaru1)
|
||||
// fmt.Printf("GEN #1: %+v\n\n", subaru1.getAPIGen())
|
||||
|
||||
// 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 OPL_MIL PANPM-TUIRWAOC PWAAADWWAP RAB_MIL RCC REARBRK RES RESCC RHSF RPOI RPOIA RTGU RVFS SRH_MIL SRS_MIL TEL_MIL TIF_35 TIR_33 TLD TPMS_MIL VALET VDC_MIL WASH_MIL g3
|
||||
subaru := ms.GetVehicleByVIN("4S4BTGPD0P3199198")
|
||||
subaru.GetLocation(true)
|
||||
// subaru.EngineStart()
|
||||
fmt.Printf("SUBARU #1 (Vehicle Status):\n")
|
||||
subaru.GetVehicleStatus()
|
||||
// fmt.Printf("SUBARU #1 (Vehicle Condition):\n")
|
||||
// subaru.GetVehicleCondition()
|
||||
// fmt.Printf("SUBARU #1: %+v\n", subaru)
|
||||
// subaru.GetClimatePresets()
|
||||
// subaru.GetClimateUserPresets()
|
||||
// fmt.Printf("SUBARU #2: %+v\n", subaru)
|
||||
// subaru.GetVehicleHealth()
|
||||
// subaru.GetFeaturesList()
|
||||
|
||||
// subaru.LightsStart()
|
||||
// time.Sleep(10 * time.Second)
|
||||
// subaru.LightsStop()
|
||||
|
||||
// subaru := mysubaru.GetVehicles()[0]
|
||||
|
||||
// fmt.Printf("SUBARU: %+v\n", subaru)
|
||||
|
||||
// fmt.Printf("Subaru Gen: %+v\n\n", subaru.getAPIGen())
|
||||
|
||||
// subaru.EngineOn()
|
||||
// subaru.GetLocation(false)
|
||||
|
||||
// subaru.GetVehicleStatus()
|
||||
// subaru.GetVehicleCondition()
|
||||
// fmt.Printf("SUBARU: %+v\n", subaru)
|
||||
|
||||
// subaru.GetClimateQuickPresets()
|
||||
// subaru.GetClimatePresets()
|
||||
// subaru.GetClimateUserPresets()
|
||||
|
||||
// subaru.LightsStart()
|
||||
// time.Sleep(15 * time.Second)
|
||||
// subaru.LightsStop()
|
||||
|
||||
// subaru.listDevices()
|
||||
|
||||
// subaru.GetVehicleStatus()
|
||||
|
||||
// subaru.GetClimateSettings()
|
||||
|
||||
// subaru.EngineStart()
|
||||
// time.Sleep(15 * time.Second)
|
||||
// subaru.EngineStop()
|
||||
|
||||
// subaru.Unlock()
|
||||
// time.Sleep(20 * time.Second)
|
||||
// subaru.Lock()
|
||||
|
||||
// subaru.LightsStart()
|
||||
// time.Sleep(15 * time.Second)
|
||||
// subaru.LightsStop()
|
||||
|
||||
// subaru.GetLocation()
|
||||
}
|
31
example/go.mod
Normal file
31
example/go.mod
Normal file
@ -0,0 +1,31 @@
|
||||
module example
|
||||
|
||||
go 1.21
|
||||
|
||||
require github.com/alex-savin/go-mysubaru v0.0.0-20231207172256-23b354b0f2c1
|
||||
|
||||
require (
|
||||
github.com/Jeffail/gabs/v2 v2.7.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-resty/resty/v2 v2.10.0 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.11.0 // indirect
|
||||
github.com/spf13/cast v1.6.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/spf13/viper v1.18.0 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect
|
||||
golang.org/x/net v0.19.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
Reference in New Issue
Block a user