-
Notifications
You must be signed in to change notification settings - Fork 41
Add Naturstrom #1022
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
Merged
benderl
merged 10 commits into
openWB:main
from
AlexanderHa98:feature_Naturstrom-tariffs
Aug 6, 2026
Merged
Add Naturstrom #1022
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e2a6547
Add Naturstrom
AlexanderHa98 fe873d2
Add suggestions
AlexanderHa98 b02391d
Remove Warning
AlexanderHa98 537d1cb
Change Auth to local
AlexanderHa98 86896b6
Fix lint error
AlexanderHa98 bfdffb5
Change URL to Code
AlexanderHa98 bf841f9
Change callback to JSON
AlexanderHa98 ac4625f
Fix default text-input
AlexanderHa98 3d77ce1
Add requested changes
AlexanderHa98 285bea3
Update to PROD-URL
AlexanderHa98 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
213 changes: 213 additions & 0 deletions
213
src/components/electricity_pricing/flexible_tariffs/naturstrom/flexible_tariff.vue
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,213 @@ | ||
| <template> | ||
| <div class="flexible-tariff-naturstrom"> | ||
| <openwb-base-alert subtype="info"> | ||
| Über die Naturstrom-Authentifizierung kannst Du Deine Stromtarif-Daten für die Ladeplanung nutzen. Nach der Anmeldung | ||
| bei Naturstrom wird eine Access- und Refresh-Token angezeigt, welche Du hier einfügen musst. | ||
| </openwb-base-alert> | ||
| <openwb-base-alert subtype="warning"> | ||
| Die Naturstrom-Authentifizierung kann nur über einen Computer oder die openWB-Cloud (remote.openwb.de) durchgeführt | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
| werden. Das Eintragen von Kunden- und Vertragsnummer ist nicht ausreichend, da nach der Anmeldung bei Naturstrom noch | ||
| die Zustimmung erteilt werden muss. | ||
| </openwb-base-alert> | ||
|
|
||
| <openwb-base-button-input | ||
| title="1. Bei Naturstrom anmelden" | ||
|
benderl marked this conversation as resolved.
|
||
| button-text="Bei Naturstrom Anmelden" | ||
| subtype="success" | ||
| @button-clicked="() => naturstrom_login_window()" | ||
| > | ||
| <template #help> | ||
| Es wird ein neues Browserfenster geöffnet, in dem Du Dich bei Naturstrom mit Deinen Zugangsdaten anmelden kannst. | ||
| </template> | ||
| </openwb-base-button-input> | ||
|
|
||
| <openwb-base-text-input | ||
| ref="tokenInput" | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
| title="Access-Token" | ||
| required | ||
| pattern="^ory_at_.*$" | ||
| :model-value="flexibleTariff.configuration.token?.access_token || ''" | ||
| @update:model-value="updateConfiguration($event, 'configuration.token.access_token')" | ||
| > | ||
|
benderl marked this conversation as resolved.
|
||
| <template #help> | ||
| Nachdem die Naturstrom-Authentifizierung abgeschlossen wurde, wird im geöffneten Browserfenster eine Access-Token | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
| angezeigt. Dieses kopieren und hier einfügen. Dieses wird benötigt, um auf Ihre Tarif-Daten zugreifen zu können. | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
| </template> | ||
| </openwb-base-text-input> | ||
|
|
||
| <openwb-base-text-input | ||
| ref="tokenInput" | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
| title="Refresh-Token" | ||
| required | ||
| pattern="^ory_rt_.*$" | ||
| :model-value="flexibleTariff.configuration.token?.refresh_token || ''" | ||
| @update:model-value="updateConfiguration($event, 'configuration.token.refresh_token')" | ||
| > | ||
|
benderl marked this conversation as resolved.
|
||
| <template #help> | ||
| Nachdem die Naturstrom-Authentifizierung abgeschlossen wurde, wird im geöffneten Browserfenster eine Refresh-Token | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
| angezeigt. Dieses kopieren und hier einfügen. Dieses wird benötigt, um auf Ihre Tarif-Daten zugreifen zu können. | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
| </template> | ||
| </openwb-base-text-input> | ||
|
|
||
| <openwb-base-button-input | ||
| title="3. Accounts abrufen" | ||
| button-text="Accounts laden" | ||
| subtype="info" | ||
| :disabled="!flexibleTariff.configuration.token?.refresh_token" | ||
| @button-clicked="fetch_accounts" | ||
| > | ||
| <template #help> | ||
| Mit dem Refresh-Token wird automatisch die zugehörige Account-Information von Naturstrom abgerufen. | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
| </template> | ||
| </openwb-base-button-input> | ||
|
|
||
| <openwb-base-select-input | ||
| title="Accounts" | ||
| :options="accountsOptions" | ||
| :model-value="flexibleTariff.configuration.account_id" | ||
| @update:model-value="updateSelectedAccount" | ||
| > | ||
| <template #help> | ||
| Wähle eine der verfügbaren Accounts aus. Diese wird für den Zugriff auf die Tarif-Daten benötigt. | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
| </template> | ||
| </openwb-base-select-input> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script> | ||
| import axios from "axios"; | ||
| import FlexibleTariffConfigMixin from "../FlexibleTariffConfigMixin.vue"; | ||
|
|
||
| export default { | ||
| name: "FlexibleTariffNaturstrom", | ||
| mixins: [FlexibleTariffConfigMixin], | ||
| data() { | ||
| return { | ||
| accounts: [], | ||
| }; | ||
| }, | ||
| computed: { | ||
| accountsOptions() { | ||
| const options = this.accounts.map((account) => ({ | ||
| value: account.id, | ||
| text: account.name, | ||
| })); | ||
|
|
||
| // Fallback: Wenn keine Optionen vorhanden sind, aber eine Account-ID in der Config existiert | ||
| if (options.length === 0 && this.flexibleTariff.configuration.account_id) { | ||
| options.push({ | ||
| value: this.flexibleTariff.configuration.account_id, | ||
| text: this.flexibleTariff.configuration.account_name || this.flexibleTariff.configuration.account_id, | ||
| }); | ||
| } | ||
|
|
||
| return options; | ||
| }, | ||
| }, | ||
| methods: { | ||
| updateSelectedAccount(accountId) { | ||
| this.updateConfiguration(accountId, "configuration.account_id"); | ||
|
|
||
| const selectedAccount = this.accounts.find((account) => account.id === accountId); | ||
| if (selectedAccount?.name) { | ||
| this.updateConfiguration(selectedAccount.name, "configuration.account_name"); | ||
| } | ||
| }, | ||
|
|
||
| naturstrom_login_window() { | ||
| // Open popup immediately to avoid popup blocker | ||
| const naturstromLogin = window.open( | ||
| "about:blank", | ||
| "NaturstromLogin", | ||
| "width=800,height=600,status=yes,scrollbars=yes,resizable=yes", | ||
| ); | ||
| naturstromLogin.focus(); | ||
|
benderl marked this conversation as resolved.
|
||
|
|
||
| // Then get the auth URL and redirect the popup | ||
| this.createAuthUrl() | ||
| .then((authResponse) => { | ||
| naturstromLogin.location.href = authResponse.authorizationUrl; | ||
| }) | ||
| .catch((error) => { | ||
| naturstromLogin.close(); | ||
| console.error("Fehler beim Erstellen des Naturstrom-Links:", error); | ||
| this.$root.postClientMessage( | ||
| "Fehler beim Erstellen der NaturstromAuthentifizierung: " + (error.response?.data?.message || error.message), | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
| "danger", | ||
| ); | ||
| }); | ||
| }, | ||
|
|
||
| async createAuthUrl() { | ||
| // Call local server endpoint | ||
| const response = await axios.post("https://naturstrom.openwb.de/naturstrom-auth.php", { | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| }, | ||
| }); | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
|
|
||
| if (!response.data.success) { | ||
| throw new Error("Server-Fehler beim Erstellen der Naturstrom-Authentifizierung"); | ||
| } | ||
| return response.data; | ||
| }, | ||
|
|
||
| async fetch_accounts() { | ||
| if (!this.flexibleTariff.configuration.token?.refresh_token) { | ||
| this.$root.postClientMessage("Bitte gib zuerst ein Refresh-Token ein.", "warning"); | ||
| return; | ||
| } | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| try { | ||
| // Call the Naturstrom proxy endpoint to get accounts | ||
| const response = await axios.get( | ||
| `https://naturstrom.openwb.de/naturstrom-proxy.php/accounts`, | ||
| { | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "Accept": "application/json", | ||
| "Authorization": `Bearer ${this.flexibleTariff.configuration.token?.access_token}`, | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| const accounts = Array.isArray(response.data?.data) ? response.data.data : []; | ||
| const normalizedAccounts = accounts | ||
| .filter((account) => account && account.id) | ||
| .map((account) => ({ | ||
| id: account.id, | ||
| name: account.name || account.reference || account.id, | ||
| })); | ||
|
|
||
| if (normalizedAccounts.length > 0) { | ||
| // Speichere alle Accounts für die Auswahlliste | ||
| this.accounts = normalizedAccounts; | ||
|
|
||
| // Wenn mehrere Accounts vorhanden sind, den ersten verwenden | ||
| const firstAccount = normalizedAccounts[0]; | ||
| this.updateConfiguration(firstAccount.id, "configuration.account_id"); | ||
| this.updateConfiguration(firstAccount.name, "configuration.account_name"); | ||
|
|
||
| if (normalizedAccounts.length > 1) { | ||
| this.$root.postClientMessage( | ||
| `${normalizedAccounts.length} Accounts gefunden. Erster Account ausgewählt: ${firstAccount.name}. Du kannst einen anderen Account aus der Liste wählen.`, | ||
| "success", | ||
| ); | ||
| } else { | ||
| this.$root.postClientMessage("Account erfolgreich abgerufen: " + firstAccount.name, "success"); | ||
| } | ||
| } else { | ||
| this.$root.postClientMessage("Keine Accounts für dieses Refresh-Token gefunden.", "warning"); | ||
|
benderl marked this conversation as resolved.
Outdated
|
||
| } | ||
| } catch (error) { | ||
| console.error("Fehler beim Abrufen der Accounts:", error); | ||
| this.$root.postClientMessage( | ||
| "Fehler beim Abrufen der Accounts: " + (error.response?.data?.message || error.message), | ||
| "danger", | ||
| ); | ||
| } | ||
| }, | ||
| }, | ||
| }; | ||
| </script> | ||
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.
Uh oh!
There was an error while loading. Please reload this page.