From 4244fbe98874e8708da3708a9208a84f791aab5e Mon Sep 17 00:00:00 2001 From: Alex Savin Date: Thu, 5 Jun 2025 14:29:54 -0400 Subject: [PATCH] Changes the way to parse parts --- go.mod | 6 +++--- workers/mysubaru.go | 16 +++++----------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index de8b370..7997923 100644 --- a/go.mod +++ b/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-20250604212821-af28d7b2eddf + git.savin.nyc/alex/mysubaru v0.0.0-20250605181433-57e0e7899dc0 github.com/eclipse/paho.mqtt.golang v1.5.0 github.com/hashicorp/consul/api v1.32.1 github.com/spf13/viper v1.20.1 @@ -43,9 +43,9 @@ require ( 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/sync v0.14.0 // indirect + golang.org/x/sync v0.15.0 // indirect golang.org/x/sys v0.33.0 // indirect - golang.org/x/text v0.25.0 // indirect + golang.org/x/text v0.26.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect resty.dev/v3 v3.0.0-beta.3 // indirect ) diff --git a/workers/mysubaru.go b/workers/mysubaru.go index e18d76b..ed10467 100644 --- a/workers/mysubaru.go +++ b/workers/mysubaru.go @@ -308,24 +308,18 @@ func (s *MySubaruClient) mySubaruConfigToMQTTHassioConfig(v *mysubaru.Vehicle) [ for n, d := range v.Doors { // homeassistant/sensor/mysubaru/VIN-NUMBER-HERE/door_frontleft_status/config - position := d.Position - if len(d.SubPosition) > 0 { - position = position + ` ` + d.SubPosition - } - hassioConfig[s.config.Hassio.Topics.Discovery+`/sensor/`+v.Vin+`/door_`+n+`_status/config`] = `{` + device + origin + topic + `"name":"Door ` + position + ` Status","uniq_id":"` + v.Vin + `_door_` + n + `_status","obj_id":"` + obj_id_prefix + `_door_` + n + `_status","ic":"mdi:car-door","stat_t":"mysubarumq/` + v.Vin + `/doors/state","val_tpl":"{{value_json.` + n + `}}"}` + position := d.Position + ` ` + d.SubPosition + hassioConfig[s.config.Hassio.Topics.Discovery+`/sensor/`+v.Vin+`/`+n+`_status/config`] = `{` + device + origin + topic + `"name":"Door ` + position + ` Status","uniq_id":"` + v.Vin + n + `_status","obj_id":"` + obj_id_prefix + n + `_status","ic":"mdi:car-door","stat_t":"mysubarumq/` + v.Vin + `/doors/state","val_tpl":"{{value_json.` + n + `}}"}` } for n, w := range v.Windows { // homeassistant/sensor/mysubaru/VIN-NUMBER-HERE/window_frontleft/config - position := w.Position - if len(w.SubPosition) > 0 { - position = position + ` ` + w.SubPosition - } - hassioConfig[s.config.Hassio.Topics.Discovery+`/sensor/`+v.Vin+`/window_`+n+`/config`] = `{` + device + origin + topic + `"name":"Window ` + position + `","uniq_id":"` + v.Vin + `_window_` + n + `","obj_id":"` + obj_id_prefix + `_window_` + n + `","ic":"mdi:car-door","stat_t":"mysubarumq/` + v.Vin + `/windows/state","val_tpl":"{{value_json.window_` + n + `}}"}` + position := w.Position + ` ` + w.SubPosition + hassioConfig[s.config.Hassio.Topics.Discovery+`/sensor/`+v.Vin+`/`+n+`/config`] = `{` + device + origin + topic + `"name":"Window ` + position + `","uniq_id":"` + v.Vin + n + `_status","obj_id":"` + obj_id_prefix + n + `_status","ic":"mdi:car-door","stat_t":"mysubarumq/` + v.Vin + `/windows/state","val_tpl":"{{value_json.` + n + `}}"}` } for n, t := range v.Tires { // homeassistant/sensor/mysubaru/VIN-NUMBER-HERE/tire_frontleft_psi/config position := t.Position + ` ` + t.SubPosition - hassioConfig[s.config.Hassio.Topics.Discovery+`/sensor/`+v.Vin+`/tire_`+n+`_psi/config`] = `{` + device + origin + topic + `"name":"Tire ` + position + ` (Psi)","uniq_id":"` + v.Vin + `_tire_` + n + `_psi","obj_id":"` + obj_id_prefix + `_tire_` + n + `_psi","ic":"mdi:car-tire-alert","stat_t":"mysubarumq/` + v.Vin + `/tires/state","val_tpl":"{{value_json.tire_` + n + `}}"}` + hassioConfig[s.config.Hassio.Topics.Discovery+`/sensor/`+v.Vin+`/`+n+`_psi/config`] = `{` + device + origin + topic + `"name":"Tire ` + position + ` (Psi)","uniq_id":"` + v.Vin + n + `_psi","obj_id":"` + obj_id_prefix + n + `_psi","ic":"mdi:car-tire-alert","stat_t":"mysubarumq/` + v.Vin + `/tires/state","val_tpl":"{{value_json.` + n + `}}"}` } topicState := `mysubarumq/` + v.Vin + `/ignition`