Home chargers: your own wallbox as a record, imported the way a car is
The Home chargers tab has been showing a hardcoded "Home charger · 11 kW · NACS" since it was drawn, and the control card asked for a serial as free text — a number printed on a box hanging in a garage, typed in by hand while the connected account already knew it. The garage solved the same problem for cars a while ago, so this is that solution aimed at the wall: pick the charger off a service you have connected, press Import, and it becomes a record of yours. A charger is a record rather than a live listing because it has to outlive the account it came from. Disconnect Anker and the wallbox is still on the wall; the integration is how the charger was found, not what it is. Hence home_chargers, owned by a person and not related to any car — it charges whichever car is plugged into it, and it outlives all of them — and hence no sharing: a charger is one household's business in a way a car shared with a partner is not. The provider layer is vehicleproviders.go's shape on purpose, down to the soft gate: a listing answers 200 with an empty list and the sentence that says what to do about a closed gate, a write answers 400, because there the caller asked for something that did not happen. Anker and Greencell are two adapters over plugins that already exist, so the next charger service is an adapter appended to chargerSources() and nothing else. What is deliberately absent is the car import's checkbox panel: a charger is a name, a serial and the hardware behind it, all of which the list already carries, so there is nothing to choose and the whole screen is pick one, press Import. Only the name is editable afterwards. The rest describes hardware and came from the service, and the provider link is written by the import endpoint alone, so renaming a charger cannot quietly orphan it from the account it tracks. Deleting one says as much in its confirmation: the charger is untouched, and importing it again brings the record straight back. The Anker gate moved into ankerGate() beside greencellGate(), because the same four-case switch was about to exist in a third place. Behaviour is unchanged — the same sentences, and the probe still skips the personal opt-in, since checking credentials is what you do before switching the integration on. The phone app still has the old tab; parity there is a separate change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
a809980d8b
commit
a3f69fa5ef
@@ -317,6 +317,24 @@ func (s *Server) ankerView(who *callerIdentity, res ankerResolution) map[string]
|
||||
return out
|
||||
}
|
||||
|
||||
// ankerGate returns the reason the integration cannot run for this caller, or ""
|
||||
// when it can. requireOptIn additionally demands the personal enable flag, which
|
||||
// a live probe deliberately does not: the probe is how you check credentials
|
||||
// before switching the integration on.
|
||||
func ankerGate(res ankerResolution, requireOptIn bool) string {
|
||||
switch {
|
||||
case !res.available:
|
||||
return "The Anker Solix integration is disabled by the administrator"
|
||||
case !res.orgEnabled:
|
||||
return "The Anker Solix integration is disabled for your organization"
|
||||
case requireOptIn && !res.enabled:
|
||||
return "Enable the Anker Solix integration in Settings to load your chargers"
|
||||
case strings.TrimSpace(res.eff.Email) == "" || strings.TrimSpace(res.eff.Password) == "":
|
||||
return "Enter your Anker account email and password to connect"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GET /api/integrations/anker-solix — resolved Anker Solix view for the caller.
|
||||
func (s *Server) handleGetAnker(w http.ResponseWriter, r *http.Request) {
|
||||
who := caller(r)
|
||||
@@ -454,18 +472,8 @@ func (s *Server) handleAnkerHealth(w http.ResponseWriter, r *http.Request) {
|
||||
userRaw := s.userPluginSettings(r.Context(), who.ID)
|
||||
res := s.resolveAnker(r.Context(), who, userRaw)
|
||||
|
||||
down := func(detail string) {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"health": map[string]any{"status": "down", "detail": detail}})
|
||||
}
|
||||
switch {
|
||||
case !res.available:
|
||||
down("The Anker Solix integration is disabled by the administrator")
|
||||
return
|
||||
case !res.orgEnabled:
|
||||
down("The Anker Solix integration is disabled for your organization")
|
||||
return
|
||||
case strings.TrimSpace(res.eff.Email) == "" || strings.TrimSpace(res.eff.Password) == "":
|
||||
down("Enter your Anker account email and password to connect")
|
||||
if reason := ankerGate(res, false); reason != "" {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"health": map[string]any{"status": "down", "detail": reason}})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -496,21 +504,8 @@ func (s *Server) handleAnkerChargers(w http.ResponseWriter, r *http.Request) {
|
||||
userRaw := s.userPluginSettings(r.Context(), who.ID)
|
||||
res := s.resolveAnker(r.Context(), who, userRaw)
|
||||
|
||||
unavailable := func(detail string) {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"chargers": []any{}, "unavailable": true, "detail": detail})
|
||||
}
|
||||
switch {
|
||||
case !res.available:
|
||||
unavailable("The Anker Solix integration is disabled by the administrator")
|
||||
return
|
||||
case !res.orgEnabled:
|
||||
unavailable("The Anker Solix integration is disabled for your organization")
|
||||
return
|
||||
case !res.enabled:
|
||||
unavailable("Enable the Anker Solix integration in Settings to load your chargers")
|
||||
return
|
||||
case strings.TrimSpace(res.eff.Email) == "" || strings.TrimSpace(res.eff.Password) == "":
|
||||
unavailable("Enter your Anker account email and password to connect")
|
||||
if reason := ankerGate(res, true); reason != "" {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"chargers": []any{}, "unavailable": true, "detail": reason})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user