Toyota Connected: Toyota, Lexus and Subaru as three plugins
One connector, registered once per brand with the brand fixed, so the
panel, the Web App and the Phone App each list Toyota, Lexus and Subaru
separately: own card, own account, own enable switch, own
/api/integrations/{brand} routes and vehicle provider. The brand picker
is gone.
Settings saved before the split under pluginSettings.toyota with brand
L or S move onto their brand's key on read, and are written back on the
next save. Cars linked as provider "toyota" read through their make's
brand.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9d8636ee73
commit
914aeeee23
21 files changed
+837
-471
No files matched your search
@@ -49,6 +49,7 @@ import (
|
||||
|
||||
"drivervault/apiserver/internal/models"
|
||||
"drivervault/apiserver/internal/plugins"
|
||||
"drivervault/apiserver/internal/plugins/builtin/toyota"
|
||||
)
|
||||
|
||||
// vehicleSource adapts one plugin that can enumerate the caller's vehicles and
|
||||
@@ -73,9 +74,30 @@ type vehicleSource interface {
|
||||
sections() []providerSection
|
||||
}
|
||||
|
||||
// vehicleSources are the registered providers, in menu order.
|
||||
// vehicleSources are the registered providers, in menu order: one per brand of
|
||||
// the Toyota Connected Europe connector.
|
||||
func vehicleSources() []vehicleSource {
|
||||
return []vehicleSource{toyotaSource{}}
|
||||
out := make([]vehicleSource, 0, len(toyota.Brands))
|
||||
for _, b := range toyota.Brands {
|
||||
out = append(out, toyotaSource{b})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// carVehicleSource is the provider a linked car reads from. A Lexus or a Subaru
|
||||
// linked before the brands were split carries provider "toyota" — there was only
|
||||
// the one — so its make picks the brand it now belongs to; reading it through
|
||||
// the Toyota account would log in to the wrong app.
|
||||
func carVehicleSource(provider, carMake string) (vehicleSource, bool) {
|
||||
if provider == toyotaBrand.Name && strings.TrimSpace(carMake) != "" {
|
||||
mk := toyotaMake(carMake)
|
||||
for _, b := range toyota.Brands {
|
||||
if b.Make == mk {
|
||||
return toyotaSource{b}, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return vehicleSourceByID(provider)
|
||||
}
|
||||
|
||||
func vehicleSourceByID(id string) (vehicleSource, bool) {
|
||||
@@ -282,8 +304,13 @@ func (s *Server) linkedVehicles(ctx context.Context, userID, provider string) ma
|
||||
if userID == "" || provider == "" {
|
||||
return out
|
||||
}
|
||||
filter := fmt.Sprintf("provider='%s'", provider)
|
||||
if b, ok := brandByName(provider); ok && b.Name != toyotaBrand.Name {
|
||||
// Cars of this brand linked before the split are under "toyota".
|
||||
filter = fmt.Sprintf("(%s || (provider='%s' && make='%s'))", filter, toyotaBrand.Name, b.Make)
|
||||
}
|
||||
res, err := s.pb.List(ctx, colCars, url.Values{
|
||||
"filter": {fmt.Sprintf("owner='%s' && provider='%s'", userID, provider)},
|
||||
"filter": {fmt.Sprintf("owner='%s' && %s", userID, filter)},
|
||||
"perPage": {"200"},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -531,7 +558,7 @@ func (s *Server) handleCarProvider(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, http.StatusNotFound, "this car is not linked to a connected service")
|
||||
return
|
||||
}
|
||||
src, found := vehicleSourceByID(rec.Provider)
|
||||
src, found := carVehicleSource(rec.Provider, rec.Make)
|
||||
if !found {
|
||||
writeError(w, http.StatusNotFound, "unknown vehicle provider")
|
||||
return
|
||||
@@ -822,7 +849,7 @@ func (s *Server) handleSyncCarProvider(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, http.StatusBadRequest, "this car is not linked to a connected service")
|
||||
return
|
||||
}
|
||||
src, found := vehicleSourceByID(rec.Provider)
|
||||
src, found := carVehicleSource(rec.Provider, rec.Make)
|
||||
if !found {
|
||||
writeError(w, http.StatusNotFound, "unknown vehicle provider")
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user