diff --git a/README.md b/README.md index fbe43fd..87ae694 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,13 @@ If you like the adapter and want to support me, you can do so here: Placeholder for the next version (at the beginning of the line): ### **WORK IN PROGRESS** --> +### **WORK IN PROGRESS** +- Added: Migration to jsonConfig in Adapter-settings +- Added: New state "car_connected", which indicates, that a car is connected +- Added: Resume, Pause check - less error messages (e.g. if Wallbox is in Pause Mode and should be set to pause, don't throw any error) +- Added: Option, to unlock the wallbox first if it should enter the resume mode (Default: wallbox will not resume, if locked) +- Added: Some minor improvements, updates dependencies and smal cosmetics + ### 1.1.1 (2024-09-18) - updated dependencies diff --git a/admin/i18n/de/translations.json b/admin/i18n/de/translations.json index 63f7713..e538689 100644 --- a/admin/i18n/de/translations.json +++ b/admin/i18n/de/translations.json @@ -1,10 +1,11 @@ { - "charger_serial": "Seriennummer Ihrer Wallbox", - "default_settings": "Standardeinstellungen", + "charger_id": "Seriennummer Ihrer Wallbox", "donate": "Wenn Ihnen dieser Adapter gefällt, denken Sie bitte über eine Spende nach, um meine Arbeit zu unterstützen.", "email": "E-Mail", - "ex_charger_serial": "Zu finden auf:", + "ex_charger_id": "Zu finden auf:", + "ex_unlock_before_resume": "(Sonst: Wallbox muss zuvor über den Status „control.locked“ entsperrt werden)", + "main_settings": "Haupteinstellungen", "password": "Passwort", "poll_time": "Poll-Zeit in Sekunden (min. 30 Sekunden)", - "wallbox adapter settings": "Adaptereinstellungen für Wallbox" + "unlock_before_resume": "Entsperren Sie die Wallbox automatisch, wenn die Aktion „Fortsetzen“ ausgelöst wird" } diff --git a/admin/i18n/en/translations.json b/admin/i18n/en/translations.json index 16f0363..b3c2012 100644 --- a/admin/i18n/en/translations.json +++ b/admin/i18n/en/translations.json @@ -1,10 +1,11 @@ { - "charger_serial": "Serial Number of your Wallbox", - "default_settings": "Standard settings", + "charger_id": "Serial Number of your Wallbox", "donate": "If you like this adapter, please consider making a donation to support my work.", "email": "E-Mail", - "ex_charger_serial": "Can be found on:", + "ex_charger_id": "Can be found on:", + "ex_unlock_before_resume": "(Else: Wallbox needs to be unlocked before via the 'control.locked' state)", + "main_settings": "Main Settings", "password": "Password", "poll_time": "Poll-Time in Seconds (min. 30 seconds)", - "wallbox adapter settings": "Adapter settings for wallbox" + "unlock_before_resume": "Unlock the Wallbox automatically when the 'resume' action is triggered" } diff --git a/admin/i18n/es/translations.json b/admin/i18n/es/translations.json index f035ebe..c7764f1 100644 --- a/admin/i18n/es/translations.json +++ b/admin/i18n/es/translations.json @@ -1,10 +1,11 @@ { - "charger_serial": "Número de serie de su Wallbox", - "default_settings": "Configuraciones estándar", + "charger_id": "Número de serie de tu Wallbox", "donate": "Si le gusta este adaptador, considere hacer una donación para apoyar mi trabajo.", "email": "Correo electrónico", - "ex_charger_serial": "Se puede encontrar en:", - "password": "Clave", - "poll_time": "Tiempo de sondeo en segundos (mín. 30 segundos)", - "wallbox adapter settings": "Ajustes del adaptador para Wallbox" + "ex_charger_id": "Se puede encontrar en:", + "ex_unlock_before_resume": "(De lo contrario: Wallbox debe desbloquearse antes mediante el estado 'control.locked')", + "main_settings": "Configuración principal", + "password": "Contraseña", + "poll_time": "Tiempo de encuesta en segundos (mínimo 30 segundos)", + "unlock_before_resume": "Desbloquea el Wallbox automáticamente cuando se activa la acción 'reanudar'" } diff --git a/admin/i18n/fr/translations.json b/admin/i18n/fr/translations.json index 8e421bf..fb1b588 100644 --- a/admin/i18n/fr/translations.json +++ b/admin/i18n/fr/translations.json @@ -1,10 +1,11 @@ { - "charger_serial": "Numéro de série de votre Wallbox", - "default_settings": "Paramètres standards", + "charger_id": "Numéro de série de votre Wallbox", "donate": "Si vous aimez cet adaptateur, pensez à faire un don pour soutenir mon travail.", "email": "E-mail", - "ex_charger_serial": "A retrouver sur :", + "ex_charger_id": "Peut être trouvé sur :", + "ex_unlock_before_resume": "(Sinon : la Wallbox doit être déverrouillée au préalable via l'état « control.locked »)", + "main_settings": "Paramètres principaux", "password": "Mot de passe", - "poll_time": "Temps d'interrogation en secondes (min. 30 secondes)", - "wallbox adapter settings": "Paramètres de l'adaptateur pour wallbox" + "poll_time": "Durée d'interrogation en secondes (min. 30 secondes)", + "unlock_before_resume": "Déverrouillez automatiquement la Wallbox lorsque l'action « reprendre » est déclenchée" } diff --git a/admin/i18n/it/translations.json b/admin/i18n/it/translations.json index 1356c11..d379fbd 100644 --- a/admin/i18n/it/translations.json +++ b/admin/i18n/it/translations.json @@ -1,10 +1,11 @@ { - "charger_serial": "Numero di serie della tua Wallbox", - "default_settings": "Impostazioni standard", + "charger_id": "Numero di serie della tua Wallbox", "donate": "Se ti piace questo adattatore, considera di fare una donazione per sostenere il mio lavoro.", "email": "E-mail", - "ex_charger_serial": "Può essere trovato su:", - "password": "Parola d'ordine", + "ex_charger_id": "Può essere trovato su:", + "ex_unlock_before_resume": "(Altrimenti: la Wallbox deve essere sbloccata prima tramite lo stato 'control.locked')", + "main_settings": "Impostazioni principali", + "password": "Password", "poll_time": "Tempo di polling in secondi (min. 30 secondi)", - "wallbox adapter settings": "Impostazioni dell'adattatore per wallbox" + "unlock_before_resume": "Sblocca automaticamente la Wallbox quando viene attivata l'azione \"riprendi\"." } diff --git a/admin/i18n/nl/translations.json b/admin/i18n/nl/translations.json index 2e580d5..088307a 100644 --- a/admin/i18n/nl/translations.json +++ b/admin/i18n/nl/translations.json @@ -1,10 +1,11 @@ { - "charger_serial": "Serienummer van je Wallbox", - "default_settings": "Standaard instellingen", + "charger_id": "Serienummer van uw Wallbox", "donate": "Als je deze adapter leuk vindt, overweeg dan een donatie te doen om mijn werk te ondersteunen.", "email": "E-mail", - "ex_charger_serial": "Te vinden op:", + "ex_charger_id": "Te vinden op:", + "ex_unlock_before_resume": "(Anders: Wallbox moet eerst worden ontgrendeld via de status 'control.locked')", + "main_settings": "Hoofdinstellingen", "password": "Wachtwoord", "poll_time": "Poll-tijd in seconden (min. 30 seconden)", - "wallbox adapter settings": "Adapterinstellingen voor wallbox" + "unlock_before_resume": "Ontgrendel de Wallbox automatisch wanneer de 'hervatten'-actie wordt geactiveerd" } diff --git a/admin/i18n/pl/translations.json b/admin/i18n/pl/translations.json index b12029b..888aa99 100644 --- a/admin/i18n/pl/translations.json +++ b/admin/i18n/pl/translations.json @@ -1,10 +1,11 @@ { - "charger_serial": "Numer seryjny Twojego Wallbox", - "default_settings": "Ustawienia standardowe", + "charger_id": "Numer seryjny Twojej stacji Wallbox", "donate": "Jeśli podoba Ci się ten adapter, rozważ przekazanie darowizny na wsparcie mojej pracy.", "email": "E-mail", - "ex_charger_serial": "Można znaleźć na:", + "ex_charger_id": "Można znaleźć na:", + "ex_unlock_before_resume": "(W przeciwnym razie: Wallbox musi zostać wcześniej odblokowany w stanie „control.locked”)", + "main_settings": "Główne ustawienia", "password": "Hasło", "poll_time": "Czas odpytywania w sekundach (min. 30 sekund)", - "wallbox adapter settings": "Ustawienia adaptera do Wallbox" + "unlock_before_resume": "Odblokuj Wallbox automatycznie po uruchomieniu akcji „wznów”." } diff --git a/admin/i18n/pt/translations.json b/admin/i18n/pt/translations.json index b085edd..457b643 100644 --- a/admin/i18n/pt/translations.json +++ b/admin/i18n/pt/translations.json @@ -1,10 +1,11 @@ { - "charger_serial": "Número de série da Wallbox", - "default_settings": "Configurações padrão", + "charger_id": "Número de série da sua Wallbox", "donate": "Se você gosta deste adaptador, considere fazer uma doação para apoiar meu trabalho.", "email": "E-mail", - "ex_charger_serial": "Pode ser encontrado em:", + "ex_charger_id": "Pode ser encontrado em:", + "ex_unlock_before_resume": "(Senão: a Wallbox precisa ser desbloqueada antes através do estado 'control.locked')", + "main_settings": "Configurações principais", "password": "Senha", - "poll_time": "Tempo de pesquisa em segundos (mín. 30 segundos)", - "wallbox adapter settings": "Configurações do adaptador para wallbox" + "poll_time": "Tempo de pesquisa em segundos (min. 30 segundos)", + "unlock_before_resume": "Desbloqueie a Wallbox automaticamente quando a ação 'reiniciar' for acionada" } diff --git a/admin/i18n/ru/translations.json b/admin/i18n/ru/translations.json index 8da80c7..9289032 100644 --- a/admin/i18n/ru/translations.json +++ b/admin/i18n/ru/translations.json @@ -1,10 +1,11 @@ { - "charger_serial": "Серийный номер вашего Wallbox", - "default_settings": "Стандартные настройки", + "charger_id": "Серийный номер вашего Wallbox", "donate": "Если вам нравится этот адаптер, пожалуйста, рассмотрите возможность сделать пожертвование в поддержку моей работы.", "email": "Электронная почта", - "ex_charger_serial": "Можно найти на:", + "ex_charger_id": "Можно найти на:", + "ex_unlock_before_resume": "(Иначе: перед этим необходимо разблокировать Wallbox через состояние «control.locked»).", + "main_settings": "Основные настройки", "password": "Пароль", - "poll_time": "Время опроса в секундах (мин. 30 секунд)", - "wallbox adapter settings": "Настройки адаптера для wallbox" + "poll_time": "Время опроса в секундах (минимум 30 секунд)", + "unlock_before_resume": "Автоматически разблокируйте Wallbox при срабатывании действия «возобновить»" } diff --git a/admin/i18n/uk/translations.json b/admin/i18n/uk/translations.json index 7426d42..1d22c72 100644 --- a/admin/i18n/uk/translations.json +++ b/admin/i18n/uk/translations.json @@ -1,10 +1,11 @@ { - "charger_serial": "Серійний номер вашої Wallbox", - "default_settings": "Стандартні налаштування", + "charger_id": "Серійний номер вашої Wallbox", "donate": "Якщо вам подобається цей адаптер, зробіть пожертву на підтримку моєї роботи.", "email": "Електронна пошта", - "ex_charger_serial": "Можна знайти на:", + "ex_charger_id": "Можна знайти на:", + "ex_unlock_before_resume": "(Інакше: перед цим Wallbox потрібно розблокувати за допомогою стану «control.locked»)", + "main_settings": "Основні налаштування", "password": "Пароль", "poll_time": "Час опитування в секундах (мін. 30 секунд)", - "wallbox adapter settings": "Налаштування адаптера для Wallbox" + "unlock_before_resume": "Розблокуйте Wallbox автоматично, коли активується дія «відновити»." } diff --git a/admin/i18n/zh-cn/translations.json b/admin/i18n/zh-cn/translations.json index 4574cea..61b09a8 100644 --- a/admin/i18n/zh-cn/translations.json +++ b/admin/i18n/zh-cn/translations.json @@ -1,10 +1,11 @@ { - "charger_serial": "Wallbox 的序列号", - "default_settings": "标准设置", + "charger_id": "Wallbox 的序列号", "donate": "如果您喜欢这个适配器,请考虑捐赠以支持我的工作。", "email": "电子邮件", - "ex_charger_serial": "可以在以下位置找到:", + "ex_charger_id": "可以在以下位置找到:", + "ex_unlock_before_resume": "(否则:Wallbox 需要先通过“control.locked”状态解锁)", + "main_settings": "主要设置", "password": "密码", - "poll_time": "轮询时间以秒为单位(最少 30 秒)", - "wallbox adapter settings": "墙盒的适配器设置" + "poll_time": "轮询时间(以秒为单位)(最短 30 秒)", + "unlock_before_resume": "触发“恢复”操作时自动解锁 Wallbox" } diff --git a/admin/jsonConfig.json b/admin/jsonConfig.json index 57bf53f..0fe1984 100644 --- a/admin/jsonConfig.json +++ b/admin/jsonConfig.json @@ -7,7 +7,7 @@ "items": { "_StandardTab": { "type": "panel", - "label": "default_settings", + "label": "main_settings", "items": { "email": { "type": "text", @@ -31,7 +31,7 @@ }, "charger_id": { "type": "text", - "label": "charger_serial", + "label": "charger_id", "xs": 12, "sm": 12, "md": 12, @@ -39,6 +39,27 @@ "xl": 6, "newLine": true }, + "ex_charger_id": { + "type": "staticText", + "text": "ex_charger_id", + "xs": 12, + "sm": 12, + "md": 12, + "lg": 12, + "xl": 12, + "newLine": true + }, + "ex_charger_link": { + "type": "staticLink", + "label": "https://my.wallbox.com/chargers", + "href": "https://my.wallbox.com/chargers", + "xs": 12, + "sm": 12, + "md": 12, + "lg": 12, + "xl": 12, + "newLine": false + }, "poll_time": { "type": "number", "label": "poll_time", @@ -51,6 +72,20 @@ "xl": 6, "newLine": true }, + "unlock_before_resume": { + "type": "checkbox", + "label": "unlock_before_resume" + }, + "ex_unlock_before_resume": { + "type": "staticText", + "text": "ex_unlock_before_resume", + "xs": 12, + "sm": 12, + "md": 12, + "lg": 12, + "xl": 12, + "newLine": false + }, "_divider0": { "newLine": true, "type": "divider", diff --git a/admin/words.js b/admin/words.js index f10d393..1de87f1 100644 --- a/admin/words.js +++ b/admin/words.js @@ -8,12 +8,13 @@ 'use strict'; systemDictionary = { - "charger_serial": { "en": "Serial Number of your Wallbox", "de": "Seriennummer Ihrer Wallbox", "ru": "Серийный номер вашего Wallbox", "pt": "Número de série da Wallbox", "nl": "Serienummer van je Wallbox", "fr": "Numéro de série de votre Wallbox", "it": "Numero di serie della tua Wallbox", "es": "Número de serie de su Wallbox", "pl": "Numer seryjny Twojego Wallbox", "uk": "Серійний номер вашої Wallbox", "zh-cn": "Wallbox 的序列号"}, - "default_settings": { "en": "Standard settings", "de": "Standardeinstellungen", "ru": "Стандартные настройки", "pt": "Configurações padrão", "nl": "Standaard instellingen", "fr": "Paramètres standards", "it": "Impostazioni standard", "es": "Configuraciones estándar", "pl": "Ustawienia standardowe", "uk": "Стандартні налаштування", "zh-cn": "标准设置"}, + "charger_id": { "en": "Serial Number of your Wallbox", "de": "Seriennummer Ihrer Wallbox", "ru": "Серийный номер вашего Wallbox", "pt": "Número de série da sua Wallbox", "nl": "Serienummer van uw Wallbox", "fr": "Numéro de série de votre Wallbox", "it": "Numero di serie della tua Wallbox", "es": "Número de serie de tu Wallbox", "pl": "Numer seryjny Twojej stacji Wallbox", "uk": "Серійний номер вашої Wallbox", "zh-cn": "Wallbox 的序列号"}, "donate": { "en": "If you like this adapter, please consider making a donation to support my work.", "de": "Wenn Ihnen dieser Adapter gefällt, denken Sie bitte über eine Spende nach, um meine Arbeit zu unterstützen.", "ru": "Если вам нравится этот адаптер, пожалуйста, рассмотрите возможность сделать пожертвование в поддержку моей работы.", "pt": "Se você gosta deste adaptador, considere fazer uma doação para apoiar meu trabalho.", "nl": "Als je deze adapter leuk vindt, overweeg dan een donatie te doen om mijn werk te ondersteunen.", "fr": "Si vous aimez cet adaptateur, pensez à faire un don pour soutenir mon travail.", "it": "Se ti piace questo adattatore, considera di fare una donazione per sostenere il mio lavoro.", "es": "Si le gusta este adaptador, considere hacer una donación para apoyar mi trabajo.", "pl": "Jeśli podoba Ci się ten adapter, rozważ przekazanie darowizny na wsparcie mojej pracy.", "uk": "Якщо вам подобається цей адаптер, зробіть пожертву на підтримку моєї роботи.", "zh-cn": "如果您喜欢这个适配器,请考虑捐赠以支持我的工作。"}, "email": { "en": "E-Mail", "de": "E-Mail", "ru": "Электронная почта", "pt": "E-mail", "nl": "E-mail", "fr": "E-mail", "it": "E-mail", "es": "Correo electrónico", "pl": "E-mail", "uk": "Електронна пошта", "zh-cn": "电子邮件"}, - "ex_charger_serial": { "en": "Can be found on:", "de": "Zu finden auf:", "ru": "Можно найти на:", "pt": "Pode ser encontrado em:", "nl": "Te vinden op:", "fr": "A retrouver sur :", "it": "Può essere trovato su:", "es": "Se puede encontrar en:", "pl": "Można znaleźć na:", "uk": "Можна знайти на:", "zh-cn": "可以在以下位置找到:"}, - "password": { "en": "Password", "de": "Passwort", "ru": "Пароль", "pt": "Senha", "nl": "Wachtwoord", "fr": "Mot de passe", "it": "Parola d'ordine", "es": "Clave", "pl": "Hasło", "uk": "Пароль", "zh-cn": "密码"}, - "poll_time": { "en": "Poll-Time in Seconds (min. 30 seconds)", "de": "Poll-Zeit in Sekunden (min. 30 Sekunden)", "ru": "Время опроса в секундах (мин. 30 секунд)", "pt": "Tempo de pesquisa em segundos (mín. 30 segundos)", "nl": "Poll-tijd in seconden (min. 30 seconden)", "fr": "Temps d'interrogation en secondes (min. 30 secondes)", "it": "Tempo di polling in secondi (min. 30 secondi)", "es": "Tiempo de sondeo en segundos (mín. 30 segundos)", "pl": "Czas odpytywania w sekundach (min. 30 sekund)", "uk": "Час опитування в секундах (мін. 30 секунд)", "zh-cn": "轮询时间以秒为单位(最少 30 秒)"}, - "wallbox adapter settings": { "en": "Adapter settings for wallbox", "de": "Adaptereinstellungen für Wallbox", "ru": "Настройки адаптера для wallbox", "pt": "Configurações do adaptador para wallbox", "nl": "Adapterinstellingen voor wallbox", "fr": "Paramètres de l'adaptateur pour wallbox", "it": "Impostazioni dell'adattatore per wallbox", "es": "Ajustes del adaptador para Wallbox", "pl": "Ustawienia adaptera do Wallbox", "uk": "Налаштування адаптера для Wallbox", "zh-cn": "墙盒的适配器设置"}, + "ex_charger_id": { "en": "Can be found on:", "de": "Zu finden auf:", "ru": "Можно найти на:", "pt": "Pode ser encontrado em:", "nl": "Te vinden op:", "fr": "Peut être trouvé sur :", "it": "Può essere trovato su:", "es": "Se puede encontrar en:", "pl": "Można znaleźć na:", "uk": "Можна знайти на:", "zh-cn": "可以在以下位置找到:"}, + "main_settings": { "en": "Main Settings", "de": "Haupteinstellungen", "ru": "Основные настройки", "pt": "Configurações principais", "nl": "Hoofdinstellingen", "fr": "Paramètres principaux", "it": "Impostazioni principali", "es": "Configuración principal", "pl": "Główne ustawienia", "uk": "Основні налаштування", "zh-cn": "主要设置"}, + "password": { "en": "Password", "de": "Passwort", "ru": "Пароль", "pt": "Senha", "nl": "Wachtwoord", "fr": "Mot de passe", "it": "Password", "es": "Contraseña", "pl": "Hasło", "uk": "Пароль", "zh-cn": "密码"}, + "poll_time": { "en": "Poll-Time in Seconds (min. 30 seconds)", "de": "Poll-Zeit in Sekunden (min. 30 Sekunden)", "ru": "Время опроса в секундах (минимум 30 секунд)", "pt": "Tempo de pesquisa em segundos (min. 30 segundos)", "nl": "Poll-tijd in seconden (min. 30 seconden)", "fr": "Durée d'interrogation en secondes (min. 30 secondes)", "it": "Tempo di polling in secondi (min. 30 secondi)", "es": "Tiempo de encuesta en segundos (mínimo 30 segundos)", "pl": "Czas odpytywania w sekundach (min. 30 sekund)", "uk": "Час опитування в секундах (мін. 30 секунд)", "zh-cn": "轮询时间(以秒为单位)(最短 30 秒)"}, + "unlock_before_resume": { "en": "Unlock the Wallbox automatically when the 'resume' action is triggered", "de": "Entsperren Sie die Wallbox automatisch, wenn die Aktion „Fortsetzen“ ausgelöst wird", "ru": "Автоматически разблокируйте Wallbox при срабатывании действия «возобновить»", "pt": "Desbloqueie a Wallbox automaticamente quando a ação 'reiniciar' for acionada", "nl": "Ontgrendel de Wallbox automatisch wanneer de 'hervatten'-actie wordt geactiveerd", "fr": "Déverrouillez automatiquement la Wallbox lorsque l'action « reprendre » est déclenchée", "it": "Sblocca automaticamente la Wallbox quando viene attivata l'azione \"riprendi\".", "es": "Desbloquea el Wallbox automáticamente cuando se activa la acción 'reanudar'", "pl": "Odblokuj Wallbox automatycznie po uruchomieniu akcji „wznów”.", "uk": "Розблокуйте Wallbox автоматично, коли активується дія «відновити».", "zh-cn": "触发“恢复”操作时自动解锁 Wallbox"}, + "ex_unlock_before_resume": { "en": "(Else: Wallbox needs to be unlocked before via the 'control.locked' state)", "de": "(Sonst: Wallbox muss zuvor über den Status „control.locked“ entsperrt werden)", "ru": "(Иначе: перед этим необходимо разблокировать Wallbox через состояние «control.locked»).", "pt": "(Senão: a Wallbox precisa ser desbloqueada antes através do estado 'control.locked')", "nl": "(Anders: Wallbox moet eerst worden ontgrendeld via de status 'control.locked')", "fr": "(Sinon : la Wallbox doit être déverrouillée au préalable via l'état « control.locked »)", "it": "(Altrimenti: la Wallbox deve essere sbloccata prima tramite lo stato 'control.locked')", "es": "(De lo contrario: Wallbox debe desbloquearse antes mediante el estado 'control.locked')", "pl": "(W przeciwnym razie: Wallbox musi zostać wcześniej odblokowany w stanie „control.locked”)", "uk": "(Інакше: перед цим Wallbox потрібно розблокувати за допомогою стану «control.locked»)", "zh-cn": "(否则:Wallbox 需要先通过“control.locked”状态解锁)"}, }; \ No newline at end of file diff --git a/io-package.json b/io-package.json index dcbd8e8..2749502 100644 --- a/io-package.json +++ b/io-package.json @@ -145,7 +145,8 @@ "passsword": "", "charger_id": "", "email": "", - "poll_time": 30 + "poll_time": 30, + "unlock_before_resume": false }, "objects": [], "instanceObjects": [ diff --git a/main.js b/main.js index a73024b..01ff3d0 100644 --- a/main.js +++ b/main.js @@ -25,19 +25,15 @@ class MyWallbox extends utils.Adapter { name: 'mywallbox', }); // Min Poll 30 sec. - Max. 600 sec. - this.poll_time = Math.max(30, Math.min(600, this.config.poll_time || 30)); + this.poll_time = 30; + this.unlock_resume = false; this.charger_data = null; + this.conn_timeout = 25000; + this.charger_id = undefined; this.extended_charger_data = null; this.adapterIntervals = { readAllStates: undefined }; - this.BASEURL = 'https://api.wall-box.com/'; - this.URL_AUTHENTICATION = 'auth/token/user'; - this.URL_CHARGER = 'v2/charger/'; - this.URL_CHARGER_CONTROL = 'v3/chargers/'; - this.URL_CHARGER_ACTION = '/remote-action'; - this.URL_STATUS = 'chargers/status/'; - this.on('ready', this.onReady.bind(this)); this.on('stateChange', this.onStateChange.bind(this)); @@ -54,23 +50,34 @@ class MyWallbox extends utils.Adapter { // Reset the connection indicator during startup this.setState('info.connection', false, true); - this.conn_timeout = (this.poll_time * 1000) - 5000; if (this.config.email == '' || this.config.password == '') { this.log.error('No Email and/or password set. Please review adapter config!'); } else { + // Min Poll 30 sec. - Max. 600 sec. + this.poll_time = Math.max(30, Math.min(600, this.config.poll_time || 30)); + this.conn_timeout = (this.poll_time * 1000) - 5000; + this.unlock_resume = this.config.unlock_before_resume || false; + this.charger_id = this.config.charger_id; + this.BASEURL = 'https://api.wall-box.com/'; + this.URL_AUTHENTICATION = `${this.BASEURL}auth/token/user`; + this.URL_CHARGER = `${this.BASEURL}v2/charger/${this.charger_id}`; + this.URL_CHARGER_CONTROL = `${this.BASEURL}v3/chargers/${this.charger_id}/remote-action`; + this.URL_STATUS = `${this.BASEURL}chargers/status/${this.charger_id}`; + // Log into Wallbox Account - this.log.info('Logging into My-Wallbox-API'); + this.log.info('Logging into My-Wallbox-API!'); // Login and create the states after confirm this.getWallboxToken().then(async () => { - await this.createStates(this.config.charger_id); + await this.createStates(this.charger_id); // Activate Polling Timer this.adapterIntervals.readAllStates = this.setInterval(() => { this.requestPolling(); }, this.poll_time * 1000); - this.log.info(`Polling activated with an interval of ${this.poll_time} seconds! Timeout for connection to API is set to ${this.conn_timeout}ms!`); + this.log.info('Login successfully!'); + this.log.info(`Polling activated with an interval of ${this.poll_time} seconds! Timeout for connection to API is set to ${this.conn_timeout / 1000} seconds!`); // Request Poll await this.requestPolling(); @@ -170,7 +177,20 @@ class MyWallbox extends utils.Adapter { case 'resume': if (state.val === true) { + // Check, if the charger is locked! + if (this.charger_data.locked === 1) { + if (this.unlock_resume) { + this.log.info('Automatic unlocking of the wallbox is enabled. Unlocking wallbox first!'); + await this.changeChargerData(token, JSON.stringify({ locked: 0 })); + this.log.info('Unlocking done!'); + } else { + this.log.warn('The wallbox is locked and will not resume! If you want to unlock the charger automatically before, please enable this in the adapter settings!'); + return; + } + } + this.log.info('Requesting to set the Wallbox into Resume-Mode!'); + this.controlCharger(token, JSON.stringify({ action: 1 })) .then(async (response) => { this.log.info(response); @@ -182,6 +202,7 @@ class MyWallbox extends utils.Adapter { this.log.warn(`Error on controling the Wallbox: ${JSON.stringify(error.message)}`); } }); + } break; @@ -227,7 +248,9 @@ class MyWallbox extends utils.Adapter { // Request new poll - this.requestSinglePoll(token); + this.setTimeout(() => { + this.requestSinglePoll(token); + }, 5000); }).catch((error) => { this.log.warn(`Error on Wallbox Control. Error: ${JSON.stringify(error.message)}`); }); @@ -240,7 +263,7 @@ class MyWallbox extends utils.Adapter { return new Promise((resolve, reject) => { this.log.silly("Email: " + this.config.email + " | Password: " + this.config.password); axios({ - url: this.BASEURL + this.URL_AUTHENTICATION, + url: this.URL_AUTHENTICATION, timeout: this.conn_timeout, method: 'POST', headers: { @@ -265,7 +288,7 @@ class MyWallbox extends utils.Adapter { async getChargerData(token) { return new Promise((resolve, reject) => { axios({ - url: this.BASEURL + this.URL_CHARGER + this.config.charger_id, + url: this.URL_CHARGER, timeout: this.conn_timeout, method: 'PUT', headers: { @@ -290,7 +313,7 @@ class MyWallbox extends utils.Adapter { async getExtendedChargerData(token) { return new Promise((resolve, reject) => { axios({ - url: this.BASEURL + this.URL_STATUS + this.config.charger_id, + url: this.URL_STATUS, timeout: this.conn_timeout, method: 'GET', headers: { @@ -315,7 +338,7 @@ class MyWallbox extends utils.Adapter { async changeChargerData(token, data) { return new Promise((resolve, reject) => { axios({ - url: this.BASEURL + this.URL_CHARGER + this.config.charger_id, + url: this.URL_CHARGER, timeout: this.conn_timeout, method: 'PUT', headers: { @@ -339,7 +362,7 @@ class MyWallbox extends utils.Adapter { async controlCharger(token, data) { return new Promise((resolve, reject) => { axios({ - url: this.BASEURL + this.URL_CHARGER_CONTROL + this.config.charger_id + this.URL_CHARGER_ACTION, + url: this.URL_CHARGER_CONTROL, timeout: this.conn_timeout, method: 'POST', headers: { @@ -382,7 +405,7 @@ class MyWallbox extends utils.Adapter { let folder = ""; // RAW Data - await this.setStateAsync(this.config.charger_id + '.info._rawData', { + await this.setStateAsync(this.charger_id + '.info._rawData', { val: JSON.stringify(states), ack: true }); @@ -402,7 +425,7 @@ class MyWallbox extends utils.Adapter { /* Additional states */ // lastConnection if (key == 'lastConnection') { - await this.setStateAsync(`${this.config.charger_id}.info.lastSyncDT`, { + await this.setStateAsync(`${this.charger_id}.info.lastSyncDT`, { val: this.getDateTime(states.lastConnection * 1000), ack: true }); @@ -410,8 +433,18 @@ class MyWallbox extends utils.Adapter { // Car Connected if (key == 'status') { - await this.setStateAsync(`${this.config.charger_id}.info.car_connected`, { - val: ![161, 163, 166].includes(states.status) ? true : false, + + await this.setStateAsync(`${this.charger_id}.info.car_connected`, { + /* + "14": "Error", + "15": "Error", + "161": "Ready", + "162": "Ready", + "163": "Disconnected", + "166": "Updating", + "209": "Locked", + */ + val: [14, 15, 161, 162, 163, 166, 209].includes(states.status) ? false : true, ack: true }); } @@ -430,7 +463,7 @@ class MyWallbox extends utils.Adapter { /* Additional states */ if (key == 'maxChargingCurrent') { - await this.setStateAsync(`${this.config.charger_id}.control.maxChargingCurrent`, { + await this.setStateAsync(`${this.charger_id}.control.maxChargingCurrent`, { val: states.maxChargingCurrent, ack: true }); @@ -459,7 +492,7 @@ class MyWallbox extends utils.Adapter { case 'resume': folder = ""; for (const _key of Object.keys(states['resume'])) { - await this.setStateAsync(`${this.config.charger_id}.chargingData.monthly.${_key}`, { + await this.setStateAsync(`${this.charger_id}.chargingData.monthly.${_key}`, { val: isNaN(states['resume'][_key]) ? states['resume'][_key] : parseInt(states['resume'][_key]), ack: true }); @@ -478,8 +511,8 @@ class MyWallbox extends utils.Adapter { // Set the proper state if (folder != "") { - this.log.debug(`Setting: ${this.config.charger_id}.${folder}.${key} with ${states[key]}`); - await this.setStateAsync(`${this.config.charger_id}.${folder}.${key}`, { + this.log.debug(`Setting: ${this.charger_id}.${folder}.${key} with ${states[key]}`); + await this.setStateAsync(`${this.charger_id}.${folder}.${key}`, { val: states[key], ack: true }); @@ -493,7 +526,7 @@ class MyWallbox extends utils.Adapter { let state = ""; // RAW Data - await this.setStateAsync(`${this.config.charger_id}.info._rawDataExtended`, { + await this.setStateAsync(`${this.charger_id}.info._rawDataExtended`, { val: JSON.stringify(states), ack: true }); @@ -529,8 +562,8 @@ class MyWallbox extends utils.Adapter { // Set the proper state if (folder != "" && state != "") { - this.log.debug(`Setting: ${this.config.charger_id}.${folder}.${key} with ${states[key]}`); - await this.setStateAsync(`${this.config.charger_id}.${folder}.${key}`, { + this.log.debug(`Setting: ${this.charger_id}.${folder}.${key} with ${states[key]}`); + await this.setStateAsync(`${this.charger_id}.${folder}.${key}`, { val: state, ack: true }); @@ -541,34 +574,34 @@ class MyWallbox extends utils.Adapter { // Sometimes chargerData is not delivered - prevent crash with checking of existence if (this.charger_data !== undefined) { if (this.charger_data.hasOwnProperty('resume')) { - await this.setStateAsync(this.config.charger_id + '.chargingData.monthly.cost', { + await this.setStateAsync(this.charger_id + '.chargingData.monthly.cost', { val: parseFloat(((this.charger_data.resume.totalEnergy * states.depot_price) / 1000).toFixed(2)), ack: true }); } } - await this.setStateAsync(this.config.charger_id + '.info.software.currentVersion', { + await this.setStateAsync(this.charger_id + '.info.software.currentVersion', { val: states.config_data.software.currentVersion, ack: true }); - await this.setStateAsync(this.config.charger_id + '.info.software.latestVersion', { + await this.setStateAsync(this.charger_id + '.info.software.latestVersion', { val: states.config_data.software.latestVersion, ack: true }); - await this.setStateAsync(this.config.charger_id + '.info.software.updateAvailable', { + await this.setStateAsync(this.charger_id + '.info.software.updateAvailable', { val: states.config_data.software.updateAvailable, ack: true }); - await this.setStateAsync(this.config.charger_id + '.info.lock.auto_lock', { + await this.setStateAsync(this.charger_id + '.info.lock.auto_lock', { val: states.config_data.auto_lock, ack: true }); - await this.setStateAsync(this.config.charger_id + '.info.lock.auto_lock_time', { + await this.setStateAsync(this.charger_id + '.info.lock.auto_lock_time', { val: states.config_data.auto_lock_time, ack: true });