diff --git a/consts.go b/consts.go index ab41ad0..99e377e 100644 --- a/consts.go +++ b/consts.go @@ -135,24 +135,24 @@ var features = map[string]string{ } var troubles = map[string]string{ + "SRS_MIL": "Airbag System", + "AWD_MIL": "All-Wheel Drive / Symmetrical Full-Time ", "ABS_MIL": "Anti-Lock Braking System", + "ISS_MIL": "Auto Start Stop (Idling Stop System)", "AHBL_MIL": "Automatic Headlight Beam Leveler", "ATF_MIL": "Automatic Transmission Oil Temperature", - "AWD_MIL": "Symmetrical Full-Time AWD", + "EBD_MIL": "Brake System / Electronic Brake Force Distribution", "BSDRCT_MIL": "Blind-Spot Detection", "CEL_MIL": "Check Engine Light", - "EBD_MIL": "Electronic Brake Force Distribution", "EOL_MIL": "Engine Oil Level", - "EPAS_MIL": "Electric Power Assisted Steering", - "EPB_MIL": "Parking Brake", "ESS_MIL": "EyeSight Exclusive Advanced Driver-Assist System", - "ISS_MIL": "iss", + "TEL_MIL": "MySubau Emergency Services", + "EPB_MIL": "Parking Brake", "OPL_MIL": "Oil Pressure", + "EPAS_MIL": "Power Steering / Electric Power Assisted Steering", "RAB_MIL": "Reverse Auto Braking", - "SRH_MIL": "Steering Responsive Headlights", - "SRS_MIL": "Airbag System", - "TEL_MIL": "telematics", - "TPMS_MIL": "tpms", + "SRH_MIL": "Steering Responsive Headlights (SRH)", + "TPMS_MIL": "Tire Pressure", "VDC_MIL": "Vehicle Dynamics Control", "WASH_MIL": "Windshield Washer Fluid Level", } diff --git a/vehicle.go b/vehicle.go index 71babc6..0b2bf37 100644 --- a/vehicle.go +++ b/vehicle.go @@ -5,6 +5,7 @@ import ( "fmt" "reflect" "regexp" + "slices" "strconv" "strings" "time" @@ -478,23 +479,23 @@ func (v *Vehicle) GetClimatePresets() { for _, cp := range cProfiles { if v.isEV() && cp.VehicleType == "phev" { if _, ok := v.ClimateProfiles[cp.PresetType+strings.ReplaceAll(cp.Name, " ", "")]; ok { - v.ClimateProfiles[cp.PresetType+cp.Name] = cp + v.ClimateProfiles[cp.PresetType+strings.ReplaceAll(cp.Name, " ", "")] = cp } else { if _, ok := v.ClimateProfiles[cp.PresetType+strings.ReplaceAll(cp.Name, " ", "")]; ok { - v.ClimateProfiles[cp.PresetType+cp.Name] = cp + v.ClimateProfiles[cp.PresetType+strings.ReplaceAll(cp.Name, " ", "")] = cp } else { - v.ClimateProfiles[cp.PresetType+cp.Name] = cp + v.ClimateProfiles[cp.PresetType+strings.ReplaceAll(cp.Name, " ", "")] = cp } } } if !v.isEV() && cp.VehicleType == "gas" { if _, ok := v.ClimateProfiles[cp.PresetType+strings.ReplaceAll(cp.Name, " ", "")]; ok { - v.ClimateProfiles[cp.PresetType+cp.Name] = cp + v.ClimateProfiles[cp.PresetType+strings.ReplaceAll(cp.Name, " ", "")] = cp } else { if _, ok := v.ClimateProfiles[cp.PresetType+strings.ReplaceAll(cp.Name, " ", "")]; ok { - v.ClimateProfiles[cp.PresetType+cp.Name] = cp + v.ClimateProfiles[cp.PresetType+strings.ReplaceAll(cp.Name, " ", "")] = cp } else { - v.ClimateProfiles[cp.PresetType+cp.Name] = cp + v.ClimateProfiles[cp.PresetType+strings.ReplaceAll(cp.Name, " ", "")] = cp } } } @@ -625,17 +626,9 @@ func (v *Vehicle) GetVehicleStatus() { val := reflect.ValueOf(vs) typeOfS := val.Type() + badValues := []any{"NOT_EQUIPPED", "UNKNOWN", "None", "16383", "65535", "-64", "", 0, float64(0), nil} for i := 0; i < val.NumField(); i++ { - if val.Field(i).Interface() == "NOT_EQUIPPED" || - val.Field(i).Interface() == "UNKNOWN" || - val.Field(i).Interface() == "None" || - val.Field(i).Interface() == "16383" || - val.Field(i).Interface() == "65535" || - val.Field(i).Interface() == "-64" || - val.Field(i).Interface() == "" || - val.Field(i).Interface() == 0 || - val.Field(i).Interface() == float64(0) || - val.Field(i).Interface() == nil { + if slices.Contains(badValues, val.Field(i).Interface()) { continue } else { v.client.logger.Debug("parsing a car part", "field", typeOfS.Field(i).Name, "value", val.Field(i).Interface(), "type", val.Field(i).Type()) @@ -682,17 +675,9 @@ func (v *Vehicle) GetVehicleCondition() { val := reflect.ValueOf(vc) typeOfS := val.Type() + badValues := []any{"NOT_EQUIPPED", "UNKNOWN", "None", "16383", "65535", "-64", "", 0, float64(0), nil} for i := 0; i < val.NumField(); i++ { - if val.Field(i).Interface() == "NOT_EQUIPPED" || - val.Field(i).Interface() == "UNKNOWN" || - val.Field(i).Interface() == "None" || - val.Field(i).Interface() == "16383" || - val.Field(i).Interface() == "65535" || - val.Field(i).Interface() == "-64" || - val.Field(i).Interface() == "" || - val.Field(i).Interface() == 0 || - val.Field(i).Interface() == float64(0) || - val.Field(i).Interface() == nil { + if slices.Contains(badValues, val.Field(i).Interface()) { continue } else { v.client.logger.Debug("parsing a car part", "field", typeOfS.Field(i).Name, "value", val.Field(i).Interface(), "type", val.Field(i).Type()) @@ -731,17 +716,18 @@ func (v *Vehicle) GetVehicleHealth() { v.client.logger.Error("error while parsing json", "request", "GetVehicleHealth", "error", err.Error()) } v.client.logger.Debug("http request output", "request", "GetVehicleHealth", "vehicle health", vh) - // TODO: Loop over all the Vehicle Health Items + for i, vhi := range vh.VehicleHealthItems { v.client.logger.Debug("vehicle health item", "id", i, "item", vhi) if vhi.IsTrouble { - // if contains(troubles, vhi.FeatureCode) {} + if _, ok := troubles[vhi.FeatureCode]; ok { + v.client.logger.Debug("found troubled vehicle health item", "id", i, "item", vhi) + } } } } else { v.client.logger.Error("active STARLINK Security Plus subscription required") } - } // GetFeaturesList .