From 5c2c78758b3c33d68ebdd7587e2e1369431cfeab Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 7 Feb 2021 08:14:12 +0100 Subject: [PATCH 01/83] info updated --- plugin_info/info.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin_info/info.json b/plugin_info/info.json index a6e75ba..44e188f 100644 --- a/plugin_info/info.json +++ b/plugin_info/info.json @@ -14,6 +14,6 @@ "maxDependancyInstallTime" : 0, "changelog" : "https://ioxfr.github.io/jeedom-wallbox/#language#/changelog", "documentation" : "https://ioxfr.github.io/jeedom-wallbox/#language#/", - "language" : ["fr_FR","en_US"], + "language" : ["fr_FR"], "compatibility" : ["miniplus","smart","rpi","docker","diy","mobile","v4"] } From 1533c68554ed159338649830d3292c5dc4111105 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 23 Oct 2022 16:28:11 +0200 Subject: [PATCH 02/83] Control plugin configuration --- desktop/php/wallbox.php | 9 +++++++++ plugin_info/configuration.php | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/desktop/php/wallbox.php b/desktop/php/wallbox.php index 5ee15a4..dbe587d 100644 --- a/desktop/php/wallbox.php +++ b/desktop/php/wallbox.php @@ -7,7 +7,16 @@ sendVarToJS('eqType', $plugin->getId()); $eqLogics = eqLogic::byType($plugin->getId()); if(count($eqLogics) != 0){ + $username = config::byKey("username", "wallbox"); + $password = config::byKey("password", "wallbox"); + if($username != null || $password != null){ $chargers = $eqLogics[0]->getChargerList(); +} +else{ + log::add('wallbox', 'error', 'Plugin is not configured with username & password wallbox account.' ); + $charger = []; +} + }else{$charger = [];} ?> diff --git a/plugin_info/configuration.php b/plugin_info/configuration.php index a95d022..9df5c83 100644 --- a/plugin_info/configuration.php +++ b/plugin_info/configuration.php @@ -21,7 +21,12 @@ include_file('desktop', '404', 'php'); die(); } +$username = config::byKey("username", "wallbox"); +$password = config::byKey("password", "wallbox"); +if($username == null || $password == null){ ?> +

{{Username & Password are required for plugin.}}

+
From 350c44c52e1fd0db033ebaa49790b34fc04a78d7 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 23 Oct 2022 21:00:05 +0200 Subject: [PATCH 03/83] message added before creating object --- core/class/wallbox.class.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index a779790..1afed37 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -94,7 +94,11 @@ public static function cronDaily() { // Fonction exécutée automatiquement avant la création de l'équipement public function preInsert() { - + $username = config::byKey("username", "wallbox"); +$password = config::byKey("password", "wallbox"); +if($username == null || $password == null){ + throw new Exception("You must configure username and password to be able to use this plugin"); +} } // Fonction exécutée automatiquement après la création de l'équipement From e747d3a4d76109ce50123ed4f3c41ef130c54488 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 06:20:18 +0200 Subject: [PATCH 04/83] Check mandatory config for CRON --- core/class/wallbox.class.php | 16 ++++++++++++---- docs/fr_FR/changelog.md | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 1afed37..d5ffa60 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -31,7 +31,12 @@ class wallbox extends eqLogic { // Fonction exécutée automatiquement toutes les minutes par Jeedom public static function cron() { - foreach (self::byType('wallbox') as $wallbox) {//parcours tous les équipements du plugin vdm + $username = config::byKey("username", "wallbox"); + $password = config::byKey("password", "wallbox"); + if($username == null || $password == null){ + throw new Exception("You must configure username and password to be able to use this plugin"); + } + foreach (self::byType('wallbox') as $wallbox) {//parcours tous les équipements du plugin if ($wallbox->getIsEnable() == 1) {//vérifie que l'équipement est actif $cmd = $wallbox->getCmd(null, 'refresh');//retourne la commande "refresh si elle existe if (!is_object($cmd)) {//Si la commande n'existe pas @@ -46,7 +51,12 @@ public static function cron() { // Fonction exécutée automatiquement toutes les 5 minutes par Jeedom public static function cron5() { - foreach (self::byType('wallbox') as $wallbox) {//parcours tous les équipements du plugin vdm + $username = config::byKey("username", "wallbox"); + $password = config::byKey("password", "wallbox"); + if($username == null || $password == null){ + throw new Exception("You must configure username and password to be able to use this plugin"); + } + foreach (self::byType('wallbox') as $wallbox) {//parcours tous les équipements du plugin if ($wallbox->getIsEnable() == 1) {//vérifie que l'équipement est actif $cmd = $wallbox->getCmd(null, 'refresh');//retourne la commande "refresh si elle existe if (!is_object($cmd)) {//Si la commande n'existe pas @@ -257,8 +267,6 @@ public function getWallboxToken(){ $baseurl = "https://api.wall-box.com/"; log::add('wallbox', 'debug', 'in authentication ' ); // AUTHENTICATION - //$username = $this->getConfiguration("username"); - //$password = $this->getConfiguration("password"); $username = config::byKey("username", "wallbox"); $password = config::byKey("password", "wallbox"); diff --git a/docs/fr_FR/changelog.md b/docs/fr_FR/changelog.md index 29b9a7b..f1aad5a 100644 --- a/docs/fr_FR/changelog.md +++ b/docs/fr_FR/changelog.md @@ -1,5 +1,8 @@ # Changelog wallbox plugin +# 10/2022 +- Ajout de vérification de configuration du plugin avant de pouvoir effectuer l'ajout d'équipement ou l'activation des CRON + # 30/01/2021 - Implementation of API call to get chargers of account - Changed input to dropdownlist for charger selection From 6a567c36ce6e11dea3d95f06ff212413f3553be4 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 06:26:04 +0200 Subject: [PATCH 05/83] Change error message --- plugin_info/configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin_info/configuration.php b/plugin_info/configuration.php index 9df5c83..b2eb7c0 100644 --- a/plugin_info/configuration.php +++ b/plugin_info/configuration.php @@ -25,7 +25,7 @@ $password = config::byKey("password", "wallbox"); if($username == null || $password == null){ ?> -

{{Username & Password are required for plugin.}}

+

{{Username & Password are required for plugin.}}

From dbdcb19cb50ddbc33bcaab4d68cae7630c63e780 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 06:27:35 +0200 Subject: [PATCH 06/83] added exception to configuration page --- plugin_info/configuration.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin_info/configuration.php b/plugin_info/configuration.php index b2eb7c0..037b3c7 100644 --- a/plugin_info/configuration.php +++ b/plugin_info/configuration.php @@ -26,7 +26,9 @@ if($username == null || $password == null){ ?>

{{Username & Password are required for plugin.}}

- +
From 9b7e61ceef7e919028e10fd4a575613fb17f87e0 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 06:33:24 +0200 Subject: [PATCH 07/83] synthax problem fixed --- plugin_info/configuration.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin_info/configuration.php b/plugin_info/configuration.php index 037b3c7..ccfe4bc 100644 --- a/plugin_info/configuration.php +++ b/plugin_info/configuration.php @@ -27,8 +27,7 @@ ?>

{{Username & Password are required for plugin.}}

+throw new Exception("A username and password is required for the plugin to work"); } ?>
From bc315eead740b0f4bac35080f6a7c6e1d4a773af Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 06:49:20 +0200 Subject: [PATCH 08/83] fix for UTC time --- core/class/wallbox.class.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index d5ffa60..723d6ba 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -401,7 +401,7 @@ public function execute($_options = null) { $info = $this->getEqLogic()->getChargerStatus(); $eqlogic->checkAndUpdateCmd('name', $info['name']); - $eqlogic->checkAndUpdateCmd('lastsync', $info['last_sync']); + $eqlogic->checkAndUpdateCmd('lastsync', utctolocal($info['last_sync'])); $eqlogic->checkAndUpdateCmd('status', $info['status_description']); $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); $eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); @@ -412,6 +412,19 @@ public function execute($_options = null) { } } + + // Utility + public function utctolocal($date) + { + $time = new DateTime($date, new DateTimeZone('UTC')); + $tm_tz_from = $timeZone; + $tm_tz_to = new DateTimeZone(date_default_timezone_get()); + $dt = new DateTime($date, new DateTimeZone($tm_tz_from)); + $dt->setTimeZone(new DateTimeZone($tm_tz_to)); + $utc_time_from =$dt->format("d-m-Y h:i:s"); + + return $utc_time_from; + } /* * **********************Getteur Setteur*************************** */ } From 4dab1d4a6bc6ad4eeb395346ee4e8f95a83b758c Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 06:57:50 +0200 Subject: [PATCH 09/83] Added logs to date conversion --- core/class/wallbox.class.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 723d6ba..28470fa 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -416,12 +416,16 @@ public function execute($_options = null) { // Utility public function utctolocal($date) { + log::add('wallbox', 'debug', 'starting date conversion from UTC to local'); $time = new DateTime($date, new DateTimeZone('UTC')); $tm_tz_from = $timeZone; - $tm_tz_to = new DateTimeZone(date_default_timezone_get()); + $localtimezone = date_default_timezone_get(); + log::add('wallbox', 'debug', 'local timezone is defined on '.$localtimezone); + $tm_tz_to = new DateTimeZone($localtimezone); $dt = new DateTime($date, new DateTimeZone($tm_tz_from)); $dt->setTimeZone(new DateTimeZone($tm_tz_to)); $utc_time_from =$dt->format("d-m-Y h:i:s"); + log::add('wallbox', 'debug', 'Date converted '.$utc_time_from); return $utc_time_from; } From c5a536e5074413a4d00c315882a4eef3f49b23e9 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 06:59:24 +0200 Subject: [PATCH 10/83] synthax problem fixed --- core/class/wallbox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 28470fa..19f42d6 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -401,7 +401,7 @@ public function execute($_options = null) { $info = $this->getEqLogic()->getChargerStatus(); $eqlogic->checkAndUpdateCmd('name', $info['name']); - $eqlogic->checkAndUpdateCmd('lastsync', utctolocal($info['last_sync'])); + $eqlogic->checkAndUpdateCmd('lastsync', $this->utctolocal($info['last_sync'])); $eqlogic->checkAndUpdateCmd('status', $info['status_description']); $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); $eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); From 149dae8d68c9ed77c847f0acf67cee4faf53b6bf Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 07:02:54 +0200 Subject: [PATCH 11/83] synthax function fixed --- core/class/wallbox.class.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 19f42d6..0161972 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -349,6 +349,23 @@ public function getChargerStatus(){ throw new Exception("User is not authenticated"); } } + + // Utility + public function utctolocal($date) + { + log::add('wallbox', 'debug', 'starting date conversion from UTC to local'); + $time = new DateTime($date, new DateTimeZone('UTC')); + $tm_tz_from = $timeZone; + $localtimezone = date_default_timezone_get(); + log::add('wallbox', 'debug', 'local timezone is defined on '.$localtimezone); + $tm_tz_to = new DateTimeZone($localtimezone); + $dt = new DateTime($date, new DateTimeZone($tm_tz_from)); + $dt->setTimeZone(new DateTimeZone($tm_tz_to)); + $utc_time_from =$dt->format("d-m-Y h:i:s"); + log::add('wallbox', 'debug', 'Date converted '.$utc_time_from); + + return $utc_time_from; + } /* * Non obligatoire : permet de modifier l'affichage du widget (également utilisable par les commandes) @@ -401,7 +418,7 @@ public function execute($_options = null) { $info = $this->getEqLogic()->getChargerStatus(); $eqlogic->checkAndUpdateCmd('name', $info['name']); - $eqlogic->checkAndUpdateCmd('lastsync', $this->utctolocal($info['last_sync'])); + $eqlogic->checkAndUpdateCmd('lastsync', $this->getEqLogic()->utctolocal($info['last_sync'])); $eqlogic->checkAndUpdateCmd('status', $info['status_description']); $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); $eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); @@ -413,23 +430,6 @@ public function execute($_options = null) { } - // Utility - public function utctolocal($date) - { - log::add('wallbox', 'debug', 'starting date conversion from UTC to local'); - $time = new DateTime($date, new DateTimeZone('UTC')); - $tm_tz_from = $timeZone; - $localtimezone = date_default_timezone_get(); - log::add('wallbox', 'debug', 'local timezone is defined on '.$localtimezone); - $tm_tz_to = new DateTimeZone($localtimezone); - $dt = new DateTime($date, new DateTimeZone($tm_tz_from)); - $dt->setTimeZone(new DateTimeZone($tm_tz_to)); - $utc_time_from =$dt->format("d-m-Y h:i:s"); - log::add('wallbox', 'debug', 'Date converted '.$utc_time_from); - - return $utc_time_from; - } - /* * **********************Getteur Setteur*************************** */ } From 7daa77d28fe23efeaf01a0b96a9a3738e655bea7 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 07:06:49 +0200 Subject: [PATCH 12/83] Change date format --- core/class/wallbox.class.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 0161972..a959de5 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -354,12 +354,10 @@ public function getChargerStatus(){ public function utctolocal($date) { log::add('wallbox', 'debug', 'starting date conversion from UTC to local'); - $time = new DateTime($date, new DateTimeZone('UTC')); - $tm_tz_from = $timeZone; $localtimezone = date_default_timezone_get(); log::add('wallbox', 'debug', 'local timezone is defined on '.$localtimezone); $tm_tz_to = new DateTimeZone($localtimezone); - $dt = new DateTime($date, new DateTimeZone($tm_tz_from)); + $dt = new DateTime($date, new DateTimeZone('UTC')); $dt->setTimeZone(new DateTimeZone($tm_tz_to)); $utc_time_from =$dt->format("d-m-Y h:i:s"); log::add('wallbox', 'debug', 'Date converted '.$utc_time_from); From 7c50b8bc042e618b91054271882595f50b120cde Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 07:11:45 +0200 Subject: [PATCH 13/83] timezone problem fixed --- core/class/wallbox.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index a959de5..7d40f64 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -356,9 +356,9 @@ public function utctolocal($date) log::add('wallbox', 'debug', 'starting date conversion from UTC to local'); $localtimezone = date_default_timezone_get(); log::add('wallbox', 'debug', 'local timezone is defined on '.$localtimezone); - $tm_tz_to = new DateTimeZone($localtimezone); + $tm_tz_to = new DateTimeZone($localtimezone->getName()); $dt = new DateTime($date, new DateTimeZone('UTC')); - $dt->setTimeZone(new DateTimeZone($tm_tz_to)); + $dt->setTimeZone(new DateTimeZone($tm_tz_to->getName())); $utc_time_from =$dt->format("d-m-Y h:i:s"); log::add('wallbox', 'debug', 'Date converted '.$utc_time_from); From d36276a5dab9b2b08d892cac5fd53aea9a2e236a Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 07:13:52 +0200 Subject: [PATCH 14/83] Synthax problem fixed --- core/class/wallbox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 7d40f64..6bf502a 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -356,7 +356,7 @@ public function utctolocal($date) log::add('wallbox', 'debug', 'starting date conversion from UTC to local'); $localtimezone = date_default_timezone_get(); log::add('wallbox', 'debug', 'local timezone is defined on '.$localtimezone); - $tm_tz_to = new DateTimeZone($localtimezone->getName()); + $tm_tz_to = new DateTimeZone($localtimezone); $dt = new DateTime($date, new DateTimeZone('UTC')); $dt->setTimeZone(new DateTimeZone($tm_tz_to->getName())); $utc_time_from =$dt->format("d-m-Y h:i:s"); From 805770444b83f4c3d77b28144d502638391298b7 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 08:56:26 +0200 Subject: [PATCH 15/83] fix problem with values + adapted values fetched --- core/class/wallbox.class.php | 67 ++++++++++++++++++++++++++++++------ docs/fr_FR/changelog.md | 3 ++ 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 6bf502a..99a7c44 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -158,12 +158,12 @@ public function postSave() { $maxpower->setType('info'); $maxpower->setSubType('numeric'); $maxpower->setUnite('Amp'); - $power->setConfiguration('minValue' , '0'); - $power->setConfiguration('maxValue' , '32'); + $maxpower->setConfiguration('minValue' , '0'); + $maxpower->setConfiguration('maxValue' , '32'); $maxpower->save(); // charging speed - $speed = $this->getCmd(null, 'speed'); + /*$speed = $this->getCmd(null, 'speed'); if (!is_object($speed)) { $speed = new wallboxCmd(); $speed->setName(__('Vitesse de charge', __FILE__)); @@ -175,10 +175,10 @@ public function postSave() { $power->setConfiguration('minValue' , '0'); $power->setConfiguration('maxValue' , '32'); $speed->setUnite('Amp/h'); - $speed->save(); + $speed->save();*/ // state of charge - $chargestatus = $this->getCmd(null, 'chargestatus'); + /*$chargestatus = $this->getCmd(null, 'chargestatus'); if (!is_object($chargestatus)) { $chargestatus = new wallboxCmd(); $chargestatus->setName(__('Statut de la charge', __FILE__)); @@ -187,7 +187,7 @@ public function postSave() { $chargestatus->setEqLogic_id($this->getId()); $chargestatus->setType('info'); $chargestatus->setSubType('string'); - $chargestatus->save(); + $chargestatus->save();*/ // last sync $lastsync = $this->getCmd(null, 'lastsync'); @@ -200,6 +200,33 @@ public function postSave() { $lastsync->setType('info'); $lastsync->setSubType('string'); $lastsync->save(); + + // Charging Time + $chargingtime = $this->getCmd(null, 'chargingtime'); + if (!is_object($lastsync)) { + $chargingtime = new wallboxCmd(); + $chargingtime->setName(__('Temps de charge', __FILE__)); + } + $chargingtime->setLogicalId('chargingtime'); + $chargingtime->setEqLogic_id($this->getId()); + $chargingtime->setType('info'); + $chargingtime->setSubType('string'); + $chargingtime->save(); + + // Energie consommée + $energyconsumed = $this->getCmd(null, 'energyconsumed'); + if (!is_object($lastsync)) { + $energyconsumed = new wallboxCmd(); + $energyconsumed->setName(__('Energie consommée', __FILE__)); + } + $energyconsumed->setLogicalId('energyconsumed'); + $energyconsumed->setEqLogic_id($this->getId()); + $energyconsumed->setType('info'); + $energyconsumed->setSubType('numeric'); + $energyconsumed->setUnite('Kwh'); + $energyconsumed->setConfiguration('minValue' , '0'); + $energyconsumed->setConfiguration('maxValue' , '60'); + $energyconsumed->save(); //status $status = $this->getCmd(null, 'status'); @@ -417,17 +444,37 @@ public function execute($_options = null) { $info = $this->getEqLogic()->getChargerStatus(); $eqlogic->checkAndUpdateCmd('name', $info['name']); $eqlogic->checkAndUpdateCmd('lastsync', $this->getEqLogic()->utctolocal($info['last_sync'])); - $eqlogic->checkAndUpdateCmd('status', $info['status_description']); + $eqlogic->checkAndUpdateCmd('status_id', $info['status_id']); + $eqlogic->checkAndUpdateCmd('status', $this->statustotext($info['status_id'])); $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); - $eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); - $eqlogic->checkAndUpdateCmd('chargestatus', $info['state_of_charge']); + //$eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); $eqlogic->checkAndUpdateCmd('maxpower', $info['max_available_power']); - + $eqlogic->checkAndUpdateCmd('chargingtime',$info['charging_time']);// in second + $eqlogic->checkAndUpdateCmd('energyconsumed',$info['added_energy']); // kwh return; } } + public function statustotext($statusid) + { + switch($statusid) + { + case 209: + return 'Verrouillée'; + break; + case 161: + return 'En attente'; + break; + case 194: + return 'En charge'; + break; + case 182: + return 'En pause'; + break; + } + } + /* * **********************Getteur Setteur*************************** */ } diff --git a/docs/fr_FR/changelog.md b/docs/fr_FR/changelog.md index f1aad5a..d5a0c2d 100644 --- a/docs/fr_FR/changelog.md +++ b/docs/fr_FR/changelog.md @@ -2,6 +2,9 @@ # 10/2022 - Ajout de vérification de configuration du plugin avant de pouvoir effectuer l'ajout d'équipement ou l'activation des CRON +- Correction sur le format de l'heure de la dernière synchronisation avec la borne UTC => Local Date Time +- Ajout de la fonctionnalité de contrôle de charge via le widget +- Ajout de la fonctionnalité de modification du maximum d'ampère d'un chargeur # 30/01/2021 - Implementation of API call to get chargers of account From 57968b8f68e1636cd73ee055844ec4842607926c Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 09:16:46 +0200 Subject: [PATCH 16/83] Command issue fixed --- core/class/wallbox.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 99a7c44..8a361b1 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -105,10 +105,10 @@ public static function cronDaily() { // Fonction exécutée automatiquement avant la création de l'équipement public function preInsert() { $username = config::byKey("username", "wallbox"); -$password = config::byKey("password", "wallbox"); -if($username == null || $password == null){ - throw new Exception("You must configure username and password to be able to use this plugin"); -} + $password = config::byKey("password", "wallbox"); + if($username == null || $password == null){ + throw new Exception("You must configure username and password to be able to use this plugin"); + } } // Fonction exécutée automatiquement après la création de l'équipement @@ -203,7 +203,7 @@ public function postSave() { // Charging Time $chargingtime = $this->getCmd(null, 'chargingtime'); - if (!is_object($lastsync)) { + if (!is_object($chargingtime)) { $chargingtime = new wallboxCmd(); $chargingtime->setName(__('Temps de charge', __FILE__)); } @@ -215,7 +215,7 @@ public function postSave() { // Energie consommée $energyconsumed = $this->getCmd(null, 'energyconsumed'); - if (!is_object($lastsync)) { + if (!is_object($energyconsumed)) { $energyconsumed = new wallboxCmd(); $energyconsumed->setName(__('Energie consommée', __FILE__)); } From 6f6adf5cdf5e281c59ba1fb65ae2c11dd900456e Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 09:21:03 +0200 Subject: [PATCH 17/83] Format of charging time --- core/class/wallbox.class.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 8a361b1..1463f79 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -449,7 +449,7 @@ public function execute($_options = null) { $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); //$eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); $eqlogic->checkAndUpdateCmd('maxpower', $info['max_available_power']); - $eqlogic->checkAndUpdateCmd('chargingtime',$info['charging_time']);// in second + $eqlogic->checkAndUpdateCmd('chargingtime', $this->sectohhmmss($info['charging_time']));// in second $eqlogic->checkAndUpdateCmd('energyconsumed',$info['added_energy']); // kwh return; } @@ -475,6 +475,12 @@ public function statustotext($statusid) } } + public function sectohhmmss($seconds) + { + $seconds = round($seconds); + return sprintf('%02d:%02d:%02d', ($seconds/ 3600),($seconds/ 60 % 60), $seconds% 60); + } + /* * **********************Getteur Setteur*************************** */ } From 6c786884d9fb3a4132064a82e079f80ebb940961 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 13:07:36 +0200 Subject: [PATCH 18/83] manage visibility of fields --- core/class/wallbox.class.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 1463f79..fcad972 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -444,13 +444,32 @@ public function execute($_options = null) { $info = $this->getEqLogic()->getChargerStatus(); $eqlogic->checkAndUpdateCmd('name', $info['name']); $eqlogic->checkAndUpdateCmd('lastsync', $this->getEqLogic()->utctolocal($info['last_sync'])); + + $statusid=$info['status_id']; + $eqlogic->checkAndUpdateCmd('status_id', $info['status_id']); $eqlogic->checkAndUpdateCmd('status', $this->statustotext($info['status_id'])); - $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); + //$eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); $eqlogic->checkAndUpdateCmd('maxpower', $info['max_available_power']); - $eqlogic->checkAndUpdateCmd('chargingtime', $this->sectohhmmss($info['charging_time']));// in second - $eqlogic->checkAndUpdateCmd('energyconsumed',$info['added_energy']); // kwh + + if($statusid == 194){ + $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); + $eqlogic->checkAndUpdateCmd('chargingtime', $this->sectohhmmss($info['charging_time']));// in second + $eqlogic->checkAndUpdateCmd('energyconsumed',$info['added_energy']); // kwh + $eqlogic->getLogicalId('energyconsumed')->setIsVisible(true); + $eqlogic->getLogicalId('chargingtime')->setIsVisible(true); + $eqlogic->getLogicalId('power')->setIsVisible(true); + + } + else + { + $eqlogic->getLogicalId('energyconsumed')->setIsVisible(false); + $eqlogic->getLogicalId('chargingtime')->setIsVisible(false); + $eqlogic->getLogicalId('power')->setIsVisible(false); + } + + return; } From a704a4d40e02a3033cd6a393c4863259ebb7fd37 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 13:11:38 +0200 Subject: [PATCH 19/83] synthax problem fixed --- core/class/wallbox.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index fcad972..88271db 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -457,16 +457,16 @@ public function execute($_options = null) { $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); $eqlogic->checkAndUpdateCmd('chargingtime', $this->sectohhmmss($info['charging_time']));// in second $eqlogic->checkAndUpdateCmd('energyconsumed',$info['added_energy']); // kwh - $eqlogic->getLogicalId('energyconsumed')->setIsVisible(true); - $eqlogic->getLogicalId('chargingtime')->setIsVisible(true); - $eqlogic->getLogicalId('power')->setIsVisible(true); + $eqlogic->getCmd(null,'energyconsumed')->setIsVisible(true); + $eqlogic->getCmd(null,'chargingtime')->setIsVisible(true); + $eqlogic->getCmd(null,'power')->setIsVisible(true); } else { - $eqlogic->getLogicalId('energyconsumed')->setIsVisible(false); - $eqlogic->getLogicalId('chargingtime')->setIsVisible(false); - $eqlogic->getLogicalId('power')->setIsVisible(false); + $eqlogic->getCmd(null,'energyconsumed')->setIsVisible(false); + $eqlogic->getCmd(null,'chargingtime')->setIsVisible(false); + $eqlogic->getCmd(null,'power')->setIsVisible(false); } From a3709280726b809683bda8bee9d77050257466b2 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 13:16:23 +0200 Subject: [PATCH 20/83] save for visibility added --- core/class/wallbox.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 88271db..bfb2212 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -457,16 +457,16 @@ public function execute($_options = null) { $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); $eqlogic->checkAndUpdateCmd('chargingtime', $this->sectohhmmss($info['charging_time']));// in second $eqlogic->checkAndUpdateCmd('energyconsumed',$info['added_energy']); // kwh - $eqlogic->getCmd(null,'energyconsumed')->setIsVisible(true); - $eqlogic->getCmd(null,'chargingtime')->setIsVisible(true); - $eqlogic->getCmd(null,'power')->setIsVisible(true); + $eqlogic->getCmd(null,'energyconsumed')->setIsVisible(true).save(); + $eqlogic->getCmd(null,'chargingtime')->setIsVisible(true).save(); + $eqlogic->getCmd(null,'power')->setIsVisible(true).save(); } else { - $eqlogic->getCmd(null,'energyconsumed')->setIsVisible(false); - $eqlogic->getCmd(null,'chargingtime')->setIsVisible(false); - $eqlogic->getCmd(null,'power')->setIsVisible(false); + $eqlogic->getCmd(null,'energyconsumed')->setIsVisible(false).save(); + $eqlogic->getCmd(null,'chargingtime')->setIsVisible(false).save(); + $eqlogic->getCmd(null,'power')->setIsVisible(false).save(); } From f3c5459df85aee3b884fcc89076e6f3659d5d0cb Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 13:24:28 +0200 Subject: [PATCH 21/83] Visibility change --- core/class/wallbox.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index bfb2212..11c2773 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -457,16 +457,16 @@ public function execute($_options = null) { $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); $eqlogic->checkAndUpdateCmd('chargingtime', $this->sectohhmmss($info['charging_time']));// in second $eqlogic->checkAndUpdateCmd('energyconsumed',$info['added_energy']); // kwh - $eqlogic->getCmd(null,'energyconsumed')->setIsVisible(true).save(); - $eqlogic->getCmd(null,'chargingtime')->setIsVisible(true).save(); - $eqlogic->getCmd(null,'power')->setIsVisible(true).save(); + $eqlogic->byLogicalId('energyconsumed','info')->setIsVisible(true); + $eqlogic->byLogicalId('chargingtime','info')->setIsVisible(true); + $eqlogic->byLogicalId('power','info')->setIsVisible(true); } else { - $eqlogic->getCmd(null,'energyconsumed')->setIsVisible(false).save(); - $eqlogic->getCmd(null,'chargingtime')->setIsVisible(false).save(); - $eqlogic->getCmd(null,'power')->setIsVisible(false).save(); + $eqlogic->byLogicalId('energyconsumed','info')->setIsVisible(false); + $eqlogic->byLogicalId('chargingtime','info')->setIsVisible(false); + $eqlogic->byLogicalId('power','info')->setIsVisible(false); } From eb843a8516b21789f7cbf4cccd04ba2f215a2e19 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 13:29:14 +0200 Subject: [PATCH 22/83] visibility changed on fields --- core/class/wallbox.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 11c2773..6f9b510 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -457,16 +457,16 @@ public function execute($_options = null) { $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); $eqlogic->checkAndUpdateCmd('chargingtime', $this->sectohhmmss($info['charging_time']));// in second $eqlogic->checkAndUpdateCmd('energyconsumed',$info['added_energy']); // kwh - $eqlogic->byLogicalId('energyconsumed','info')->setIsVisible(true); - $eqlogic->byLogicalId('chargingtime','info')->setIsVisible(true); - $eqlogic->byLogicalId('power','info')->setIsVisible(true); + $this->getEqLogic()->byLogicalId('energyconsumed')->setIsVisible(true); + $this->getEqLogic()->byLogicalId('chargingtime')->setIsVisible(true); + $this->getEqLogic()->byLogicalId('power')->setIsVisible(true); } else { - $eqlogic->byLogicalId('energyconsumed','info')->setIsVisible(false); - $eqlogic->byLogicalId('chargingtime','info')->setIsVisible(false); - $eqlogic->byLogicalId('power','info')->setIsVisible(false); + $this->getEqLogic()->byLogicalId('energyconsumed')->setIsVisible(false); + $this->getEqLogic()->byLogicalId('chargingtime')->setIsVisible(false); + $this->getEqLogic()->byLogicalId('power')->setIsVisible(false); } From 1bf2327d1f60b61a6efb3fe60167808359450025 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 13:31:26 +0200 Subject: [PATCH 23/83] parameter missing fixed --- core/class/wallbox.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 6f9b510..de935ab 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -457,16 +457,16 @@ public function execute($_options = null) { $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); $eqlogic->checkAndUpdateCmd('chargingtime', $this->sectohhmmss($info['charging_time']));// in second $eqlogic->checkAndUpdateCmd('energyconsumed',$info['added_energy']); // kwh - $this->getEqLogic()->byLogicalId('energyconsumed')->setIsVisible(true); - $this->getEqLogic()->byLogicalId('chargingtime')->setIsVisible(true); - $this->getEqLogic()->byLogicalId('power')->setIsVisible(true); + $this->getEqLogic()->byLogicalId('energyconsumed',null)->setIsVisible(true); + $this->getEqLogic()->byLogicalId('chargingtime',null)->setIsVisible(true); + $this->getEqLogic()->byLogicalId('power',null)->setIsVisible(true); } else { - $this->getEqLogic()->byLogicalId('energyconsumed')->setIsVisible(false); - $this->getEqLogic()->byLogicalId('chargingtime')->setIsVisible(false); - $this->getEqLogic()->byLogicalId('power')->setIsVisible(false); + $this->getEqLogic()->byLogicalId('energyconsumed',null)->setIsVisible(false); + $this->getEqLogic()->byLogicalId('chargingtime',null)->setIsVisible(false); + $this->getEqLogic()->byLogicalId('power',null)->setIsVisible(false); } From 40c3c958bab061228acb24920682dcc13963def3 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 13:57:22 +0200 Subject: [PATCH 24/83] test fix --- core/class/wallbox.class.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index de935ab..5e5e556 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -457,16 +457,17 @@ public function execute($_options = null) { $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); $eqlogic->checkAndUpdateCmd('chargingtime', $this->sectohhmmss($info['charging_time']));// in second $eqlogic->checkAndUpdateCmd('energyconsumed',$info['added_energy']); // kwh - $this->getEqLogic()->byLogicalId('energyconsumed',null)->setIsVisible(true); - $this->getEqLogic()->byLogicalId('chargingtime',null)->setIsVisible(true); - $this->getEqLogic()->byLogicalId('power',null)->setIsVisible(true); + $eqlogic->byLogicalId('energyconsumed',null)->setIsVisible(true); + $eqlogic->byLogicalId('chargingtime',null)->setIsVisible(true); + $eqlogic->byLogicalId('power',null)->setIsVisible(true); } else { - $this->getEqLogic()->byLogicalId('energyconsumed',null)->setIsVisible(false); - $this->getEqLogic()->byLogicalId('chargingtime',null)->setIsVisible(false); - $this->getEqLogic()->byLogicalId('power',null)->setIsVisible(false); + $obj = $eqlogic->byLogicalId('energyconsumed',null); + $obj->setIsVisible(false); + /*$this->getEqLogic()->byLogicalId('chargingtime',null)->setIsVisible(false); + $this->getEqLogic()->byLogicalId('power',null)->setIsVisible(false);*/ } From a68935bbffc205497242c253a8c92a81d2192f6a Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 13:59:38 +0200 Subject: [PATCH 25/83] setIsVisible(false) --- core/class/wallbox.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 5e5e556..6b4775b 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -464,8 +464,7 @@ public function execute($_options = null) { } else { - $obj = $eqlogic->byLogicalId('energyconsumed',null); - $obj->setIsVisible(false); + $eqlogic->getCmd(null, 'energyconsumed')->setIsVisible(false); /*$this->getEqLogic()->byLogicalId('chargingtime',null)->setIsVisible(false); $this->getEqLogic()->byLogicalId('power',null)->setIsVisible(false);*/ } From ce431d31070ebabe01ef1fcb3202f258e13fd372 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 14:01:46 +0200 Subject: [PATCH 26/83] missing save added --- core/class/wallbox.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 6b4775b..4037619 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -464,7 +464,9 @@ public function execute($_options = null) { } else { - $eqlogic->getCmd(null, 'energyconsumed')->setIsVisible(false); + $obj = $eqlogic->getCmd(null, 'energyconsumed'); + $obj->setIsVisible(false); + $obj->save(); /*$this->getEqLogic()->byLogicalId('chargingtime',null)->setIsVisible(false); $this->getEqLogic()->byLogicalId('power',null)->setIsVisible(false);*/ } From 166106d0a143caf4c3320bf146edbb6d3a4e3978 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 14:04:41 +0200 Subject: [PATCH 27/83] code fixed for visibility --- core/class/wallbox.class.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 4037619..b9acc50 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -457,18 +457,28 @@ public function execute($_options = null) { $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); $eqlogic->checkAndUpdateCmd('chargingtime', $this->sectohhmmss($info['charging_time']));// in second $eqlogic->checkAndUpdateCmd('energyconsumed',$info['added_energy']); // kwh - $eqlogic->byLogicalId('energyconsumed',null)->setIsVisible(true); - $eqlogic->byLogicalId('chargingtime',null)->setIsVisible(true); - $eqlogic->byLogicalId('power',null)->setIsVisible(true); + $obj = $eqlogic->getCmd(null, 'energyconsumed'); + $obj->setIsVisible(1); + $obj->save(); + $obj = $eqlogic->getCmd(null, 'chargingtime'); + $obj->setIsVisible(1); + $obj->save(); + $obj = $eqlogic->getCmd(null, 'power'); + $obj->setIsVisible(1); + $obj->save(); } else { $obj = $eqlogic->getCmd(null, 'energyconsumed'); - $obj->setIsVisible(false); + $obj->setIsVisible(0); + $obj->save(); + $obj = $eqlogic->getCmd(null, 'chargingtime'); + $obj->setIsVisible(0); + $obj->save(); + $obj = $eqlogic->getCmd(null, 'power'); + $obj->setIsVisible(0); $obj->save(); - /*$this->getEqLogic()->byLogicalId('chargingtime',null)->setIsVisible(false); - $this->getEqLogic()->byLogicalId('power',null)->setIsVisible(false);*/ } From 91c782b7476c0b97cf96d3ab3924bf5ef73533df Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 16:30:29 +0200 Subject: [PATCH 28/83] Implementation of charge control action --- core/class/wallbox.class.php | 72 +++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index b9acc50..8ff5962 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -264,6 +264,18 @@ public function postSave() { $refresh->setSubType('other'); $refresh->save(); + // Charge command action + $chargecontrol = $this->getCmd(null, 'chargecontrol'); + if (!is_object($chargecontrol)) { + $chargecontrol = new wallboxCmd(); + $chargecontrol->setName(__('Contrôle de la charge', __FILE__)); + } + $chargecontrol->setEqLogic_id($this->getId()); + $chargecontrol->setLogicalId('chargecontrol'); + $chargecontrol->setType('action'); + $chargecontrol->setSubType('other'); + $chargecontrol->save(); + // TODO: CRON Configuration /* $cron = cron::byClassAndFunction('weather', 'updateWeatherData', array('weather_id' => intval($this->getId()))); if (!is_object($cron)) { @@ -377,6 +389,42 @@ public function getChargerStatus(){ } } + // function to pause or resume charging + public function defineChargingState($resume) + { + $baseurl = "https://api.wall-box.com/v3/"; + $chargerId = $this->getConfiguration("chargerid"); + log::add('wallbox', 'debug', 'Define charging state '. $chargerId); + $jwt = $this->getWallboxToken(); + + log::add('wallbox', 'debug', 'jwt '. $jwt); + if($jwt != null && $chargerId != null){ + + $data = '{"action":1}'; //resume id + if(!$resume) + { + $data = '{"action":2}'; // pause id + } + + $opts = array('http' => + array( + 'method' => 'GET', + 'header' => 'Authorization: Bearer '.$jwt, + 'content' => http_build_query($data) + ) + ); + + $context = stream_context_create($opts); + + $result = file_get_contents($baseurl.'chargers/'.$chargerId.'/remote-action', false, $context); + $objectresult = json_decode($result,true); + return $objectresult; + } + else{ + throw new Exception("User is not authenticated"); + } + } + // Utility public function utctolocal($date) { @@ -466,7 +514,9 @@ public function execute($_options = null) { $obj = $eqlogic->getCmd(null, 'power'); $obj->setIsVisible(1); $obj->save(); - + $obj = $eqlogic->getCmd(null, 'chargecontrol'); + $obj->setIsVisible(1); + $obj->save(); } else { @@ -479,12 +529,30 @@ public function execute($_options = null) { $obj = $eqlogic->getCmd(null, 'power'); $obj->setIsVisible(0); $obj->save(); + $obj = $eqlogic->getCmd(null, 'chargecontrol'); + $obj->setIsVisible(0); + $obj->save(); } return; } - + else if ($this->getLogicalId() == 'chargecontrol') + { + $info = $this->getEqLogic()->getChargerStatus(); + $statusid=$info['status_id']; + + if($statusid == 194) + { + // charging, we switch to pause + $this->getEqLogic()->getChargerStatus(false); + } + else if($statusid == 182) + { + // in pause, we resume charge + $this->getEqLogic()->defineChargingState(true); + } + } } public function statustotext($statusid) From 6159b76d1ea1f12d95e8bc0bde57917bd2cb808b Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 17:34:40 +0200 Subject: [PATCH 29/83] Implementation for lock/unlock a charger --- core/class/wallbox.class.php | 94 ++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 15 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 8ff5962..f3652bd 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -264,17 +264,29 @@ public function postSave() { $refresh->setSubType('other'); $refresh->save(); - // Charge command action - $chargecontrol = $this->getCmd(null, 'chargecontrol'); - if (!is_object($chargecontrol)) { - $chargecontrol = new wallboxCmd(); - $chargecontrol->setName(__('Contrôle de la charge', __FILE__)); - } - $chargecontrol->setEqLogic_id($this->getId()); - $chargecontrol->setLogicalId('chargecontrol'); - $chargecontrol->setType('action'); - $chargecontrol->setSubType('other'); - $chargecontrol->save(); + // Charge command action + $chargecontrol = $this->getCmd(null, 'chargecontrol'); + if (!is_object($chargecontrol)) { + $chargecontrol = new wallboxCmd(); + $chargecontrol->setName(__('Contrôle de la charge', __FILE__)); + } + $chargecontrol->setEqLogic_id($this->getId()); + $chargecontrol->setLogicalId('chargecontrol'); + $chargecontrol->setType('action'); + $chargecontrol->setSubType('other'); + $chargecontrol->save(); + + // Lock command action + $chargecontrol = $this->getCmd(null, 'lockcontrol'); + if (!is_object($chargecontrol)) { + $chargecontrol = new wallboxCmd(); + $chargecontrol->setName(__('Verouillage du chargeur', __FILE__)); + } + $chargecontrol->setEqLogic_id($this->getId()); + $chargecontrol->setLogicalId('lockcontrol'); + $chargecontrol->setType('action'); + $chargecontrol->setSubType('other'); + $chargecontrol->save(); // TODO: CRON Configuration /* $cron = cron::byClassAndFunction('weather', 'updateWeatherData', array('weather_id' => intval($this->getId()))); @@ -425,6 +437,42 @@ public function defineChargingState($resume) } } + // function to lock/unlock a charger + public function defineLockState($locked) + { + $baseurl = "https://api.wall-box.com/v3/"; + $chargerId = $this->getConfiguration("chargerid"); + log::add('wallbox', 'debug', 'Define charging state '. $chargerId); + $jwt = $this->getWallboxToken(); + + log::add('wallbox', 'debug', 'jwt '. $jwt); + if($jwt != null && $chargerId != null){ + + $data = '{"locked":1}'; //resume id + if(!$resume) + { + $data = '{"locked":0}'; // pause id + } + + $opts = array('http' => + array( + 'method' => 'GET', + 'header' => 'Authorization: Bearer '.$jwt, + 'content' => http_build_query($data) + ) + ); + + $context = stream_context_create($opts); + + $result = file_get_contents($baseurl.'chargers/'.$chargerId, false, $context); + $objectresult = json_decode($result,true); + return $objectresult; + } + else{ + throw new Exception("User is not authenticated"); + } + } + // Utility public function utctolocal($date) { @@ -514,9 +562,9 @@ public function execute($_options = null) { $obj = $eqlogic->getCmd(null, 'power'); $obj->setIsVisible(1); $obj->save(); - $obj = $eqlogic->getCmd(null, 'chargecontrol'); + /*$obj = $eqlogic->getCmd(null, 'chargecontrol'); $obj->setIsVisible(1); - $obj->save(); + $obj->save();*/ } else { @@ -529,9 +577,9 @@ public function execute($_options = null) { $obj = $eqlogic->getCmd(null, 'power'); $obj->setIsVisible(0); $obj->save(); - $obj = $eqlogic->getCmd(null, 'chargecontrol'); + /*$obj = $eqlogic->getCmd(null, 'chargecontrol'); $obj->setIsVisible(0); - $obj->save(); + $obj->save();*/ } @@ -553,6 +601,22 @@ public function execute($_options = null) { $this->getEqLogic()->defineChargingState(true); } } + else if($this->getLogicalId() == 'lockcontrol') + { + $info = $this->getEqLogic()->getChargerStatus(); + $statusid=$info['config_data']['locked']; + + if($statusid == 0) + { + // charging, we switch to pause + $this->getEqLogic()->defineLockState(true); + } + else if($statusid == 1) + { + // in pause, we resume charge + $this->getEqLogic()->defineLockState(false); + } + } } public function statustotext($statusid) From 2252d74ecf6ebd384f177ce0c01ea96d7da4000f Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 17:37:23 +0200 Subject: [PATCH 30/83] Implementation of the function to define max AMP --- core/class/wallbox.class.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index f3652bd..87a3d45 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -473,6 +473,38 @@ public function defineLockState($locked) } } + // function to define max amp of a charge + public function defineMaxAmp($ampvalue) + { + $baseurl = "https://api.wall-box.com/v2/"; + $chargerId = $this->getConfiguration("chargerid"); + log::add('wallbox', 'debug', 'Define charging state '. $chargerId); + $jwt = $this->getWallboxToken(); + + log::add('wallbox', 'debug', 'jwt '. $jwt); + if($jwt != null && $chargerId != null){ + + $data = '{ "maxChargingCurrent":'.$ampvalue.'}'; //resume id + + $opts = array('http' => + array( + 'method' => 'GET', + 'header' => 'Authorization: Bearer '.$jwt, + 'content' => http_build_query($data) + ) + ); + + $context = stream_context_create($opts); + + $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context); + $objectresult = json_decode($result,true); + return $objectresult; + } + else{ + throw new Exception("User is not authenticated"); + } + } + // Utility public function utctolocal($date) { From 5fe455426fce82c1d8dcdef89e87e3a3f81edcb8 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 17:37:46 +0200 Subject: [PATCH 31/83] Fix for URI on lock/unlock function --- core/class/wallbox.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 87a3d45..d34f9c1 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -440,7 +440,7 @@ public function defineChargingState($resume) // function to lock/unlock a charger public function defineLockState($locked) { - $baseurl = "https://api.wall-box.com/v3/"; + $baseurl = "https://api.wall-box.com/v2/"; $chargerId = $this->getConfiguration("chargerid"); log::add('wallbox', 'debug', 'Define charging state '. $chargerId); $jwt = $this->getWallboxToken(); @@ -464,7 +464,7 @@ public function defineLockState($locked) $context = stream_context_create($opts); - $result = file_get_contents($baseurl.'chargers/'.$chargerId, false, $context); + $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context); $objectresult = json_decode($result,true); return $objectresult; } From 67d06aedc044d6cca5ac9ae3873064686150cbeb Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 17:48:11 +0200 Subject: [PATCH 32/83] Implementation of maxpower change --- core/class/wallbox.class.php | 45 +++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index d34f9c1..e9efa23 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -155,7 +155,7 @@ public function postSave() { } $maxpower->setLogicalId('maxpower'); $maxpower->setEqLogic_id($this->getId()); - $maxpower->setType('info'); + $maxpower->setType('action'); $maxpower->setSubType('numeric'); $maxpower->setUnite('Amp'); $maxpower->setConfiguration('minValue' , '0'); @@ -277,16 +277,31 @@ public function postSave() { $chargecontrol->save(); // Lock command action - $chargecontrol = $this->getCmd(null, 'lockcontrol'); - if (!is_object($chargecontrol)) { - $chargecontrol = new wallboxCmd(); - $chargecontrol->setName(__('Verouillage du chargeur', __FILE__)); - } - $chargecontrol->setEqLogic_id($this->getId()); - $chargecontrol->setLogicalId('lockcontrol'); - $chargecontrol->setType('action'); - $chargecontrol->setSubType('other'); - $chargecontrol->save(); + $lockcontrol = $this->getCmd(null, 'lockcontrol'); + if (!is_object($lockcontrol)) { + $lockcontrol = new wallboxCmd(); + $lockcontrol->setName(__('Verouillage du chargeur', __FILE__)); + } + $lockcontrol->setEqLogic_id($this->getId()); + $lockcontrol->setLogicalId('lockcontrol'); + $lockcontrol->setType('action'); + $lockcontrol->setSubType('other'); + $lockcontrol->save(); + + // Amp command action + /* $maxamp = $this->getCmd(null, 'maxamp'); + if (!is_object($maxamp)) { + $maxamp = new wallboxCmd(); + $maxamp->setName(__('Amperage maximum', __FILE__)); + } + $maxamp->setEqLogic_id($this->getId()); + $maxamp->setLogicalId('maxamp'); + $maxamp->setType('action'); + $maxamp->setSubType('numeric'); + $maxamp->setUnite('Amp'); + $maxamp->setConfiguration('minValue' , '1'); + $maxamp->setConfiguration('maxValue' , '32'); + $maxamp->save();*/ // TODO: CRON Configuration /* $cron = cron::byClassAndFunction('weather', 'updateWeatherData', array('weather_id' => intval($this->getId()))); @@ -649,6 +664,14 @@ public function execute($_options = null) { $this->getEqLogic()->defineLockState(false); } } + else if($this->getLogicalId() == 'maxpower') + { + $obj = $eqlogic->getCmd(null, 'maxpower'); + + // charging, we switch to pause + $this->getEqLogic()->defineMaxAmp($obj->getCmdValue()); + + } } public function statustotext($statusid) From 1b8b4d68fbdf4d27840fd1ab62e7e0273b290a1b Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 17:58:40 +0200 Subject: [PATCH 33/83] Logs added --- core/class/wallbox.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index e9efa23..4ad90bf 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -353,7 +353,7 @@ public function getWallboxToken(){ if($objectresult['status'] == "200"){ - log::add('wallbox', 'debug', 'Authentication ' . json_decode($result,true)); + log::add('wallbox', 'information', 'Authentication Success'); $token = $objectresult['jwt']; return $token; } @@ -366,7 +366,6 @@ public function getChargerList(){ log::add('wallbox', 'debug', 'start charger list'); $jwt = $this->getWallboxToken(); - log::add('wallbox', 'debug', 'jwt '. $jwt); if($jwt != null){ $opts = array('http' => array( @@ -396,7 +395,6 @@ public function getChargerStatus(){ log::add('wallbox', 'debug', 'start for charger '. $chargerId); $jwt = $this->getWallboxToken(); - log::add('wallbox', 'debug', 'jwt '. $jwt); if($jwt != null && $chargerId != null){ $opts = array('http' => array( @@ -424,7 +422,6 @@ public function defineChargingState($resume) log::add('wallbox', 'debug', 'Define charging state '. $chargerId); $jwt = $this->getWallboxToken(); - log::add('wallbox', 'debug', 'jwt '. $jwt); if($jwt != null && $chargerId != null){ $data = '{"action":1}'; //resume id @@ -444,6 +441,8 @@ public function defineChargingState($resume) $context = stream_context_create($opts); $result = file_get_contents($baseurl.'chargers/'.$chargerId.'/remote-action', false, $context); + log::add('wallbox', 'debug', 'defineMaxAmp '. $result); + $objectresult = json_decode($result,true); return $objectresult; } @@ -460,7 +459,6 @@ public function defineLockState($locked) log::add('wallbox', 'debug', 'Define charging state '. $chargerId); $jwt = $this->getWallboxToken(); - log::add('wallbox', 'debug', 'jwt '. $jwt); if($jwt != null && $chargerId != null){ $data = '{"locked":1}'; //resume id @@ -480,6 +478,8 @@ public function defineLockState($locked) $context = stream_context_create($opts); $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context); + log::add('wallbox', 'debug', 'defineMaxAmp '. $result); + $objectresult = json_decode($result,true); return $objectresult; } @@ -496,7 +496,6 @@ public function defineMaxAmp($ampvalue) log::add('wallbox', 'debug', 'Define charging state '. $chargerId); $jwt = $this->getWallboxToken(); - log::add('wallbox', 'debug', 'jwt '. $jwt); if($jwt != null && $chargerId != null){ $data = '{ "maxChargingCurrent":'.$ampvalue.'}'; //resume id @@ -512,6 +511,7 @@ public function defineMaxAmp($ampvalue) $context = stream_context_create($opts); $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context); + log::add('wallbox', 'debug', 'defineMaxAmp '. $result); $objectresult = json_decode($result,true); return $objectresult; } From 09a951cd71d95ae9c4c958cceda6dfd40233af05 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Mon, 24 Oct 2022 18:01:37 +0200 Subject: [PATCH 34/83] HTTP Method fixed --- core/class/wallbox.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 4ad90bf..8c0c651 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -432,7 +432,7 @@ public function defineChargingState($resume) $opts = array('http' => array( - 'method' => 'GET', + 'method' => 'POST', 'header' => 'Authorization: Bearer '.$jwt, 'content' => http_build_query($data) ) @@ -469,7 +469,7 @@ public function defineLockState($locked) $opts = array('http' => array( - 'method' => 'GET', + 'method' => 'PUT', 'header' => 'Authorization: Bearer '.$jwt, 'content' => http_build_query($data) ) @@ -502,7 +502,7 @@ public function defineMaxAmp($ampvalue) $opts = array('http' => array( - 'method' => 'GET', + 'method' => 'PUT', 'header' => 'Authorization: Bearer '.$jwt, 'content' => http_build_query($data) ) From 1efe69355736878d8ec8fdf3e81d7de826fd6858 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 05:43:37 +0200 Subject: [PATCH 35/83] time to 24 hour format --- core/class/wallbox.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 8c0c651..fd794a5 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -441,7 +441,7 @@ public function defineChargingState($resume) $context = stream_context_create($opts); $result = file_get_contents($baseurl.'chargers/'.$chargerId.'/remote-action', false, $context); - log::add('wallbox', 'debug', 'defineMaxAmp '. $result); + log::add('wallbox', 'debug', 'defineChargingState '. $result); $objectresult = json_decode($result,true); return $objectresult; @@ -456,15 +456,15 @@ public function defineLockState($locked) { $baseurl = "https://api.wall-box.com/v2/"; $chargerId = $this->getConfiguration("chargerid"); - log::add('wallbox', 'debug', 'Define charging state '. $chargerId); + log::add('wallbox', 'debug', 'Define lock state '. $chargerId); $jwt = $this->getWallboxToken(); if($jwt != null && $chargerId != null){ - $data = '{"locked":1}'; //resume id - if(!$resume) + $data = '{"locked":1}'; //lock id + if(!$locked) { - $data = '{"locked":0}'; // pause id + $data = '{"locked":0}'; // unlock id } $opts = array('http' => @@ -478,7 +478,7 @@ public function defineLockState($locked) $context = stream_context_create($opts); $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context); - log::add('wallbox', 'debug', 'defineMaxAmp '. $result); + log::add('wallbox', 'debug', 'defineLockState '. $result); $objectresult = json_decode($result,true); return $objectresult; @@ -493,7 +493,7 @@ public function defineMaxAmp($ampvalue) { $baseurl = "https://api.wall-box.com/v2/"; $chargerId = $this->getConfiguration("chargerid"); - log::add('wallbox', 'debug', 'Define charging state '. $chargerId); + log::add('wallbox', 'debug', 'Define max amp state '. $chargerId); $jwt = $this->getWallboxToken(); if($jwt != null && $chargerId != null){ @@ -529,7 +529,7 @@ public function utctolocal($date) $tm_tz_to = new DateTimeZone($localtimezone); $dt = new DateTime($date, new DateTimeZone('UTC')); $dt->setTimeZone(new DateTimeZone($tm_tz_to->getName())); - $utc_time_from =$dt->format("d-m-Y h:i:s"); + $utc_time_from =$dt->format("d-m-Y H:i:s"); log::add('wallbox', 'debug', 'Date converted '.$utc_time_from); return $utc_time_from; From 09c2cee6b849565b27f3bc6f9326c60ee4d34ddc Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 05:46:46 +0200 Subject: [PATCH 36/83] function synthax problem fixed --- core/class/wallbox.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index fd794a5..7f592e6 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -583,7 +583,7 @@ public function execute($_options = null) { $eqlogic = $this->getEqLogic(); //récupère l'éqlogic de la commande $this if ($this->getLogicalId() == 'refresh') { - + log::add('wallbox', 'info', 'execute refresh'); $info = $this->getEqLogic()->getChargerStatus(); $eqlogic->checkAndUpdateCmd('name', $info['name']); $eqlogic->checkAndUpdateCmd('lastsync', $this->getEqLogic()->utctolocal($info['last_sync'])); @@ -634,13 +634,14 @@ public function execute($_options = null) { } else if ($this->getLogicalId() == 'chargecontrol') { + log::add('wallbox', 'info', 'execute chargecontrol'); $info = $this->getEqLogic()->getChargerStatus(); $statusid=$info['status_id']; if($statusid == 194) { // charging, we switch to pause - $this->getEqLogic()->getChargerStatus(false); + $this->getEqLogic()->defineChargingState(false); } else if($statusid == 182) { @@ -650,6 +651,7 @@ public function execute($_options = null) { } else if($this->getLogicalId() == 'lockcontrol') { + log::add('wallbox', 'info', 'execute lockcontrol'); $info = $this->getEqLogic()->getChargerStatus(); $statusid=$info['config_data']['locked']; @@ -666,6 +668,7 @@ public function execute($_options = null) { } else if($this->getLogicalId() == 'maxpower') { + log::add('wallbox', 'info', 'execute lockcontrol'); $obj = $eqlogic->getCmd(null, 'maxpower'); // charging, we switch to pause From 6e434f3d0cc73f17368b8f4730ca69302d2148f0 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 05:52:59 +0200 Subject: [PATCH 37/83] lock state changed --- core/class/wallbox.class.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 7f592e6..9a6fa7a 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -462,7 +462,7 @@ public function defineLockState($locked) if($jwt != null && $chargerId != null){ $data = '{"locked":1}'; //lock id - if(!$locked) + if($locked == 1) { $data = '{"locked":0}'; // unlock id } @@ -655,16 +655,9 @@ public function execute($_options = null) { $info = $this->getEqLogic()->getChargerStatus(); $statusid=$info['config_data']['locked']; - if($statusid == 0) - { - // charging, we switch to pause - $this->getEqLogic()->defineLockState(true); - } - else if($statusid == 1) - { - // in pause, we resume charge - $this->getEqLogic()->defineLockState(false); - } + log::add('wallbox', 'debug', 'statusid is '.$statusid); + $this->getEqLogic()->defineLockState(0); + } else if($this->getLogicalId() == 'maxpower') { From 484fd2da9ff0335e9810fb6e11da54fbad39d967 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 06:05:06 +0200 Subject: [PATCH 38/83] http request fixed --- core/class/wallbox.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 9a6fa7a..3b36bab 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -433,7 +433,7 @@ public function defineChargingState($resume) $opts = array('http' => array( 'method' => 'POST', - 'header' => 'Authorization: Bearer '.$jwt, + 'header' => array('Authorization: Bearer '.$jwt,'Accept: application/json','Content-Type:application/json;charset=UTF-8'), 'content' => http_build_query($data) ) ); @@ -470,7 +470,7 @@ public function defineLockState($locked) $opts = array('http' => array( 'method' => 'PUT', - 'header' => 'Authorization: Bearer '.$jwt, + 'header' => array('Authorization: Bearer '.$jwt,'Accept: application/json','Content-Type:application/json;charset=UTF-8'), 'content' => http_build_query($data) ) ); @@ -503,7 +503,7 @@ public function defineMaxAmp($ampvalue) $opts = array('http' => array( 'method' => 'PUT', - 'header' => 'Authorization: Bearer '.$jwt, + 'header' => array('Authorization: Bearer '.$jwt,'Accept: application/json','Content-Type:application/json;charset=UTF-8'), 'content' => http_build_query($data) ) ); From 96014d700a4e0c8d2d258df31920002a84223e8a Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 06:15:29 +0200 Subject: [PATCH 39/83] var dump added --- core/class/wallbox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 3b36bab..6e4f003 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -476,7 +476,7 @@ public function defineLockState($locked) ); $context = stream_context_create($opts); - + log::add('wallbox', 'debug', 'defineLockState '. var_dump($context)); $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context); log::add('wallbox', 'debug', 'defineLockState '. $result); From 908774b31929ca5cd6c5bc418be63b41d5b4b844 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 06:17:30 +0200 Subject: [PATCH 40/83] log added --- core/class/wallbox.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 6e4f003..c3f2585 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -466,7 +466,7 @@ public function defineLockState($locked) { $data = '{"locked":0}'; // unlock id } - + log::add('wallbox', 'debug', 'defineLockState data'. $data); $opts = array('http' => array( 'method' => 'PUT', @@ -476,7 +476,7 @@ public function defineLockState($locked) ); $context = stream_context_create($opts); - log::add('wallbox', 'debug', 'defineLockState '. var_dump($context)); + log::add('wallbox', 'debug', 'defineLockState '. $context); $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context); log::add('wallbox', 'debug', 'defineLockState '. $result); From 0daf7840cfa362dc931b000b790970d742b2ed7e Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 06:19:14 +0200 Subject: [PATCH 41/83] fix lock state function --- core/class/wallbox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index c3f2585..b9e0f7e 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -656,7 +656,7 @@ public function execute($_options = null) { $statusid=$info['config_data']['locked']; log::add('wallbox', 'debug', 'statusid is '.$statusid); - $this->getEqLogic()->defineLockState(0); + $this->getEqLogic()->defineLockState($statusid); } else if($this->getLogicalId() == 'maxpower') From 9dae22c547f09f477f1368060bacecdb3a817137 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 06:38:50 +0200 Subject: [PATCH 42/83] lockstate method changed --- core/class/wallbox.class.php | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index b9e0f7e..6c86963 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -467,6 +467,8 @@ public function defineLockState($locked) $data = '{"locked":0}'; // unlock id } log::add('wallbox', 'debug', 'defineLockState data'. $data); + + /* $opts = array('http' => array( 'method' => 'PUT', @@ -478,9 +480,25 @@ public function defineLockState($locked) $context = stream_context_create($opts); log::add('wallbox', 'debug', 'defineLockState '. $context); $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context); - log::add('wallbox', 'debug', 'defineLockState '. $result); - - $objectresult = json_decode($result,true); + log::add('wallbox', 'debug', 'defineLockState '. $result);*/ + + $client = new http\Client; + $request = new http\Client\Request; + $request->setRequestUrl($baseurl.'charger/'.$chargerId); + $request->setRequestMethod('PUT'); + $body = new http\Message\Body; + $body->append($data); + $request->setBody($body); + $request->setOptions(array()); + $request->setHeaders(array( + 'Accept' => 'application/json', + 'Content-Type' => 'application/json;charset=UTF-8', + 'Authorization' => 'Bearer '.$jwt + )); + $client->enqueue($request)->send(); + $response = $client->getResponse(); + + $objectresult = json_decode($response->getBody(),true); return $objectresult; } else{ @@ -503,7 +521,11 @@ public function defineMaxAmp($ampvalue) $opts = array('http' => array( 'method' => 'PUT', - 'header' => array('Authorization: Bearer '.$jwt,'Accept: application/json','Content-Type:application/json;charset=UTF-8'), + 'header' => array( + 'Authorization: Bearer '.$jwt, + 'Accept: application/json', + 'Content-Type:application/json;charset=UTF-8' + ), 'content' => http_build_query($data) ) ); From 2baf24f24ad3f66c229ba8c02615caac78f6104f Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 07:09:59 +0200 Subject: [PATCH 43/83] test for lock --- core/class/wallbox.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 6c86963..831d31e 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -484,16 +484,16 @@ public function defineLockState($locked) $client = new http\Client; $request = new http\Client\Request; - $request->setRequestUrl($baseurl.'charger/'.$chargerId); + $request->setRequestUrl('https://api.wall-box.com/v2/charger/46367'); $request->setRequestMethod('PUT'); $body = new http\Message\Body; - $body->append($data); + $body->append('{"locked":1}'); $request->setBody($body); $request->setOptions(array()); $request->setHeaders(array( 'Accept' => 'application/json', 'Content-Type' => 'application/json;charset=UTF-8', - 'Authorization' => 'Bearer '.$jwt + 'Authorization' => 'Bearer '.$jwt, )); $client->enqueue($request)->send(); $response = $client->getResponse(); From 1c2084e620ba9c48fd67d4e7cb1715195096407e Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 07:12:56 +0200 Subject: [PATCH 44/83] lock function changed --- core/class/wallbox.class.php | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 831d31e..de4b2e3 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -468,37 +468,22 @@ public function defineLockState($locked) } log::add('wallbox', 'debug', 'defineLockState data'. $data); - /* + $opts = array('http' => array( 'method' => 'PUT', 'header' => array('Authorization: Bearer '.$jwt,'Accept: application/json','Content-Type:application/json;charset=UTF-8'), - 'content' => http_build_query($data) + 'content' => http_build_query(json_encode($data)) ) ); $context = stream_context_create($opts); log::add('wallbox', 'debug', 'defineLockState '. $context); $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context); - log::add('wallbox', 'debug', 'defineLockState '. $result);*/ - - $client = new http\Client; - $request = new http\Client\Request; - $request->setRequestUrl('https://api.wall-box.com/v2/charger/46367'); - $request->setRequestMethod('PUT'); - $body = new http\Message\Body; - $body->append('{"locked":1}'); - $request->setBody($body); - $request->setOptions(array()); - $request->setHeaders(array( - 'Accept' => 'application/json', - 'Content-Type' => 'application/json;charset=UTF-8', - 'Authorization' => 'Bearer '.$jwt, - )); - $client->enqueue($request)->send(); - $response = $client->getResponse(); - - $objectresult = json_decode($response->getBody(),true); + log::add('wallbox', 'debug', 'defineLockState '. $result); + + + $objectresult = json_decode($result,true); return $objectresult; } else{ From 97963d5765bc87e224c41041933f1347586e9f2f Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 07:20:15 +0200 Subject: [PATCH 45/83] http query changed --- core/class/wallbox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index de4b2e3..4c054ce 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -473,7 +473,7 @@ public function defineLockState($locked) array( 'method' => 'PUT', 'header' => array('Authorization: Bearer '.$jwt,'Accept: application/json','Content-Type:application/json;charset=UTF-8'), - 'content' => http_build_query(json_encode($data)) + 'content' => json_encode($data) ) ); From 7c92ce856cdd4b9fa0e73d1ab115263cf8151954 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 07:22:58 +0200 Subject: [PATCH 46/83] http req changed --- core/class/wallbox.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 4c054ce..5f7d084 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -472,8 +472,8 @@ public function defineLockState($locked) $opts = array('http' => array( 'method' => 'PUT', - 'header' => array('Authorization: Bearer '.$jwt,'Accept: application/json','Content-Type:application/json;charset=UTF-8'), - 'content' => json_encode($data) + 'header' => 'Authorization: Bearer '.$jwt.',Accept: application/json,Content-Type:application/json;charset=UTF-8', + 'content' => http_build_query($data) ) ); From 1380a392324815ce4da66a4af63b8bb58effcd3f Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 07:24:31 +0200 Subject: [PATCH 47/83] header changed --- core/class/wallbox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 5f7d084..ee22386 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -472,7 +472,7 @@ public function defineLockState($locked) $opts = array('http' => array( 'method' => 'PUT', - 'header' => 'Authorization: Bearer '.$jwt.',Accept: application/json,Content-Type:application/json;charset=UTF-8', + 'header' => array('Authorization: Bearer '.$jwt,'Accept: application/json','Content-Type:application/json;charset=UTF-8'), 'content' => http_build_query($data) ) ); From 6f303faae4740b1c76433c4d75747a2009f9ff19 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 07:30:56 +0200 Subject: [PATCH 48/83] var dump added --- core/class/wallbox.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index ee22386..2d6fd98 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -478,6 +478,7 @@ public function defineLockState($locked) ); $context = stream_context_create($opts); + var_dump($context); log::add('wallbox', 'debug', 'defineLockState '. $context); $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context); log::add('wallbox', 'debug', 'defineLockState '. $result); From efd569864b21ebe2845d6fae3bf6d43bd29256f0 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 07:33:19 +0200 Subject: [PATCH 49/83] http changed --- core/class/wallbox.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 2d6fd98..3fd33f2 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -469,7 +469,7 @@ public function defineLockState($locked) log::add('wallbox', 'debug', 'defineLockState data'. $data); - $opts = array('http' => + $opts = array('https' => array( 'method' => 'PUT', 'header' => array('Authorization: Bearer '.$jwt,'Accept: application/json','Content-Type:application/json;charset=UTF-8'), @@ -478,7 +478,7 @@ public function defineLockState($locked) ); $context = stream_context_create($opts); - var_dump($context); + log::add('wallbox', 'debug', 'defineLockState '. $context); $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context); log::add('wallbox', 'debug', 'defineLockState '. $result); From cc0fcacc3a2ff22698594a763fb854075b35c874 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 07:37:56 +0200 Subject: [PATCH 50/83] http req changed for lock --- core/class/wallbox.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 3fd33f2..54f1a1f 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -469,11 +469,11 @@ public function defineLockState($locked) log::add('wallbox', 'debug', 'defineLockState data'. $data); - $opts = array('https' => + $opts = array('http' => array( 'method' => 'PUT', - 'header' => array('Authorization: Bearer '.$jwt,'Accept: application/json','Content-Type:application/json;charset=UTF-8'), - 'content' => http_build_query($data) + 'header' => 'Authorization: Bearer '."$jwt \r\n".'Accept: application/json'."\r\n".'Content-Type:application/json;charset=UTF-8'."\r\n", + 'content' => json_encode($data) ) ); From 87a95c0d16318a195e82edadd0e8be876312deca Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 07:38:51 +0200 Subject: [PATCH 51/83] req body changed --- core/class/wallbox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 54f1a1f..22ce989 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -473,7 +473,7 @@ public function defineLockState($locked) array( 'method' => 'PUT', 'header' => 'Authorization: Bearer '."$jwt \r\n".'Accept: application/json'."\r\n".'Content-Type:application/json;charset=UTF-8'."\r\n", - 'content' => json_encode($data) + 'content' => http_build_query($data) ) ); From 14c5ffcd8b4cad80d04cdfcc250a9f42de546efd Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Thu, 27 Oct 2022 07:43:35 +0200 Subject: [PATCH 52/83] req changed --- core/class/wallbox.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 22ce989..19bd55b 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -467,13 +467,13 @@ public function defineLockState($locked) $data = '{"locked":0}'; // unlock id } log::add('wallbox', 'debug', 'defineLockState data'. $data); - +$data = http_build_query($data); $opts = array('http' => array( 'method' => 'PUT', - 'header' => 'Authorization: Bearer '."$jwt \r\n".'Accept: application/json'."\r\n".'Content-Type:application/json;charset=UTF-8'."\r\n", - 'content' => http_build_query($data) + 'header' => 'Authorization: Bearer '."$jwt \r\n".'Accept: application/json'."\r\n".'Content-Type:application/json;charset=UTF-8'."\r\n". "Content-Length: " . strlen($data) . "\r\n", + 'content' => $data ) ); From b248045ed3c53d040eabb789b31522e641499fc9 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 04:08:41 +0100 Subject: [PATCH 53/83] changed headers --- core/class/wallbox.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 19bd55b..9f4001a 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -467,12 +467,12 @@ public function defineLockState($locked) $data = '{"locked":0}'; // unlock id } log::add('wallbox', 'debug', 'defineLockState data'. $data); -$data = http_build_query($data); + $data = http_build_query($data); $opts = array('http' => array( 'method' => 'PUT', - 'header' => 'Authorization: Bearer '."$jwt \r\n".'Accept: application/json'."\r\n".'Content-Type:application/json;charset=UTF-8'."\r\n". "Content-Length: " . strlen($data) . "\r\n", + 'header' => array("Authorization: Bearer ".$jwt,"Accept: application/json","Content-Type: application/json;charset=UTF-8", "Content-Length: " . strlen($data),"Host: ".$SERVER_NAME ), 'content' => $data ) ); From 749802c6eeb11e0e4a106527f502d928cf8aae40 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 04:18:10 +0100 Subject: [PATCH 54/83] test with curl --- core/class/wallbox.class.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 9f4001a..1646be9 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -467,7 +467,7 @@ public function defineLockState($locked) $data = '{"locked":0}'; // unlock id } log::add('wallbox', 'debug', 'defineLockState data'. $data); - $data = http_build_query($data); + /*$data = http_build_query($data); $opts = array('http' => array( @@ -484,8 +484,32 @@ public function defineLockState($locked) log::add('wallbox', 'debug', 'defineLockState '. $result); - $objectresult = json_decode($result,true); - return $objectresult; + $objectresult = json_decode($result,true);*/ + + $curl = curl_init(); + +curl_setopt_array($curl, array( + CURLOPT_URL => 'https://api.wall-box.com/v2/charger/46367', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'PUT', + CURLOPT_POSTFIELDS =>$data, + CURLOPT_HTTPHEADER => array( + 'Accept: application/json', + 'Content-Type: application/json', + 'Authorization: Bearer '.$jwt, + 'Cookie: _cfuvid=5AbnFbc0xnt7DTbC4snRgtuCBeb4FW3bh3q1LbPYpCM-1666847691510-0-604800000' + ), +)); + +$response = curl_exec($curl); + +curl_close($curl); + return $response; } else{ throw new Exception("User is not authenticated"); From 7b35f40eb3e6fce60d15550a90e591ba038d2bae Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 04:32:54 +0100 Subject: [PATCH 55/83] Updating controls --- core/class/wallbox.class.php | 101 ++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 42 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 1646be9..1017fb0 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -280,7 +280,7 @@ public function postSave() { $lockcontrol = $this->getCmd(null, 'lockcontrol'); if (!is_object($lockcontrol)) { $lockcontrol = new wallboxCmd(); - $lockcontrol->setName(__('Verouillage du chargeur', __FILE__)); + $lockcontrol->setName(__('Verouiller le chargeur', __FILE__)); } $lockcontrol->setEqLogic_id($this->getId()); $lockcontrol->setLogicalId('lockcontrol'); @@ -488,28 +488,43 @@ public function defineLockState($locked) $curl = curl_init(); -curl_setopt_array($curl, array( - CURLOPT_URL => 'https://api.wall-box.com/v2/charger/46367', - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => '', - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 0, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => 'PUT', - CURLOPT_POSTFIELDS =>$data, - CURLOPT_HTTPHEADER => array( - 'Accept: application/json', - 'Content-Type: application/json', - 'Authorization: Bearer '.$jwt, - 'Cookie: _cfuvid=5AbnFbc0xnt7DTbC4snRgtuCBeb4FW3bh3q1LbPYpCM-1666847691510-0-604800000' - ), -)); - -$response = curl_exec($curl); - -curl_close($curl); - return $response; + curl_setopt_array($curl, array( + CURLOPT_URL => 'https://api.wall-box.com/v2/charger/'.$chargerId, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'PUT', + CURLOPT_POSTFIELDS =>$data, + CURLOPT_HTTPHEADER => array( + 'Accept: application/json', + 'Content-Type: application/json', + 'Authorization: Bearer '.$jwt + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + log::add('wallbox', 'debug', 'defineLockState '. $response); + + // Control Update + $responseobj = json_decode($response,true); + $lockcontrol = $this->getCmd(null, 'lockcontrol'); + if($responseobj.["data"].["chargerData"].["locked"] == 1){ + $lockcontrol->setName(__('Deverouiller le chargeur', __FILE__)); + } + else{ + $lockcontrol->setName(__('Verouiller le chargeur', __FILE__)); + } + $lockcontrol->save(); + + $eqlogic = $this->getEqLogic(); + $eqlogic->checkAndUpdateCmd('status', $this->getEqLogic()->statustotext($responseobj.["data"].["chargerData"].["status"])); + + return $responseobj; } else{ throw new Exception("User is not authenticated"); @@ -566,6 +581,26 @@ public function utctolocal($date) return $utc_time_from; } + + public function statustotext($statusid) + { + switch($statusid) + { + case 209: + return 'Verrouillée'; + break; + case 161: + return 'En attente'; + break; + case 194: + return 'En charge'; + break; + case 182: + return 'En pause'; + break; + } + } + /* * Non obligatoire : permet de modifier l'affichage du widget (également utilisable par les commandes) @@ -623,7 +658,7 @@ public function execute($_options = null) { $statusid=$info['status_id']; $eqlogic->checkAndUpdateCmd('status_id', $info['status_id']); - $eqlogic->checkAndUpdateCmd('status', $this->statustotext($info['status_id'])); + $eqlogic->checkAndUpdateCmd('status', $this->getEqLogic()->statustotext($info['status_id'])); //$eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); $eqlogic->checkAndUpdateCmd('maxpower', $info['max_available_power']); @@ -702,24 +737,6 @@ public function execute($_options = null) { } } - public function statustotext($statusid) - { - switch($statusid) - { - case 209: - return 'Verrouillée'; - break; - case 161: - return 'En attente'; - break; - case 194: - return 'En charge'; - break; - case 182: - return 'En pause'; - break; - } - } public function sectohhmmss($seconds) { From 841c1b08ce5b7c52dfdcf0cfef345fc007588af6 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 04:37:15 +0100 Subject: [PATCH 56/83] removed status update --- core/class/wallbox.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 1017fb0..346f57f 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -514,15 +514,15 @@ public function defineLockState($locked) $responseobj = json_decode($response,true); $lockcontrol = $this->getCmd(null, 'lockcontrol'); if($responseobj.["data"].["chargerData"].["locked"] == 1){ - $lockcontrol->setName(__('Deverouiller le chargeur', __FILE__)); + $lockcontrol->setName(__('Deverrouiller le chargeur', __FILE__)); } else{ - $lockcontrol->setName(__('Verouiller le chargeur', __FILE__)); + $lockcontrol->setName(__('Verrouiller le chargeur', __FILE__)); } $lockcontrol->save(); - $eqlogic = $this->getEqLogic(); - $eqlogic->checkAndUpdateCmd('status', $this->getEqLogic()->statustotext($responseobj.["data"].["chargerData"].["status"])); + /*$eqlogic = $this->getEqLogic(); + $eqlogic->checkAndUpdateCmd('status', $this->getEqLogic()->statustotext($responseobj.["data"].["chargerData"].["status"]));*/ return $responseobj; } From edd6197830bb32b6ad4e938711604aba82d33ce2 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 04:51:56 +0100 Subject: [PATCH 57/83] Control update changed for lock --- core/class/wallbox.class.php | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 346f57f..470d7e4 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -512,17 +512,6 @@ public function defineLockState($locked) // Control Update $responseobj = json_decode($response,true); - $lockcontrol = $this->getCmd(null, 'lockcontrol'); - if($responseobj.["data"].["chargerData"].["locked"] == 1){ - $lockcontrol->setName(__('Deverrouiller le chargeur', __FILE__)); - } - else{ - $lockcontrol->setName(__('Verrouiller le chargeur', __FILE__)); - } - $lockcontrol->save(); - - /*$eqlogic = $this->getEqLogic(); - $eqlogic->checkAndUpdateCmd('status', $this->getEqLogic()->statustotext($responseobj.["data"].["chargerData"].["status"]));*/ return $responseobj; } @@ -663,7 +652,7 @@ public function execute($_options = null) { //$eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); $eqlogic->checkAndUpdateCmd('maxpower', $info['max_available_power']); - if($statusid == 194){ + if($statusid == 194){ // Waiting $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); $eqlogic->checkAndUpdateCmd('chargingtime', $this->sectohhmmss($info['charging_time']));// in second $eqlogic->checkAndUpdateCmd('energyconsumed',$info['added_energy']); // kwh @@ -720,10 +709,19 @@ public function execute($_options = null) { { log::add('wallbox', 'info', 'execute lockcontrol'); $info = $this->getEqLogic()->getChargerStatus(); - $statusid=$info['config_data']['locked']; + $locked=$info['config_data']['locked']; - log::add('wallbox', 'debug', 'statusid is '.$statusid); - $this->getEqLogic()->defineLockState($statusid); + log::add('wallbox', 'debug', 'locked is '.$locked); + $this->getEqLogic()->defineLockState($locked); + + $eqlogic->getCmd(null, 'lockcontrol'); + if($locked ==0){ + $lockcontrol->setName(__('Verrouiller le chargeur', __FILE__)); + } + else + { + $lockcontrol->setName(__('Déverrouiller le chargeur', __FILE__)); + } } else if($this->getLogicalId() == 'maxpower') From 736c3e1a7ee8db0f6322f1730d405fceb123fbab Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 05:00:38 +0100 Subject: [PATCH 58/83] fix for commands --- core/class/wallbox.class.php | 62 +++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 470d7e4..53a7d7b 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -430,7 +430,7 @@ public function defineChargingState($resume) $data = '{"action":2}'; // pause id } - $opts = array('http' => + /* $opts = array('http' => array( 'method' => 'POST', 'header' => array('Authorization: Bearer '.$jwt,'Accept: application/json','Content-Type:application/json;charset=UTF-8'), @@ -440,10 +440,33 @@ public function defineChargingState($resume) $context = stream_context_create($opts); - $result = file_get_contents($baseurl.'chargers/'.$chargerId.'/remote-action', false, $context); - log::add('wallbox', 'debug', 'defineChargingState '. $result); + $result = file_get_contents($baseurl.'chargers/'.$chargerId.'/remote-action', false, $context);*/ - $objectresult = json_decode($result,true); + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => 'https://api.wall-box.com/v3/chargers/'.$chargerId.'/remote-action', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_POSTFIELDS =>$data, + CURLOPT_HTTPHEADER => array( + 'Accept: application/json', + 'Content-Type: application/json', + 'Authorization: Bearer '.$jwt + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + log::add('wallbox', 'debug', 'defineChargingState '. $response); + + $objectresult = json_decode($response,true); return $objectresult; } else{ @@ -532,7 +555,7 @@ public function defineMaxAmp($ampvalue) $data = '{ "maxChargingCurrent":'.$ampvalue.'}'; //resume id - $opts = array('http' => + /*$opts = array('http' => array( 'method' => 'PUT', 'header' => array( @@ -546,9 +569,32 @@ public function defineMaxAmp($ampvalue) $context = stream_context_create($opts); - $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context); - log::add('wallbox', 'debug', 'defineMaxAmp '. $result); - $objectresult = json_decode($result,true); + $result = file_get_contents($baseurl.'charger/'.$chargerId, false, $context);*/ + + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => 'https://api.wall-box.com/v2/charger/'.$chargerId, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'PUT', + CURLOPT_POSTFIELDS =>$data, + CURLOPT_HTTPHEADER => array( + 'Accept: application/json', + 'Content-Type: application/json', + 'Authorization: Bearer '.$jwt + ), + )); + + $response = curl_exec($curl); + + curl_close($curl); + log::add('wallbox', 'debug', 'defineMaxAmp '. $response); + $objectresult = json_decode($response,true); return $objectresult; } else{ From 6ab6c28d25b6ed7610c24eef0be04d9da52a81b9 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 05:05:41 +0100 Subject: [PATCH 59/83] log changed for max amp --- core/class/wallbox.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 53a7d7b..cb85480 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -548,12 +548,12 @@ public function defineMaxAmp($ampvalue) { $baseurl = "https://api.wall-box.com/v2/"; $chargerId = $this->getConfiguration("chargerid"); - log::add('wallbox', 'debug', 'Define max amp state '. $chargerId); + log::add('wallbox', 'debug', 'Define max amp value '. $ampvalue); $jwt = $this->getWallboxToken(); if($jwt != null && $chargerId != null){ - $data = '{ "maxChargingCurrent":'.$ampvalue.'}'; //resume id + $data = '{ "maxChargingCurrent":'.$ampvalue.'}'; //amp value /*$opts = array('http' => array( From 14fb6b8ddf198716e38003bb58189fa939980143 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 05:08:39 +0100 Subject: [PATCH 60/83] log added for max power --- core/class/wallbox.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index cb85480..b9a4c32 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -772,10 +772,10 @@ public function execute($_options = null) { } else if($this->getLogicalId() == 'maxpower') { - log::add('wallbox', 'info', 'execute lockcontrol'); + log::add('wallbox', 'info', 'execute maxpower'); $obj = $eqlogic->getCmd(null, 'maxpower'); - - // charging, we switch to pause + log::add('wallbox', 'info', 'setting value to'.$obj->getCmdValue()); + // we change max amp value $this->getEqLogic()->defineMaxAmp($obj->getCmdValue()); } From 5dbbc48f9550fda7efe57130b78f396df244292c Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 05:12:42 +0100 Subject: [PATCH 61/83] fix for getValue() max amp --- core/class/wallbox.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index b9a4c32..1086be9 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -696,6 +696,7 @@ public function execute($_options = null) { $eqlogic->checkAndUpdateCmd('status', $this->getEqLogic()->statustotext($info['status_id'])); //$eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); + log::add('wallbox','info','current max power: '.$info['max_available_power']); $eqlogic->checkAndUpdateCmd('maxpower', $info['max_available_power']); if($statusid == 194){ // Waiting @@ -774,9 +775,9 @@ public function execute($_options = null) { { log::add('wallbox', 'info', 'execute maxpower'); $obj = $eqlogic->getCmd(null, 'maxpower'); - log::add('wallbox', 'info', 'setting value to'.$obj->getCmdValue()); + log::add('wallbox', 'info', 'setting value to'.$obj->getValue()); // we change max amp value - $this->getEqLogic()->defineMaxAmp($obj->getCmdValue()); + $this->getEqLogic()->defineMaxAmp($obj->getValue()); } } From f436e7d0784e2a7e8d4eb43263314fd5484dd534 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 05:16:03 +0100 Subject: [PATCH 62/83] changed to getLastValue --- core/class/wallbox.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 1086be9..4ad6f93 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -775,9 +775,9 @@ public function execute($_options = null) { { log::add('wallbox', 'info', 'execute maxpower'); $obj = $eqlogic->getCmd(null, 'maxpower'); - log::add('wallbox', 'info', 'setting value to'.$obj->getValue()); + log::add('wallbox', 'info', 'setting value to'.$obj->getLastValue()); // we change max amp value - $this->getEqLogic()->defineMaxAmp($obj->getValue()); + $this->getEqLogic()->defineMaxAmp($obj->getLastValue()); } } From 78f0c9c413a8460a587faaf416f0ab3ddc769c23 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 05:53:54 +0100 Subject: [PATCH 63/83] readme update + logs --- README.md | 11 +++++++---- core/class/wallbox.class.php | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 80eac03..9066b02 100644 --- a/README.md +++ b/README.md @@ -10,18 +10,21 @@ Jeedom plugin implementation for wallbox charger solution. ## How to get it -Will be available on jeedom market soon - -Market cost help me to contribute to projects +Available from jeedom market and for free! ## Contribute -No contribution is required at this moment +Please check project tab for in progress task. Feel free to help and contribute! ## Support If you need help or got bug, please open issue from github. +## Donators +Thanks to all donators that help me to drink some coffees :) + +- Laurent Mario + ## Donate If you want to support my work or just to pay me a coffee :) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 4ad6f93..da27ffd 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -696,8 +696,8 @@ public function execute($_options = null) { $eqlogic->checkAndUpdateCmd('status', $this->getEqLogic()->statustotext($info['status_id'])); //$eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); - log::add('wallbox','info','current max power: '.$info['max_available_power']); - $eqlogic->checkAndUpdateCmd('maxpower', $info['max_available_power']); + log::add('wallbox','info','current max power: '.$info['config_data']['max_charging_current']); + $eqlogic->checkAndUpdateCmd('maxpower', $info['config_data']['max_charging_current']); if($statusid == 194){ // Waiting $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); @@ -774,6 +774,7 @@ public function execute($_options = null) { else if($this->getLogicalId() == 'maxpower') { log::add('wallbox', 'info', 'execute maxpower'); + log::add('wallbox','debug',print_r($_options)); $obj = $eqlogic->getCmd(null, 'maxpower'); log::add('wallbox', 'info', 'setting value to'.$obj->getLastValue()); // we change max amp value From c70a98b3f445f51b4f872ba410421cbdde6def78 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 06:11:17 +0100 Subject: [PATCH 64/83] value changed max amp --- core/class/wallbox.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index da27ffd..f5cb3f4 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -774,11 +774,10 @@ public function execute($_options = null) { else if($this->getLogicalId() == 'maxpower') { log::add('wallbox', 'info', 'execute maxpower'); - log::add('wallbox','debug',print_r($_options)); $obj = $eqlogic->getCmd(null, 'maxpower'); - log::add('wallbox', 'info', 'setting value to'.$obj->getLastValue()); + log::add('wallbox', 'info', 'setting value to'.$obj->getValue()); // we change max amp value - $this->getEqLogic()->defineMaxAmp($obj->getLastValue()); + $this->getEqLogic()->defineMaxAmp($obj->getValue()); } } From cb77be1c3d59faa1b7004cd65fc49c64ade5268e Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 07:01:05 +0100 Subject: [PATCH 65/83] log input value --- core/class/wallbox.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index f5cb3f4..0a0cbe2 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -774,6 +774,7 @@ public function execute($_options = null) { else if($this->getLogicalId() == 'maxpower') { log::add('wallbox', 'info', 'execute maxpower'); + log::add('wallbox','debug',$_options['slider']); $obj = $eqlogic->getCmd(null, 'maxpower'); log::add('wallbox', 'info', 'setting value to'.$obj->getValue()); // we change max amp value From 8e725060d3b17699e638aec3c302e62509d2c806 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 07:03:00 +0100 Subject: [PATCH 66/83] Fix for max amp --- core/class/wallbox.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 0a0cbe2..f3023df 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -773,12 +773,12 @@ public function execute($_options = null) { } else if($this->getLogicalId() == 'maxpower') { + $inputValue = $_options['slider']; log::add('wallbox', 'info', 'execute maxpower'); - log::add('wallbox','debug',$_options['slider']); $obj = $eqlogic->getCmd(null, 'maxpower'); - log::add('wallbox', 'info', 'setting value to'.$obj->getValue()); + log::add('wallbox', 'info', 'setting value to'.$inputValue); // we change max amp value - $this->getEqLogic()->defineMaxAmp($obj->getValue()); + $this->getEqLogic()->defineMaxAmp($inputValue); } } From e565007bc4c6459fb9523c2b6f5cce459f9b15f0 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 07:10:15 +0100 Subject: [PATCH 67/83] fix maxpower value --- core/class/wallbox.class.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index f3023df..e8fa72a 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -698,6 +698,9 @@ public function execute($_options = null) { //$eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); log::add('wallbox','info','current max power: '.$info['config_data']['max_charging_current']); $eqlogic->checkAndUpdateCmd('maxpower', $info['config_data']['max_charging_current']); + $obj = $eqlogic->getCmd(null, 'maxpower'); + $obj->setValue($info['config_data']['max_charging_current']); + $obj->save(); if($statusid == 194){ // Waiting $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); From 9f7067320769578b98e643647d00107f1a153674 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 07:13:49 +0100 Subject: [PATCH 68/83] changes for maxpower --- core/class/wallbox.class.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index e8fa72a..bdf8261 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -697,10 +697,7 @@ public function execute($_options = null) { //$eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); log::add('wallbox','info','current max power: '.$info['config_data']['max_charging_current']); - $eqlogic->checkAndUpdateCmd('maxpower', $info['config_data']['max_charging_current']); - $obj = $eqlogic->getCmd(null, 'maxpower'); - $obj->setValue($info['config_data']['max_charging_current']); - $obj->save(); + $eqlogic->checkAndUpdateCmd('maxpower', intval($info['config_data']['max_charging_current'])); if($statusid == 194){ // Waiting $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); From 950b0561ede150334bd347f1fdd2c83517bbc9b1 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 07:16:38 +0100 Subject: [PATCH 69/83] subtype fixed for maxpower --- core/class/wallbox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index bdf8261..6f752df 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -156,7 +156,7 @@ public function postSave() { $maxpower->setLogicalId('maxpower'); $maxpower->setEqLogic_id($this->getId()); $maxpower->setType('action'); - $maxpower->setSubType('numeric'); + $maxpower->setSubType('cursor'); $maxpower->setUnite('Amp'); $maxpower->setConfiguration('minValue' , '0'); $maxpower->setConfiguration('maxValue' , '32'); From 2223ffa2b1c81ca3a973f9ce8c57d40be9539466 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 07:18:17 +0100 Subject: [PATCH 70/83] fix for subtype --- core/class/wallbox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 6f752df..71a16c9 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -156,7 +156,7 @@ public function postSave() { $maxpower->setLogicalId('maxpower'); $maxpower->setEqLogic_id($this->getId()); $maxpower->setType('action'); - $maxpower->setSubType('cursor'); + $maxpower->setSubType('slider'); $maxpower->setUnite('Amp'); $maxpower->setConfiguration('minValue' , '0'); $maxpower->setConfiguration('maxValue' , '32'); From 25040a729a55ef11a19f7917ab84f0c53ba011a7 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 07:57:59 +0100 Subject: [PATCH 71/83] Icon added --- core/class/wallbox.class.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 71a16c9..e945ae7 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -274,18 +274,20 @@ public function postSave() { $chargecontrol->setLogicalId('chargecontrol'); $chargecontrol->setType('action'); $chargecontrol->setSubType('other'); + $chargecontrol->setDisplay('icon', ''); $chargecontrol->save(); // Lock command action $lockcontrol = $this->getCmd(null, 'lockcontrol'); if (!is_object($lockcontrol)) { $lockcontrol = new wallboxCmd(); - $lockcontrol->setName(__('Verouiller le chargeur', __FILE__)); + $lockcontrol->setName(__('Verrouillage/Déverrouillage du chargeur', __FILE__)); } $lockcontrol->setEqLogic_id($this->getId()); $lockcontrol->setLogicalId('lockcontrol'); $lockcontrol->setType('action'); $lockcontrol->setSubType('other'); + $lockcontrol->setDisplay('icon', ''); $lockcontrol->save(); // Amp command action @@ -692,6 +694,21 @@ public function execute($_options = null) { $statusid=$info['status_id']; + if($statusid == 182) + { + //pause + $obj = $eqlogic->getCmd(null, 'chargecontrol'); + $obj->setDisplay('icon', ''); + $obj->save(); + } + else ($statusid == 194) + { + // Charge + $obj = $eqlogic->getCmd(null, 'chargecontrol'); + $obj->setDisplay('icon', ''); + $obj->save(); + } + $eqlogic->checkAndUpdateCmd('status_id', $info['status_id']); $eqlogic->checkAndUpdateCmd('status', $this->getEqLogic()->statustotext($info['status_id'])); From 78c4f52fbfcc294958c8c9adf97cda688352ecd9 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 07:59:11 +0100 Subject: [PATCH 72/83] fix syntax error --- core/class/wallbox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index e945ae7..89e7dd4 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -701,7 +701,7 @@ public function execute($_options = null) { $obj->setDisplay('icon', ''); $obj->save(); } - else ($statusid == 194) + else if($statusid == 194) { // Charge $obj = $eqlogic->getCmd(null, 'chargecontrol'); From 823cf0c47664976b08219df3bff92b96c7e81e91 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 08:05:53 +0100 Subject: [PATCH 73/83] icon updated --- core/class/wallbox.class.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 89e7dd4..21784f5 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -694,6 +694,7 @@ public function execute($_options = null) { $statusid=$info['status_id']; + // charge control icon if($statusid == 182) { //pause @@ -709,6 +710,22 @@ public function execute($_options = null) { $obj->save(); } + // lock icon + if($statusid == 209) + { + //locked + $obj = $eqlogic->getCmd(null, 'lockcontrol'); + $obj->setDisplay('icon', ''); + $obj->save(); + } + else + { + // other + $obj = $eqlogic->getCmd(null, 'lockcontrol'); + $obj->setDisplay('icon', ''); + $obj->save(); + } + $eqlogic->checkAndUpdateCmd('status_id', $info['status_id']); $eqlogic->checkAndUpdateCmd('status', $this->getEqLogic()->statustotext($info['status_id'])); @@ -729,9 +746,9 @@ public function execute($_options = null) { $obj = $eqlogic->getCmd(null, 'power'); $obj->setIsVisible(1); $obj->save(); - /*$obj = $eqlogic->getCmd(null, 'chargecontrol'); + $obj = $eqlogic->getCmd(null, 'chargecontrol'); $obj->setIsVisible(1); - $obj->save();*/ + $obj->save(); } else { @@ -744,9 +761,9 @@ public function execute($_options = null) { $obj = $eqlogic->getCmd(null, 'power'); $obj->setIsVisible(0); $obj->save(); - /*$obj = $eqlogic->getCmd(null, 'chargecontrol'); + $obj = $eqlogic->getCmd(null, 'chargecontrol'); $obj->setIsVisible(0); - $obj->save();*/ + $obj->save(); } From e102badded4775d962ea24aab7624f245d403fd7 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 17:16:48 +0100 Subject: [PATCH 74/83] set value for charging current --- core/class/wallbox.class.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 21784f5..1227159 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -730,8 +730,12 @@ public function execute($_options = null) { $eqlogic->checkAndUpdateCmd('status', $this->getEqLogic()->statustotext($info['status_id'])); //$eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); - log::add('wallbox','info','current max power: '.$info['config_data']['max_charging_current']); - $eqlogic->checkAndUpdateCmd('maxpower', intval($info['config_data']['max_charging_current'])); + $maxchargingcurrent = $info['config_data']['max_charging_current']; + log::add('wallbox','info','current max power: '.$maxchargingcurrent); + $eqlogic->checkAndUpdateCmd('maxpower', $maxchargingcurrent); + $obj = $eqlogic->getCmd(null, 'maxpower'); + $obj->setValue($maxchargingcurrent); + $obj->save(); if($statusid == 194){ // Waiting $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); From dc6ef1bad54bc3e7faec9028d4840d5ef9afc1bc Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 17:28:34 +0100 Subject: [PATCH 75/83] setting max available current for max slider --- core/class/wallbox.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 1227159..1ddc0ec 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -735,6 +735,7 @@ public function execute($_options = null) { $eqlogic->checkAndUpdateCmd('maxpower', $maxchargingcurrent); $obj = $eqlogic->getCmd(null, 'maxpower'); $obj->setValue($maxchargingcurrent); + $obj->setConfiguration('maxValue' , $info['config_data']['max_available_current']); $obj->save(); if($statusid == 194){ // Waiting From b223ebe0a8b8918fedcc4c76d4fcf7062b76c524 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 17:35:49 +0100 Subject: [PATCH 76/83] fix for setvalue --- core/class/wallbox.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 1ddc0ec..4251cd0 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -732,11 +732,12 @@ public function execute($_options = null) { //$eqlogic->checkAndUpdateCmd('speed', $info['charging_speed']); $maxchargingcurrent = $info['config_data']['max_charging_current']; log::add('wallbox','info','current max power: '.$maxchargingcurrent); - $eqlogic->checkAndUpdateCmd('maxpower', $maxchargingcurrent); + $obj = $eqlogic->getCmd(null, 'maxpower'); - $obj->setValue($maxchargingcurrent); + //$obj->setValue($maxchargingcurrent); $obj->setConfiguration('maxValue' , $info['config_data']['max_available_current']); $obj->save(); + $eqlogic->checkAndUpdateCmd('maxpower', $maxchargingcurrent); if($statusid == 194){ // Waiting $eqlogic->checkAndUpdateCmd('power', $info['charging_power']); From 91a4267d9105dff3e61672384500ae0e835c59cb Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 17:39:06 +0100 Subject: [PATCH 77/83] min max power fixed --- core/class/wallbox.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 4251cd0..43228f2 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -158,7 +158,7 @@ public function postSave() { $maxpower->setType('action'); $maxpower->setSubType('slider'); $maxpower->setUnite('Amp'); - $maxpower->setConfiguration('minValue' , '0'); + $maxpower->setConfiguration('minValue' , '6'); $maxpower->setConfiguration('maxValue' , '32'); $maxpower->save(); From 001e12f09ed0a66fb40b78680191076adac11184 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 18:58:49 +0100 Subject: [PATCH 78/83] Auto refresh configuration --- core/class/wallbox.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 43228f2..d5ac759 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -244,7 +244,7 @@ public function postSave() { $name = $this->getCmd(null, 'name'); if (!is_object($name)) { $name = new wallboxCmd(); - $name->setName(__('Name', __FILE__)); + $name->setName(__('Nom', __FILE__)); } $name->setLogicalId('name'); $name->setEqLogic_id($this->getId()); @@ -281,7 +281,7 @@ public function postSave() { $lockcontrol = $this->getCmd(null, 'lockcontrol'); if (!is_object($lockcontrol)) { $lockcontrol = new wallboxCmd(); - $lockcontrol->setName(__('Verrouillage/Déverrouillage du chargeur', __FILE__)); + $lockcontrol->setName(__('Verrouillage & Déverrouillage du chargeur', __FILE__)); } $lockcontrol->setEqLogic_id($this->getId()); $lockcontrol->setLogicalId('lockcontrol'); @@ -290,6 +290,9 @@ public function postSave() { $lockcontrol->setDisplay('icon', ''); $lockcontrol->save(); + // Define auto refresh + $this->setConfiguration('autorefresh','*/5 * * * *'); + // Amp command action /* $maxamp = $this->getCmd(null, 'maxamp'); if (!is_object($maxamp)) { From ad6cef79d9ba6da0286a11638917a2c08fb864fe Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 19:04:23 +0100 Subject: [PATCH 79/83] save added for autorefresh --- core/class/wallbox.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index d5ac759..539a139 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -292,6 +292,7 @@ public function postSave() { // Define auto refresh $this->setConfiguration('autorefresh','*/5 * * * *'); + $this->save(); // Amp command action /* $maxamp = $this->getCmd(null, 'maxamp'); From bb2d3bdc5f5926d21941601e2f84594f77743fd1 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 19:07:46 +0100 Subject: [PATCH 80/83] change for autorefresh default value --- core/class/wallbox.class.php | 4 ---- desktop/php/wallbox.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index 539a139..de17e61 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -290,10 +290,6 @@ public function postSave() { $lockcontrol->setDisplay('icon', ''); $lockcontrol->save(); - // Define auto refresh - $this->setConfiguration('autorefresh','*/5 * * * *'); - $this->save(); - // Amp command action /* $maxamp = $this->getCmd(null, 'maxamp'); if (!is_object($maxamp)) { diff --git a/desktop/php/wallbox.php b/desktop/php/wallbox.php index dbe587d..deef4ea 100644 --- a/desktop/php/wallbox.php +++ b/desktop/php/wallbox.php @@ -152,7 +152,7 @@
- + From db1a3fc33f64ff43b9efdc6d42ba381e4f477b69 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 19:10:06 +0100 Subject: [PATCH 81/83] defaultvalue changed --- core/class/wallbox.class.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/class/wallbox.class.php b/core/class/wallbox.class.php index de17e61..a2d20c3 100644 --- a/core/class/wallbox.class.php +++ b/core/class/wallbox.class.php @@ -109,6 +109,9 @@ public function preInsert() { if($username == null || $password == null){ throw new Exception("You must configure username and password to be able to use this plugin"); } + + // Define auto refresh + $this->setConfiguration('autorefresh','*/5 * * * *'); } // Fonction exécutée automatiquement après la création de l'équipement @@ -290,6 +293,7 @@ public function postSave() { $lockcontrol->setDisplay('icon', ''); $lockcontrol->save(); + // Amp command action /* $maxamp = $this->getCmd(null, 'maxamp'); if (!is_object($maxamp)) { From 2389247782fe386e412c2047a2c78581fb51538a Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 19:12:43 +0100 Subject: [PATCH 82/83] ChangeLog updated --- docs/fr_FR/changelog.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/fr_FR/changelog.md b/docs/fr_FR/changelog.md index d5a0c2d..277e2de 100644 --- a/docs/fr_FR/changelog.md +++ b/docs/fr_FR/changelog.md @@ -2,9 +2,11 @@ # 10/2022 - Ajout de vérification de configuration du plugin avant de pouvoir effectuer l'ajout d'équipement ou l'activation des CRON -- Correction sur le format de l'heure de la dernière synchronisation avec la borne UTC => Local Date Time +- Correction sur le format de l'heure de la dernière synchronisation avec la borne UTC => Local Date Time (24h) - Ajout de la fonctionnalité de contrôle de charge via le widget - Ajout de la fonctionnalité de modification du maximum d'ampère d'un chargeur +- Ajout de la fonctionnalité de verrouillage via le widget +- Ajout de l'autorefresh par défaut # 30/01/2021 - Implementation of API call to get chargers of account From 0be7c170169bcd4defd7357eee5956e0ec307921 Mon Sep 17 00:00:00 2001 From: Valentin LECERF Date: Sun, 30 Oct 2022 19:14:14 +0100 Subject: [PATCH 83/83] Update changelog.md --- docs/fr_FR/changelog.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/fr_FR/changelog.md b/docs/fr_FR/changelog.md index 277e2de..35d4890 100644 --- a/docs/fr_FR/changelog.md +++ b/docs/fr_FR/changelog.md @@ -1,6 +1,6 @@ # Changelog wallbox plugin -# 10/2022 +# 10/2022 (1.0.0) - Ajout de vérification de configuration du plugin avant de pouvoir effectuer l'ajout d'équipement ou l'activation des CRON - Correction sur le format de l'heure de la dernière synchronisation avec la borne UTC => Local Date Time (24h) - Ajout de la fonctionnalité de contrôle de charge via le widget @@ -8,11 +8,11 @@ - Ajout de la fonctionnalité de verrouillage via le widget - Ajout de l'autorefresh par défaut -# 30/01/2021 +# 30/01/2021 (1.0 Beta) - Implementation of API call to get chargers of account - Changed input to dropdownlist for charger selection -# 28/01/2021 +# 28/01/2021 (1.0 Beta) - Initialisation du projet - Ajouts d'éléments d'informations et de paramètres pour les commandes