Update go.mod dependencies and improve vehicle retrieval error handling
This commit is contained in:
14
go.mod
14
go.mod
@ -5,7 +5,7 @@ go 1.24
|
||||
replace github.com/armon/go-metrics => github.com/hashicorp/go-metrics v0.5.3
|
||||
|
||||
require (
|
||||
git.savin.nyc/alex/mysubaru v0.0.0-20250609164614-21a928bf7040
|
||||
git.savin.nyc/alex/mysubaru v0.0.0-20250722205404-92d4266f8b5a
|
||||
github.com/eclipse/paho.mqtt.golang v1.5.0
|
||||
github.com/hashicorp/consul/api v1.32.1
|
||||
github.com/spf13/viper v1.20.1
|
||||
@ -17,7 +17,7 @@ require (
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/fatih/color v1.18.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.3 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||
@ -38,14 +38,14 @@ require (
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.14.0 // indirect
|
||||
github.com/spf13/cast v1.9.2 // indirect
|
||||
github.com/spf13/pflag v1.0.6 // indirect
|
||||
github.com/spf13/pflag v1.0.7 // indirect
|
||||
github.com/subosito/gotenv v1.6.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.41.0 // indirect
|
||||
golang.org/x/sync v0.15.0 // indirect
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/text v0.26.0 // indirect
|
||||
golang.org/x/net v0.42.0 // indirect
|
||||
golang.org/x/sync v0.16.0 // indirect
|
||||
golang.org/x/sys v0.34.0 // indirect
|
||||
golang.org/x/text v0.27.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
resty.dev/v3 v3.0.0-beta.3 // indirect
|
||||
)
|
||||
|
@ -71,7 +71,10 @@ func (s *MySubaruClient) Init(log *slog.Logger) error {
|
||||
func (s *MySubaruClient) OneTime() error {
|
||||
if s.config.Hassio.AutoDiscovery {
|
||||
time.Sleep(3 * time.Second)
|
||||
vehicles := s.mysubaru.GetVehicles()
|
||||
vehicles, err := s.mysubaru.GetVehicles()
|
||||
if err != nil {
|
||||
s.log.Error("couldn't get vehicles from MySubaru", "error", err.Error())
|
||||
}
|
||||
|
||||
for _, vehicle := range vehicles {
|
||||
err := s.bus.Publish("mqtt:publish", s.mySubaruConfigToMQTTHassioConfig(vehicle))
|
||||
@ -148,7 +151,7 @@ func (s *MySubaruClient) Serve() {
|
||||
for {
|
||||
select {
|
||||
case <-tickerS.C:
|
||||
vehicles := s.mysubaru.GetVehicles()
|
||||
vehicles, _ := s.mysubaru.GetVehicles()
|
||||
for _, vehicle := range vehicles {
|
||||
err := s.bus.Publish("mqtt:publish", s.mySubaruStatusToMQTTMessage(vehicle))
|
||||
if err != nil {
|
||||
@ -156,7 +159,7 @@ func (s *MySubaruClient) Serve() {
|
||||
}
|
||||
}
|
||||
case <-tickerM.C:
|
||||
vehicles := s.mysubaru.GetVehicles()
|
||||
vehicles, _ := s.mysubaru.GetVehicles()
|
||||
for _, vehicle := range vehicles {
|
||||
vehicle.GetLocation(true)
|
||||
err := s.bus.Publish("mqtt:publish", s.mySubaruStatusToMQTTMessage(vehicle))
|
||||
@ -195,14 +198,14 @@ func (s *MySubaruClient) eventLoop(ctx context.Context, chMQTTLockStatus, chMQTT
|
||||
for _, message := range event.Data.([]*bus.Message) {
|
||||
s.log.Debug("received a message with mysubary lock status", "topic", message.Topic, "payload", message.Payload)
|
||||
if message.Payload == "LOCK" {
|
||||
v := s.mysubaru.GetVehicleByVIN("4S4BTGPD0P3199198")
|
||||
v, _ := s.mysubaru.GetVehicleByVin("4S4BTGPD0P3199198")
|
||||
v.Lock()
|
||||
var msgs []*bus.Message
|
||||
msgs = s.messages("mysubarumq/4S4BTGPD0P3199198/lock", 0, true, "LOCK", msgs)
|
||||
s.bus.Publish("mqtt:publish", msgs)
|
||||
}
|
||||
if message.Payload == "UNLOCK" {
|
||||
v := s.mysubaru.GetVehicleByVIN("4S4BTGPD0P3199198")
|
||||
v, _ := s.mysubaru.GetVehicleByVin("4S4BTGPD0P3199198")
|
||||
v.Unlock()
|
||||
var msgs []*bus.Message
|
||||
msgs = s.messages("mysubarumq/4S4BTGPD0P3199198/lock", 0, true, "UNLOCK", msgs)
|
||||
@ -213,14 +216,14 @@ func (s *MySubaruClient) eventLoop(ctx context.Context, chMQTTLockStatus, chMQTT
|
||||
for _, message := range event.Data.([]*bus.Message) {
|
||||
s.log.Debug("received a message with mysubary ignition status", "topic", message.Topic, "payload", message.Payload)
|
||||
if message.Payload == "ON" {
|
||||
v := s.mysubaru.GetVehicleByVIN("4S4BTGPD0P3199198")
|
||||
v.EngineStart()
|
||||
v, _ := s.mysubaru.GetVehicleByVin("4S4BTGPD0P3199198")
|
||||
v.EngineStart(10, 0, false)
|
||||
var msgs []*bus.Message
|
||||
msgs = s.messages("mysubarumq/4S4BTGPD0P3199198/ignition", 0, true, "ON", msgs)
|
||||
s.bus.Publish("mqtt:publish", msgs)
|
||||
}
|
||||
if message.Payload == "OFF" {
|
||||
v := s.mysubaru.GetVehicleByVIN("4S4BTGPD0P3199198")
|
||||
v, _ := s.mysubaru.GetVehicleByVin("4S4BTGPD0P3199198")
|
||||
v.EngineStop()
|
||||
var msgs []*bus.Message
|
||||
msgs = s.messages("mysubarumq/4S4BTGPD0P3199198/ignition", 0, true, "OFF", msgs)
|
||||
@ -375,7 +378,7 @@ func (s *MySubaruClient) mySubaruStatusToMQTTMessage(v *mysubaru.Vehicle) []*bus
|
||||
tank = `"dist_to_empty_pc":` + strconv.Itoa(v.DistanceToEmpty.Percentage) + `,`
|
||||
}
|
||||
state[`mysubarumq/`+v.Vin+`/state`] = `{` + tank + `"odometer_km":` + strconv.Itoa(v.Odometer.Kilometers) + `,"odometer_mi":` + strconv.Itoa(v.Odometer.Miles) + `,"dist_to_empty_km":` + strconv.Itoa(v.DistanceToEmpty.Kilometers) + `,"dist_to_empty_mi":` + strconv.Itoa(v.DistanceToEmpty.Miles) + `,"consumption_us":` + fmt.Sprintf("%.2f", v.FuelConsumptionAvg.MPG) + `,"consumption_eu":` + fmt.Sprintf("%.2f", v.FuelConsumptionAvg.LP100Km) + `,"engine_state":"` + v.EngineState + `","troubles":"` + strconv.Itoa(len(v.Troubles)) + `"}`
|
||||
state[`mysubarumq/`+v.Vin+`/attr`] = `{"source_type":"gps","latitude":` + fmt.Sprintf("%.6f", v.GeoLocation.Latitude) + `,"longitude":` + fmt.Sprintf("%.6f", v.GeoLocation.Longitude) + `,"course":` + strconv.Itoa(v.GeoLocation.Heading) + `,"speed":` + fmt.Sprintf("%.2f", v.GeoLocation.Speed) + `,"friendly_name":"` + v.CarNickname + `"}`
|
||||
state[`mysubarumq/`+v.Vin+`/attr`] = `{"source_type":"gps","latitude":` + fmt.Sprintf("%.6f", v.GeoLocation.Latitude) + `,"longitude":` + fmt.Sprintf("%.6f", v.GeoLocation.Longitude) + `,"course":` + strconv.Itoa(v.GeoLocation.Heading) + `,"speed":` + fmt.Sprintf("%d", v.GeoLocation.Speed) + `,"friendly_name":"` + v.CarNickname + `"}`
|
||||
|
||||
// Doors
|
||||
doors := `{`
|
||||
|
Reference in New Issue
Block a user