-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add generic ioBroker vehicle template #33113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andig
wants to merge
3
commits into
master
Choose a base branch
from
iobroker-vehicle
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+283
−0
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| template: ioBroker.bmw | ||
| deprecated: true | ||
| products: | ||
| - description: | ||
| generic: ioBroker.bmw | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| {{ define "iobroker-get" }} | ||
| {{ .name }}: | ||
| source: http | ||
| uri: {{ .uri }}/rest-api/v1/state/{{ .state }}/plain?extraPlain=true | ||
| headers: | ||
| - accept: text/plain;charset=UTF-8 | ||
| cache: {{ .cache }} | ||
| {{- if .jq }} | ||
| quote: true | ||
| jq: {{ .jq }} | ||
| {{- end }} | ||
| {{- if .user }} | ||
| auth: | ||
| type: basic | ||
| user: {{ .user }} | ||
| password: {{ .password }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{ define "iobroker-set" }} | ||
| {{ .name }}: | ||
| source: http | ||
| uri: {{ .uri }}/rest-api/v1/state/{{ .state }}?value={{ .value }} | ||
| headers: | ||
| - accept: text/plain;charset=UTF-8 | ||
| {{- if .user }} | ||
| auth: | ||
| type: basic | ||
| user: {{ .user }} | ||
| password: {{ .password }} | ||
| {{- end }} | ||
| {{- end }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| template: iobroker | ||
| products: | ||
| - brand: ioBroker | ||
| group: generic | ||
| requirements: | ||
| evcc: ["skiptest"] | ||
| description: | ||
| de: | | ||
| Auf der verwendeten ioBroker Instanz muss der `rest-api` adapter (nicht `simple-api`) als Extension eines Web-Adapters installiert sein. | ||
| Authentifiziert werden kann nur mittels `basic` authentication. Wird kein Passwort angegeben, so wird keine Authentifizierung durchgeführt. | ||
| Bei der Angabe der Datenpunkte ist darauf zu achten, dass diese korrekt URL-Encoded sind. | ||
| So wird aus `bmw.0.WBA8E9G50GM091234#status` `bmw.0.WBA8E9G50GM091234%23status` | ||
| en: | | ||
| The `rest-api` adapter (not `simple-api`) must be installed as extension to a web adapter. | ||
| Authentication can only be performed using `basic` authentication. If no password is provided, no authentication will be performed. | ||
| When specifying the datapoints, ensure that they are correctly URL-encoded. | ||
| For example, `bmw.0.WBA8E9G50GM091234#status` becomes `bmw.0.WBA8E9G50GM091234%23status` | ||
| params: | ||
| - preset: vehicle-common | ||
| - name: uri | ||
| required: true | ||
| description: | ||
| en: The full uri of the host to query | ||
|
andig marked this conversation as resolved.
|
||
| de: Der vollständige URI der ioBroker Instanz | ||
|
andig marked this conversation as resolved.
|
||
| example: https://iobroker.homelab.lan:8082 | ||
| - name: cache | ||
| default: 15m | ||
| - name: user | ||
| - name: password | ||
| - name: soc | ||
| description: | ||
| de: Ladestand | ||
| en: State of charge | ||
| unit: "%" | ||
| type: string | ||
| required: true | ||
| example: bmw.0.WBA8E9G50GM091234.status.chargingLevelHv | ||
| - name: range | ||
| description: | ||
| de: Restreichweite | ||
| en: Remaining range | ||
| unit: km | ||
| type: string | ||
| - name: status | ||
| description: | ||
| de: Ladestatus | ||
| en: Charging status | ||
| type: string | ||
| help: | ||
| en: Datapoint for charge status (A=disconnected, B=connected, C=charging) | ||
| de: Datenpunkt für Ladestatus (A=getrennt, B=verbunden, C=laden) | ||
| - name: statusA | ||
| description: | ||
| de: Werte für Status A | ||
| en: Values for status A | ||
| example: not_plugged, disconnected | ||
| advanced: true | ||
| help: | ||
| en: Comma-separated list of datapoint values meaning disconnected | ||
| de: Komma-getrennte Liste von Datenpunkt-Werten für getrennt | ||
| - name: statusB | ||
| description: | ||
| de: Werte für Status B | ||
| en: Values for status B | ||
| example: CONNECTED, charging_stopped | ||
| advanced: true | ||
| help: | ||
| en: Comma-separated list of datapoint values meaning connected | ||
| de: Komma-getrennte Liste von Datenpunkt-Werten für verbunden | ||
| - name: statusC | ||
| description: | ||
| de: Werte für Status C | ||
| en: Values for status C | ||
| example: CHARGINGACTIVE, instant_charging | ||
| advanced: true | ||
| help: | ||
| en: Comma-separated list of datapoint values meaning charging | ||
| de: Komma-getrennte Liste von Datenpunkt-Werten für laden | ||
| - name: limitSoc | ||
| description: | ||
| de: Ladeziel | ||
| en: Charge limit | ||
| unit: "%" | ||
| type: string | ||
| advanced: true | ||
| - name: odometer | ||
| description: | ||
| de: Kilometerstand | ||
| en: Odometer | ||
| unit: km | ||
| type: string | ||
| advanced: true | ||
| - name: climater | ||
| description: | ||
| de: Vorklimatisierung | ||
| en: Preconditioning | ||
| type: string | ||
| advanced: true | ||
| - name: finishTime | ||
| description: | ||
| de: Geschätztes Ladeende | ||
| en: Estimated finish time | ||
| type: string | ||
| advanced: true | ||
| help: | ||
| en: Datapoint holding a timestamp, duration or remaining seconds | ||
| de: Datenpunkt mit Zeitstempel, Dauer oder verbleibenden Sekunden | ||
| - name: chargeEnable | ||
| description: | ||
| de: Laden starten/stoppen | ||
| en: Start/stop charging | ||
| type: string | ||
| advanced: true | ||
| help: | ||
| en: Writable datapoint, requires charging status. Only useful with the [docs.evcc.io](https://docs.evcc.io/en/docs/devices/chargers#vehicle-api-only-charger). | ||
| de: Beschreibbarer Datenpunkt, benötigt Ladestatus. Nur sinnvoll mit der [docs.evcc.io](https://docs.evcc.io/docs/devices/chargers#vehicle-api-only-charger). | ||
| - name: setMaxCurrent | ||
| description: | ||
| de: Ladestromstärke setzen | ||
| en: Set charging current | ||
| unit: A | ||
| type: string | ||
| advanced: true | ||
| help: | ||
| en: Writable datapoint, requires charging status | ||
| de: Beschreibbarer Datenpunkt, benötigt Ladestatus | ||
| - name: wakeup | ||
| description: | ||
| de: Fahrzeug aufwecken | ||
| en: Wake up vehicle | ||
| type: string | ||
| advanced: true | ||
| help: | ||
| en: Writable datapoint that wakes up the vehicle | ||
| de: Beschreibbarer Datenpunkt zum Aufwecken des Fahrzeugs | ||
| - preset: vehicle-features | ||
| render: | | ||
| type: custom | ||
| {{- include "common" . }} | ||
| {{- include "iobroker-get" (merge (dict "name" "soc" "state" .soc) .) }} | ||
| {{- if .range }} | ||
| {{- include "iobroker-get" (merge (dict "name" "range" "state" .range) .) }} | ||
| {{- end }} | ||
| {{- if .status }} | ||
| {{- $a := .statusA | nospace | splitList "," | compact }} | ||
| {{- $b := .statusB | nospace | splitList "," | compact }} | ||
| {{- $c := .statusC | nospace | splitList "," | compact }} | ||
| {{- $jq := "" }} | ||
| {{- if or $a $b $c }} | ||
| {{- $jq = printf "'. as $s | if %s | index($s) then \"C\" elif %s | index($s) then \"B\" elif %s | index($s) then \"A\" else $s end'" (toJson $c) (toJson $b) (toJson $a) }} | ||
| {{- end }} | ||
| {{- include "iobroker-get" (merge (dict "name" "status" "state" .status "jq" $jq) .) }} | ||
| {{- end }} | ||
| {{- if .limitSoc }} | ||
| {{- include "iobroker-get" (merge (dict "name" "limitsoc" "state" .limitSoc) .) }} | ||
| {{- end }} | ||
| {{- if .odometer }} | ||
| {{- include "iobroker-get" (merge (dict "name" "odometer" "state" .odometer) .) }} | ||
| {{- end }} | ||
| {{- if .climater }} | ||
| {{- include "iobroker-get" (merge (dict "name" "climater" "state" .climater) .) }} | ||
| {{- end }} | ||
| {{- if .finishTime }} | ||
| {{- include "iobroker-get" (merge (dict "name" "finishtime" "state" .finishTime) .) }} | ||
| {{- end }} | ||
| {{- if .chargeEnable }} | ||
| {{- include "iobroker-set" (merge (dict "name" "chargeenable" "state" .chargeEnable "value" "${chargeenable}") .) }} | ||
| {{- end }} | ||
| {{- if .setMaxCurrent }} | ||
| {{- include "iobroker-set" (merge (dict "name" "maxcurrent" "state" .setMaxCurrent "value" "${maxcurrent}") .) }} | ||
| {{- end }} | ||
| {{- if .wakeup }} | ||
| {{- include "iobroker-set" (merge (dict "name" "wakeup" "state" .wakeup "value" "${wakeup}") .) }} | ||
| {{- end }} | ||
| {{ include "features" . }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package vehicle | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/evcc-io/evcc/api" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestIobrokerTemplate verifies soc reading and the statusA/B/C value mapping | ||
| func TestIobrokerTemplate(t *testing.T) { | ||
| // datapoint id is the value it reports | ||
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| id, ok := strings.CutSuffix(strings.TrimPrefix(r.URL.Path, "/rest-api/v1/state/"), "/plain") | ||
| if !ok { | ||
| http.NotFound(w, r) | ||
| return | ||
| } | ||
| w.Write([]byte(id)) | ||
| })) | ||
| defer srv.Close() | ||
|
|
||
| for _, tc := range []struct { | ||
| status string | ||
| res api.ChargeStatus | ||
| err bool | ||
| }{ | ||
| {"CHARGINGACTIVE", api.StatusC, false}, | ||
| {"plugged", api.StatusB, false}, | ||
| {"A", api.StatusA, false}, | ||
| {"unknown", api.StatusNone, true}, | ||
| } { | ||
| t.Run(tc.status, func(t *testing.T) { | ||
| v, err := NewFromConfig(t.Context(), "template", map[string]any{ | ||
| "template": "iobroker", | ||
| "uri": srv.URL, | ||
| "soc": "42", | ||
| "status": tc.status, | ||
| "statusB": "CONNECTED, plugged", | ||
| "statusC": "CHARGINGACTIVE", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| soc, err := v.Soc() | ||
| require.NoError(t, err) | ||
| assert.Equal(t, 42.0, soc) | ||
|
|
||
| cs, ok := api.Cap[api.ChargeState](v) | ||
| require.True(t, ok) | ||
|
|
||
| s, err := cs.Status() | ||
| if tc.err { | ||
| assert.Error(t, err) | ||
| return | ||
| } | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tc.res, s) | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): The template enables Basic authentication when
.useris set, even if.passwordis absent. This contradicts the template's documented behavior that no password means no authentication and sends requests with an empty password instead of unauthenticated requests.Triggers: When a configuration supplies
userwithoutpassword.Suggested fix: Gate the
authblocks on.password(or on both.userand.password) so missing credentials do not enable Basic authentication.