diff --git a/client.go b/client.go index 68481e0..2478829 100644 --- a/client.go +++ b/client.go @@ -3,6 +3,7 @@ package mysubaru import ( "encoding/json" "fmt" + "io" "log/slog" "net/http" "sync" @@ -10,7 +11,7 @@ import ( "git.savin.nyc/alex/mysubaru/config" "github.com/Jeffail/gabs/v2" - "github.com/go-resty/resty/v2" + "resty.dev/v3" ) // credentials . @@ -252,7 +253,7 @@ func (c *Client) listDevices() { fmt.Println(" Status Code:", resp.StatusCode()) fmt.Println(" Status :", resp.Status()) fmt.Println(" Proto :", resp.Proto()) - fmt.Println(" Time :", resp.Time()) + fmt.Println(" Time :", resp.Duration()) fmt.Println(" Received At:", resp.ReceivedAt()) // fmt.Println(" Body :\n", resp) fmt.Println() @@ -271,7 +272,7 @@ func (c *Client) listDevices() { fmt.Println(" IsConnWasIdle :", ti.IsConnWasIdle) fmt.Println(" ConnIdleTime :", ti.ConnIdleTime) fmt.Println(" RequestAttempt:", ti.RequestAttempt) - fmt.Println(" RemoteAddr :", ti.RemoteAddr.String()) + fmt.Println(" RemoteAddr :", ti.RemoteAddr) // c.log.Debug("LIST DEVICES OUTPUT", "body", string([]byte(resp.Body()))) @@ -785,20 +786,24 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str Post(requestUrl) } } - - respParsed, err := gabs.ParseJSON([]byte(resp.Body())) + resBytes, _ := io.ReadAll(resp.Body) + // if err != nil { + // fmt.Println(err) + // return + // } + respParsed, err := gabs.ParseJSON(resBytes) if err != nil { panic(err) } - c.log.Debug("HTTP OUTPUT", "body", string(resp.Body())) + c.log.Debug("HTTP OUTPUT", "body", string(resBytes)) _, ok := respParsed.Path("success").Data().(bool) // value == string, ok == false if !ok { // TODO: Work with errorCode // panic(success) - fmt.Printf("ERROR: %+v", string([]byte(resp.Body()))) + fmt.Printf("ERROR: %+v", string(resBytes)) } if pollingUrl != "" { @@ -817,10 +822,10 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str }). Get(pollingUrl) - c.log.Debug("POLLING HTTP OUTPUT", "body", string([]byte(resp.Body()))) + c.log.Debug("POLLING HTTP OUTPUT", "body", string(resBytes)) // {"success":false,"errorCode":"404-soa-unableToParseResponseBody","dataName":"errorResponse","data":{"errorLabel":"404-soa-unableToParseResponseBody","errorDescription":null}} - respParsed, err := gabs.ParseJSON(resp.Body()) + respParsed, err := gabs.ParseJSON(resBytes) if err != nil { panic(err) } @@ -849,7 +854,7 @@ func (c *Client) execute(requestUrl string, method string, params map[string]str // fmt.Printf("[DEBUG] HTTP OUTPUT >> %v\n", string([]byte(resp.Body()))) - return resp.Body() + return resBytes } // isResponseSuccessfull . diff --git a/example/go.mod b/example/go.mod index 336ff45..24aad08 100644 --- a/example/go.mod +++ b/example/go.mod @@ -2,7 +2,7 @@ module example go 1.24 -require git.savin.nyc/alex/mysubaru v0.0.0-20250521042901-f241375645e3 +require git.savin.nyc/alex/mysubaru v0.0.0-20250521052308-a803671a3ce2 require ( github.com/Jeffail/gabs/v2 v2.7.0 // indirect diff --git a/go.mod b/go.mod index fd85179..99f7cc1 100644 --- a/go.mod +++ b/go.mod @@ -4,34 +4,23 @@ go 1.24 require ( github.com/Jeffail/gabs/v2 v2.7.0 - github.com/go-resty/resty/v2 v2.16.5 - github.com/sirupsen/logrus v1.9.3 github.com/spf13/viper v1.20.1 + resty.dev/v3 v3.0.0-beta.3 ) require ( github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/go-viper/mapstructure/v2 v2.2.1 // indirect - github.com/hashicorp/hcl v1.0.0 // indirect - github.com/magiconair/properties v1.8.10 // indirect - github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/sagikazarmark/locafero v0.9.0 // indirect - github.com/sagikazarmark/slog-shim v0.1.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/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.6 // indirect github.com/subosito/gotenv v1.6.0 // indirect - go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // 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/ini.v1 v1.67.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/vehicle.go b/vehicle.go index 6dea8ec..756cf48 100644 --- a/vehicle.go +++ b/vehicle.go @@ -919,7 +919,9 @@ func (v *Vehicle) GetVehicleStatus() { v.DistanceToEmpty.Kilometers = vSta.DistanceToEmptyFuelKilometers v.DistanceToEmpty.Miles10s = vSta.DistanceToEmptyFuelMiles10s v.DistanceToEmpty.Kilometers10s = vSta.DistanceToEmptyFuelKilometers10s - v.DistanceToEmpty.Percentage = vSta.RemainingFuelPercent + if vSta.RemainingFuelPercent >= 0 && vSta.RemainingFuelPercent <= 100 { + v.DistanceToEmpty.Percentage = vSta.RemainingFuelPercent + } v.FuelConsumptionAvg.MPG = float64(vSta.AvgFuelConsumptionMpg) v.FuelConsumptionAvg.LP100Km = float64(vSta.AvgFuelConsumptionLitersPer100Kilometers) @@ -940,11 +942,13 @@ func (v *Vehicle) GetVehicleStatus() { for _, element := range submatchall { fmt.Println(element) } + door := Door{} door.Position = submatchall[0] if len(submatchall) >= 3 { door.SubPosition = submatchall[1] } + door.Status = child.Data().(string) door.Updated = time.Now() v.Doors = append(v.Doors, &door) @@ -955,11 +959,13 @@ func (v *Vehicle) GetVehicleStatus() { for _, element := range submatchall { fmt.Println(element) } + door := Door{} door.Position = submatchall[0] if len(submatchall) >= 3 { door.SubPosition = submatchall[1] } + door.Status = child.Data().(string) door.Updated = time.Now() v.Doors = append(v.Doors, &door) @@ -970,11 +976,13 @@ func (v *Vehicle) GetVehicleStatus() { for _, element := range submatchall { fmt.Println(element) } + window := Window{} window.Position = submatchall[0] if len(submatchall) >= 3 { window.SubPosition = submatchall[1] } + window.Status = child.Data().(string) window.Updated = time.Now() v.Windows = append(v.Windows, &window)