Skip to content

Conversation

@dreadnought
Copy link
Contributor

Add support for optional authentication token for myStrom WiFi Switch devices. The token can be configured on the device to restrict API access. When a token is set on the device, it must be provided via the Token HTTP header in all API requests. Devices without a token configured continue to work as before.

The authentication is described in the Security section of their API documentation:
https://api.mystrom.ch/

Add support for optional authentication token for myStrom WiFi Switch devices. The token can be configured on the device to restrict API access. When a token is set on the device, it must be provided via the Token HTTP header in all API requests. Devices without a token configured continue to work as before.
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • The logic for attaching the Token header is duplicated in both Connection.Request and Connection.Report; consider centralizing this in a small helper (e.g., a method that builds requests with the base URI and optional token) to reduce repetition and keep future changes localized.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The logic for attaching the Token header is duplicated in both Connection.Request and Connection.Report; consider centralizing this in a small helper (e.g., a method that builds requests with the base URI and optional token) to reduce repetition and keep future changes localized.

## Individual Comments

### Comment 1
<location> `templates/definition/charger/mystrom.yaml:17-19` </location>
<code_context>
   type: mystrom
   uri: http://{{ .host }}
+  {{- if .token }}
+  token: {{ .token }}
+  {{- end }}
   {{ include "switchsocket" . }}
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Quote the rendered token value to avoid YAML parsing issues with special characters.

Unquoted tokens containing `:`, `#`, or braces can break YAML parsing. Please quote the interpolation (e.g. `token: "{{ .token }}"` or single quotes) so arbitrary token values are handled safely.

```suggestion
  {{- if .token }}
  token: "{{ .token }}"
  {{- end }}
```
</issue_to_address>

### Comment 2
<location> `templates/definition/meter/mystrom.yaml:19` </location>
<code_context>
   type: mystrom
   uri: http://{{ .host }}
+  {{- if .token }}
+  token: {{ .token }}
+  {{- end }}
   {{ include "switchsocket" . }}
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Similarly, quote the token value here to keep YAML robust for arbitrary token strings.

This also keeps it consistent with the charger template; please use `token: "{{ .token }}"` here.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

type: mystrom
uri: http://{{ .host }}
{{- if .token }}
token: {{ .token }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Similarly, quote the token value here to keep YAML robust for arbitrary token strings.

This also keeps it consistent with the charger template; please use token: "{{ .token }}" here.

@andig andig added the devices Specific device support label Jan 27, 2026
@dreadnought
Copy link
Contributor Author

Thanks for the feedback. I've applied and tested the suggested changes.

@andig andig merged commit f8d0980 into evcc-io:master Jan 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devices Specific device support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants