iobroker.sma-local 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/admin/i18n/de/translations.json +10 -0
  4. package/admin/i18n/en/translations.json +10 -0
  5. package/admin/i18n/es/translations.json +10 -0
  6. package/admin/i18n/fr/translations.json +10 -0
  7. package/admin/i18n/it/translations.json +10 -0
  8. package/admin/i18n/nl/translations.json +10 -0
  9. package/admin/i18n/pl/translations.json +10 -0
  10. package/admin/i18n/pt/translations.json +10 -0
  11. package/admin/i18n/ru/translations.json +10 -0
  12. package/admin/i18n/uk/translations.json +10 -0
  13. package/admin/i18n/zh-cn/translations.json +10 -0
  14. package/admin/jsonConfig.json +76 -0
  15. package/admin/sma-local.png +0 -0
  16. package/build/SmaDevice.js +115 -0
  17. package/build/SmaDevice.js.map +7 -0
  18. package/build/SmaEnnexosDevice.js +96 -0
  19. package/build/SmaEnnexosDevice.js.map +7 -0
  20. package/build/SmaLegacyDevice.js +70 -0
  21. package/build/SmaLegacyDevice.js.map +7 -0
  22. package/build/data/ev-charger.devices.js +25 -0
  23. package/build/data/ev-charger.devices.js.map +7 -0
  24. package/build/data/ev-charger.messages.de.js +25 -0
  25. package/build/data/ev-charger.messages.de.js.map +7 -0
  26. package/build/data/ev-charger.messages.en.js +25 -0
  27. package/build/data/ev-charger.messages.en.js.map +7 -0
  28. package/build/data/ev-charger.meta.de.js +25 -0
  29. package/build/data/ev-charger.meta.de.js.map +7 -0
  30. package/build/data/ev-charger.meta.en.js +25 -0
  31. package/build/data/ev-charger.meta.en.js.map +7 -0
  32. package/build/data/index.js +85 -0
  33. package/build/data/index.js.map +7 -0
  34. package/build/data/tripower-x.device.js +25 -0
  35. package/build/data/tripower-x.device.js.map +7 -0
  36. package/build/data/tripower-x.messages.de.js +25 -0
  37. package/build/data/tripower-x.messages.de.js.map +7 -0
  38. package/build/data/tripower-x.messages.en.js +25 -0
  39. package/build/data/tripower-x.messages.en.js.map +7 -0
  40. package/build/data/tripower-x.meta.de.js +25 -0
  41. package/build/data/tripower-x.meta.de.js.map +7 -0
  42. package/build/data/tripower-x.meta.en.js +25 -0
  43. package/build/data/tripower-x.meta.en.js.map +7 -0
  44. package/build/main.js +445 -0
  45. package/build/main.js.map +7 -0
  46. package/build/script.js +2 -0
  47. package/build/script.js.map +7 -0
  48. package/build/types.js +2 -0
  49. package/build/types.js.map +7 -0
  50. package/io-package.json +135 -0
  51. package/package.json +86 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 jb-io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ ![Logo](admin/sma-local.png)
2
+ # ioBroker.sma-local
3
+
4
+ [![NPM version](https://img.shields.io/npm/v/iobroker.sma-local.svg)](https://www.npmjs.com/package/iobroker.sma-local)
5
+ [![Downloads](https://img.shields.io/npm/dm/iobroker.sma-local.svg)](https://www.npmjs.com/package/iobroker.sma-local)
6
+ ![Number of Installations](https://iobroker.live/badges/sma-local-installed.svg)
7
+ ![Current version in stable repository](https://iobroker.live/badges/sma-local-stable.svg)
8
+
9
+ [![NPM](https://nodei.co/npm/iobroker.sma-local.png?downloads=true)](https://nodei.co/npm/iobroker.sma-local/)
10
+
11
+ **Tests:** ![Test and Release](https://github.com/jb-io/ioBroker.sma-local/workflows/Test%20and%20Release/badge.svg)
12
+
13
+ ## sma-local adapter for ioBroker
14
+
15
+ Integration of Local SMA devices without cloud connection
16
+
17
+ ## Description
18
+
19
+ The **ioBroker SMA Local Device Adapter** allows you to regularly monitor and control your SMA device without using the Cloud API
20
+
21
+ ## Compatible Devices:
22
+
23
+ https://www.sma.de/produkte
24
+
25
+ * Sunny Tripower X
26
+ * Sunny Tripower Smart Energy
27
+ * SMA EV Charger
28
+
29
+ **Unknown Compatibility:**
30
+ * Sunny Tripower
31
+ * Sunny Boy
32
+ * Sunny Boy Smart Energy
33
+ * SMA eCharger
34
+ * SMA EV Charger Business
35
+
36
+
37
+
38
+
39
+
40
+ ## Changelog
41
+ <!--
42
+ Placeholder for the next version (at the beginning of the line):
43
+ ### **WORK IN PROGRESS**
44
+ -->
45
+ ### 0.1.0 (2024-10-09)
46
+ * [TASK] initial release
47
+
48
+ ## License
49
+
50
+ [Licensed under GPLv3](LICENSE) Copyright (c) 2024 jb-io
@@ -0,0 +1,10 @@
1
+ {
2
+ "host": "Hostname oder IP",
3
+ "legacy_device": "Gerätetyp",
4
+ "store_session_token": "Session Token als Datenobjekt speichern",
5
+ "interval_full": "Abfrage Interval (sek) Vollständig",
6
+ "interval_live_data": "Abfrage Interval (sek) Live Daten",
7
+ "general": "Allgemein",
8
+ "username": "Benutzername",
9
+ "password": "Passwort"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "host": "Hostname or IP",
3
+ "legacy_device": "Devicetype",
4
+ "store_session_token": "Store session token as data object",
5
+ "interval_full": "Request interval (sec) Full",
6
+ "interval_live_data": "Request interval (sec) Live data",
7
+ "general": "General",
8
+ "username": "Username",
9
+ "password": "Password"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "host": "Nombre de host o IP",
3
+ "legacy_device": "Tipo de dispositivo",
4
+ "store_session_token": "Almacenar token de sesión como objeto de datos",
5
+ "interval_full": "Intervalo de solicitud (seg) Completo",
6
+ "interval_live_data": "Intervalo de solicitud (seg.) Datos en vivo",
7
+ "general": "General",
8
+ "username": "Nombre de usuario",
9
+ "password": "Contraseña"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "host": "Nom d'hôte ou IP",
3
+ "legacy_device": "Type d'appareil",
4
+ "store_session_token": "Stocker le jeton de session en tant qu'objet de données",
5
+ "interval_full": "Intervalle de requête (sec) Complet",
6
+ "interval_live_data": "Intervalle de requête (sec) Données en direct",
7
+ "general": "Général",
8
+ "username": "Nom d'utilisateur",
9
+ "password": "Mot de passe"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "host": "Nome host o IP",
3
+ "legacy_device": "Tipo di dispositivo",
4
+ "store_session_token": "Memorizza il token di sessione come oggetto dati",
5
+ "interval_full": "Intervallo di richiesta (sec) Pieno",
6
+ "interval_live_data": "Intervallo di richiesta (sec) Dati in tempo reale",
7
+ "general": "Generale",
8
+ "username": "Nome utente",
9
+ "password": "Password"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "host": "Hostnaam of IP",
3
+ "legacy_device": "Apparaattype",
4
+ "store_session_token": "Sla sessietoken op als gegevensobject",
5
+ "interval_full": "Verzoekinterval (sec) Vol",
6
+ "interval_live_data": "Interval opvragen (sec) Live data",
7
+ "general": "Algemeen",
8
+ "username": "Gebruikersnaam",
9
+ "password": "Wachtwoord"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "host": "Nazwa hosta lub adres IP",
3
+ "legacy_device": "Typ urządzenia",
4
+ "store_session_token": "Przechowuj token sesji jako obiekt danych",
5
+ "interval_full": "Interwał żądania (s) Pełny",
6
+ "interval_live_data": "Interwał żądania (s) Dane na żywo",
7
+ "general": "Ogólny",
8
+ "username": "Nazwa użytkownika",
9
+ "password": "Hasło"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "host": "Nome do host ou IP",
3
+ "legacy_device": "Tipo de dispositivo",
4
+ "store_session_token": "Armazene o token de sessão como objeto de dados",
5
+ "interval_full": "Intervalo de solicitação (seg) Completo",
6
+ "interval_live_data": "Intervalo de solicitação (seg) Dados ativos",
7
+ "general": "Em geral",
8
+ "username": "Nome de usuário",
9
+ "password": "Senha"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "host": "Имя хоста или IP",
3
+ "legacy_device": "Тип устройства",
4
+ "store_session_token": "Сохранять токен сеанса как объект данных",
5
+ "interval_full": "Интервал запроса (сек) Полный",
6
+ "interval_live_data": "Интервал запроса (сек) Текущие данные",
7
+ "general": "Общий",
8
+ "username": "Имя пользователя",
9
+ "password": "Пароль"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "host": "Ім'я хосту або IP",
3
+ "legacy_device": "Тип пристрою",
4
+ "store_session_token": "Зберігати маркер сеансу як об’єкт даних",
5
+ "interval_full": "Інтервал запиту (с) Повний",
6
+ "interval_live_data": "Інтервал запиту (сек) Живі дані",
7
+ "general": "Загальний",
8
+ "username": "Ім'я користувача",
9
+ "password": "Пароль"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "host": "主机名或IP",
3
+ "legacy_device": "设备类型",
4
+ "store_session_token": "将会话令牌存储为数据对象",
5
+ "interval_full": "请求间隔(秒) 已满",
6
+ "interval_live_data": "请求间隔(秒) 实时数据",
7
+ "general": "一般的",
8
+ "username": "用户名",
9
+ "password": "密码"
10
+ }
@@ -0,0 +1,76 @@
1
+ {
2
+ "i18n": true,
3
+ "type": "tabs",
4
+ "items": {
5
+ "general": {
6
+ "type": "panel",
7
+ "label": "general",
8
+ "items": {
9
+ "host": {
10
+ "xs": 12,
11
+ "sm": 6,
12
+ "md": 4,
13
+ "type": "text",
14
+ "label": "host"
15
+ },
16
+ "legacyDevice": {
17
+ "xs": 12,
18
+ "sm": 6,
19
+ "md": 4,
20
+ "type": "select",
21
+ "label": "legacy_device",
22
+ "options": [
23
+ {
24
+ "label": {
25
+ "en": "Legacy"
26
+ },
27
+ "value": true
28
+ },
29
+ {
30
+ "label": {
31
+ "en": "ennexOS"
32
+ },
33
+ "value": false
34
+ }
35
+ ]
36
+ },
37
+ "username": {
38
+ "xs": 12,
39
+ "sm": 6,
40
+ "md": 4,
41
+ "type": "text",
42
+ "label": "username",
43
+ "hidden": "data.legacyDevice === true",
44
+ "hideOnlyControl": true,
45
+ "newLine": true
46
+ },
47
+ "password": {
48
+ "xs": 12,
49
+ "sm": 6,
50
+ "md": 4,
51
+ "type": "password",
52
+ "label": "password"
53
+ },
54
+ "storeSessionToken": {
55
+ "type": "checkbox",
56
+ "label": "store_session_token"
57
+ },
58
+ "intervalFull": {
59
+ "xs": 12,
60
+ "sm": 4,
61
+ "md": 2,
62
+ "type": "number",
63
+ "label": "interval_full",
64
+ "newLine": true
65
+ },
66
+ "intervalLiveData": {
67
+ "xs": 12,
68
+ "sm": 4,
69
+ "md": 2,
70
+ "type": "number",
71
+ "label": "interval_live_data"
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
Binary file
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var SmaDevice_exports = {};
30
+ __export(SmaDevice_exports, {
31
+ default: () => SmaDevice
32
+ });
33
+ module.exports = __toCommonJS(SmaDevice_exports);
34
+ var import_axios = __toESM(require("axios"));
35
+ var import_https = __toESM(require("https"));
36
+ class SmaDevice {
37
+ _config;
38
+ _client;
39
+ _sessionToken = null;
40
+ _onAuthenticate = null;
41
+ constructor(config) {
42
+ this._config = config;
43
+ this._client = import_axios.default.create({
44
+ baseURL: "https://" + config.host,
45
+ headers: {
46
+ "accept": "application/json",
47
+ "content-type": "application/json"
48
+ },
49
+ httpsAgent: new import_https.default.Agent({
50
+ rejectUnauthorized: false,
51
+ keepAlive: true
52
+ }),
53
+ withCredentials: true
54
+ });
55
+ let isRetryAttempt = false;
56
+ this._client.interceptors.response.use(
57
+ (response) => {
58
+ const data = response.data;
59
+ if (typeof data === "object" && "err" in data && data.err === 401) {
60
+ response.status = 401;
61
+ return Promise.reject({
62
+ status: 401,
63
+ response
64
+ });
65
+ }
66
+ return response;
67
+ },
68
+ (error) => {
69
+ if (error.response && error.response.status === 500 && error.config.headers.Authorization) {
70
+ error.status = 401;
71
+ error.response.status = 401;
72
+ return Promise.reject(error);
73
+ }
74
+ return Promise.reject(error);
75
+ }
76
+ );
77
+ this._client.interceptors.response.use(
78
+ (response) => response,
79
+ async (error) => {
80
+ if (error.status === 401 || error.response && error.response.status === 401) {
81
+ if (!isRetryAttempt) {
82
+ isRetryAttempt = true;
83
+ try {
84
+ await this.authenticate();
85
+ const originalRequest = error.config;
86
+ return this._client(originalRequest);
87
+ } catch (tokenError) {
88
+ return Promise.reject(tokenError);
89
+ }
90
+ }
91
+ }
92
+ return Promise.reject(error);
93
+ }
94
+ );
95
+ }
96
+ async authenticate() {
97
+ this.setSessionToken(null);
98
+ const response = await this.login().catch(() => null);
99
+ if (response) {
100
+ if (this._onAuthenticate) {
101
+ this._onAuthenticate(response);
102
+ }
103
+ this.setSessionToken(response.access_token);
104
+ }
105
+ return response;
106
+ }
107
+ onAuthenticate(handler) {
108
+ this._onAuthenticate = handler;
109
+ }
110
+ setSessionToken(token) {
111
+ this._sessionToken = token;
112
+ this._client.defaults.headers.common["Authorization"] = token ? `Bearer ${token}` : null;
113
+ }
114
+ }
115
+ //# sourceMappingURL=SmaDevice.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/SmaDevice.ts"],
4
+ "sourcesContent": ["import axios from 'axios';\nimport https from 'https';\n\nexport interface LoginResponse {\n access_token: string,\n expires_in?: number,\n}\n\nexport interface SmaDeviceConfig {\n host: string,\n username?: string,\n password: string,\n}\n\ntype OnHandler<T> = (data: T) => void | Promise<void>;\ntype OnAuthenticationHandler = OnHandler<LoginResponse>;\n\nexport default abstract class SmaDevice {\n\n protected _config: SmaDeviceConfig;\n protected _client: axios.AxiosInstance;\n protected _sessionToken: string | null = null;\n\n private _onAuthenticate: OnAuthenticationHandler | null = null;\n\n constructor(config: SmaDeviceConfig) {\n this._config = config;\n\n this._client = axios.create({\n baseURL: 'https://' + config.host,\n headers: {\n \"accept\": \"application/json\",\n \"content-type\": \"application/json\",\n },\n httpsAgent: new https.Agent({\n rejectUnauthorized: false,\n keepAlive: true,\n }),\n withCredentials: true,\n });\n\n let isRetryAttempt = false;\n\n this._client.interceptors.response.use(\n (response) => {\n const data = response.data;\n if ((typeof data === 'object') && \"err\" in data && data.err === 401) {\n response.status = 401;\n return Promise.reject({\n status: 401,\n response: response,\n });\n }\n return response;\n },\n (error) => {\n if (error.response && error.response.status === 500 && error.config.headers.Authorization) {\n error.status = 401;\n error.response.status = 401;\n return Promise.reject(error);\n }\n return Promise.reject(error);\n }\n );\n this._client.interceptors.response.use(\n response => response,\n async (error) => {\n // 401 (Unauthorized)\n if (error.status === 401 || (error.response && error.response.status === 401)) {\n if (!isRetryAttempt) {\n isRetryAttempt = true;\n try {\n await this.authenticate();\n const originalRequest = error.config;\n return this._client(originalRequest);\n } catch (tokenError) {\n return Promise.reject(tokenError);\n }\n }\n }\n return Promise.reject(error);\n }\n );\n }\n\n protected abstract login(): Promise<LoginResponse>;\n\n public async authenticate(): Promise<LoginResponse | null> {\n this.setSessionToken(null);\n const response = await this.login().catch(() => null);\n if (response) {\n if (this._onAuthenticate) {\n this._onAuthenticate(response);\n }\n this.setSessionToken(response.access_token);\n }\n\n return response;\n }\n\n public onAuthenticate(handler: (response: LoginResponse) => void | Promise<void>): void {\n this._onAuthenticate = handler;\n }\n\n public setSessionToken(token: null|string): void {\n this._sessionToken = token;\n this._client.defaults.headers.common['Authorization'] = token ? `Bearer ${token}` : null;\n }\n\n\n}\n\n\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,mBAAkB;AAgBlB,MAAO,UAAiC;AAAA,EAE1B;AAAA,EACA;AAAA,EACA,gBAA+B;AAAA,EAEjC,kBAAkD;AAAA,EAE1D,YAAY,QAAyB;AACjC,SAAK,UAAU;AAEf,SAAK,UAAU,aAAAA,QAAM,OAAO;AAAA,MACxB,SAAS,aAAa,OAAO;AAAA,MAC7B,SAAS;AAAA,QACL,UAAU;AAAA,QACV,gBAAgB;AAAA,MACpB;AAAA,MACA,YAAY,IAAI,aAAAC,QAAM,MAAM;AAAA,QACxB,oBAAoB;AAAA,QACpB,WAAW;AAAA,MACf,CAAC;AAAA,MACD,iBAAiB;AAAA,IACrB,CAAC;AAED,QAAI,iBAAiB;AAErB,SAAK,QAAQ,aAAa,SAAS;AAAA,MAC/B,CAAC,aAAa;AACV,cAAM,OAAO,SAAS;AACtB,YAAK,OAAO,SAAS,YAAa,SAAS,QAAQ,KAAK,QAAQ,KAAK;AACjE,mBAAS,SAAS;AAClB,iBAAO,QAAQ,OAAO;AAAA,YAClB,QAAQ;AAAA,YACR;AAAA,UACJ,CAAC;AAAA,QACL;AACA,eAAO;AAAA,MACX;AAAA,MACA,CAAC,UAAU;AACP,YAAI,MAAM,YAAY,MAAM,SAAS,WAAW,OAAO,MAAM,OAAO,QAAQ,eAAe;AACvF,gBAAM,SAAS;AACf,gBAAM,SAAS,SAAS;AACxB,iBAAO,QAAQ,OAAO,KAAK;AAAA,QAC/B;AACA,eAAO,QAAQ,OAAO,KAAK;AAAA,MAC/B;AAAA,IACJ;AACA,SAAK,QAAQ,aAAa,SAAS;AAAA,MAC/B,cAAY;AAAA,MACZ,OAAO,UAAU;AAEb,YAAI,MAAM,WAAW,OAAQ,MAAM,YAAY,MAAM,SAAS,WAAW,KAAM;AAC3E,cAAI,CAAC,gBAAgB;AACjB,6BAAiB;AACjB,gBAAI;AACA,oBAAM,KAAK,aAAa;AACxB,oBAAM,kBAAkB,MAAM;AAC9B,qBAAO,KAAK,QAAQ,eAAe;AAAA,YACvC,SAAS,YAAY;AACjB,qBAAO,QAAQ,OAAO,UAAU;AAAA,YACpC;AAAA,UACJ;AAAA,QACJ;AACA,eAAO,QAAQ,OAAO,KAAK;AAAA,MAC/B;AAAA,IACJ;AAAA,EACJ;AAAA,EAIA,MAAa,eAA8C;AACvD,SAAK,gBAAgB,IAAI;AACzB,UAAM,WAAW,MAAM,KAAK,MAAM,EAAE,MAAM,MAAM,IAAI;AACpD,QAAI,UAAU;AACV,UAAI,KAAK,iBAAiB;AACtB,aAAK,gBAAgB,QAAQ;AAAA,MACjC;AACA,WAAK,gBAAgB,SAAS,YAAY;AAAA,IAC9C;AAEA,WAAO;AAAA,EACX;AAAA,EAEO,eAAe,SAAkE;AACpF,SAAK,kBAAkB;AAAA,EAC3B;AAAA,EAEO,gBAAgB,OAA0B;AAC7C,SAAK,gBAAgB;AACrB,SAAK,QAAQ,SAAS,QAAQ,OAAO,eAAe,IAAI,QAAQ,UAAU,KAAK,KAAK;AAAA,EACxF;AAGJ;",
6
+ "names": ["axios", "https"]
7
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var SmaEnnexosDevice_exports = {};
30
+ __export(SmaEnnexosDevice_exports, {
31
+ default: () => SmaEnnexosDevice
32
+ });
33
+ module.exports = __toCommonJS(SmaEnnexosDevice_exports);
34
+ var import_SmaDevice = __toESM(require("./SmaDevice"));
35
+ var import_data = require("./data");
36
+ class SmaEnnexosDevice extends import_SmaDevice.default {
37
+ componentId = "IGULD:SELF";
38
+ async login() {
39
+ return this._client.post("/api/v1/token", {
40
+ grant_type: "password",
41
+ username: this._config.username,
42
+ password: this._config.password
43
+ }, {
44
+ headers: {
45
+ "content-type": "application/x-www-form-urlencoded"
46
+ }
47
+ }).then(({ data }) => data);
48
+ }
49
+ async getLiveMeasurementValues() {
50
+ return this._client.post(
51
+ `/api/v1/measurements/live`,
52
+ [{ componentId: this.componentId }]
53
+ ).then(({ data }) => data);
54
+ }
55
+ async getParameters() {
56
+ return this._client.post(
57
+ `/api/v1/parameters/search`,
58
+ { queryItems: [{ componentId: this.componentId }] }
59
+ ).then(({ data }) => data);
60
+ }
61
+ async getWidgets() {
62
+ return this._client.get(
63
+ `/api/v1/dashboard/widgets?componentId=${this.componentId}`
64
+ ).then(({ data }) => data);
65
+ }
66
+ async getWidgetData(name) {
67
+ let url = "";
68
+ switch (name) {
69
+ case "DeviceInfo":
70
+ url = `/api/v1/widgets/deviceinfo?deviceId=${this.componentId}`;
71
+ break;
72
+ case "State":
73
+ url = `/api/v1/widgets/states?componentId=${this.componentId}`;
74
+ break;
75
+ case "EMobilityInformation":
76
+ url = `/api/v1/widgets/emobility?componentId=${this.componentId}`;
77
+ break;
78
+ case "EnergyAndPowerChargingStation":
79
+ url = `/api/v1/widgets/gauge/power?componentId=${this.componentId}&type=ChargingStation`;
80
+ break;
81
+ case "EnergyAndPower":
82
+ url = `/api/v1/widgets/gauge/power?componentId=${this.componentId}&type=PvProduction`;
83
+ break;
84
+ default:
85
+ return null;
86
+ }
87
+ return this._client.get(url).then(({ data }) => data);
88
+ }
89
+ async getDeviceDefinitions() {
90
+ return Promise.resolve((0, import_data.getDevices)("TripowerX"));
91
+ }
92
+ async getTranslations() {
93
+ return Promise.resolve((0, import_data.getMeta)("TripowerX", "de").META);
94
+ }
95
+ }
96
+ //# sourceMappingURL=SmaEnnexosDevice.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/SmaEnnexosDevice.ts"],
4
+ "sourcesContent": ["import SmaDevice from \"./SmaDevice\";\nimport {getDevices, getMeta, Devices, MetaItems} from \"./data\";\n\ninterface SmaLoginResponse {\n access_token: string,\n expires_in: number,\n refresh_token: string,\n token_type: string,\n uiIdleTime: number|string,\n}\n\n\nexport type LiveRequestResponse = Channels[]\n\nexport interface Channels {\n channelId: string\n componentId: string\n values: ParameterValue[]|Values[]\n}\n\n// export interface Value {\n// time: string\n// value?: number\n// }\nexport interface Values {\n time: string\n values?: number[]\n}\n\n\n\n// const WidgetTypeMap: { [key: string]: string } = {\n// State: 'states',\n// EMobilityInformation: 'emobility',\n// EnergyAndPowerChargingStation: 'power',\n// }\n\nexport type StateWidgetResponse = WidgetStateResponseItem[]\n\nexport interface WidgetStateResponseItem {\n componentId: string\n componentType: string\n name: string\n state: number\n stateFunctionTag: number\n}\n\nexport interface EMobilityInformationWidgetResponse {\n chargeStatus: string\n evStatus: number\n evseName: string\n evseStatus: number\n notificationList: any[]\n power: number\n sessionEnergy: number\n}\n\nexport interface PowerGaugeWidgetResponse {\n max: number\n min: number\n value: number|'NaN'\n timestamp?: string\n}\n\nexport interface DeviceInfoWidgetResponse {\n deviceId: string\n deviceInfoFeatures: DeviceInfoFeature[]\n name: string\n plantId: string\n productGroupTagId: number\n productTagId: number\n serial: string\n}\n\nexport interface DeviceInfoFeature {\n infoWidgetType: string\n value: string\n}\n\ntype WidgetResponse = {\n 'DeviceInfo': DeviceInfoWidgetResponse,\n 'State': StateWidgetResponse,\n 'EMobilityInformation': EMobilityInformationWidgetResponse\n 'EnergyAndPowerChargingStation': PowerGaugeWidgetResponse\n 'EnergyAndPower': PowerGaugeWidgetResponse\n}\n\nexport type WidgetsResponse = WidgetsResponseItem[]\n\nexport interface WidgetsResponseItem {\n widgetType: keyof WidgetResponse\n}\n\nexport type ParametersResponse = ParametersData[]\n\nexport interface ParametersData {\n componentId: string\n values: (ParameterValue|ParametersValue)[]\n}\n\nexport interface ParameterValue {\n channelId: string\n editable: boolean\n state: string\n timestamp: string\n value: string\n possibleValues?: string[]\n max?: number\n min?: number\n}\nexport interface ParametersValue {\n channelId: string\n editable: boolean\n state: string\n timestamp: string\n values: string[]\n possibleValues?: string[]\n max?: number\n min?: number\n}\n\n\nexport default class SmaEnnexosDevice extends SmaDevice{\n\n private componentId = 'IGULD:SELF';\n\n protected async login(): Promise<SmaLoginResponse> {\n return this._client.post<SmaLoginResponse>('/api/v1/token', {\n grant_type: 'password',\n username: this._config.username,\n password: this._config.password,\n },{\n headers: {\n \"content-type\": \"application/x-www-form-urlencoded\",\n },\n } )\n .then(({data}) => data)\n }\n\n public async getLiveMeasurementValues (): Promise<LiveRequestResponse> {\n return this._client.post<LiveRequestResponse>(`/api/v1/measurements/live`,\n [{componentId: this.componentId}],\n ).then(({data}) => data)\n ;\n\n }\n\n public async getParameters (): Promise<ParametersResponse> {\n return this._client.post<ParametersResponse>(`/api/v1/parameters/search`,\n {queryItems:[{componentId:this.componentId}]},\n ).then(({data}) => data)\n ;\n\n }\n\n public async getWidgets (): Promise<WidgetsResponse> {\n\n return this._client.get<WidgetsResponse>(`/api/v1/dashboard/widgets?componentId=${this.componentId}`,\n ).then(({data}) => data)\n ;\n }\n\n public async getWidgetData<K extends keyof WidgetResponse>(name: K): Promise<WidgetResponse[K]|null> {\n // const widget = WidgetTypeMap[name];\n let url = '';\n switch (name) {\n case 'DeviceInfo':\n url = `/api/v1/widgets/deviceinfo?deviceId=${this.componentId}`;\n break;\n case 'State':\n url = `/api/v1/widgets/states?componentId=${this.componentId}`;\n break;\n case 'EMobilityInformation':\n url = `/api/v1/widgets/emobility?componentId=${this.componentId}`;\n break;\n case 'EnergyAndPowerChargingStation':\n url = `/api/v1/widgets/gauge/power?componentId=${this.componentId}&type=ChargingStation`;\n break;\n case 'EnergyAndPower':\n url = `/api/v1/widgets/gauge/power?componentId=${this.componentId}&type=PvProduction`;\n break;\n default:\n return null;\n }\n\n return this._client.get<WidgetResponse[K]>(url)\n .then(({data}) => data)\n ;\n }\n\n public async getDeviceDefinitions(): Promise<Devices> {\n return Promise.resolve(getDevices('TripowerX'));\n }\n public async getTranslations(): Promise<MetaItems> {\n return Promise.resolve(getMeta('TripowerX', 'de').META);\n }\n}\n\n\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AACtB,kBAAsD;AAyHtD,MAAO,yBAAuC,iBAAAA,QAAS;AAAA,EAE3C,cAAc;AAAA,EAEtB,MAAgB,QAAmC;AAC/C,WAAO,KAAK,QAAQ,KAAuB,iBAAiB;AAAA,MACxD,YAAY;AAAA,MACZ,UAAU,KAAK,QAAQ;AAAA,MACvB,UAAU,KAAK,QAAQ;AAAA,IAC3B,GAAE;AAAA,MACE,SAAS;AAAA,QACL,gBAAgB;AAAA,MACpB;AAAA,IACJ,CAAE,EACG,KAAK,CAAC,EAAC,KAAI,MAAM,IAAI;AAAA,EAC9B;AAAA,EAEA,MAAa,2BAA0D;AACnE,WAAO,KAAK,QAAQ;AAAA,MAA0B;AAAA,MAC1C,CAAC,EAAC,aAAa,KAAK,YAAW,CAAC;AAAA,IACpC,EAAE,KAAK,CAAC,EAAC,KAAI,MAAM,IAAI;AAAA,EAG3B;AAAA,EAEA,MAAa,gBAA8C;AACvD,WAAO,KAAK,QAAQ;AAAA,MAAyB;AAAA,MACzC,EAAC,YAAW,CAAC,EAAC,aAAY,KAAK,YAAW,CAAC,EAAC;AAAA,IAChD,EAAE,KAAK,CAAC,EAAC,KAAI,MAAM,IAAI;AAAA,EAG3B;AAAA,EAEA,MAAa,aAAwC;AAEjD,WAAO,KAAK,QAAQ;AAAA,MAAqB,yCAAyC,KAAK,WAAW;AAAA,IAClG,EAAE,KAAK,CAAC,EAAC,KAAI,MAAM,IAAI;AAAA,EAE3B;AAAA,EAEA,MAAa,cAA8C,MAA0C;AAEjG,QAAI,MAAM;AACV,YAAQ,MAAM;AAAA,MACV,KAAK;AACD,cAAM,uCAAuC,KAAK,WAAW;AAC7D;AAAA,MACJ,KAAK;AACD,cAAM,sCAAsC,KAAK,WAAW;AAC5D;AAAA,MACJ,KAAK;AACD,cAAM,yCAAyC,KAAK,WAAW;AAC/D;AAAA,MACJ,KAAK;AACD,cAAM,2CAA2C,KAAK,WAAW;AACjE;AAAA,MACJ,KAAK;AACD,cAAM,2CAA2C,KAAK,WAAW;AACjE;AAAA,MACJ;AACI,eAAO;AAAA,IACf;AAEA,WAAO,KAAK,QAAQ,IAAuB,GAAG,EACzC,KAAK,CAAC,EAAC,KAAI,MAAM,IAAI;AAAA,EAE9B;AAAA,EAEA,MAAa,uBAAyC;AAClD,WAAO,QAAQ,YAAQ,wBAAW,WAAW,CAAC;AAAA,EAClD;AAAA,EACA,MAAa,kBAAsC;AAC/C,WAAO,QAAQ,YAAQ,qBAAQ,aAAa,IAAI,EAAE,IAAI;AAAA,EAC1D;AACJ;",
6
+ "names": ["SmaDevice"]
7
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var SmaLegacyDevice_exports = {};
30
+ __export(SmaLegacyDevice_exports, {
31
+ default: () => SmaLegacyDevice
32
+ });
33
+ module.exports = __toCommonJS(SmaLegacyDevice_exports);
34
+ var import_SmaDevice = __toESM(require("./SmaDevice"));
35
+ class SmaLegacyDevice extends import_SmaDevice.default {
36
+ constructor(config) {
37
+ super(config);
38
+ this._client.interceptors.request.use((config2) => {
39
+ if (this._sessionToken) {
40
+ const url = new URL(config2.url, config2.baseURL);
41
+ url.searchParams.append("sid", this._sessionToken);
42
+ config2.url = url.toString().replace(config2.baseURL, "");
43
+ }
44
+ return config2;
45
+ });
46
+ }
47
+ async login() {
48
+ return this._client.post("/dyn/login.json", {
49
+ right: "istl",
50
+ pass: this._config.password
51
+ }).then(({ data }) => {
52
+ return {
53
+ access_token: data.result.sid
54
+ };
55
+ });
56
+ }
57
+ async getAllOnlValues() {
58
+ return this._client.post(`/dyn/getAllOnlValues.json`, { "destDev": [] }).then((response) => response.data);
59
+ }
60
+ async getValues(keys) {
61
+ return this._client.post(`/dyn/getValues.json`, { "destDev": [], "keys": keys }).then((response) => response.data);
62
+ }
63
+ async getObjectMetaData() {
64
+ return this._client.get(`/data/ObjectMetadata_Istl.json`).then((response) => response.data);
65
+ }
66
+ async getTagTranslations() {
67
+ return this._client.get(`/data/l10n/de-DE.json`).then((response) => response.data);
68
+ }
69
+ }
70
+ //# sourceMappingURL=SmaLegacyDevice.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/SmaLegacyDevice.ts"],
4
+ "sourcesContent": ["import SmaDevice, {LoginResponse, SmaDeviceConfig} from \"./SmaDevice\";\n\n\ntype SmaLoginResponse = {\n result: {sid: string}\n}\n\ntype ObjectValueData = {\n [key: string]: N0DataNode | N1DataNode | N9DataNode;\n};\n\nexport type N0DataNode = { \"0\": N0Data[] };\nexport type N1DataNode = { \"1\": N1Data[] };\nexport type N9DataNode = { \"9\": N9Data[] };\nexport type N0Data = {\n val: string\n}\nexport type N1Data = {\n val: number\n}\nexport type N9Data = {\n val: number | string | TaggedVal[] | null;\n low?: number|null;\n high?: number|null;\n validVals?: number[];\n};\ntype TaggedVal = {tag: number}\n\nexport type GetAllOnlValuesResponse = GetValuesResponse\nexport type GetValuesResponse = {\n result: {\n [key: string]: ObjectValueData;\n };\n};\n\ntype TagTranslationResponse = {\n [key: number|string]: string;\n};\n\nexport interface ObjectMetadata {\n Prio: number;\n TagId: number;\n TagIdEvtMsg: number | string;\n Unit?: number;\n DataFrmt: number;\n Scale?: number;\n Typ: number;\n WriteLevel: number;\n TagHier: number[];\n Min?: boolean;\n Max?: boolean;\n Avg?: boolean;\n Cnt?: boolean;\n MinD?: boolean;\n MaxD?: boolean;\n Sum?: boolean;\n SumD?: boolean;\n Deprecated?: boolean;\n Len?: number;\n ParaInfo?: string;\n Hidden?: boolean;\n GridGuard?: boolean;\n AvgD?: boolean;\n SortTranslation?: boolean;\n GroupChange?: string[];\n}\n\ntype ObjectMetadataResponse = {\n [key: string]: ObjectMetadata;\n};\n\n\n\n\nexport default class SmaLegacyDevice extends SmaDevice {\n\n constructor(config: SmaDeviceConfig) {\n super(config);\n\n this._client.interceptors.request.use((config) => {\n if (this._sessionToken) {\n const url = new URL(config.url as string, config.baseURL);\n url.searchParams.append('sid', this._sessionToken);\n config.url = url.toString().replace(config.baseURL as string, '');\n }\n return config;\n });\n }\n\n protected async login(): Promise<LoginResponse> {\n return this._client.post<SmaLoginResponse>('/dyn/login.json', {\n right: 'istl',\n pass: this._config.password,\n } )\n .then(({data}): LoginResponse => {\n return {\n access_token: data.result.sid,\n };\n })\n }\n\n public async getAllOnlValues (): Promise<GetAllOnlValuesResponse> {\n return this._client.post(`/dyn/getAllOnlValues.json`, {\"destDev\":[]})\n .then(response => response.data)\n ;\n }\n public async getValues (keys: string[]): Promise<GetAllOnlValuesResponse> {\n return this._client.post(`/dyn/getValues.json`, {\"destDev\":[], \"keys\": keys})\n .then(response => response.data)\n ;\n }\n\n public async getObjectMetaData (): Promise<ObjectMetadataResponse> {\n\n return this._client.get(`/data/ObjectMetadata_Istl.json`)\n .then(response => response.data)\n ;\n }\n\n public async getTagTranslations (): Promise<TagTranslationResponse> {\n\n return this._client.get(`/data/l10n/de-DE.json`)\n .then((response) => response.data)\n ;\n }\n\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAwD;AA0ExD,MAAO,wBAAsC,iBAAAA,QAAU;AAAA,EAEnD,YAAY,QAAyB;AACjC,UAAM,MAAM;AAEZ,SAAK,QAAQ,aAAa,QAAQ,IAAI,CAACC,YAAW;AAC9C,UAAI,KAAK,eAAe;AACpB,cAAM,MAAM,IAAI,IAAIA,QAAO,KAAeA,QAAO,OAAO;AACxD,YAAI,aAAa,OAAO,OAAO,KAAK,aAAa;AACjD,QAAAA,QAAO,MAAM,IAAI,SAAS,EAAE,QAAQA,QAAO,SAAmB,EAAE;AAAA,MACpE;AACA,aAAOA;AAAA,IACX,CAAC;AAAA,EACL;AAAA,EAEA,MAAgB,QAAgC;AAC5C,WAAO,KAAK,QAAQ,KAAuB,mBAAmB;AAAA,MAC1D,OAAO;AAAA,MACP,MAAM,KAAK,QAAQ;AAAA,IACvB,CAAE,EACG,KAAK,CAAC,EAAC,KAAI,MAAqB;AAC7B,aAAO;AAAA,QACH,cAAc,KAAK,OAAO;AAAA,MAC9B;AAAA,IACJ,CAAC;AAAA,EACT;AAAA,EAEA,MAAa,kBAAqD;AAC9D,WAAO,KAAK,QAAQ,KAAK,6BAA6B,EAAC,WAAU,CAAC,EAAC,CAAC,EAC/D,KAAK,cAAY,SAAS,IAAI;AAAA,EAEvC;AAAA,EACA,MAAa,UAAW,MAAkD;AACtE,WAAO,KAAK,QAAQ,KAAK,uBAAuB,EAAC,WAAU,CAAC,GAAG,QAAQ,KAAI,CAAC,EACvE,KAAK,cAAY,SAAS,IAAI;AAAA,EAEvC;AAAA,EAEA,MAAa,oBAAsD;AAE/D,WAAO,KAAK,QAAQ,IAAI,gCAAgC,EACnD,KAAK,cAAY,SAAS,IAAI;AAAA,EAEvC;AAAA,EAEA,MAAa,qBAAuD;AAEhE,WAAO,KAAK,QAAQ,IAAI,uBAAuB,EAC1C,KAAK,CAAC,aAAa,SAAS,IAAI;AAAA,EAEzC;AAEJ;",
6
+ "names": ["SmaDevice", "config"]
7
+ }