diff --git a/example/example.go b/example/example.go index 0f66baa..7528916 100644 --- a/example/example.go +++ b/example/example.go @@ -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) } diff --git a/example/go.mod b/example/go.mod index 27b3dfd..5ce6900 100644 --- a/example/go.mod +++ b/example/go.mod @@ -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 ) diff --git a/vehicle.go b/vehicle.go index 5518a0d..1e10c11 100644 --- a/vehicle.go +++ b/vehicle.go @@ -380,41 +380,6 @@ func (v *Vehicle) HornStop() { // ChargeStart . func (v *Vehicle) ChargeOn() { - // { - // "success": true, - // "errorCode": null, - // "dataName": "remoteServiceStatus", - // "data": { - // "serviceRequestId": "4S4BTGND8L3137058_1640542818241_31_@NGTP", - // "success": false, - // "cancelled": false, - // "remoteServiceType": "phevChargeNow", - // "remoteServiceState": "started", - // "subState": null, - // "errorCode": null, - // "result": null, - // "updateTime": null, - // "vin": "4S4BTGND8L3137058" - // } - // } - // { - // "success": true, - // "errorCode": null, - // "dataName": "remoteServiceStatus", - // "data": { - // "serviceRequestId": "4S4BTGND8L3137058_1640542818241_31_@NGTP", - // "success": false, - // "cancelled": false, - // "remoteServiceType": "phevChargeNow", - // "remoteServiceState": "finished", - // "subState": null, - // "errorCode": "NegativeAcknowledge:unknown", - // "result": null, - // "updateTime": 1640542824000, - // "vin": "4S4BTGND8L3137058" - // } - // } - if v.isEV() { v.selectVehicle() params := map[string]string{ @@ -430,46 +395,6 @@ func (v *Vehicle) ChargeOn() { // GetLocation . func (v *Vehicle) GetLocation(force bool) { if force { // Sends a locate command to the vehicle to get real time position - // { - // "success": true, - // "errorCode": null, - // "dataName": "remoteServiceStatus", - // "data": { - // "serviceRequestId": "4S4BTGND8L3137058_1640454589498_11_@NGTP", - // "success": false, - // "cancelled": false, - // "remoteServiceType": "vehicleStatus", - // "remoteServiceState": "started", - // "subState": null, - // "errorCode": null, - // "result": null, - // "updateTime": 1640454589000, - // "vin": "4S4BTGND8L3137058" - // } - // } - // { - // "success": true, - // "errorCode": null, - // "dataName": "remoteServiceStatus", - // "data": { - // "serviceRequestId": null, - // "success": true, - // "cancelled": false, - // "remoteServiceType": "locate", - // "remoteServiceState": "finished", - // "subState": null, - // "errorCode": null, - // "result": { - // "latitude": 40.700294, - // "longitude": -74.401344, - // "speed": 0, - // "heading": 189, - // "timestamp": 1640454600000 - // }, - // "updateTime": null, - // "vin": "4S4BTGND8L3137058" - // } - // } v.selectVehicle() reqURL := MOBILE_API_VERSION + apiURLs["API_G2_LOCATE_UPDATE"] pollingURL := MOBILE_API_VERSION + apiURLs["API_G2_LOCATE_STATUS"] @@ -482,29 +407,6 @@ func (v *Vehicle) GetLocation(force bool) { } v.client.execute(reqURL, POST, params, pollingURL, true) } else { // Reports the last location the vehicle has reported to Subaru - // { - // "success": true, - // "errorCode": null, - // "dataName": "remoteServiceStatus", - // "data": { - // "serviceRequestId": null, - // "success": true, - // "cancelled": false, - // "remoteServiceType": "locate", - // "remoteServiceState": "finished", - // "subState": null, - // "errorCode": null, - // "result": { - // "latitude": 40.700203, - // "longitude": -74.40142, - // "speed": 0, - // "heading": 156, - // "timestamp": 1642526388000 - // }, - // "updateTime": null, - // "vin": "4S4BTGND8L3137058" - // } - // } v.selectVehicle() params := map[string]string{ "vin": v.Vin, @@ -517,9 +419,6 @@ func (v *Vehicle) GetLocation(force bool) { // GetClimateQuickPresets . func (v *Vehicle) GetClimateQuickPresets() { if v.getRemoteOptionsStatus() { - // params := map[string]string{ - // "vin": v.Vin, - // "pin": v.Client.credentials.PIN} v.selectVehicle() reqURL := MOBILE_API_VERSION + apiURLs["API_G2_FETCH_RES_QUICK_START_SETTINGS"] resp := v.client.execute(reqURL, GET, map[string]string{}, "", false)