From 9461cd01836dcbe74aef65c817cb4b46aab165c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Wed, 7 Mar 2018 14:13:46 -0500 Subject: [PATCH 01/16] =?UTF-8?q?It=C3=A9ration=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/ajax/teleinfo.ajax.php | 15 +- core/api/teleinfo.api.php | 4 +- core/class/teleinfo.class.php | 826 +++++++++------------------------- plugin_info/info.json | 2 +- plugin_info/install.php | 100 ++-- 5 files changed, 262 insertions(+), 685 deletions(-) diff --git a/core/ajax/teleinfo.ajax.php b/core/ajax/teleinfo.ajax.php index f675b01..13000aa 100644 --- a/core/ajax/teleinfo.ajax.php +++ b/core/ajax/teleinfo.ajax.php @@ -25,7 +25,7 @@ } if (init('action') == 'stopDeamon') { - teleinfo::stopDeamon(); + teleinfo::deamon_stop(); ajax::success(); } @@ -38,7 +38,7 @@ if ($port == 'none') { ajax::success(); } - teleinfo::stopDeamon(); + teleinfo::deamon_stop(); if (teleinfo::deamonRunning()) { throw new \Exception(__('Impossible d\'arrêter le démon', __FILE__)); } @@ -58,17 +58,6 @@ ajax::success(); } - if (init('action') == 'stopSlaveDeamon') { - if (config::byKey('jeeNetwork::mode') == 'master') { - $jeeNetwork = jeeNetwork::byId(init('id')); - if (!is_object($jeeNetwork)) { - throw new \Exception(__('Impossible de trouver l\'esclave : ', __FILE__) . init('id')); - } - $jeeNetwork->sendRawRequest('stopDeamon', array('plugin' => 'teleinfo')); - } - ajax::success(); - } - if (init('action') == 'getTeleinfo') { if (init('object_id') == '') { $_GET['object_id'] = $_SESSION['user']->getOptions('defaultDashboardObject'); diff --git a/core/api/teleinfo.api.php b/core/api/teleinfo.api.php index fa48073..603ea83 100644 --- a/core/api/teleinfo.api.php +++ b/core/api/teleinfo.api.php @@ -29,11 +29,11 @@ } if ($jsonrpc->getMethod() == 'stopDeamon') { - $jsonrpc->makeSuccess(teleinfo::stopDeamon()); + $jsonrpc->makeSuccess(teleinfo::deamon_stop()); } if ($jsonrpc->getMethod() == 'restartDeamon') { - teleinfo::stopDeamon(); + teleinfo::deamon_stop(); if (teleinfo::deamonRunning()) { throw new \Exception(__('Impossible d\'arrêter le démon', __FILE__)); } diff --git a/core/class/teleinfo.class.php b/core/class/teleinfo.class.php index 9d003a1..4f80f02 100644 --- a/core/class/teleinfo.class.php +++ b/core/class/teleinfo.class.php @@ -34,12 +34,12 @@ public static function getTeleinfoInfo($_url) public static function cron() { - self::Calculate_PAPP(); + self::calculatePAPP(); } public static function cronHourly() { - self::Moy_Last_Hour(); + self::moyLastHour(); } public static function createFromDef($_def) @@ -78,17 +78,14 @@ public static function createCmdFromDef($_oADCO, $_oKey, $_oValue) } $teleinfo = teleinfo::byLogicalId($_oADCO, 'teleinfo'); if (!is_object($teleinfo)) { - //$eqLogic = new teleinfo(); - //$eqLogic->setName($_def['ADCO']); + return false; } if ($teleinfo->getConfiguration('AutoCreateFromCompteur') == '1') { log::add('teleinfo', 'info', 'Création de la commande ' . $_oKey . ' sur l\'ADCO ' . $_oADCO); $cmd = new teleinfoCmd(); $cmd->setName($_oKey); - //$cmd->setEqLogic_id($_oADCO); $cmd->setEqLogic_id($teleinfo->id); - log::add('teleinfo', 'debug', 'EqLogicID'); $cmd->setLogicalId($_oKey); $cmd->setType('info'); $cmd->setConfiguration('info_conso', $_oKey); @@ -115,123 +112,30 @@ public static function createCmdFromDef($_oADCO, $_oKey, $_oValue) $cmd->setEventOnly(1); $cmd->setIsVisible(1); $cmd->save(); - $cmd->setValue($_oValue); $cmd->event($_oValue); return $cmd; } } - /** - * @deprecated - */ - public static function runExternalDeamon($_debug = false) - { - log::add('teleinfo', 'info', 'Démarrage du service en mode satellite'); - $teleinfo_path = realpath(dirname(__FILE__) . '/../../ressources'); - $modem_serie_addr = config::byKey('port', 'teleinfo'); - $_debug = config::byKey('debug', 'teleinfo'); - $_force = config::byKey('force', 'teleinfo'); - $_2cpt_cartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); - - if (config::byKey('modem_vitesse', 'teleinfo') == "") { - $modem_vitesse = '1200'; - } else { - $modem_vitesse = config::byKey('modem_vitesse', 'teleinfo'); - } - - if ($modem_serie_addr == "serie") { - $port = config::byKey('modem_serie_addr', 'teleinfo'); - goto lancement; - } - $port = jeedom::getUsbMapping(config::byKey('port', 'teleinfo')); - if ($_2cpt_cartelectronic == 1) { - $port = '/dev/ttyUSB1'; - goto lancement; - } - if (!file_exists($port)) { - log::add('teleinfo', 'error', 'Le port n\'existe pas'); - goto end; - } - lancement: - exec('sudo chmod 777 ' . $port . ' > /dev/null 2>&1'); - $parsed_url = parse_url(config::byKey('jeeNetwork::master::ip')); - - log::add('teleinfo', 'info', '--------- Informations sur le master --------'); - log::add('teleinfo', 'info', 'Adresse : ' . config::byKey('jeeNetwork::master::ip')); - log::add('teleinfo', 'info', 'Host / Port : ' . $parsed_url['host'] . ':' . $parsed_url['port']); - log::add('teleinfo', 'info', 'Path complémentaire : ' . $parsed_url['path']); - $ip_externe = $parsed_url['scheme'] . '://' . $parsed_url['host'] . ':' . $parsed_url['port'] . $parsed_url['path']; - log::add('teleinfo', 'info', 'Mise en forme pour le service : ' . $ip_externe); - log::add('teleinfo', 'info', 'Port modem : ' . $port); - log::add('teleinfo', 'info', '---------------------------------------------'); - if ($parsed_url['host'] == "") { - $ip_externe = config::byKey('jeeNetwork::master::ip'); - log::add('teleinfo', 'error', 'Attention, vérifiez que l\'ip est bien renseignée dans la partie Configuration Réseau.'); - } - - $cle_api = config::byKey('jeeNetwork::master::apikey'); - if ($cle_api == '') { - log::add('teleinfo', 'error', 'Erreur de clé api, veuillez la vérifier.'); - goto end; - } - if ($_debug) { - $_debug = "1"; - } else { - $_debug = "0"; - } - if ($_force != "1") { - $_force = "0"; - } - if ($_2cpt_cartelectronic == 1) { - log::add('teleinfo', 'info', 'Fonctionnement en mode 2 compteurs'); - //exec('sudo chmod 777 /dev/bus/usb/* > /dev/null 2>&1'); - $teleinfo_path = $teleinfo_path . '/teleinfo_2_cpt.py'; - $cmd = 'sudo nice -n 19 /usr/bin/python ' . $teleinfo_path . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modem_vitesse . ' -e ' . $ip_externe . ' -c ' . config::byKey('jeeNetwork::master::apikey') . ' -f ' . $_force . ' -r ' . realpath(dirname(__FILE__)); - } else { - log::add('teleinfo', 'info', 'Fonctionnement en mode 1 compteur'); - $teleinfo_path = $teleinfo_path . '/teleinfo.py'; - $cmd = 'nice -n 19 /usr/bin/python ' . $teleinfo_path . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modem_vitesse . ' -e ' . $ip_externe . ' -c ' . config::byKey('jeeNetwork::master::apikey') . ' -f ' . $_force . ' -r ' . realpath(dirname(__FILE__)); - } - - log::add('teleinfo', 'info', 'Exécution du service : ' . $cmd); - $result = exec('nohup ' . $cmd . ' >> ' . log::getPathToLog('teleinfo') . ' 2>&1 &'); - if (strpos(strtolower($result), 'error') !== false || strpos(strtolower($result), 'traceback') !== false) { - log::add('teleinfo', 'error', $result); - return false; - } - sleep(2); - if (!self::deamonRunning()) { - sleep(10); - if (!self::deamonRunning()) { - log::add('teleinfo', 'error', 'Impossible de lancer le démon téléinfo, vérifiez l\'ip', 'unableStartDeamon'); - return false; - } - } - message::removeAll('teleinfo', 'unableStartDeamon'); - log::add('teleinfo', 'info', 'Service OK'); - log::add('teleinfo', 'info', '---------------------------------------------'); - end: - } - public static function runDeamon($_debug = false, $type = 'conso') { - log::add('teleinfo', 'info', 'Mode local'); - $teleinfo_path = realpath(dirname(__FILE__) . '/../../ressources'); - $modem_serie_addr = config::byKey('port', 'teleinfo'); + log::add('teleinfo', 'info', 'Démarrage compteur de consommation'); + $teleinfoPath = realpath(dirname(__FILE__) . '/../../ressources'); + $modemSerieAddr = config::byKey('port', 'teleinfo'); $_debug = config::byKey('debug', 'teleinfo'); $_force = config::byKey('force', 'teleinfo'); - $_2cpt_cartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); + $twoCptCartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); if (config::byKey('modem_vitesse', 'teleinfo') == "") { - $modem_vitesse = '1200'; + $modemVitesse = '1200'; } else { - $modem_vitesse = config::byKey('modem_vitesse', 'teleinfo'); + $modemVitesse = config::byKey('modem_vitesse', 'teleinfo'); } - if ($modem_serie_addr == "serie") { + if ($modemSerieAddr == "serie") { $port = config::byKey('modem_serie_addr', 'teleinfo'); goto lancement; } $port = jeedom::getUsbMapping(config::byKey('port', 'teleinfo')); - if ($_2cpt_cartelectronic == 1) { + if ($twoCptCartelectronic == 1) { $port = '/dev/ttyUSB1'; goto lancement; } @@ -258,27 +162,28 @@ public static function runDeamon($_debug = false, $type = 'conso') log::add('teleinfo', 'info', 'Force : ' . $_force); log::add('teleinfo', 'info', 'Port modem : ' . $port); log::add('teleinfo', 'info', 'Type : ' . $type); - - if ($_debug) { - $_debug = "1"; - } else { - $_debug = "0"; - } - if ($_force != "1") { - $_force = "0"; - } + + $_debug = ($_debug) ? "1" : "0"; + $_force = ($_force) ? "1" : "0"; + + // if ($_debug) { + // $_debug = "1"; + // } else { + // $_debug = "0"; + // } + // if ($_force != "1") { + // $_force = "0"; + // } log::add('teleinfo', 'info', '---------------------------------------------'); - if ($_2cpt_cartelectronic == 1) { + if ($twoCptCartelectronic == 1) { log::add('teleinfo', 'info', 'Fonctionnement en mode 2 compteur'); - //exec('sudo chmod 777 /dev/bus/usb/* > /dev/null 2>&1'); - $teleinfo_path = $teleinfo_path . '/teleinfo_2_cpt.py'; - $cmd = 'sudo nice -n 19 /usr/bin/python ' . $teleinfo_path . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modem_vitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -r ' . realpath(dirname(__FILE__)); + $teleinfoPath = $teleinfoPath . '/teleinfo_2_cpt.py'; + $cmd = 'sudo nice -n 19 /usr/bin/python ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -r ' . realpath(dirname(__FILE__)); } else { log::add('teleinfo', 'info', 'Fonctionnement en mode 1 compteur'); - $teleinfo_path = $teleinfo_path . '/teleinfo.py'; - // $cmd = 'sudo nice -n 19 /usr/bin/python ' . $teleinfo_path . ' -d 0 -p ' . $port . ' -v ' . $modem_vitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -r ' . realpath(dirname(__FILE__)); - $cmd = 'nice -n 19 /usr/bin/python ' . $teleinfo_path . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modem_vitesse . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -t ' . $type . ' -r ' . realpath(dirname(__FILE__)); + $teleinfoPath = $teleinfoPath . '/teleinfo.py'; + $cmd = 'nice -n 19 /usr/bin/python ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -t ' . $type . ' -r ' . realpath(dirname(__FILE__)); } log::add('teleinfo', 'info', 'Exécution du service : ' . $cmd); @@ -304,22 +209,22 @@ public static function runDeamon($_debug = false, $type = 'conso') public static function runProductionDeamon($_debug = false, $type = 'prod') { log::add('teleinfo', 'info', '[Production] Mode local'); - $teleinfo_path = realpath(dirname(__FILE__) . '/../../ressources'); - $modem_serie_addr = config::byKey('port_production', 'teleinfo'); + $teleinfoPath = realpath(dirname(__FILE__) . '/../../ressources'); + $modemSerieAddr = config::byKey('port_production', 'teleinfo'); $_debug = config::byKey('debug_production', 'teleinfo'); $_force = config::byKey('force_production', 'teleinfo'); - $_2cpt_cartelectronic = config::byKey('2cpt_cartelectronic_production', 'teleinfo'); + $twoCptCartelectronic = config::byKey('2cpt_cartelectronic_production', 'teleinfo'); if (config::byKey('modem_vitesse_production', 'teleinfo') == "") { - $modem_vitesse = '1200'; + $modemVitesse = '1200'; } else { - $modem_vitesse = config::byKey('modem_vitesse_production', 'teleinfo'); + $modemVitesse = config::byKey('modem_vitesse_production', 'teleinfo'); } - if ($modem_serie_addr == "serie") { + if ($modemSerieAddr == "serie") { $port = config::byKey('modem_serie_production_addr', 'teleinfo'); goto lancement; } $port = jeedom::getUsbMapping(config::byKey('port_production', 'teleinfo')); - if ($_2cpt_cartelectronic == 1) { + if ($twoCptCartelectronic == 1) { $port = '/dev/ttyUSB1'; goto lancement; } @@ -347,26 +252,18 @@ public static function runProductionDeamon($_debug = false, $type = 'prod') log::add('teleinfo', 'info', 'Port modem : ' . $port); log::add('teleinfo', 'info', 'Type : ' . $type); - if ($_debug) { - $_debug = "1"; - } else { - $_debug = "0"; - } - if ($_force != "1") { - $_force = "0"; - } + $_debug = ($_debug) ? "1" : "0"; + $_force = ($_force) ? "1" : "0"; log::add('teleinfo', 'info', '---------------------------------------------'); - if ($_2cpt_cartelectronic == 1) { + if ($twoCptCartelectronic == 1) { log::add('teleinfo', 'info', 'Fonctionnement en mode 2 compteur'); - //exec('sudo chmod 777 /dev/bus/usb/* > /dev/null 2>&1'); - $teleinfo_path = $teleinfo_path . '/teleinfo_2_cpt.py'; - $cmd = 'sudo nice -n 19 /usr/bin/python ' . $teleinfo_path . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modem_vitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -r ' . realpath(dirname(__FILE__)); + $teleinfoPath = $teleinfoPath . '/teleinfo_2_cpt.py'; + $cmd = 'sudo nice -n 19 /usr/bin/python ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -r ' . realpath(dirname(__FILE__)); } else { log::add('teleinfo', 'info', 'Fonctionnement en mode 1 compteur'); - $teleinfo_path = $teleinfo_path . '/teleinfo.py'; - // $cmd = 'sudo nice -n 19 /usr/bin/python ' . $teleinfo_path . ' -d 0 -p ' . $port . ' -v ' . $modem_vitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -r ' . realpath(dirname(__FILE__)); - $cmd = 'nice -n 19 /usr/bin/python ' . $teleinfo_path . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modem_vitesse . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -t ' . $type . ' -r ' . realpath(dirname(__FILE__)); + $teleinfoPath = $teleinfoPath . '/teleinfo.py'; + $cmd = 'nice -n 19 /usr/bin/python ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -t ' . $type . ' -r ' . realpath(dirname(__FILE__)); } log::add('teleinfo', 'info', '[Production] Exécution du service : ' . $cmd); @@ -391,11 +288,10 @@ public static function runProductionDeamon($_debug = false, $type = 'prod') public static function deamonRunning() { - $_2cpt_cartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); - if ($_2cpt_cartelectronic == 1) { + $twoCptCartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); + if ($twoCptCartelectronic == 1) { $result = exec("ps aux | grep teleinfo_2_cpt.py | grep -v grep | awk '{print $2}'"); if ($result != "") { - //log::add('teleinfo', 'info', 'Vérification de l\'état du service : OK '); return true; } log::add('teleinfo', 'info', 'Vérification de l\'état du service : NOK '); @@ -403,7 +299,6 @@ public static function deamonRunning() } else { $result = exec("ps aux | grep teleinfo.py | grep -v grep | awk '{print $2}'"); if ($result != "") { - //log::add('teleinfo', 'info', 'Vérification de l\'état du service : OK '); return true; } log::add('teleinfo', 'info', 'Vérification de l\'état du service : NOK '); @@ -416,17 +311,14 @@ public static function deamon_info() $return = array(); $return['log'] = 'teleinfo'; $return['state'] = 'nok'; - $pid_file = '/tmp/teleinfo_conso.pid'; - if (file_exists($pid_file)) { - if (posix_getsid(trim(file_get_contents($pid_file)))) { + $pidFile = '/tmp/teleinfo_conso.pid'; + if (file_exists($pidFile)) { + if (posix_getsid(trim(file_get_contents($pidFile)))) { $return['state'] = 'ok'; } else { - shell_exec('sudo rm -rf ' . $pid_file . ' 2>&1 > /dev/null;rm -rf ' . $pid_file . ' 2>&1 > /dev/null;'); + shell_exec('sudo rm -rf ' . $pidFile . ' 2>&1 > /dev/null;rm -rf ' . $pidFile . ' 2>&1 > /dev/null;'); } } - /* if(self::deamonRunning()){ - $return['state'] = 'ok'; - } */ $return['launchable'] = 'ok'; return $return; } @@ -437,22 +329,17 @@ public static function deamon_info() public static function deamon_start($_debug = false) { $productionActivated = config::byKey('activation_production', 'teleinfo'); - if (config::byKey('jeeNetwork::mode') == 'slave') { //Je suis l'esclave + if (config::byKey('port', 'teleinfo') != "") { // Si un port est sélectionné if (!self::deamonRunning()) { - self::runExternalDeamon($_debug); + self::runDeamon($_debug); } - } else { // Je suis le jeedom master - if (config::byKey('port', 'teleinfo') != "") { // Si un port est sélectionné - if (!self::deamonRunning()) { - self::runDeamon($_debug); - } - if ($productionActivated == 1) { - self::runProductionDeamon($_debug); - } - message::removeAll('teleinfo', 'noTeleinfoPort'); - } else { - log::add('teleinfo', 'info', 'Pas d\'informations sur le port USB (Modem série ?)'); + if ($productionActivated == 1) { + self::runProductionDeamon($_debug); } + message::removeAll('teleinfo', 'noTeleinfoPort'); + } + else { + log::add('teleinfo', 'info', 'Pas d\'informations sur le port USB (Modem série ?)'); } } @@ -464,16 +351,16 @@ public static function deamon_stop() log::add('teleinfo', 'info', '[deamon_stop] Arret du service'); $deamon_info = self::deamon_info(); if ($deamon_info['state'] == 'ok') { - $_2cpt_cartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); - if ($_2cpt_cartelectronic == 1) { + $twoCptCartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); + if ($twoCptCartelectronic == 1) { $result = exec("ps aux | grep teleinfo_2_cpt.py | grep -v grep | awk '{print $2}'"); system::kill($result); } else { $productionActivated = config::byKey('activation_production', 'teleinfo'); if ($productionActivated == 1) { - $pid_file = '/tmp/teleinfo_prod.pid'; - if (file_exists($pid_file)) { - $pid = intval(trim(file_get_contents($pid_file))); + $pidFile = '/tmp/teleinfo_prod.pid'; + if (file_exists($pidFile)) { + $pid = intval(trim(file_get_contents($pidFile))); $kill = posix_kill($pid, 15); usleep(500); if ($kill) { @@ -484,9 +371,9 @@ public static function deamon_stop() } } prod_stop_success: - $pid_file = '/tmp/teleinfo_conso.pid'; - if (file_exists($pid_file)) { - $pid = intval(trim(file_get_contents($pid_file))); + $pidFile = '/tmp/teleinfo_conso.pid'; + if (file_exists($pidFile)) { + $pid = intval(trim(file_get_contents($pidFile))); $kill = posix_kill($pid, 15); usleep(500); if ($kill) { @@ -502,64 +389,11 @@ public static function deamon_stop() system::fuserk(jeedom::getUsbMapping($port)); sleep(1); } - //$result = exec("ps aux | grep teleinfo.py | grep -v grep | awk '{print $2}'"); } } } - /* - * @deprecated - */ - - public static function stopDeamon() - { - if (!self::deamonRunning()) { - return true; - } - - log::add('teleinfo', 'info', 'Tentative d\'arrêt du service'); - - $_2cpt_cartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); - if ($_2cpt_cartelectronic == 1) { - $result = exec("ps aux | grep teleinfo_2_cpt.py | grep -v grep | awk '{print $2}'"); - } else { - $result = exec("ps aux | grep teleinfo.py | grep -v grep | awk '{print $2}'"); - } - //foreach ($result as $pid) { - exec('kill ' . $result); - //} - $check = self::deamonRunning(); - $retry = 0; - while ($check) { - $check = self::deamonRunning(); - $retry++; - if ($retry > 10) { - $check = false; - } else { - posix_kill($result, 9); - sleep(1); - } - } - try { - exec('sudo kill 9 ' . $result . ' > /dev/null 2&1'); - } catch (Exception $e) { - log::add('teleinfo', 'error', 'Impossible d\'arrêter le service'); - } - $check = self::deamonRunning(); - $retry = 0; - while ($check) { - $check = self::deamonRunning(); - $retry++; - if ($retry > 10) { - $check = false; - } else { - sleep(1); - } - } - return true; - } - - public static function CalculateTodayStats() + public static function calculateTodayStats() { $STAT_TODAY_HP = 0; $STAT_TODAY_HC = 0; @@ -603,17 +437,11 @@ public static function CalculateTodayStats() log::add('teleinfo', 'info', 'Date de début : ' . date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), date("d"), date("Y")))); log::add('teleinfo', 'info', 'Date de fin : ' . date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")))); log::add('teleinfo', 'info', '----------------------------------------------'); - //log::add('teleinfo', 'info', '----- Calcul des statistiques horraires -----'); - //log::add('teleinfo', 'info', 'StartDateLastHour : ' . date("Y-m-d H:i:s" ,mktime(date("H")-1, date("i"),date("s"), date("m") , date("d"), date("Y"))); - //log::add('teleinfo', 'info', 'EndDateLastHour : ' . date("Y-m-d H:i:s" ,mktime(date("H"), date("i"),date("s"), date("m") , date("d"), date("Y"))); $startdatetoday = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), date("d"), date("Y"))); $enddatetoday = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y"))); $startdateyesterday = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), date("d") - 1, date("Y"))); - //$startdatelasthour = date("Y-m-d H:i:s" ,mktime(date("H")-1, date("i"),date("s"), date("m") , date("d"), date("Y"))); - //$enddatelasthour = date("Y-m-d H:i:s" ,mktime(date("H"), date("i"),date("s"), date("m") , date("d"), date("Y"))); - if ($TYPE_TENDANCE == 1) { $enddateyesterday = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), date("d") - 1, date("Y"))); } else { @@ -622,12 +450,7 @@ public static function CalculateTodayStats() foreach ($stat_hc_to_cumul as $key => $value) { log::add('teleinfo', 'debug', 'Commande HC N°' . $value); - //$cache = cache::byKey('teleinfo::stats::' . $value, false, true); $cmd = cmd::byId($value); - /* log::add('teleinfo', 'info', 'HC : '); - foreach($cmd->getStatistique($startdatetoday,$enddatetoday) as $key => $value){ - log::add('teleinfo', 'info', '[' . $key . '] ' . $value ); - } */ log::add('teleinfo', 'debug', ' ==> Valeur HC MAX : ' . $cmd->getStatistique($startdatetoday, $enddatetoday)['max']); log::add('teleinfo', 'debug', ' ==> Valeur HC MIN : ' . $cmd->getStatistique($startdatetoday, $enddatetoday)['min']); @@ -636,13 +459,8 @@ public static function CalculateTodayStats() log::add('teleinfo', 'debug', 'Total HC --> ' . $STAT_TODAY_HC); } foreach ($stat_hp_to_cumul as $key => $value) { - //log::add('teleinfo', 'debug', 'ID HP --> ' . $value); log::add('teleinfo', 'debug', 'Commande HP N°' . $value); $cmd = cmd::byId($value); - /* log::add('teleinfo', 'info', 'HP : '); - foreach($cmd->getStatistique($startdatetoday,$enddatetoday) as $key => $value){ - log::add('teleinfo', 'info', '[' . $key . '] ' . $value ); - } */ log::add('teleinfo', 'debug', ' ==> Valeur HP MAX : ' . $cmd->getStatistique($startdatetoday, $enddatetoday)['max']); log::add('teleinfo', 'debug', ' ==> Valeur HP MIN : ' . $cmd->getStatistique($startdatetoday, $enddatetoday)['min']); @@ -651,14 +469,6 @@ public static function CalculateTodayStats() log::add('teleinfo', 'debug', 'Total HP --> ' . $STAT_TODAY_HP); } - /* if(($STAT_MAX_YESTERDAY - $STAT_TODAY) > 100){ - $STAT_TENDANCE = -1; - } - else if (($STAT_MAX_YESTERDAY - $STAT_TODAY) < 100){ - $STAT_TENDANCE = 1; - } */ - - foreach (eqLogic::byType('teleinfo') as $eqLogic) { foreach ($eqLogic->getCmd('info') as $cmd) { @@ -685,9 +495,8 @@ public static function CalculateTodayStats() } } - public static function CalculateOtherStats() + public static function calculateOtherStats() { - //$STAT_YESTERDAY = 0; $STAT_YESTERDAY_HC = 0; $STAT_YESTERDAY_HP = 0; $STAT_LASTMONTH = 0; @@ -855,142 +664,143 @@ public static function CalculateOtherStats() foreach (eqLogic::byType('teleinfo') as $eqLogic) { foreach ($eqLogic->getCmd('info') as $cmd) { - if ($cmd->getConfiguration('type') == "stat" || $cmd->getConfiguration('type') == "panel") { - if ($cmd->getConfiguration('info_conso') == "STAT_YESTERDAY") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique hier ==> ' . intval($STAT_YESTERDAY_HC) + intval($STAT_YESTERDAY_HP)); - $cmd->setValue(intval($STAT_YESTERDAY_HC) + intval($STAT_YESTERDAY_HP)); - $cmd->event(intval($STAT_YESTERDAY_HC) + intval($STAT_YESTERDAY_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_YESTERDAY_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique hier (HP) ==> ' . intval($STAT_YESTERDAY_HP)); - $cmd->setValue(intval($STAT_YESTERDAY_HP)); - $cmd->event(intval($STAT_YESTERDAY_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_YESTERDAY_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique hier (HC) ==> ' . intval($STAT_YESTERDAY_HC)); - $cmd->setValue(intval($STAT_YESTERDAY_HC)); - $cmd->event(intval($STAT_YESTERDAY_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_MONTH_LAST_YEAR") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique mois an -1 ==> ' . intval($stat_month_last_year_hc) + intval($stat_month_last_year_hp)); - $cmd->setValue(intval($stat_month_last_year_hc) + intval($stat_month_last_year_hp)); - $cmd->event(intval($stat_month_last_year_hc) + intval($stat_month_last_year_hp)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_YEAR_LAST_YEAR") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique an-1 ==> ' . intval($stat_year_last_year_hc) + intval($stat_year_last_year_hp)); - $cmd->setValue(intval($stat_year_last_year_hc) + intval($stat_year_last_year_hp)); - $cmd->event(intval($stat_year_last_year_hc) + intval($stat_year_last_year_hp)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_LASTMONTH") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique mois dernier ==> ' . intval($STAT_LASTMONTH)); - $cmd->setValue(intval($STAT_LASTMONTH)); - $cmd->event(intval($STAT_LASTMONTH)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_MONTH") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique mois en cours ==> ' . intval($STAT_MONTH)); - $cmd->setValue(intval($STAT_MONTH)); - $cmd->event(intval($STAT_MONTH)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_YEAR") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique anuelle ==> ' . intval($STAT_YEAR)); - $cmd->setValue(intval($STAT_YEAR)); - $cmd->event(intval($STAT_YEAR)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_JAN_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique janvier (HP) ==> ' . intval($STAT_JAN_HP)); - $cmd->setValue(intval($STAT_JAN_HP)); - $cmd->event(intval($STAT_JAN_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_JAN_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique janvier (HC) ==> ' . intval($STAT_JAN_HC)); - $cmd->setValue(intval($STAT_JAN_HC)); - $cmd->event(intval($STAT_JAN_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_FEV_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique février (HP) ==> ' . intval($STAT_FEV_HP)); - $cmd->setValue(intval($STAT_FEV_HP)); - $cmd->event(intval($STAT_FEV_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_FEV_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique février (HC) ==> ' . intval($STAT_FEV_HC)); - $cmd->setValue(intval($STAT_FEV_HC)); - $cmd->event(intval($STAT_FEV_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_MAR_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique mars (HP) ==> ' . intval($STAT_MAR_HP)); - $cmd->setValue(intval($STAT_MAR_HP)); - $cmd->event(intval($STAT_MAR_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_MAR_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique mars (HC) ==> ' . intval($STAT_MAR_HC)); - $cmd->setValue(intval($STAT_MAR_HC)); - $cmd->event(intval($STAT_MAR_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_AVR_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique avril (HP) ==> ' . intval($STAT_AVR_HP)); - $cmd->setValue(intval($STAT_AVR_HP)); - $cmd->event(intval($STAT_AVR_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_AVR_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique avril (HC) ==> ' . intval($STAT_AVR_HC)); - $cmd->setValue(intval($STAT_AVR_HC)); - $cmd->event(intval($STAT_AVR_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_MAI_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique mai (HP) ==> ' . intval($STAT_MAI_HP)); - $cmd->setValue(intval($STAT_MAI_HP)); - $cmd->event(intval($STAT_MAI_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_MAI_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique mai (HC) ==> ' . intval($STAT_MAI_HC)); - $cmd->setValue(intval($STAT_MAI_HC)); - $cmd->event(intval($STAT_MAI_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_JUIN_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique juin (HP) ==> ' . intval($STAT_JUIN_HP)); - $cmd->setValue(intval($STAT_JUIN_HP)); - $cmd->event(intval($STAT_JUIN_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_JUIN_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique juin (HC) ==> ' . intval($STAT_JUIN_HC)); - $cmd->setValue(intval($STAT_JUIN_HC)); - $cmd->event(intval($STAT_JUIN_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_JUI_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique juillet (HP) ==> ' . intval($STAT_JUI_HP)); - $cmd->setValue(intval($STAT_JUI_HP)); - $cmd->event(intval($STAT_JUI_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_JUI_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique juillet (HC) ==> ' . intval($STAT_JUI_HC)); - $cmd->setValue(intval($STAT_JUI_HC)); - $cmd->event(intval($STAT_JUI_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_AOU_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique août (HP) ==> ' . intval($STAT_AOU_HP)); - $cmd->setValue(intval($STAT_AOU_HP)); - $cmd->event(intval($STAT_AOU_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_AOU_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique août (HC) ==> ' . intval($STAT_AOU_HC)); - $cmd->setValue(intval($STAT_AOU_HC)); - $cmd->event(intval($STAT_AOU_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_SEP_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique septembre (HP) ==> ' . intval($STAT_SEP_HP)); - $cmd->setValue(intval($STAT_SEP_HP)); - $cmd->event(intval($STAT_SEP_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_SEP_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique septembre (HC) ==> ' . intval($STAT_SEP_HC)); - $cmd->setValue(intval($STAT_SEP_HC)); - $cmd->event(intval($STAT_SEP_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_OCT_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique octobre (HP) ==> ' . intval($STAT_OCT_HP)); - $cmd->setValue(intval($STAT_OCT_HP)); - $cmd->event(intval($STAT_OCT_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_OCT_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique octobre (HC) ==> ' . intval($STAT_OCT_HC)); - $cmd->setValue(intval($STAT_OCT_HC)); - $cmd->event(intval($STAT_OCT_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_NOV_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique novembre (HP) ==> ' . intval($STAT_NOV_HP)); - $cmd->setValue(intval($STAT_NOV_HP)); - $cmd->event(intval($STAT_NOV_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_NOV_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique novembre (HC) ==> ' . intval($STAT_NOV_HC)); - $cmd->setValue(intval($STAT_NOV_HC)); - $cmd->event(intval($STAT_NOV_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_DEC_HP") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique décembre (HP) ==> ' . intval($STAT_DEC_HP)); - $cmd->setValue(intval($STAT_DEC_HP)); - $cmd->event(intval($STAT_DEC_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_DEC_HC") { - log::add('teleinfo', 'debug', 'Mise à jour de la statistique décembre (HC) ==> ' . intval($STAT_DEC_HC)); - $cmd->setValue(intval($STAT_DEC_HC)); - $cmd->event(intval($STAT_DEC_HC)); + if ($cmd->getConfiguration('type') == "stat" || $cmd->getConfiguration('type') == "panel") { + switch ($cmd->getConfiguration('info_conso')) { + case "STAT_YESTERDAY": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique hier ==> ' . intval($STAT_YESTERDAY_HC) + intval($STAT_YESTERDAY_HP)); + $cmd->event(intval($STAT_YESTERDAY_HC) + intval($STAT_YESTERDAY_HP)); + break; + case "STAT_YESTERDAY_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique hier (HP) ==> ' . intval($STAT_YESTERDAY_HP)); + $cmd->event(intval($STAT_YESTERDAY_HP)); + break; + case "STAT_YESTERDAY_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique hier (HC) ==> ' . intval($STAT_YESTERDAY_HC)); + $cmd->event(intval($STAT_YESTERDAY_HC)); + break; + case "STAT_MONTH_LAST_YEAR": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique mois an -1 ==> ' . intval($stat_month_last_year_hc) + intval($stat_month_last_year_hp)); + $cmd->event(intval($stat_month_last_year_hc) + intval($stat_month_last_year_hp)); + break; + case "STAT_YEAR_LAST_YEAR": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique an-1 ==> ' . intval($stat_year_last_year_hc) + intval($stat_year_last_year_hp)); + $cmd->event(intval($stat_year_last_year_hc) + intval($stat_year_last_year_hp)); + break; + case "STAT_LASTMONTH": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique mois dernier ==> ' . intval($STAT_LASTMONTH)); + $cmd->event(intval($STAT_LASTMONTH)); + break; + case "STAT_MONTH": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique mois en cours ==> ' . intval($STAT_MONTH)); + $cmd->event(intval($STAT_MONTH)); + break; + case "STAT_YEAR": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique anuelle ==> ' . intval($STAT_YEAR)); + $cmd->event(intval($STAT_YEAR)); + break; + case "STAT_JAN_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique janvier (HP) ==> ' . intval($STAT_JAN_HP)); + $cmd->event(intval($STAT_JAN_HP)); + break; + case "STAT_JAN_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique janvier (HC) ==> ' . intval($STAT_JAN_HC)); + $cmd->event(intval($STAT_JAN_HC)); + break; + case "STAT_FEV_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique février (HP) ==> ' . intval($STAT_FEV_HP)); + $cmd->event(intval($STAT_FEV_HP)); + break; + case "STAT_FEV_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique février (HC) ==> ' . intval($STAT_FEV_HC)); + $cmd->event(intval($STAT_FEV_HC)); + break; + case "STAT_MAR_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique mars (HP) ==> ' . intval($STAT_MAR_HP)); + $cmd->event(intval($STAT_MAR_HP)); + break; + case "STAT_MAR_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique mars (HC) ==> ' . intval($STAT_MAR_HC)); + $cmd->event(intval($STAT_MAR_HC)); + break; + case "STAT_AVR_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique avril (HP) ==> ' . intval($STAT_AVR_HP)); + $cmd->event(intval($STAT_AVR_HP)); + break; + case "STAT_AVR_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique avril (HC) ==> ' . intval($STAT_AVR_HC)); + $cmd->event(intval($STAT_AVR_HC)); + break; + case "STAT_MAI_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique mai (HP) ==> ' . intval($STAT_MAI_HP)); + $cmd->event(intval($STAT_MAI_HP)); + break; + case "STAT_MAI_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique mai (HC) ==> ' . intval($STAT_MAI_HC)); + $cmd->event(intval($STAT_MAI_HC)); + break; + case "STAT_JUIN_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique juin (HP) ==> ' . intval($STAT_JUIN_HP)); + $cmd->event(intval($STAT_JUIN_HP)); + break; + case "STAT_JUIN_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique juin (HC) ==> ' . intval($STAT_JUIN_HC)); + $cmd->event(intval($STAT_JUIN_HC)); + break; + case "STAT_JUI_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique juillet (HP) ==> ' . intval($STAT_JUI_HP)); + $cmd->event(intval($STAT_JUI_HP)); + break; + case "STAT_JUI_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique juillet (HC) ==> ' . intval($STAT_JUI_HC)); + $cmd->event(intval($STAT_JUI_HC)); + break; + case "STAT_AOU_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique août (HP) ==> ' . intval($STAT_AOU_HP)); + $cmd->event(intval($STAT_AOU_HP)); + break; + case "STAT_AOU_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique août (HC) ==> ' . intval($STAT_AOU_HC)); + $cmd->event(intval($STAT_AOU_HC)); + break; + case "STAT_SEP_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique septembre (HP) ==> ' . intval($STAT_SEP_HP)); + $cmd->event(intval($STAT_SEP_HP)); + break; + case "STAT_SEP_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique septembre (HC) ==> ' . intval($STAT_SEP_HC)); + $cmd->event(intval($STAT_SEP_HC)); + break; + case "STAT_OCT_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique octobre (HP) ==> ' . intval($STAT_OCT_HP)); + $cmd->event(intval($STAT_OCT_HP)); + break; + case "STAT_OCT_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique octobre (HC) ==> ' . intval($STAT_OCT_HC)); + $cmd->event(intval($STAT_OCT_HC)); + break; + case "STAT_NOV_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique novembre (HP) ==> ' . intval($STAT_NOV_HP)); + $cmd->event(intval($STAT_NOV_HP)); + break; + case "STAT_NOV_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique novembre (HC) ==> ' . intval($STAT_NOV_HC)); + $cmd->event(intval($STAT_NOV_HC)); + break; + case "STAT_DEC_HP": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique décembre (HP) ==> ' . intval($STAT_DEC_HP)); + $cmd->event(intval($STAT_DEC_HP)); + break; + case "STAT_DEC_HC": + log::add('teleinfo', 'debug', 'Mise à jour de la statistique décembre (HC) ==> ' . intval($STAT_DEC_HC)); + $cmd->event(intval($STAT_DEC_HC)); + break; } } } } } - public static function Moy_Last_Hour() + public static function moyLastHour() { $ppap_hp = 0; $ppap_hc = 0; @@ -1051,7 +861,7 @@ public static function Moy_Last_Hour() } } - public static function Calculate_PAPP() + public static function calculatePAPP() { $ppap_hp = 0; $ppap_hc = 0; @@ -1101,11 +911,8 @@ public static function Calculate_PAPP() $datetime2 = time(); $interval = $datetime2 - $datetime_mesure; log::add('teleinfo', 'debug', 'Intervale depuis la dernière valeur : ' . $interval); - // log::add('teleinfo', 'debug', 'Conso calculée : ' . (($ppap_hp - $cache_hp) + ($ppap_hc - $cache_hc)) . ' Wh' ); log::add('teleinfo', 'debug', 'Conso calculée : ' . ((($ppap_hp - $cache_hp) + ($ppap_hc - $cache_hc)) / $interval) * 3600 . ' Wh'); - // $cmd_ppap->setValue(intval((($ppap_hp - $cache_hp) + ($ppap_hc - $cache_hc))* $interval)); - $cmd_ppap->setValue(intval(((($ppap_hp - $cache_hp) + ($ppap_hc - $cache_hc)) / $interval) * 3600)); - // $cmd_ppap->event(intval((($ppap_hp - $cache_hp) + ($ppap_hc - $cache_hc))* $interval)); + //$cmd_ppap->setValue(intval(((($ppap_hp - $cache_hp) + ($ppap_hc - $cache_hc)) / $interval) * 3600)); $cmd_ppap->event(intval(((($ppap_hp - $cache_hp) + ($ppap_hc - $cache_hc)) / $interval) * 3600)); cache::set('teleinfo::ppap_manuelle::hc', $ppap_hc, 150); @@ -1119,7 +926,6 @@ public static function Calculate_PAPP() public function preSave() { $this->setCategory('energy', 1); - $cmd = $this->getCmd('info', 'HEALTH'); if (is_object($cmd)) { $cmd->remove(); @@ -1130,21 +936,7 @@ public function preSave() public function postSave() { log::add('teleinfo', 'debug', '-------- Sauvegarde de l\'objet --------'); - //$template_name = ""; - - /* if($this->getConfiguration('template') == 'bleu'){ - $template_name = "teleinfo_bleu_"; - } - else if($this->getConfiguration('template') == 'base'){ - $template_name = "teleinfo_base_"; - } - else if($this->getConfiguration('template') == ''){ - goto after_template; - } - log::add('teleinfo', 'info', '==> Gestion des templates'); - */ foreach ($this->getCmd(null, null, true) as $cmd) { - //$replace['#'.$cmd->getLogicalId().'#'] = $cmd->toHtml($_version); switch ($cmd->getConfiguration('info_conso')) { case "BASE": case "HCHP": @@ -1161,8 +953,6 @@ public function postSave() if ($cmd->getDisplay('generic_type') == '') { $cmd->setDisplay('generic_type', 'GENERIC_INFO'); } - //$cmd->setTemplate('dashboard', $template_name . 'teleinfo_new_index'); - //$cmd->setTemplate('mobile', $template_name . 'teleinfo_new_index'); $cmd->save(); $cmd->refresh(); break; @@ -1172,8 +962,6 @@ public function postSave() $cmd->setDisplay('generic_type', 'GENERIC_INFO'); $cmd->setDisplay('icon', '<\/i>'); } - //$cmd->setTemplate('dashboard', $template_name . 'teleinfo_conso_inst'); - //$cmd->setTemplate('mobile', $template_name . 'teleinfo_conso_inst'); $cmd->save(); $cmd->refresh(); break; @@ -1182,8 +970,6 @@ public function postSave() if ($cmd->getDisplay('generic_type') == '') { $cmd->setDisplay('generic_type', 'GENERIC_INFO'); } - //$cmd->setTemplate('dashboard', $template_name . 'teleinfo_ptec'); - //$cmd->setTemplate('mobile', $template_name . 'teleinfo_ptec'); $cmd->save(); $cmd->refresh(); break; @@ -1198,7 +984,6 @@ public function postSave() after_template: log::add('teleinfo', 'info', '==> Gestion des id des commandes'); foreach ($this->getCmd('info') as $cmd) { - //foreach ($this->getCmd(null, null, true) as $cmd) { log::add('teleinfo', 'debug', 'Commande : ' . $cmd->getConfiguration('info_conso')); $cmd->setLogicalId($cmd->getConfiguration('info_conso')); $cmd->save(); @@ -1209,14 +994,10 @@ public function postSave() $this->CreateFromAbo($this->getConfiguration('abonnement')); } - $this->CreateOtherCmd(); + $this->createOtherCmd(); - $this->CreatePanelStats(); + $this->createPanelStats(); - /* foreach ($this->getCmd(null, null, true) as $cmd) { - $cmd->setLogicalId($cmd->getConfiguration('info_conso')); - $cmd->save(); - } */ } public function preRemove() @@ -1224,7 +1005,7 @@ public function preRemove() log::add('teleinfo', 'debug', 'Suppression d\'un objet'); } - public function CreateOtherCmd() + public function createOtherCmd() { $array = array("HEALTH"); for ($ii = 0; $ii < 1; $ii++) { @@ -1248,7 +1029,7 @@ public function CreateOtherCmd() } } - public function CreatePanelStats() + public function createPanelStats() { $array = array("STAT_JAN_HP", "STAT_JAN_HC", "STAT_FEV_HP", "STAT_FEV_HC", "STAT_MAR_HP", "STAT_MAR_HC", "STAT_AVR_HP", "STAT_AVR_HC", "STAT_MAI_HP", "STAT_MAI_HC", "STAT_JUIN_HP", "STAT_JUIN_HC", "STAT_JUI_HP", "STAT_JUI_HC", "STAT_AOU_HP", "STAT_AOU_HC", "STAT_SEP_HP", "STAT_SEP_HC", "STAT_OCT_HP", "STAT_OCT_HC", "STAT_NOV_HP", "STAT_NOV_HC", "STAT_DEC_HP", "STAT_DEC_HC", "STAT_MONTH_LAST_YEAR", "STAT_YEAR_LAST_YEAR"); for ($ii = 0; $ii < 26; $ii++) { @@ -1280,206 +1061,7 @@ public function CreateFromAbo($_abo) { $this->setConfiguration('AutoGenerateFields', '0'); $this->save(); - if ($_abo == 'base') { - - $cmd = new teleinfoCmd(); - $cmd->setName('Index'); - $cmd->setEqLogic_id($this->id); - $cmd->setLogicalId('BASE'); - $cmd->setType('info'); - $cmd->setConfiguration('info_conso', 'BASE'); - $cmd->setDisplay('generic_type', 'GENERIC_INFO'); - $cmd->setSubType('numeric'); - $cmd->setUnite('Wh'); - $cmd->setIsHistorized(1); - $cmd->setEventOnly(1); - $cmd->setIsVisible(1); - $cmd->save(); - - $cmd = new teleinfoCmd(); - $cmd->setName('Intensité Instantanée'); - $cmd->setEqLogic_id($this->id); - $cmd->setLogicalId('IINST'); - $cmd->setType('info'); - $cmd->setConfiguration('info_conso', 'IINST'); - $cmd->setDisplay('generic_type', 'DONT'); - $cmd->setSubType('numeric'); - $cmd->setUnite('A'); - $cmd->setIsHistorized(0); - $cmd->setEventOnly(1); - $cmd->setIsVisible(1); - $cmd->save(); - - $cmd = new teleinfoCmd(); - $cmd->setName('Puissance apparente'); - $cmd->setEqLogic_id($this->id); - $cmd->setLogicalId('PAPP'); - $cmd->setType('info'); - $cmd->setConfiguration('info_conso', 'PAPP'); - $cmd->setDisplay('generic_type', 'GENERIC_INFO'); - $cmd->setDisplay('icon', '<\/i>'); - $cmd->setSubType('numeric'); - $cmd->setUnite('VA (~W)'); - $cmd->setIsHistorized(1); - $cmd->setEventOnly(1); - $cmd->setIsVisible(1); - $cmd->save(); - - $cmd = new teleinfoCmd(); - $cmd->setName('Dépassement'); - $cmd->setEqLogic_id($this->id); - $cmd->setLogicalId('ADPS'); - $cmd->setType('info'); - $cmd->setConfiguration('info_conso', 'ADPS'); - $cmd->setDisplay('generic_type', 'DONT'); - $cmd->setSubType('numeric'); - $cmd->setUnite('A'); - $cmd->setIsHistorized(0); - $cmd->setEventOnly(1); - $cmd->setIsVisible(1); - $cmd->save(); - } elseif ($_abo == 'bleu') { - - $cmd = new teleinfoCmd(); - $cmd->setName('Index HP'); - $cmd->setEqLogic_id($this->id); - $cmd->setLogicalId('HCHP'); - $cmd->setType('info'); - $cmd->setConfiguration('info_conso', 'HCHP'); - $cmd->setDisplay('generic_type', 'GENERIC_INFO'); - $cmd->setSubType('numeric'); - $cmd->setUnite('Wh'); - $cmd->setIsHistorized(1); - $cmd->setEventOnly(1); - $cmd->setIsVisible(1); - $cmd->save(); - - $cmd = new teleinfoCmd(); - $cmd->setName('Index HC'); - $cmd->setEqLogic_id($this->id); - $cmd->setLogicalId('HCHC'); - $cmd->setType('info'); - $cmd->setConfiguration('info_conso', 'HCHC'); - $cmd->setDisplay('generic_type', 'GENERIC_INFO'); - $cmd->setSubType('numeric'); - $cmd->setUnite('Wh'); - $cmd->setIsHistorized(1); - $cmd->setEventOnly(1); - $cmd->setIsVisible(1); - $cmd->save(); - - $cmd = new teleinfoCmd(); - $cmd->setName('Puissance Apparente'); - $cmd->setEqLogic_id($this->id); - $cmd->setLogicalId('PAPP'); - $cmd->setType('info'); - $cmd->setConfiguration('info_conso', 'PAPP'); - $cmd->setDisplay('generic_type', 'GENERIC_INFO'); - $cmd->setDisplay('icon', '<\/i>'); - $cmd->setSubType('numeric'); - $cmd->setUnite('VA (~W)'); - $cmd->setIsHistorized(1); - $cmd->setEventOnly(1); - $cmd->setIsVisible(1); - $cmd->save(); - - $cmd = new teleinfoCmd(); - $cmd->setName('Intensité'); - $cmd->setEqLogic_id($this->id); - $cmd->setLogicalId('IINST'); - $cmd->setType('info'); - $cmd->setConfiguration('info_conso', 'IINST'); - $cmd->setDisplay('generic_type', 'DONT'); - $cmd->setSubType('numeric'); - $cmd->setUnite('A'); - $cmd->setIsHistorized(0); - $cmd->setEventOnly(1); - $cmd->setIsVisible(1); - $cmd->save(); - - $cmd = new teleinfoCmd(); - $cmd->setName('Dépassement'); - $cmd->setEqLogic_id($this->id); - $cmd->setLogicalId('ADPS'); - $cmd->setType('info'); - $cmd->setConfiguration('info_conso', 'ADPS'); - $cmd->setDisplay('generic_type', 'DONT'); - $cmd->setSubType('numeric'); - $cmd->setUnite('A'); - $cmd->setIsHistorized(0); - $cmd->setEventOnly(1); - $cmd->setIsVisible(1); - $cmd->save(); - - $cmd = new teleinfoCmd(); - $cmd->setName('Plage Horaire'); - $cmd->setEqLogic_id($this->id); - $cmd->setLogicalId('HHPHC'); - $cmd->setType('info'); - $cmd->setConfiguration('info_conso', 'HHPHC'); - $cmd->setDisplay('generic_type', 'DONT'); - $cmd->setSubType('string'); - //$cmd->setUnite(''); - $cmd->setIsHistorized(0); - $cmd->setEventOnly(1); - $cmd->setIsVisible(1); - $cmd->save(); - } } - - /* public function toHtml($_version = 'dashboard') - { - $_version = jeedom::versionAlias($_version); - $replace = array( - '#id#' => $this->getId(), - '#name#' => ($this->getIsEnable()) ? $this->getName() : '' . $this->getName() . '', - '#background_color#' => $this->getBackgroundColor($_version), - '#eqLink#' => $this->getLinkToConfiguration(), - ); - if ($this->getIsEnable()) { - foreach ($this->getCmd(null, null, true) as $cmd) { - $replace['#'.$cmd->getLogicalId().'#'] = $cmd->toHtml($_version); - } - } - if ($_version == 'dview' || $_version == 'mview') { - $object = $this->getObject(); - $replace['#name#'] = (is_object($object)) ? $object->getName() . ' - ' . $replace['#name#'] : $replace['#name#']; - } - - //log::add('presence', 'debug', 'HTML : ' . $replace["#name#"]); - $parameters = $this->getDisplay('parameters'); - if (is_array($parameters)) { - foreach ($parameters as $key => $value) { - $replace['#' . $key . '#'] = $value; - } - } - log::add('presence', 'debug', 'Template sélectionné : ' . $this->getConfiguration('template');); - - - //cache::set('weatherWidget' . $_version . $this->getId(), $html, 0); - - //return template_replace($replace, getTemplate('core', $_version, 'eqLogic','teleinfo')); - //return template_replace($replace, getTemplate('core', $_version, 'eqLogic','teleinfo')); - } - /* * *********************Methode d'instance************************* */ - - /* public function forceUpdate() { - foreach ($this->getCmd() as $cmd) { - try { - $cmd->forceUpdate(); - } catch (Exception $e) { - - } - } - try { - //self::callTeleinfo('/teleinfo'); - } catch (Exception $e) { - - } - } */ - - - /* * ******** MANAGEMENT ZONE ******* */ public static function dependancy_info() @@ -1525,7 +1107,7 @@ class teleinfoCmd extends cmd public function execute($_options = null) { - + } /* * **********************Getteur Setteur*************************** */ diff --git a/plugin_info/info.json b/plugin_info/info.json index 65e1595..e8b8ba2 100644 --- a/plugin_info/info.json +++ b/plugin_info/info.json @@ -12,5 +12,5 @@ "maxDependancyInstallTime" : 45, "changelog" : "https://Jeedom-Plugins-Extra.github.io/plugin-teleinfo/#language#/changelog", "documentation" : "https://Jeedom-Plugins-Extra.github.io/plugin-teleinfo/#language#/", - "pluginVersion" : "2.6.1" + "pluginVersion" : "2.7.0" } diff --git a/plugin_info/install.php b/plugin_info/install.php index c8c5c93..1520486 100644 --- a/plugin_info/install.php +++ b/plugin_info/install.php @@ -18,42 +18,42 @@ require_once dirname(__FILE__) . '/../../../core/php/core.inc.php'; -function teleinfo_install() { - $core_version = '1.1.1'; - if (!file_exists(dirname(__FILE__) . '/info.json')) { - log::add('teleinfo','warning','Pas de fichier info.json'); - goto step2; - } - $data = json_decode(file_get_contents(dirname(__FILE__) . '/info.json'), true); - if (!is_array($data)) { - log::add('teleinfo','warning','Impossible de décoder le fichier info.json'); - goto step2; - } - try { - $core_version = $data['pluginVersion']; - } catch (\Exception $e) { - - } +function teleinfo_install() { + $core_version = '1.1.1'; + if (!file_exists(dirname(__FILE__) . '/info.json')) { + log::add('teleinfo','warning','Pas de fichier info.json'); + goto step2; + } + $data = json_decode(file_get_contents(dirname(__FILE__) . '/info.json'), true); + if (!is_array($data)) { + log::add('teleinfo','warning','Impossible de décoder le fichier info.json'); + goto step2; + } + try { + $core_version = $data['pluginVersion']; + } catch (\Exception $e) { + + } step2: if (teleinfo::deamonRunning()) { - teleinfo::stopDeamon(); + teleinfo::deamon_stop(); } - $cron = cron::byClassAndFunction('teleinfo', 'CalculateOtherStats'); + $cron = cron::byClassAndFunction('teleinfo', 'calculateOtherStats'); if (!is_object($cron)) { $cron = new cron(); $cron->setClass('teleinfo'); - $cron->setFunction('CalculateOtherStats'); + $cron->setFunction('calculateOtherStats'); $cron->setEnable(1); $cron->setDeamon(0); $cron->setSchedule('10 00 * * *'); $cron->save(); } - $crontoday = cron::byClassAndFunction('teleinfo', 'CalculateTodayStats'); + $crontoday = cron::byClassAndFunction('teleinfo', 'calculateTodayStats'); if (!is_object($crontoday)) { $crontoday = new cron(); $crontoday->setClass('teleinfo'); - $crontoday->setFunction('CalculateTodayStats'); + $crontoday->setFunction('calculateTodayStats'); $crontoday->setEnable(1); $crontoday->setDeamon(0); $crontoday->setSchedule('*/5 * * * *'); @@ -63,24 +63,25 @@ function teleinfo_install() { } function teleinfo_update() { - $core_version = '1.1.1'; - if (!file_exists(dirname(__FILE__) . '/info.json')) { - log::add('teleinfo','warning','Pas de fichier info.json'); - goto step2; - } - $data = json_decode(file_get_contents(dirname(__FILE__) . '/info.json'), true); - if (!is_array($data)) { - log::add('teleinfo','warning','Impossible de décoder le fichier info.json'); - goto step2; - } - try { - $core_version = $data['pluginVersion']; - } catch (\Exception $e) { - - } - step2: + log::add('teleinfo','debug','teleinfo_update'); + $core_version = '1.1.1'; + if (!file_exists(dirname(__FILE__) . '/info.json')) { + log::add('teleinfo','warning','Pas de fichier info.json'); + goto step2; + } + $data = json_decode(file_get_contents(dirname(__FILE__) . '/info.json'), true); + if (!is_array($data)) { + log::add('teleinfo','warning','Impossible de décoder le fichier info.json'); + goto step2; + } + try { + $core_version = $data['pluginVersion']; + } catch (\Exception $e) { + log::add('teleinfo','warning','Pas de version de plugin'); + } + step2: if (teleinfo::deamonRunning()) { - teleinfo::stopDeamon(); + teleinfo::deamon_stop(); } message::add('Téléinfo', 'Mise à jour en cours...', null, null); log::add('teleinfo','info','*****************************************************'); @@ -88,14 +89,21 @@ function teleinfo_update() { log::add('teleinfo','info','*****************************************************'); log::add('teleinfo','info','** Core version : '. $core_version. ' **'); log::add('teleinfo','info','*****************************************************'); + + $cron = cron::byClassAndFunction('teleinfo', 'CalculateOtherStats'); + if (is_object($cron)) { + $cron->remove(); + } + $crontoday = cron::byClassAndFunction('teleinfo', 'CalculateTodayStats'); + if (is_object($crontoday)) { + $crontoday->remove(); + } - //config::save('teleinfo_core_version',$core_version,'teleinfo'); - - $cron = cron::byClassAndFunction('teleinfo', 'CalculateOtherStats'); + $cron = cron::byClassAndFunction('teleinfo', 'calculateOtherStats'); if (!is_object($cron)) { $cron = new cron(); $cron->setClass('teleinfo'); - $cron->setFunction('CalculateOtherStats'); + $cron->setFunction('calculateOtherStats'); $cron->setEnable(1); $cron->setDeamon(0); $cron->setSchedule('10 00 * * *'); @@ -107,11 +115,11 @@ function teleinfo_update() { } $cron->stop(); - $crontoday = cron::byClassAndFunction('teleinfo', 'CalculateTodayStats'); + $crontoday = cron::byClassAndFunction('teleinfo', 'calculateTodayStats'); if (!is_object($crontoday)) { $crontoday = new cron(); $crontoday->setClass('teleinfo'); - $crontoday->setFunction('CalculateTodayStats'); + $crontoday->setFunction('calculateTodayStats'); $crontoday->setEnable(1); $crontoday->setDeamon(0); $crontoday->setSchedule('*/5 * * * *'); @@ -125,7 +133,7 @@ function teleinfo_update() { function teleinfo_remove() { if (teleinfo::deamonRunning()) { - teleinfo::stopDeamon(); + teleinfo::deamon_stop(); } $cron = cron::byClassAndFunction('teleinfo', 'CalculateOtherStats'); if (is_object($cron)) { @@ -136,5 +144,3 @@ function teleinfo_remove() { $crontoday->remove(); } } - -?> From 0abb41bf2cb549f875dba967c468a81aeb83aced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Sun, 11 Mar 2018 10:05:29 -0400 Subject: [PATCH 02/16] =?UTF-8?q?It=C3=A9ratino=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/class/teleinfo.class.php | 62 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/core/class/teleinfo.class.php b/core/class/teleinfo.class.php index 4f80f02..0702d57 100644 --- a/core/class/teleinfo.class.php +++ b/core/class/teleinfo.class.php @@ -432,25 +432,25 @@ public static function calculateTodayStats() } } } - + + $startdatetoday = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), date("d"), date("Y"))); + $enddatetoday = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y"))); log::add('teleinfo', 'info', '----- Calcul des statistiques temps réel -----'); - log::add('teleinfo', 'info', 'Date de début : ' . date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), date("d"), date("Y")))); - log::add('teleinfo', 'info', 'Date de fin : ' . date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")))); + log::add('teleinfo', 'info', 'Date de début : ' . $startdatetoday); + log::add('teleinfo', 'info', 'Date de fin : ' . $enddatetoday); log::add('teleinfo', 'info', '----------------------------------------------'); - - $startdatetoday = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), date("d"), date("Y"))); - $enddatetoday = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y"))); + $startdateyesterday = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), date("d") - 1, date("Y"))); - - if ($TYPE_TENDANCE == 1) { + if ($TYPE_TENDANCE === 1) { $enddateyesterday = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), date("d") - 1, date("Y"))); } else { $enddateyesterday = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m"), date("d") - 1, date("Y"))); } - foreach ($stat_hc_to_cumul as $key => $value) { + foreach ($stat_hc_to_cumul as $key => $value) { + $cmd = cmd::byId($value); + log::add('teleinfo', 'debug', 'Commande HC N°' . $value); - $cmd = cmd::byId($value); log::add('teleinfo', 'debug', ' ==> Valeur HC MAX : ' . $cmd->getStatistique($startdatetoday, $enddatetoday)['max']); log::add('teleinfo', 'debug', ' ==> Valeur HC MIN : ' . $cmd->getStatistique($startdatetoday, $enddatetoday)['min']); @@ -458,9 +458,10 @@ public static function calculateTodayStats() $STAT_YESTERDAY_HC += intval($cmd->getStatistique($startdateyesterday, $enddateyesterday)['max']) - intval($cmd->getStatistique($startdateyesterday, $enddateyesterday)['min']); log::add('teleinfo', 'debug', 'Total HC --> ' . $STAT_TODAY_HC); } - foreach ($stat_hp_to_cumul as $key => $value) { + foreach ($stat_hp_to_cumul as $key => $value) { + $cmd = cmd::byId($value); + log::add('teleinfo', 'debug', 'Commande HP N°' . $value); - $cmd = cmd::byId($value); log::add('teleinfo', 'debug', ' ==> Valeur HP MAX : ' . $cmd->getStatistique($startdatetoday, $enddatetoday)['max']); log::add('teleinfo', 'debug', ' ==> Valeur HP MIN : ' . $cmd->getStatistique($startdatetoday, $enddatetoday)['min']); @@ -472,23 +473,24 @@ public static function calculateTodayStats() foreach (eqLogic::byType('teleinfo') as $eqLogic) { foreach ($eqLogic->getCmd('info') as $cmd) { - if ($cmd->getConfiguration('type') == "stat") { - if ($cmd->getConfiguration('info_conso') == "STAT_TODAY") { - log::add('teleinfo', 'info', 'Mise à jour de la statistique journalière ==> ' . intval($STAT_TODAY_HP + $STAT_TODAY_HC)); - $cmd->setValue(intval($STAT_TODAY_HP + $STAT_TODAY_HC)); - $cmd->event(intval($STAT_TODAY_HP + $STAT_TODAY_HC)); - } elseif ($cmd->getConfiguration('info_conso') == "TENDANCE_DAY") { - log::add('teleinfo', 'debug', 'Mise à jour de la tendance journalière ==> ' . '(Hier : ' . intval($STAT_YESTERDAY_HC + $STAT_YESTERDAY_HP) . ' Aujourd\'hui : ' . intval($STAT_TODAY_HC + $STAT_TODAY_HP) . ' Différence : ' . (intval($STAT_YESTERDAY_HC + $STAT_YESTERDAY_HP) - intval($STAT_TODAY_HC + $STAT_TODAY_HP)) . ')'); - $cmd->setValue(intval($STAT_YESTERDAY_HC + $STAT_YESTERDAY_HP) - intval($STAT_TODAY_HC + $STAT_TODAY_HP)); - $cmd->event(intval($STAT_YESTERDAY_HC + $STAT_YESTERDAY_HP) - intval($STAT_TODAY_HC + $STAT_TODAY_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_TODAY_HP") { - log::add('teleinfo', 'info', 'Mise à jour de la statistique journalière (HP) ==> ' . intval($STAT_TODAY_HP)); - $cmd->setValue(intval($STAT_TODAY_HP)); - $cmd->event(intval($STAT_TODAY_HP)); - } elseif ($cmd->getConfiguration('info_conso') == "STAT_TODAY_HC") { - log::add('teleinfo', 'info', 'Mise à jour de la statistique journalière (HC) ==> ' . intval($STAT_TODAY_HC)); - $cmd->setValue(intval($STAT_TODAY_HC)); - $cmd->event(intval($STAT_TODAY_HC)); + if ($cmd->getConfiguration('type') == "stat") { + switch ($cmd->getConfiguration('info_conso')) { + case "STAT_TODAY": + log::add('teleinfo', 'info', 'Mise à jour de la statistique journalière ==> ' . intval($STAT_TODAY_HP + $STAT_TODAY_HC)); + $cmd->event(intval($STAT_TODAY_HP + $STAT_TODAY_HC)); + break; + case "TENDANCE_DAY": + log::add('teleinfo', 'debug', 'Mise à jour de la tendance journalière ==> ' . '(Hier : ' . intval($STAT_YESTERDAY_HC + $STAT_YESTERDAY_HP) . ' Aujourd\'hui : ' . intval($STAT_TODAY_HC + $STAT_TODAY_HP) . ' Différence : ' . (intval($STAT_YESTERDAY_HC + $STAT_YESTERDAY_HP) - intval($STAT_TODAY_HC + $STAT_TODAY_HP)) . ')'); + $cmd->event(intval($STAT_YESTERDAY_HC + $STAT_YESTERDAY_HP) - intval($STAT_TODAY_HC + $STAT_TODAY_HP)); + break; + case "STAT_TODAY_HP": + log::add('teleinfo', 'info', 'Mise à jour de la statistique journalière (HP) ==> ' . intval($STAT_TODAY_HP)); + $cmd->event(intval($STAT_TODAY_HP)); + break; + case "STAT_TODAY_HC": + log::add('teleinfo', 'info', 'Mise à jour de la statistique journalière (HC) ==> ' . intval($STAT_TODAY_HC)); + $cmd->event(intval($STAT_TODAY_HC)); + break; } } } @@ -631,8 +633,6 @@ public static function calculateOtherStats() $STAT_OCT_HC += intval($cmd->getStatistique($startdate_oct, $enddate_oct)['max']) - intval($cmd->getStatistique($startdate_oct, $enddate_oct)['min']); $STAT_NOV_HC += intval($cmd->getStatistique($startdate_nov, $enddate_nov)['max']) - intval($cmd->getStatistique($startdate_nov, $enddate_nov)['min']); $STAT_DEC_HC += intval($cmd->getStatistique($startdate_dec, $enddate_dec)['max']) - intval($cmd->getStatistique($startdate_dec, $enddate_dec)['min']); - - //log::add('teleinfo', 'info', 'Conso HC --> ' . $STAT_TODAY_HC); } foreach ($stat_hp_to_cumul as $key => $value) { log::add('teleinfo', 'debug', 'Commande HP N°' . $value); From 075f7d42068e9d1b667b93a79e813f6c64c7ed6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Mon, 12 Mar 2018 11:43:30 -0400 Subject: [PATCH 03/16] =?UTF-8?q?It=C3=A9ration=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/class/teleinfo.class.php | 20 +-- core/php/jeeTeleinfo.php | 154 ++++++++++++------- desktop/js/teleinfo.js | 276 +++++++++++++++++----------------- 3 files changed, 240 insertions(+), 210 deletions(-) diff --git a/core/class/teleinfo.class.php b/core/class/teleinfo.class.php index 0702d57..d5dccee 100644 --- a/core/class/teleinfo.class.php +++ b/core/class/teleinfo.class.php @@ -42,20 +42,16 @@ public static function cronHourly() self::moyLastHour(); } - public static function createFromDef($_def) + public static function createFromDef(string $adco) { $autorisationCreationObjet = config::byKey('createNewADCO', 'teleinfo'); if ($autorisationCreationObjet != 1) { - if (!isset($_def['ADCO'])) { - log::add('teleinfo', 'info', 'Information manquante pour ajouter l\'équipement : ' . print_r($_def, true)); - return false; - } - $teleinfo = teleinfo::byLogicalId($_def['ADCO'], 'teleinfo'); + $teleinfo = teleinfo::byLogicalId($adco, 'teleinfo'); if (!is_object($teleinfo)) { $eqLogic = new teleinfo(); - $eqLogic->setName($_def['ADCO']); + $eqLogic->setName($adco); } - $eqLogic->setLogicalId($_def['ADCO']); + $eqLogic->setLogicalId($adco); $eqLogic->setEqType_name('teleinfo'); $eqLogic->setIsEnable(1); $eqLogic->setIsVisible(1); @@ -1010,8 +1006,7 @@ public function createOtherCmd() $array = array("HEALTH"); for ($ii = 0; $ii < 1; $ii++) { $cmd = $this->getCmd('info', $array[$ii]); - if ($cmd === null) { - + if ($cmd === false) { $cmd = new teleinfoCmd(); $cmd->setName($array[$ii]); $cmd->setEqLogic_id($this->id); @@ -1032,10 +1027,9 @@ public function createOtherCmd() public function createPanelStats() { $array = array("STAT_JAN_HP", "STAT_JAN_HC", "STAT_FEV_HP", "STAT_FEV_HC", "STAT_MAR_HP", "STAT_MAR_HC", "STAT_AVR_HP", "STAT_AVR_HC", "STAT_MAI_HP", "STAT_MAI_HC", "STAT_JUIN_HP", "STAT_JUIN_HC", "STAT_JUI_HP", "STAT_JUI_HC", "STAT_AOU_HP", "STAT_AOU_HC", "STAT_SEP_HP", "STAT_SEP_HC", "STAT_OCT_HP", "STAT_OCT_HC", "STAT_NOV_HP", "STAT_NOV_HC", "STAT_DEC_HP", "STAT_DEC_HC", "STAT_MONTH_LAST_YEAR", "STAT_YEAR_LAST_YEAR"); - for ($ii = 0; $ii < 26; $ii++) { + for ($ii = 0; $ii < 1; $ii++) { $cmd = $this->getCmd('info', $array[$ii]); - if ($cmd === null) { - + if ($cmd === false) { $cmd = new teleinfoCmd(); $cmd->setName($array[$ii]); $cmd->setEqLogic_id($this->id); diff --git a/core/php/jeeTeleinfo.php b/core/php/jeeTeleinfo.php index 142c06d..26b73c4 100644 --- a/core/php/jeeTeleinfo.php +++ b/core/php/jeeTeleinfo.php @@ -16,70 +16,108 @@ * along with Jeedom. If not, see . */ require_once dirname(__FILE__) . "/../../../../core/php/core.inc.php"; -if (isset($argv)) { - foreach ($argv as $arg) { - $argList = explode('=', $arg); - if (isset($argList[0]) && isset($argList[1])) { - $_GET[$argList[0]] = $argList[1]; - } - } -} set_time_limit(15); if ((php_sapi_name() != 'cli' || isset($_SERVER['REQUEST_METHOD']) || !isset($_SERVER['argc'])) && (config::byKey('api') != init('api') && init('api') != '')) { - connection::failed(); - echo 'Clef API non valide, vous n\'êtes pas autorisé à effectuer cette action (jeeTeleinfo)'; - die(); + echo 'Clef API non valide, vous n\'êtes pas autorisé à effectuer cette action (jeeTeleinfo)'; + die(); } - -if(isset($_GET['message'])){ - $text = ""; - //log::add('teleinfo', 'event', 'Log Daemon : ' . $_GET['message']); - $text = substr($_GET['message'], 0, -2); - $messages = preg_split("#(&|[\*]{2})#", $text); - $text = ""; - foreach ($messages as $key => $value){ - log::add('teleinfo', 'event', 'Log Daemon : ' . $value); - $text = $text . date("Y-m-d H:i:s") . " " . $value . "
"; - } - $cache = cache::byKey('teleinfo::console', false); - //$cache->setValue($cache->getValue("") . "\n" . $text); - cache::set('teleinfo::console', $cache->getValue("") . $text, 1440); - die(); + +$message = filter_input(INPUT_GET, 'message', FILTER_SANITIZE_STRING); +$adco = filter_input(INPUT_GET, 'ADCO', FILTER_SANITIZE_STRING); +$array_recu = ""; + +if($message != ''){ + $text = substr($message, 0, -2); + $messages = preg_split("#(&|[\*]{2})#", $text); + foreach ($messages as $key => $value){ + log::add('teleinfo', 'event', 'Log Daemon : ' . $value); + $text = $text . date("Y-m-d H:i:s") . " " . $value . "
"; + } + $cache = cache::byKey('teleinfo::console', false); + cache::set('teleinfo::console', $cache->getValue("") . $text, 1440); + die(); } -$array_recu = ""; -if (!isset($_GET["ADCO"])){ +if ($adco == ''){ log::add('teleinfo', 'info', 'Pas d\'ADCO dans la trame'); - die(); -} -$teleinfo = teleinfo::byLogicalId($_GET['ADCO'], 'teleinfo'); -if (!is_object($teleinfo)) { - $teleinfo = teleinfo::createFromDef($_GET); - if (!is_object($teleinfo)) { - log::add('teleinfo', 'info', 'Aucun équipement trouvé pour le compteur n°' . $_GET['ADCO']); - die(); - } -} - -$health_cmd = $teleinfo->getCmd('info','health'); + die(); +} -foreach ($_GET as $key => $value){ - $array_recu = $array_recu . $key . '=' . $value . ' / '; - if (is_object($health_cmd)) { - $_value = array("name" => $key, "value" => $value, "update_time" => date("Y-m-d H:i:s")); - $health_cmd->setConfiguration($key, $_value); - $health_cmd->save(); - } - $cmd = $teleinfo->getCmd('info',$key); - if (is_object($cmd)) { - $cmd->event($value); - } - else{ - if($key != 'api' && $key != 'ADCO'){ - log::add('teleinfo', 'debug', 'Commande inexistante (' . $key . ')'); - teleinfo::createCmdFromDef($teleinfo->getLogicalId(), $key, $value); - } - } -} +$teleinfo = teleinfo::byLogicalId($adco, 'teleinfo'); +if (!is_object($teleinfo)) { + $teleinfo = teleinfo::createFromDef($adco); + if (!is_object($teleinfo)) { + log::add('teleinfo', 'info', 'Aucun équipement trouvé pour le compteur n°' . $adco); + die(); + } +} + +$args = array( + 'BASE' => FILTER_SANITIZE_STRING, + 'PAPP' => FILTER_SANITIZE_STRING, + 'HCHP' => FILTER_SANITIZE_STRING, + 'HCHC' => FILTER_SANITIZE_STRING, + 'PTEC' => FILTER_SANITIZE_STRING, + 'IINST' => FILTER_SANITIZE_STRING, + 'IINST1' => FILTER_SANITIZE_STRING, + 'IINST2' => FILTER_SANITIZE_STRING, + 'IINST3' => FILTER_SANITIZE_STRING, + 'IMAX' => FILTER_SANITIZE_STRING, + 'IMAX1' => FILTER_SANITIZE_STRING, + 'IMAX2' => FILTER_SANITIZE_STRING, + 'IMAX3' => FILTER_SANITIZE_STRING, + 'PMAX' => FILTER_SANITIZE_STRING, + 'ADPS' => FILTER_SANITIZE_STRING, + 'ADIR1' => FILTER_SANITIZE_STRING, + 'ADIR2' => FILTER_SANITIZE_STRING, + 'ADIR3' => FILTER_SANITIZE_STRING, + 'OPTARIF' => FILTER_SANITIZE_STRING, + 'ISOUSC' => FILTER_SANITIZE_STRING, + 'EJPHN' => FILTER_SANITIZE_STRING, + 'EJPHPM' => FILTER_SANITIZE_STRING, + 'HHPHC' => FILTER_SANITIZE_STRING, + 'PPOT' => FILTER_SANITIZE_STRING, + 'BBRHCJB' => FILTER_SANITIZE_STRING, + 'BBRHPJB' => FILTER_SANITIZE_STRING, + 'BBRHCJW' => FILTER_SANITIZE_STRING, + 'BBRHPJW' => FILTER_SANITIZE_STRING, + 'BBRHCJR' => FILTER_SANITIZE_STRING, + 'BBRHPJR' => FILTER_SANITIZE_STRING, + 'PEJP' => FILTER_SANITIZE_STRING, + 'DEMAIN' => FILTER_SANITIZE_STRING, + 'MOTDETAT' => FILTER_SANITIZE_STRING, + 'ADCO' => FILTER_SANITIZE_STRING +); + +$myDatas = filter_input_array(INPUT_GET, $args); + +$healthCmd = $teleinfo->getCmd('info','health'); +$healthEnable = false; +if (is_object($healthCmd)) { + $healthEnable = true; +} + +foreach ($myDatas as $key => $value){ + if ($value != '') { + $array_recu = $array_recu . $key . '=' . $value . ' / '; + $cmd = $teleinfo->getCmd('info',$key); + if ($cmd === false) { + if($key != 'api' && $key != 'ADCO'){ + teleinfo::createCmdFromDef($teleinfo->getLogicalId(), $key, $value); + if($healthEnable) { + $healthCmd->setConfiguration($key, array("name" => $key, "value" => $value, "update_time" => date("Y-m-d H:i:s"))); + $healthCmd->save(); + } + } + } + else{ + $cmd->event($value); + if($healthEnable) { + $healthCmd->setConfiguration($key, array("name" => $key, "value" => $value, "update_time" => date("Y-m-d H:i:s"))); + $healthCmd->save(); + } + } + } +} log::add('teleinfo', 'debug', 'Reception de : ' . $array_recu); diff --git a/desktop/js/teleinfo.js b/desktop/js/teleinfo.js index 8593aec..0f7ed20 100644 --- a/desktop/js/teleinfo.js +++ b/desktop/js/teleinfo.js @@ -41,34 +41,34 @@ function stopTeleinfoDeamon() { } $('#create_data_teleinfo').on('click', function() { - document.getElementById("checkbox-autocreate").checked = true; - $('.eqLogicAction[data-action=save]').click(); + document.getElementById("checkbox-autocreate").checked = true; + $('.eqLogicAction[data-action=save]').click(); }); $('#bt_cout').on('click', function() { - $('#md_modal').dialog({title: "{{Gestion des coûts}}"}); + $('#md_modal').dialog({title: "{{Gestion des coûts}}"}); $('#md_modal').load('index.php?v=d&plugin=teleinfo&modal=cout').dialog('open'); }); $('#bt_info_daemon').on('click', function() { - $('#md_modal').dialog({title: "{{Informations du modem}}"}); + $('#md_modal').dialog({title: "{{Informations du modem}}"}); $('#md_modal').load('index.php?v=d&plugin=teleinfo&modal=info_daemon&plugin_id=teleinfo_deamon&slave_id=0').dialog('open'); }); $('.bt_info_external_daemon').on('click', function() { - var slave_id_tmp = $(this).attr('slave_id'); - $('#md_modal').dialog({title: "{{Informations du modem}}"}); + var slave_id_tmp = $(this).attr('slave_id'); + $('#md_modal').dialog({title: "{{Informations du modem}}"}); $('#md_modal').load('index.php?v=d&plugin=teleinfo&modal=info_daemon&plugin_id=teleinfo_deamon&slave_id=' + slave_id_tmp).dialog('open'); }); $('#bt_config').on('click', function() { - $('#md_modal').dialog({title: "{{Configuration}}"}); + $('#md_modal').dialog({title: "{{Configuration}}"}); $('#md_modal').load('index.php?v=d&p=plugin&ajax=1&id=rfxcom').dialog('open'); }); $('#bt_teleinfoHealth').on('click', function() { - $('#md_modal').dialog({title: "{{Santé Téléinformation}}"}); + $('#md_modal').dialog({title: "{{Santé Téléinformation}}"}); $('#md_modal').load('index.php?v=d&plugin=teleinfo&modal=health').dialog('open'); }); @@ -79,175 +79,173 @@ function addCmdToTable(_cmd) { if (!isset(_cmd)) { var _cmd = {configuration: {}}; } - if (!isset(_cmd.configuration)) { + if (!isset(_cmd.configuration)) { _cmd.configuration = {}; } - init(_cmd.id); - var selRequestType = ''; - var type_of_data = init(_cmd.configuration['type']); - //alert(type_of_data); - if(init(_cmd.configuration['type']) == 'stat' || init(_cmd.configuration['type']) == 'panel'){ + init(_cmd.id); + var selRequestType = ''; + var type_of_data = init(_cmd.configuration['type']); + //alert(type_of_data); + if(init(_cmd.configuration['type']) == 'stat' || init(_cmd.configuration['type']) == 'panel'){ selRequestType = ''; - } - else{ - selRequestType = ''; - } - - if(init(_cmd.configuration['type']) == 'panel'){ - var tr = ''; - }else if(init(_cmd.configuration['type']) == 'health'){ - var tr = ''; - } - else{ - var tr = ''; - } + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + selRequestType += ''; + } + else{ + selRequestType = ''; + } + + if(init(_cmd.configuration['type']) == 'panel'){ + var tr = ''; + }else if(init(_cmd.configuration['type']) == 'health'){ + var tr = ''; + } + else{ + var tr = ''; + } if(init(_cmd.configuration['type']) != 'health'){ - tr += ''; + tr += ''; tr += ''; tr += ''; tr += ''; tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; - tr += ''; + tr += ''; + tr += ''; + tr += ''; + tr += ''; + tr += ''; tr += ''; tr += selRequestType; - //tr += ''; - //tr += ''; tr += ''; tr += ''; tr += ''; tr += ' '; - tr += ' '; + tr += ' '; - if(init(_cmd.configuration['info_conso']) == 'TENDANCE_DAY'){ - tr += ' {{Journée entière}}
'; - } + if(init(_cmd.configuration['info_conso']) == 'TENDANCE_DAY'){ + tr += ' {{Journée entière}}
'; + } - tr += ''; + tr += ''; - tr += ''; + tr += ''; tr += ' '; tr += ''; - if(init(_cmd.configuration['info_conso']) == 'ADPS' || init(_cmd.configuration['info_conso']) == 'ADIR1' || init(_cmd.configuration['info_conso']) == 'ADIR2' || init(_cmd.configuration['info_conso']) == 'ADIR3'){ - //tr += ''; - tr += ''; - tr += ''; - } + if(init(_cmd.configuration['info_conso']) == 'ADPS' || init(_cmd.configuration['info_conso']) == 'ADIR1' || init(_cmd.configuration['info_conso']) == 'ADIR2' || init(_cmd.configuration['info_conso']) == 'ADIR3'){ + //tr += ''; + tr += ''; + tr += ''; + } tr += ''; tr += ''; - if (is_numeric(_cmd.id)) { + if (is_numeric(_cmd.id)) { tr += ' '; tr += ' {{Tester}}'; - } + } tr += ''; tr += ''; - if (isset(_cmd.configuration.info_conso)) { + if (isset(_cmd.configuration.info_conso)) { //$('#table_cmd tbody tr:last .cmdAttr[data-l1key=configuration][data-l2key=info_conso]').value(init(_cmd.configuration.info_conso)); //$('#table_cmd tbody tr:last .cmdAttr[data-l1key=configuration][data-l2key=info_conso]').trigger('change'); - } + } - $('#table_cmd tbody').append(tr); + $('#table_cmd tbody').append(tr); $('#table_cmd tbody tr:last').setValues(_cmd, '.cmdAttr'); - var tr = $('#table_cmd tbody tr:last'); - if(init(_cmd.unite) == ''){ - if(init(_cmd.configuration['info_conso']) == 'ADPS'){ - tr.find('.cmdAttr[data-l1key=unite]').append("A"); - tr.setValues(_cmd, '.cmdAttr'); - } - } - else{ - - } - } + var tr = $('#table_cmd tbody tr:last'); + if(init(_cmd.unite) == ''){ + if(init(_cmd.configuration['info_conso']) == 'ADPS'){ + tr.find('.cmdAttr[data-l1key=unite]').append("A"); + tr.setValues(_cmd, '.cmdAttr'); + } + } + else{ + + } + } } $('#addStatToTable').on('click', function() { - var _cmd = {type: 'info'}; - _cmd.configuration = {'type':'stat'}; - addCmdToTable(_cmd); + var _cmd = {type: 'info'}; + _cmd.configuration = {'type':'stat'}; + addCmdToTable(_cmd); }); $('#addDataToTable').on('click', function() { - var _cmd = {type: 'info'}; - _cmd.configuration = {'type':'data'}; - addCmdToTable(_cmd); + var _cmd = {type: 'info'}; + _cmd.configuration = {'type':'data'}; + addCmdToTable(_cmd); }); From 56f65aac06db0dcc5739ba9403b08646136276a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Wed, 14 Mar 2018 11:27:59 -0400 Subject: [PATCH 04/16] =?UTF-8?q?It=C3=A9ration=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/class/teleinfo.class.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/class/teleinfo.class.php b/core/class/teleinfo.class.php index d5dccee..fa3c94a 100644 --- a/core/class/teleinfo.class.php +++ b/core/class/teleinfo.class.php @@ -445,23 +445,25 @@ public static function calculateTodayStats() foreach ($stat_hc_to_cumul as $key => $value) { $cmd = cmd::byId($value); - + $statHcMaxToday = $cmd->getStatistique($startdatetoday, $enddatetoday)['max']; + $statHcMinToday = $cmd->getStatistique($startdatetoday, $enddatetoday)['min']; log::add('teleinfo', 'debug', 'Commande HC N°' . $value); - log::add('teleinfo', 'debug', ' ==> Valeur HC MAX : ' . $cmd->getStatistique($startdatetoday, $enddatetoday)['max']); - log::add('teleinfo', 'debug', ' ==> Valeur HC MIN : ' . $cmd->getStatistique($startdatetoday, $enddatetoday)['min']); + log::add('teleinfo', 'debug', ' ==> Valeur HC MAX : ' . $statHcMaxToday); + log::add('teleinfo', 'debug', ' ==> Valeur HC MIN : ' . $statHcMinToday); - $STAT_TODAY_HC += intval($cmd->getStatistique($startdatetoday, $enddatetoday)['max']) - intval($cmd->getStatistique($startdatetoday, $enddatetoday)['min']); + $STAT_TODAY_HC += intval($statHcMaxToday) - intval($statHcMinToday); $STAT_YESTERDAY_HC += intval($cmd->getStatistique($startdateyesterday, $enddateyesterday)['max']) - intval($cmd->getStatistique($startdateyesterday, $enddateyesterday)['min']); log::add('teleinfo', 'debug', 'Total HC --> ' . $STAT_TODAY_HC); } foreach ($stat_hp_to_cumul as $key => $value) { $cmd = cmd::byId($value); - + $statHcMaxToday = $cmd->getStatistique($startdatetoday, $enddatetoday)['max']; + $statHcMinToday = $cmd->getStatistique($startdatetoday, $enddatetoday)['min']; log::add('teleinfo', 'debug', 'Commande HP N°' . $value); - log::add('teleinfo', 'debug', ' ==> Valeur HP MAX : ' . $cmd->getStatistique($startdatetoday, $enddatetoday)['max']); - log::add('teleinfo', 'debug', ' ==> Valeur HP MIN : ' . $cmd->getStatistique($startdatetoday, $enddatetoday)['min']); + log::add('teleinfo', 'debug', ' ==> Valeur HP MAX : ' . $statHcMaxToday); + log::add('teleinfo', 'debug', ' ==> Valeur HP MIN : ' . $statHcMinToday); - $STAT_TODAY_HP += intval($cmd->getStatistique($startdatetoday, $enddatetoday)['max']) - intval($cmd->getStatistique($startdatetoday, $enddatetoday)['min']); + $STAT_TODAY_HP += intval($statHcMaxToday) - intval($statHcMinToday); $STAT_YESTERDAY_HP += intval($cmd->getStatistique($startdateyesterday, $enddateyesterday)['max']) - intval($cmd->getStatistique($startdateyesterday, $enddateyesterday)['min']); log::add('teleinfo', 'debug', 'Total HP --> ' . $STAT_TODAY_HP); } @@ -970,7 +972,7 @@ public function postSave() $cmd->refresh(); break; default : - log::add('teleinfo', 'debug', '=> ptec'); + log::add('teleinfo', 'debug', '=> default'); if ($cmd->getDisplay('generic_type') == '') { $cmd->setDisplay('generic_type', 'GENERIC_INFO'); } From 4aff311fd4f9e757e0affdc712d6efd767911bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Wed, 14 Mar 2018 11:37:30 -0400 Subject: [PATCH 05/16] Changelog --- docs/fr_FR/changelog.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/fr_FR/changelog.md b/docs/fr_FR/changelog.md index 23e4015..f7b602f 100644 --- a/docs/fr_FR/changelog.md +++ b/docs/fr_FR/changelog.md @@ -12,7 +12,11 @@ Change log - Noms des variables et fonctions - Compatibilité Linky -2.6.3 [![Stable](https://img.shields.io/badge/version-stable-brightgreen.svg?longCache=true&style=flat-square)](https://github.com/Jeedom-Plugins-Extra/plugin-teleinfo/releases) +2.6.4 [![Stable](https://img.shields.io/badge/version-stable-brightgreen.svg?longCache=true&style=flat-square)](https://github.com/Jeedom-Plugins-Extra/plugin-teleinfo/releases) +===== +- Bugfix erreur lors de l'enregistrement + +2.6.3 ===== - Lancement du démon pour la partie production From d428c82427817b22e7b60f427c729a0c6292fb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Wed, 14 Mar 2018 14:40:23 -0400 Subject: [PATCH 06/16] =?UTF-8?q?It=C3=A9ration=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/ajax/teleinfo.ajax.php | 11 +--- core/class/teleinfo.class.php | 116 ++++++++++++++-------------------- core/php/jeeTeleinfo.php | 76 ++++++++++++---------- ressources/teleinfo.py | 26 ++------ 4 files changed, 99 insertions(+), 130 deletions(-) diff --git a/core/ajax/teleinfo.ajax.php b/core/ajax/teleinfo.ajax.php index 13000aa..902b7cc 100644 --- a/core/ajax/teleinfo.ajax.php +++ b/core/ajax/teleinfo.ajax.php @@ -33,7 +33,7 @@ $port = config::byKey('port', 'teleinfo', 'none'); $_2cpt_cartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); if ($_2cpt_cartelectronic == 1) { - + } if ($port == 'none') { ajax::success(); @@ -197,19 +197,12 @@ if (init('action') == 'getCout') { $return = array(); - /* $data = array(); - $datetime = null; */ - //console.log("essai"); - //console.log('Commande : ' . init('id')); $return = history::byCmdIdDatetime(init('id'), date('Y-m-d H:i:s')); - //$dateEnd = date('Y-m-d H:i:s'); ajax::success($return); } - throw new \Exception('Aucune methode correspondante'); - /* * *********Catch exeption*************** */ +throw new \Exception('Aucune methode correspondante'); } catch (\Exception $e) { ajax::error(displayExeption($e), $e->getCode()); } - diff --git a/core/class/teleinfo.class.php b/core/class/teleinfo.class.php index fa3c94a..f43b203 100644 --- a/core/class/teleinfo.class.php +++ b/core/class/teleinfo.class.php @@ -78,7 +78,6 @@ public static function createCmdFromDef($_oADCO, $_oKey, $_oValue) } if ($teleinfo->getConfiguration('AutoCreateFromCompteur') == '1') { log::add('teleinfo', 'info', 'Création de la commande ' . $_oKey . ' sur l\'ADCO ' . $_oADCO); - $cmd = new teleinfoCmd(); $cmd->setName($_oKey); $cmd->setEqLogic_id($teleinfo->id); @@ -86,16 +85,13 @@ public static function createCmdFromDef($_oADCO, $_oKey, $_oValue) $cmd->setType('info'); $cmd->setConfiguration('info_conso', $_oKey); switch ($_oKey) { - case "PAPP": - $cmd->setDisplay('generic_type', 'GENERIC_INFO'); - $cmd->setDisplay('icon', '<\/i>'); - $cmd->setSubType('string'); - break; + //case "PAPP": case "OPTARIF": case "HHPHC": case "PPOT": case "PEJP": - case "DEMAIN": + case "DEMAIN": + case "PTEC": $cmd->setSubType('string'); $cmd->setDisplay('generic_type', 'GENERIC_INFO'); break; @@ -157,20 +153,10 @@ public static function runDeamon($_debug = false, $type = 'conso') log::add('teleinfo', 'info', 'Debug : ' . $_debug); log::add('teleinfo', 'info', 'Force : ' . $_force); log::add('teleinfo', 'info', 'Port modem : ' . $port); - log::add('teleinfo', 'info', 'Type : ' . $type); - + log::add('teleinfo', 'info', 'Type : ' . $type); $_debug = ($_debug) ? "1" : "0"; - $_force = ($_force) ? "1" : "0"; - - // if ($_debug) { - // $_debug = "1"; - // } else { - // $_debug = "0"; - // } - // if ($_force != "1") { - // $_force = "0"; - // } - log::add('teleinfo', 'info', '---------------------------------------------'); + $_force = ($_force) ? "1" : "0"; + log::add('teleinfo', 'info', '---------------------------------------------'); if ($twoCptCartelectronic == 1) { log::add('teleinfo', 'info', 'Fonctionnement en mode 2 compteur'); @@ -179,7 +165,7 @@ public static function runDeamon($_debug = false, $type = 'conso') } else { log::add('teleinfo', 'info', 'Fonctionnement en mode 1 compteur'); $teleinfoPath = $teleinfoPath . '/teleinfo.py'; - $cmd = 'nice -n 19 /usr/bin/python ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -t ' . $type . ' -r ' . realpath(dirname(__FILE__)); + $cmd = 'nice -n 19 /usr/bin/python ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -t ' . $type . ' -r ' . realpath(dirname(__FILE__)); } log::add('teleinfo', 'info', 'Exécution du service : ' . $cmd); @@ -259,7 +245,7 @@ public static function runProductionDeamon($_debug = false, $type = 'prod') } else { log::add('teleinfo', 'info', 'Fonctionnement en mode 1 compteur'); $teleinfoPath = $teleinfoPath . '/teleinfo.py'; - $cmd = 'nice -n 19 /usr/bin/python ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -t ' . $type . ' -r ' . realpath(dirname(__FILE__)); + $cmd = 'nice -n 19 /usr/bin/python ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -t ' . $type . ' -r ' . realpath(dirname(__FILE__)); } log::add('teleinfo', 'info', '[Production] Exécution du service : ' . $cmd); @@ -345,8 +331,8 @@ public static function deamon_start($_debug = false) public static function deamon_stop() { log::add('teleinfo', 'info', '[deamon_stop] Arret du service'); - $deamon_info = self::deamon_info(); - if ($deamon_info['state'] == 'ok') { + $deamonInfo = self::deamon_info(); + if ($deamonInfo['state'] == 'ok') { $twoCptCartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); if ($twoCptCartelectronic == 1) { $result = exec("ps aux | grep teleinfo_2_cpt.py | grep -v grep | awk '{print $2}'"); @@ -800,20 +786,19 @@ public static function calculateOtherStats() public static function moyLastHour() { - $ppap_hp = 0; - $ppap_hc = 0; - $cmd_ppap = null; + $ppapHp = 0; + $ppapHc = 0; + $cmdPpap = null; foreach (eqLogic::byType('teleinfo') as $eqLogic) { foreach ($eqLogic->getCmd('info') as $cmd) { if ($cmd->getConfiguration('type') == 'stat') { if ($cmd->getConfiguration('info_conso') == 'STAT_MOY_LAST_HOUR') { log::add('teleinfo', 'debug', '----- Calcul de la consommation moyenne sur la dernière heure -----'); - $cmd_ppap = $cmd; + $cmdPpap = $cmd; } } } - if ($cmd_ppap !== null) { - //log::add('teleinfo', 'debug', 'Cmd trouvée'); + if ($cmdPpap !== null) { foreach ($eqLogic->getCmd('info') as $cmd) { if ($cmd->getConfiguration('type') == "data" || $cmd->getConfiguration('type') == "") { switch ($cmd->getConfiguration('info_conso')) { @@ -823,7 +808,7 @@ public static function moyLastHour() case "BBRHPJW": case "BBRHPJR": case "EJPHPM": - $ppap_hp += $cmd->execCmd(); + $ppapHp += $cmd->execCmd(); log::add('teleinfo', 'debug', 'Cmd : ' . $cmd->getId() . ' / Value : ' . $cmd->execCmd()); break; } @@ -833,26 +818,26 @@ public static function moyLastHour() case "BBRHCJW": case "BBRHCJR": case "EJPHN": - $ppap_hc += $cmd->execCmd(); + $ppapHc += $cmd->execCmd(); log::add('teleinfo', 'debug', 'Cmd : ' . $cmd->getId() . ' / Value : ' . $cmd->execCmd()); break; } } } - $cache_hc = cache::byKey('teleinfo::stat_moy_last_hour::hc', false); - $cache_hp = cache::byKey('teleinfo::stat_moy_last_hour::hp', false); - $cache_hc = $cache_hc->getValue(); - $cache_hp = $cache_hp->getValue(); + $cacheHc = cache::byKey('teleinfo::stat_moy_last_hour::hc', false); + $cacheHp = cache::byKey('teleinfo::stat_moy_last_hour::hp', false); + $cacheHc = $cacheHc->getValue(); + $cacheHp = $cacheHp->getValue(); - log::add('teleinfo', 'debug', 'Cache HP : ' . $cache_hp); - log::add('teleinfo', 'debug', 'Cache HC : ' . $cache_hc); + log::add('teleinfo', 'debug', 'Cache HP : ' . $cacheHp); + log::add('teleinfo', 'debug', 'Cache HC : ' . $cacheHc); - log::add('teleinfo', 'debug', 'Conso Wh : ' . (($ppap_hp - $cache_hp) + ($ppap_hc - $cache_hc))); - $cmd_ppap->event(intval((($ppap_hp - $cache_hp) + ($ppap_hc - $cache_hc)))); + log::add('teleinfo', 'debug', 'Conso Wh : ' . (($ppapHp - $cacheHp) + ($ppapHc - $cacheHc))); + $cmdPpap->event(intval((($ppapHp - $cacheHp) + ($ppapHc - $cacheHc)))); - cache::set('teleinfo::stat_moy_last_hour::hc', $ppap_hc, 7200); - cache::set('teleinfo::stat_moy_last_hour::hp', $ppap_hp, 7200); + cache::set('teleinfo::stat_moy_last_hour::hc', $ppapHc, 7200); + cache::set('teleinfo::stat_moy_last_hour::hp', $ppapHp, 7200); } else { log::add('teleinfo', 'debug', 'Pas de calcul'); } @@ -861,19 +846,19 @@ public static function moyLastHour() public static function calculatePAPP() { - $ppap_hp = 0; - $ppap_hc = 0; - $cmd_ppap = null; + $ppapHp = 0; + $ppapHc = 0; + $cmdPpap = null; foreach (eqLogic::byType('teleinfo') as $eqLogic) { foreach ($eqLogic->getCmd('info') as $cmd) { if ($cmd->getConfiguration('type') == 'stat') { if ($cmd->getConfiguration('info_conso') == 'PPAP_MANUELLE') { log::add('teleinfo', 'debug', '----- Calcul de la puissance apparante moyenne -----'); - $cmd_ppap = $cmd; + $cmdPpap = $cmd; } } } - if ($cmd_ppap !== null) { + if ($cmdPpap !== null) { log::add('teleinfo', 'debug', 'Cmd trouvée'); foreach ($eqLogic->getCmd('info') as $cmd) { if ($cmd->getConfiguration('type') == "data" || $cmd->getConfiguration('type') == "") { @@ -884,7 +869,7 @@ public static function calculatePAPP() case "BBRHPJW": case "BBRHPJR": case "EJPHPM": - $ppap_hp += $cmd->execCmd(); + $ppapHp += $cmd->execCmd(); break; } switch ($cmd->getConfiguration('info_conso')) { @@ -893,28 +878,28 @@ public static function calculatePAPP() case "BBRHCJW": case "BBRHCJR": case "EJPHN": - $ppap_hc += $cmd->execCmd(); + $ppapHc += $cmd->execCmd(); break; } } } - $cache_hc = cache::byKey('teleinfo::ppap_manuelle::hc', false); - $datetime_mesure = date_create($cache_hc->getDatetime()); - $cache_hp = cache::byKey('teleinfo::ppap_manuelle::hp', false); - $cache_hc = $cache_hc->getValue(); - $cache_hp = $cache_hp->getValue(); + $cacheHc = cache::byKey('teleinfo::ppap_manuelle::hc', false); + $datetimeMesure = date_create($cacheHc->getDatetime()); + $cacheHp = cache::byKey('teleinfo::ppap_manuelle::hp', false); + $cacheHc = $cacheHc->getValue(); + $cacheHp = $cacheHp->getValue(); - $datetime_mesure = $datetime_mesure->getTimestamp(); - $datetime2 = time(); - $interval = $datetime2 - $datetime_mesure; + $datetimeMesure = $datetimeMesure->getTimestamp(); + $datetime2 = time(); + $interval = $datetime2 - $datetimeMesure; + $consoResultat = ((($ppapHp - $cacheHp) + ($ppapHc - $cacheHc)) / $interval) * 3600; log::add('teleinfo', 'debug', 'Intervale depuis la dernière valeur : ' . $interval); - log::add('teleinfo', 'debug', 'Conso calculée : ' . ((($ppap_hp - $cache_hp) + ($ppap_hc - $cache_hc)) / $interval) * 3600 . ' Wh'); - //$cmd_ppap->setValue(intval(((($ppap_hp - $cache_hp) + ($ppap_hc - $cache_hc)) / $interval) * 3600)); - $cmd_ppap->event(intval(((($ppap_hp - $cache_hp) + ($ppap_hc - $cache_hc)) / $interval) * 3600)); + log::add('teleinfo', 'debug', 'Conso calculée : ' . $consoResultat . ' Wh'); + $cmdPpap->event(intval($consoResultat)); - cache::set('teleinfo::ppap_manuelle::hc', $ppap_hc, 150); - cache::set('teleinfo::ppap_manuelle::hp', $ppap_hp, 150); + cache::set('teleinfo::ppap_manuelle::hc', $ppapHc, 150); + cache::set('teleinfo::ppap_manuelle::hp', $ppapHp, 150); } else { log::add('teleinfo', 'debug', 'Pas de calcul'); } @@ -1029,7 +1014,7 @@ public function createOtherCmd() public function createPanelStats() { $array = array("STAT_JAN_HP", "STAT_JAN_HC", "STAT_FEV_HP", "STAT_FEV_HC", "STAT_MAR_HP", "STAT_MAR_HC", "STAT_AVR_HP", "STAT_AVR_HC", "STAT_MAI_HP", "STAT_MAI_HC", "STAT_JUIN_HP", "STAT_JUIN_HC", "STAT_JUI_HP", "STAT_JUI_HC", "STAT_AOU_HP", "STAT_AOU_HC", "STAT_SEP_HP", "STAT_SEP_HC", "STAT_OCT_HP", "STAT_OCT_HC", "STAT_NOV_HP", "STAT_NOV_HC", "STAT_DEC_HP", "STAT_DEC_HC", "STAT_MONTH_LAST_YEAR", "STAT_YEAR_LAST_YEAR"); - for ($ii = 0; $ii < 1; $ii++) { + for ($ii = 0; $ii < 26; $ii++) { $cmd = $this->getCmd('info', $array[$ii]); if ($cmd === false) { $cmd = new teleinfoCmd(); @@ -1066,7 +1051,6 @@ public static function dependancy_info() $return['log'] = 'teleinfo_update'; $return['progress_file'] = '/tmp/teleinfo_in_progress'; $return['state'] = (self::installationOk()) ? 'ok' : 'nok'; - return $return; } @@ -1100,11 +1084,7 @@ public static function dependancy_install() class teleinfoCmd extends cmd { - public function execute($_options = null) { - } - - /* * **********************Getteur Setteur*************************** */ } diff --git a/core/php/jeeTeleinfo.php b/core/php/jeeTeleinfo.php index 26b73c4..623b3ab 100644 --- a/core/php/jeeTeleinfo.php +++ b/core/php/jeeTeleinfo.php @@ -21,38 +21,7 @@ if ((php_sapi_name() != 'cli' || isset($_SERVER['REQUEST_METHOD']) || !isset($_SERVER['argc'])) && (config::byKey('api') != init('api') && init('api') != '')) { echo 'Clef API non valide, vous n\'êtes pas autorisé à effectuer cette action (jeeTeleinfo)'; die(); -} - -$message = filter_input(INPUT_GET, 'message', FILTER_SANITIZE_STRING); -$adco = filter_input(INPUT_GET, 'ADCO', FILTER_SANITIZE_STRING); -$array_recu = ""; - -if($message != ''){ - $text = substr($message, 0, -2); - $messages = preg_split("#(&|[\*]{2})#", $text); - foreach ($messages as $key => $value){ - log::add('teleinfo', 'event', 'Log Daemon : ' . $value); - $text = $text . date("Y-m-d H:i:s") . " " . $value . "
"; - } - $cache = cache::byKey('teleinfo::console', false); - cache::set('teleinfo::console', $cache->getValue("") . $text, 1440); - die(); -} - -if ($adco == ''){ - log::add('teleinfo', 'info', 'Pas d\'ADCO dans la trame'); - die(); } - -$teleinfo = teleinfo::byLogicalId($adco, 'teleinfo'); -if (!is_object($teleinfo)) { - $teleinfo = teleinfo::createFromDef($adco); - if (!is_object($teleinfo)) { - log::add('teleinfo', 'info', 'Aucun équipement trouvé pour le compteur n°' . $adco); - die(); - } -} - $args = array( 'BASE' => FILTER_SANITIZE_STRING, 'PAPP' => FILTER_SANITIZE_STRING, @@ -88,7 +57,46 @@ 'DEMAIN' => FILTER_SANITIZE_STRING, 'MOTDETAT' => FILTER_SANITIZE_STRING, 'ADCO' => FILTER_SANITIZE_STRING -); +); + +$message = filter_input(INPUT_GET, 'message', FILTER_SANITIZE_STRING); +$adco = filter_input(INPUT_GET, 'ADCO', FILTER_SANITIZE_STRING); +$adsc = filter_input(INPUT_GET, 'ADSC', FILTER_SANITIZE_STRING); +$sentDatas = ""; + +if($message != ''){ + $text = substr($message, 0, -2); + $messages = preg_split("#(&|[\*]{2})#", $text); + foreach ($messages as $key => $value){ + log::add('teleinfo', 'event', 'Log Daemon : ' . $value); + $text = $text . date("Y-m-d H:i:s") . " " . $value . "
"; + } + $cache = cache::byKey('teleinfo::console', false); + cache::set('teleinfo::console', $cache->getValue("") . $text, 1440); + die(); +} + +if ($adco == '' && $adsc == ''){ + log::add('teleinfo', 'info', 'Pas d\'ADCO/ADSC dans la trame'); + die(); +} + +if ($adco != '') +{ + $teleinfo = teleinfo::byLogicalId($adco, 'teleinfo'); +} +else +{ + $teleinfo = teleinfo::byLogicalId($adsc, 'teleinfo'); +} + +if (!is_object($teleinfo)) { + $teleinfo = ($adco != '') ? teleinfo::createFromDef($adco) : teleinfo::createFromDef($adsc); + if (!is_object($teleinfo)) { + log::add('teleinfo', 'info', 'Aucun équipement trouvé pour le compteur n°' . $adco . $adsc); + die(); + } +} $myDatas = filter_input_array(INPUT_GET, $args); @@ -100,7 +108,7 @@ foreach ($myDatas as $key => $value){ if ($value != '') { - $array_recu = $array_recu . $key . '=' . $value . ' / '; + $sentDatas = $sentDatas . $key . '=' . $value . ' / '; $cmd = $teleinfo->getCmd('info',$key); if ($cmd === false) { if($key != 'api' && $key != 'ADCO'){ @@ -120,4 +128,4 @@ } } } -log::add('teleinfo', 'debug', 'Reception de : ' . $array_recu); +log::add('teleinfo', 'debug', 'Reception de : ' . $sentDatas); diff --git a/ressources/teleinfo.py b/ressources/teleinfo.py index a025819..bf58c74 100644 --- a/ressources/teleinfo.py +++ b/ressources/teleinfo.py @@ -241,12 +241,8 @@ def run(self): def target(): self.process = None - #logger.debug("Thread started, timeout = " + str(timeout)+", command : "+str(self.cmd)) self.process = subprocess.Popen(self.cmd + _SendData, shell=True) - #print self.cmd self.process.communicate() - #logger.debug("Return code: " + str(self.process.returncode)) - #logger.debug("Thread finished") self.timer.cancel() def timer_callback(): @@ -266,13 +262,12 @@ def timer_callback(): self.open() except TeleinfoException as err: self._log.error(err.value) - #print err.value self.terminate() return # Read a frame while(1): _RazCalcul = datetime.now() - _RAZ - if(_RazCalcul.seconds > 3600): + if(_RazCalcul.seconds > 60): _RAZ = datetime.now() for cle, valeur in Donnees.items(): Donnees.pop(cle) @@ -292,10 +287,8 @@ def timer_callback(): Donnees[cle] = valeur if(self._externalip != ""): self.cmd = "curl -L -s -G --max-time 15 " + self._externalip +"/plugins/teleinfo/core/php/jeeTeleinfo.php -d 'api=" + self._cleAPI - #self.cmd = "curl -L -s " + "192.168.1.150" +'/plugins/teleinfo/core/php/jeeTeleinfo.php?api=' + self._cleAPI _Separateur = "&" else: - #self.cmd = "curl -L -s -G " + self._externalip +"/plugins/teleinfo/core/php/jeeTeleinfo.php -d 'api=" + self._cleAPI self.cmd = 'nice -n 19 timeout 15 /usr/bin/php ' + self._realpath + '/../php/jeeTeleinfo.php api=' + self._cleAPI _Separateur = " " @@ -308,35 +301,31 @@ def timer_callback(): _SendData += _Separateur + cle +'='+ valeur _Donnees[cle] = valeur - #response = urllib2.urlopen(self.cmd) if (_SendData != ""): _SendData += _Separateur + "ADCO=" + Donnees["ADCO"] - #self.cmd += _SendData - if (self._debug == '1'): - print self.cmd - #print "" - self._log.debug(self.cmd + _SendData) if(self._externalip != ""): try: _SendData += "'" + if (self._debug == '1'): + print self.cmd + _SendData + self._log.debug(self.cmd + _SendData) thread = threading.Thread(target=target) self.timer = threading.Timer(int(5), timer_callback) self.timer.start() thread.start() - #response = urllib2.urlopen(self.cmd) except Exception, e: errorCom = "Connection error '%s'" % e else: try: + if (self._debug == '1'): + print self.cmd + _SendData + self._log.debug(self.cmd + _SendData) thread = threading.Thread(target=target) self.timer = threading.Timer(int(5), timer_callback) self.timer.start() thread.start() - #self.process = subprocess.Popen(self.cmd, shell=True) - #self.process.communicate() except Exception, e: errorCom = "Connection error '%s'" % e - # This is the End! self.terminate() def exit_handler(self, *args): self.terminate() @@ -358,7 +347,6 @@ def exit_handler(self, *args): parser.add_option("-f", "--force", dest="force", help="forcer le lancement") parser.add_option("-t", "--type", dest="type", help="type du deamon") (options, args) = parser.parse_args() - #print "opt: %s, arglen: %s" % (options, len(args)) if options.port: try: gDeviceName = options.port From f2ac4f6fd47e253a638438b16d66a9ccdc9b156a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Thu, 15 Mar 2018 20:44:02 -0400 Subject: [PATCH 07/16] Issue #28 --- core/api/teleinfo.api.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/core/api/teleinfo.api.php b/core/api/teleinfo.api.php index 603ea83..b11cb53 100644 --- a/core/api/teleinfo.api.php +++ b/core/api/teleinfo.api.php @@ -23,23 +23,23 @@ throw new \Exception(__('JSONRPC object not defined', __FILE__), -32699); } $params = $jsonrpc->getParams(); - -if ($jsonrpc->getMethod() == 'deamonRunning') { - $jsonrpc->makeSuccess(teleinfo::deamonRunning()); -} - -if ($jsonrpc->getMethod() == 'stopDeamon') { - $jsonrpc->makeSuccess(teleinfo::deamon_stop()); -} - -if ($jsonrpc->getMethod() == 'restartDeamon') { - teleinfo::deamon_stop(); - if (teleinfo::deamonRunning()) { - throw new \Exception(__('Impossible d\'arrêter le démon', __FILE__)); - } - log::clear('teleinfocmd'); - teleinfo::cron(); - $jsonrpc->makeSuccess(); -} + +switch ($jsonrpc->getMethod()) { + case 'deamonRunning': + $jsonrpc->makeSuccess(teleinfo::deamonRunning()); + break; + case 'stopDeamon': + $jsonrpc->makeSuccess(teleinfo::deamon_stop()); + break; + case 'restartDeamon': + teleinfo::deamon_stop(); + if (teleinfo::deamonRunning()) { + throw new \Exception(__('Impossible d\'arrêter le démon', __FILE__)); + } + log::clear('teleinfocmd'); + teleinfo::cron(); + $jsonrpc->makeSuccess(); + break; +} throw new \Exception(__('Aucune methode correspondante pour le plugin Teleinfo : ' . $jsonrpc->getMethod(), __FILE__)); From 22faba5b88dbcb5726fe1949a52ba9615c25366a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Thu, 15 Mar 2018 21:00:47 -0400 Subject: [PATCH 08/16] Issue #30 - displayException --- core/ajax/teleinfo.ajax.php | 326 ++++++++++++++++-------------------- plugin_info/install.php | 12 +- 2 files changed, 153 insertions(+), 185 deletions(-) diff --git a/core/ajax/teleinfo.ajax.php b/core/ajax/teleinfo.ajax.php index 902b7cc..f51d113 100644 --- a/core/ajax/teleinfo.ajax.php +++ b/core/ajax/teleinfo.ajax.php @@ -22,187 +22,151 @@ if (!isConnect('admin')) { throw new \Exception('401 Unauthorized'); + } + + switch (init('action')){ + case 'stopDeamon': + teleinfo::deamon_stop(); + ajax::success(); + break; + case 'restartDeamon': + $port = config::byKey('port', 'teleinfo', 'none'); + $_2cpt_cartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); + if ($port == 'none') { + ajax::success(); + } + teleinfo::deamon_stop(); + if (teleinfo::deamonRunning()) { + throw new \Exception(__('Impossible d\'arrêter le démon', __FILE__)); + } + log::clear('teleinfocmd'); + teleinfo::cron(); + ajax::success(); + break; + case 'getTeleinfo': + if (init('object_id') == '') { + $_GET['object_id'] = $_SESSION['user']->getOptions('defaultDashboardObject'); + } + $object = object::byId(init('object_id')); + if (!is_object($object)) { + $object = object::rootObject(); + } + if (!is_object($object)) { + throw new \Exception('{{Aucun objet racine trouv�}}'); + } + $return = array('object' => utils::o2a($object)); + + $date = array( + 'start' => init('dateStart'), + 'end' => init('dateEnd'), + ); + + if ($date['start'] == '') { + $date['start'] = date('Y-m-d', strtotime('-6 days' . date('Y-m-d'))); + } + if ($date['end'] == '') { + $date['end'] = date('Y-m-d', strtotime('+1 days' . date('Y-m-d'))); + } + $return['date'] = $date; + foreach ($object->getEqLogic() as $eqLogic) { + if ($eqLogic->getIsVisible() == '1' && $eqLogic->getEqType_name() == 'teleinfo') { + $return['eqLogics'][] = array('eqLogic' => utils::o2a($eqLogic), 'html' => $eqLogic->toHtml(init('version'))); + } + } + ajax::success($return); + break; + case 'getInformation': + if (init('eqLogic_id') !== null) { + $eqLogic = eqLogic::byId(init('eqLogic_id')); + $return[$eqLogic->getId()] = utils::o2a($eqLogic); + $return[$eqLogic->getId()]['cmd'] = array(); + foreach ($eqLogic->getCmd() as $cmd) { + $cmd_info = utils::o2a($cmd); + $cmd_info['value'] = $cmd->execCmd(null, 2); + $return[$eqLogic->getId()]['cmd'][] = $cmd_info; + } + ajax::success($return); + } else { + $eqLogics = eqLogic::byType('teleinfo'); + foreach ($eqLogics as $eqLogic) { + $return[$eqLogic->getId()] = utils::o2a($eqLogic); + $return[$eqLogic->getId()]['cmd'] = array(); + foreach ($eqLogic->getCmd() as $cmd) { + $cmd_info = utils::o2a($cmd); + $cmd_info['value'] = $cmd->execCmd(null, 2); + $return[$eqLogic->getId()]['cmd'][] = $cmd_info; + } + } + ajax::success($return); + } + break; + case 'getHealth': + if (init('eqLogicID') !== null) { + $teleinfo = teleinfo::byLogicalId(init('eqLogicID'), 'teleinfo'); + $health_cmd = $teleinfo->getCmd('info', 'health'); + $return = array('object' => utils::o2a($health_cmd)); + $return["ADCO"] = init('eqLogicID'); + ajax::success($return); + } else { + $teleinfo = teleinfo::byType('teleinfo'); + foreach ($teleinfo as $eqLogic) { + $health_cmd = $eqLogic->getCmd('info', 'health'); + $return = array('object' => utils::o2a($health_cmd)); + $return["ADCO"] = $eqLogic->getLogicalId(); + ajax::success($return); + } + } + + ajax::error("", ""); + break; + case 'getInfoDaemon': + $return = array(); + $_nbLines = 1000; + $replace = array( + '>' => '>', + ''' => '', + ); + $page = array(); + + $path = realpath(dirname(__FILE__) . '/../../ressources/teleinfo.log'); + if (!file_exists($path)) { + $return['result'] = array('Deamon non lancé'); + ajax::success($return); + } else { + $log = new SplFileObject($path); + if ($log) { + $log->seek(0); //Seek to the begening of lines + $linesRead = 0; + while ($log->valid() && $linesRead != $_nbLines) { + $line = trim($log->current()); //get current line + if ($line != '') { + array_unshift($page, $line); + } + $log->next(); //go to next line + $linesRead++; + } + } + $return['result'] = $page; + ajax::success($return); + } + break; + case 'getInfoExternalDaemon': + $jeeNetwork = jeeNetwork::byPlugin('enocean'); + $return['result'] = $jeeNetwork; + ajax::success($return); + break; + case 'getHistory': + $return = array(); + $return = history::byCmdIdDatetime(init('id'), date('Y-m-d H:i:s')); + ajax::success($return); + break; + case 'getCout': + $return = array(); + $return = history::byCmdIdDatetime(init('id'), date('Y-m-d H:i:s')); + ajax::success($return); + break; } - - if (init('action') == 'stopDeamon') { - teleinfo::deamon_stop(); - ajax::success(); - } - - if (init('action') == 'restartDeamon') { - $port = config::byKey('port', 'teleinfo', 'none'); - $_2cpt_cartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); - if ($_2cpt_cartelectronic == 1) { - - } - if ($port == 'none') { - ajax::success(); - } - teleinfo::deamon_stop(); - if (teleinfo::deamonRunning()) { - throw new \Exception(__('Impossible d\'arrêter le démon', __FILE__)); - } - log::clear('teleinfocmd'); - teleinfo::cron(); - ajax::success(); - } - - if (init('action') == 'restartSlaveDeamon') { - if (config::byKey('jeeNetwork::mode') == 'master') { - $jeeNetwork = jeeNetwork::byId(init('id')); - if (!is_object($jeeNetwork)) { - throw new \Exception(__('Impossible de trouver l\'esclave : ', __FILE__) . init('id')); - } - $jeeNetwork->sendRawRequest('restartDeamon', array('plugin' => 'teleinfo')); - } - ajax::success(); - } - - if (init('action') == 'getTeleinfo') { - if (init('object_id') == '') { - $_GET['object_id'] = $_SESSION['user']->getOptions('defaultDashboardObject'); - } - $object = object::byId(init('object_id')); - if (!is_object($object)) { - $object = object::rootObject(); - } - if (!is_object($object)) { - throw new \Exception('{{Aucun objet racine trouv�}}'); - } - $return = array('object' => utils::o2a($object)); - - $date = array( - 'start' => init('dateStart'), - 'end' => init('dateEnd'), - ); - - if ($date['start'] == '') { - $date['start'] = date('Y-m-d', strtotime('-6 days' . date('Y-m-d'))); - } - if ($date['end'] == '') { - $date['end'] = date('Y-m-d', strtotime('+1 days' . date('Y-m-d'))); - } - $return['date'] = $date; - foreach ($object->getEqLogic() as $eqLogic) { - if ($eqLogic->getIsVisible() == '1' && $eqLogic->getEqType_name() == 'teleinfo') { - $return['eqLogics'][] = array('eqLogic' => utils::o2a($eqLogic), 'html' => $eqLogic->toHtml(init('version'))); - } - } - ajax::success($return); - } - - if (init('action') == 'getInformation') { - if (init('eqLogic_id') !== null) { - $eqLogic = eqLogic::byId(init('eqLogic_id')); - $return[$eqLogic->getId()] = utils::o2a($eqLogic); - $return[$eqLogic->getId()]['cmd'] = array(); - foreach ($eqLogic->getCmd() as $cmd) { - $cmd_info = utils::o2a($cmd); - $cmd_info['value'] = $cmd->execCmd(null, 2); - $return[$eqLogic->getId()]['cmd'][] = $cmd_info; - } - ajax::success($return); - } else { - $eqLogics = eqLogic::byType('teleinfo'); - foreach ($eqLogics as $eqLogic) { - $return[$eqLogic->getId()] = utils::o2a($eqLogic); - $return[$eqLogic->getId()]['cmd'] = array(); - foreach ($eqLogic->getCmd() as $cmd) { - $cmd_info = utils::o2a($cmd); - $cmd_info['value'] = $cmd->execCmd(null, 2); - $return[$eqLogic->getId()]['cmd'][] = $cmd_info; - } - } - ajax::success($return); - } - } - if (init('action') == 'getHealth') { - //$eqLogics = eqLogic::byType('teleinfo'); - if (init('eqLogicID') !== null) { - $teleinfo = teleinfo::byLogicalId(init('eqLogicID'), 'teleinfo'); - $health_cmd = $teleinfo->getCmd('info', 'health'); - //$return[0] = $health_cmd; - $return = array('object' => utils::o2a($health_cmd)); - $return["ADCO"] = init('eqLogicID'); - ajax::success($return); - } else { - $teleinfo = teleinfo::byType('teleinfo'); - foreach ($teleinfo as $eqLogic) { - $health_cmd = $eqLogic->getCmd('info', 'health'); - //$return[0] = $health_cmd; - $return = array('object' => utils::o2a($health_cmd)); - $return["ADCO"] = $eqLogic->getLogicalId(); - ajax::success($return); - } - } - - ajax::error("", ""); - } - if (init('action') == 'getInfoDaemon') { - - $return = array(); - $_nbLines = 1000; - $replace = array( - '>' => '>', - ''' => '', - ); - $page = array(); - - $path = realpath(dirname(__FILE__) . '/../../ressources/teleinfo.log'); - //log::add('teleinfo', 'info', $path); - if (!file_exists($path)) { - $return['result'] = array('Deamon non lancé'); - ajax::success($return); - } else { - $log = new SplFileObject($path); - if ($log) { - $log->seek(0); //Seek to the begening of lines - $linesRead = 0; - while ($log->valid() && $linesRead != $_nbLines) { - $line = trim($log->current()); //get current line - if ($line != '') { - array_unshift($page, $line); - } - $log->next(); //go to next line - $linesRead++; - } - } - //return $page; - $return['result'] = $page; - ajax::success($return); - } - } - - if (init('action') == 'getInfoExternalDaemon') { - $jeeNetwork = jeeNetwork::byPlugin('enocean'); - - $return['result'] = $jeeNetwork; - ajax::success($return); - //$jeeNetwork = jeeNetwork::byId(init('id')); - // //if (!is_object($jeeNetwork)) { - // throw new Exception(__('Impossible de trouver l\'esclave : ', __FILE__) . init('id')); - // } - // $jeeNetwork->sendRawRequest('getInfoDaemon', array('plugin' => 'teleinfo')); - } - if (init('action') == 'getHistory') { - $return = array(); - /* $data = array(); - $datetime = null; */ - //console.log("essai"); - //console.log('Commande : ' . init('id')); - $return = history::byCmdIdDatetime(init('id'), date('Y-m-d H:i:s')); - //$dateEnd = date('Y-m-d H:i:s'); - ajax::success($return); - } - - if (init('action') == 'getCout') { - $return = array(); - $return = history::byCmdIdDatetime(init('id'), date('Y-m-d H:i:s')); - ajax::success($return); - } - - -throw new \Exception('Aucune methode correspondante'); + throw new \Exception('Aucune methode correspondante'); } catch (\Exception $e) { - ajax::error(displayExeption($e), $e->getCode()); + ajax::error(displayException($e), $e->getCode()); } diff --git a/plugin_info/install.php b/plugin_info/install.php index 1520486..4409f5e 100644 --- a/plugin_info/install.php +++ b/plugin_info/install.php @@ -58,7 +58,9 @@ function teleinfo_install() { $crontoday->setDeamon(0); $crontoday->setSchedule('*/5 * * * *'); $crontoday->save(); - } + } + message::removeAll('Téléinfo'); + message::add('Téléinfo', 'Installation du plugin Téléinfo terminée, vous êtes en version ' . $core_version . '.', null, null); //cache::set('teleinfo::current_core','2.610', 0); } @@ -83,7 +85,7 @@ function teleinfo_update() { if (teleinfo::deamonRunning()) { teleinfo::deamon_stop(); } - message::add('Téléinfo', 'Mise à jour en cours...', null, null); + message::add('Téléinfo', 'Mise à jour du plugin Téléinfo en cours...', null, null); log::add('teleinfo','info','*****************************************************'); log::add('teleinfo','info','*********** Mise à jour du plugin teleinfo **********'); log::add('teleinfo','info','*****************************************************'); @@ -127,7 +129,7 @@ function teleinfo_update() { } $crontoday->stop(); message::removeAll('Téléinfo'); - message::add('Téléinfo', 'Mise à jour terminée, vous êtes en version ' . $core_version . '.', null, null); + message::add('Téléinfo', 'Mise à jour du plugin Téléinfo terminée, vous êtes en version ' . $core_version . '.', null, null); teleinfo::cron(); } @@ -142,5 +144,7 @@ function teleinfo_remove() { $crontoday = cron::byClassAndFunction('teleinfo', 'CalculateTodayStats'); if (is_object($crontoday)) { $crontoday->remove(); - } + } + message::removeAll('Téléinfo'); + message::add('Téléinfo', 'Désinstallation du plugin Téléinfo terminée, vous pouvez de nouveau relever les index à la main ;)', null, null); } From c3f944f42ca2b5354de2e9944ef6989cb6a888ba Mon Sep 17 00:00:00 2001 From: ColonelMoutarde <4697568+ColonelMoutarde@users.noreply.github.com> Date: Fri, 16 Mar 2018 09:53:38 +0100 Subject: [PATCH 09/16] indentation --- core/class/teleinfo.class.php | 36 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/core/class/teleinfo.class.php b/core/class/teleinfo.class.php index 9e90b99..48673b6 100644 --- a/core/class/teleinfo.class.php +++ b/core/class/teleinfo.class.php @@ -16,14 +16,10 @@ * along with Jeedom. If not, see . */ -/* * ***************************Includes********************************* */ require_once dirname(__FILE__) . '/../../../../core/php/core.inc.php'; class teleinfo extends eqLogic { - /* * *************************Attributs****************************** */ - /* * ***********************Methode static*************************** */ - public static function getTeleinfoInfo($_url) { $return = self::deamon_info(); @@ -78,11 +74,11 @@ public static function createCmdFromDef($_oADCO, $_oKey, $_oValue) } if ($teleinfo->getConfiguration('AutoCreateFromCompteur') == '1') { log::add('teleinfo', 'info', 'Création de la commande ' . $_oKey . ' sur l\'ADCO ' . $_oADCO); - $cmd = new teleinfoCmd(); - $cmd->setName($_oKey); - $cmd->setEqLogic_id($teleinfo->id); - $cmd->setLogicalId($_oKey); - $cmd->setType('info'); + $cmd = (new teleinfoCmd()) + ->setName($_oKey) + ->setEqLogic_id($teleinfo->id) + ->setLogicalId($_oKey) + ->setType('info'); $cmd->setConfiguration('info_conso', $_oKey); switch ($_oKey) { //case "PAPP": @@ -92,17 +88,17 @@ public static function createCmdFromDef($_oADCO, $_oKey, $_oValue) case "PEJP": case "DEMAIN": case "PTEC": - $cmd->setSubType('string'); - $cmd->setDisplay('generic_type', 'GENERIC_INFO'); + $cmd->setSubType('string') + ->setDisplay('generic_type', 'GENERIC_INFO'); break; default: - $cmd->setSubType('numeric'); - $cmd->setDisplay('generic_type', 'GENERIC_INFO'); + $cmd->setSubType('numeric') + ->setDisplay('generic_type', 'GENERIC_INFO'); break; } - $cmd->setIsHistorized(1); - $cmd->setEventOnly(1); - $cmd->setIsVisible(1); + $cmd->setIsHistorized(1) + ->setEventOnly(1) + ->setIsVisible(1); $cmd->save(); $cmd->event($_oValue); return $cmd; @@ -296,8 +292,7 @@ public static function deamon_info() $twoCptCartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); if ($twoCptCartelectronic == 1) { $pidFile = '/tmp/teleinfo2cpt.pid'; - } - else { + } else { $pidFile = '/tmp/teleinfo_conso.pid'; } if (file_exists($pidFile)) { @@ -325,8 +320,7 @@ public static function deamon_start($_debug = false) self::runProductionDeamon($_debug); } message::removeAll('teleinfo', 'noTeleinfoPort'); - } - else { + } else { log::add('teleinfo', 'info', 'Pas d\'informations sur le port USB (Modem série ?)'); } } @@ -650,7 +644,6 @@ public static function calculateOtherStats() //log::add('teleinfo', 'info', 'Conso HP --> ' . $STAT_TODAY_HP); } - foreach (eqLogic::byType('teleinfo') as $eqLogic) { foreach ($eqLogic->getCmd('info') as $cmd) { @@ -986,7 +979,6 @@ public function postSave() $this->createOtherCmd(); $this->createPanelStats(); - } public function preRemove() From 1ce631d900035e7abcd21c5d17da5083bb98d1ae Mon Sep 17 00:00:00 2001 From: ColonelMoutarde <4697568+ColonelMoutarde@users.noreply.github.com> Date: Fri, 16 Mar 2018 10:44:01 +0100 Subject: [PATCH 10/16] Fluent typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Serait-il possible que tu n'utilise pas les goto c'est considéré comme une mauvaise pratique ? --- core/class/teleinfo.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/class/teleinfo.class.php b/core/class/teleinfo.class.php index 48673b6..21d2103 100644 --- a/core/class/teleinfo.class.php +++ b/core/class/teleinfo.class.php @@ -44,13 +44,13 @@ public static function createFromDef(string $adco) if ($autorisationCreationObjet != 1) { $teleinfo = teleinfo::byLogicalId($adco, 'teleinfo'); if (!is_object($teleinfo)) { - $eqLogic = new teleinfo(); - $eqLogic->setName($adco); + $eqLogic = (new teleinfo()) + ->setName($adco); } - $eqLogic->setLogicalId($adco); - $eqLogic->setEqType_name('teleinfo'); - $eqLogic->setIsEnable(1); - $eqLogic->setIsVisible(1); + $eqLogic->setLogicalId($adco) + ->setEqType_name('teleinfo') + ->setIsEnable(1) + ->setIsVisible(1); $eqLogic->save(); return $eqLogic; } else { From f30e435fe6e7e8371bc1c2247f05c2502a17d778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Fri, 16 Mar 2018 12:02:06 -0400 Subject: [PATCH 11/16] Remove deprecated & fix setEqLogic_id setEqLogic_id doesn't return this --- core/class/teleinfo.class.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/class/teleinfo.class.php b/core/class/teleinfo.class.php index 21d2103..010f892 100644 --- a/core/class/teleinfo.class.php +++ b/core/class/teleinfo.class.php @@ -44,10 +44,10 @@ public static function createFromDef(string $adco) if ($autorisationCreationObjet != 1) { $teleinfo = teleinfo::byLogicalId($adco, 'teleinfo'); if (!is_object($teleinfo)) { - $eqLogic = (new teleinfo()) + $eqLogic = (new teleinfo()) ->setName($adco); } - $eqLogic->setLogicalId($adco) + $eqLogic->setLogicalId($adco) ->setEqType_name('teleinfo') ->setIsEnable(1) ->setIsVisible(1); @@ -76,10 +76,10 @@ public static function createCmdFromDef($_oADCO, $_oKey, $_oValue) log::add('teleinfo', 'info', 'Création de la commande ' . $_oKey . ' sur l\'ADCO ' . $_oADCO); $cmd = (new teleinfoCmd()) ->setName($_oKey) - ->setEqLogic_id($teleinfo->id) ->setLogicalId($_oKey) - ->setType('info'); - $cmd->setConfiguration('info_conso', $_oKey); + ->setType('info') + ->setConfiguration('info_conso', $_oKey); + $cmd->setEqLogic_id($teleinfo->id); switch ($_oKey) { //case "PAPP": case "OPTARIF": @@ -97,7 +97,6 @@ public static function createCmdFromDef($_oADCO, $_oKey, $_oValue) break; } $cmd->setIsHistorized(1) - ->setEventOnly(1) ->setIsVisible(1); $cmd->save(); $cmd->event($_oValue); From caf64c9b2532e31aa6d32674321c039602bb4e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Fri, 16 Mar 2018 12:06:35 -0400 Subject: [PATCH 12/16] ->setConfiguration issue --- core/class/teleinfo.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/class/teleinfo.class.php b/core/class/teleinfo.class.php index 010f892..9b9d860 100644 --- a/core/class/teleinfo.class.php +++ b/core/class/teleinfo.class.php @@ -77,9 +77,9 @@ public static function createCmdFromDef($_oADCO, $_oKey, $_oValue) $cmd = (new teleinfoCmd()) ->setName($_oKey) ->setLogicalId($_oKey) - ->setType('info') - ->setConfiguration('info_conso', $_oKey); - $cmd->setEqLogic_id($teleinfo->id); + ->setType('info'); + $cmd->setEqLogic_id($teleinfo->id); + $cmd->setConfiguration('info_conso', $_oKey); switch ($_oKey) { //case "PAPP": case "OPTARIF": From cb716676695178ac546b799f0abada85d545bca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Fri, 16 Mar 2018 18:03:56 -0400 Subject: [PATCH 13/16] =?UTF-8?q?Correction=20Issue=20#26=20-=20Sant=C3=A9?= =?UTF-8?q?=20panel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/ajax/teleinfo.ajax.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/ajax/teleinfo.ajax.php b/core/ajax/teleinfo.ajax.php index f51d113..e4da397 100644 --- a/core/ajax/teleinfo.ajax.php +++ b/core/ajax/teleinfo.ajax.php @@ -76,7 +76,8 @@ ajax::success($return); break; case 'getInformation': - if (init('eqLogic_id') !== null) { + if (init('eqLogic_id') !== '') { + $eqLogic = eqLogic::byId(init('eqLogic_id')); $return[$eqLogic->getId()] = utils::o2a($eqLogic); $return[$eqLogic->getId()]['cmd'] = array(); From 7831631af7934a8ee6d4a98c559a4e993071e940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Fri, 16 Mar 2018 19:30:33 -0400 Subject: [PATCH 14/16] Correction goto #31 --- core/class/teleinfo.class.php | 92 ++++++++++++++++------------------- 1 file changed, 41 insertions(+), 51 deletions(-) diff --git a/core/class/teleinfo.class.php b/core/class/teleinfo.class.php index 9b9d860..4bd1fd3 100644 --- a/core/class/teleinfo.class.php +++ b/core/class/teleinfo.class.php @@ -107,8 +107,8 @@ public static function createCmdFromDef($_oADCO, $_oKey, $_oValue) public static function runDeamon($_debug = false, $type = 'conso') { log::add('teleinfo', 'info', 'Démarrage compteur de consommation'); - $teleinfoPath = realpath(dirname(__FILE__) . '/../../ressources'); - $modemSerieAddr = config::byKey('port', 'teleinfo'); + $teleinfoPath = realpath(dirname(__FILE__) . '/../../ressources'); + $modemSerieAddr = config::byKey('port', 'teleinfo'); $_debug = config::byKey('debug', 'teleinfo'); $_force = config::byKey('force', 'teleinfo'); $twoCptCartelectronic = config::byKey('2cpt_cartelectronic', 'teleinfo'); @@ -117,25 +117,25 @@ public static function runDeamon($_debug = false, $type = 'conso') } else { $modemVitesse = config::byKey('modem_vitesse', 'teleinfo'); } - if ($modemSerieAddr == "serie") { + if ($modemSerieAddr == "serie") { $port = config::byKey('modem_serie_addr', 'teleinfo'); - goto lancement; - } - $port = jeedom::getUsbMapping(config::byKey('port', 'teleinfo')); - if ($twoCptCartelectronic == 1) { - $port = '/dev/ttyUSB1'; - goto lancement; + } else { + $port = jeedom::getUsbMapping(config::byKey('port', 'teleinfo')); + if ($twoCptCartelectronic == 1) { + $port = '/dev/ttyUSB1'; + } else { + if (!file_exists($port)) { + log::add('teleinfo', 'error', 'Le port n\'existe pas'); + return false; + } + $cle_api = config::byKey('api'); + if ($cle_api == '') { + log::add('teleinfo', 'error', 'Erreur de clé api, veuillez la vérifier.'); + return false; + } + } } - if (!file_exists($port)) { - log::add('teleinfo', 'error', 'Le port n\'existe pas'); - goto end; - } - $cle_api = config::byKey('api'); - if ($cle_api == '') { - log::add('teleinfo', 'error', 'Erreur de clé api, veuillez la vérifier.'); - goto end; - } - lancement: + $parsed_url = parse_url(config::byKey('internalProtocol', 'core', 'http://') . config::byKey('internalAddr', 'core', '127.0.0.1') . ":" . config::byKey('internalPort', 'core', '80') . config::byKey('internalComplement', 'core')); exec('sudo chmod 777 ' . $port . ' > /dev/null 2>&1'); // TODO : Vérifier dans futur release si tjs nécessaire @@ -180,7 +180,6 @@ public static function runDeamon($_debug = false, $type = 'conso') message::removeAll('teleinfo', 'unableStartDeamon'); log::add('teleinfo', 'info', 'Service OK'); log::add('teleinfo', 'info', '---------------------------------------------'); - end: } public static function runProductionDeamon($_debug = false, $type = 'prod') @@ -198,23 +197,23 @@ public static function runProductionDeamon($_debug = false, $type = 'prod') } if ($modemSerieAddr == "serie") { $port = config::byKey('modem_serie_production_addr', 'teleinfo'); - goto lancement; + } else { + $port = jeedom::getUsbMapping(config::byKey('port_production', 'teleinfo')); + if ($twoCptCartelectronic == 1) { + $port = '/dev/ttyUSB1'; + } else { + if (!file_exists($port)) { + log::add('teleinfo', 'error', '[Production] Le port n\'existe pas'); + return false; + } + $cle_api = config::byKey('api'); + if ($cle_api == '') { + log::add('teleinfo', 'error', '[Production] Erreur de clé api, veuillez la vérifier.'); + return false; + } + } } - $port = jeedom::getUsbMapping(config::byKey('port_production', 'teleinfo')); - if ($twoCptCartelectronic == 1) { - $port = '/dev/ttyUSB1'; - goto lancement; - } - if (!file_exists($port)) { - log::add('teleinfo', 'error', '[Production] Le port n\'existe pas'); - goto end; - } - $cle_api = config::byKey('api'); - if ($cle_api == '') { - log::add('teleinfo', 'error', '[Production] Erreur de clé api, veuillez la vérifier.'); - goto end; - } - lancement: + $parsed_url = parse_url(config::byKey('internalProtocol', 'core', 'http://') . config::byKey('internalAddr', 'core', '127.0.0.1') . ":" . config::byKey('internalPort', 'core', '80') . config::byKey('internalComplement', 'core')); exec('sudo chmod 777 ' . $port . ' > /dev/null 2>&1'); @@ -236,7 +235,7 @@ public static function runProductionDeamon($_debug = false, $type = 'prod') if ($twoCptCartelectronic == 1) { log::add('teleinfo', 'info', 'Fonctionnement en mode 2 compteur'); $teleinfoPath = $teleinfoPath . '/teleinfo_2_cpt.py'; - $cmd = 'sudo nice -n 19 /usr/bin/python ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -r ' . realpath(dirname(__FILE__)); + $cmd = 'sudo nice -n 19 /usr/bin/python3 ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -r ' . realpath(dirname(__FILE__)); } else { log::add('teleinfo', 'info', 'Fonctionnement en mode 1 compteur'); $teleinfoPath = $teleinfoPath . '/teleinfo.py'; @@ -260,7 +259,6 @@ public static function runProductionDeamon($_debug = false, $type = 'prod') message::removeAll('teleinfo', 'unableStartDeamon'); log::add('teleinfo', 'info', '[Production] Service OK'); log::add('teleinfo', 'info', '---------------------------------------------'); - end: } public static function deamonRunning() @@ -344,14 +342,11 @@ public static function deamon_stop() $pid = intval(trim(file_get_contents($pidFile))); $kill = posix_kill($pid, 15); usleep(500); - if ($kill) { - goto prod_stop_success; - } else { - system::kill($pid); + if (!$kill) { + system::kill($pid); } } } - prod_stop_success: $pidFile = '/tmp/teleinfo_conso.pid'; if (file_exists($pidFile)) { $pid = intval(trim(file_get_contents($pidFile))); @@ -1067,14 +1062,9 @@ public static function installationOk() } public static function dependancy_install() - { - if (file_exists('/tmp/teleinfo_in_progress')) { - return; - } - log::remove('teleinfo_update'); - $cmd = 'sudo /bin/bash ' . dirname(__FILE__) . '/../../ressources/install.sh'; - $cmd .= ' >> ' . log::getPathToLog('teleinfo_update') . ' 2>&1 &'; - exec($cmd); + { + log::remove(__CLASS__ . '_update'); + return array('script' => dirname(__FILE__) . '/../../ressources/install_#stype#.sh ' . jeedom::getTmpFolder('teleinfo') . '/dependance', 'log' => log::getPathToLog(__CLASS__ . '_update')); } } From 86353d40fff1181f8d1cf42d49573f456dfc9226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Fri, 16 Mar 2018 19:31:09 -0400 Subject: [PATCH 15/16] Modification installation / Correction bug 2 compteurs --- .editorconfig | 5 ++++ ressources/install_apt.sh | 49 ++++++++++++++++++++++++++++++++++++ ressources/teleinfo_2_cpt.py | 7 +++--- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 ressources/install_apt.sh diff --git a/.editorconfig b/.editorconfig index 6500a5a..77ae3b3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -28,3 +28,8 @@ indent_size = 4 charset = utf-8 indent_style = space indent_size = 4 + +[*.sh] +charset = utf-8 +indent_style = space +indent_size = 4 diff --git a/ressources/install_apt.sh b/ressources/install_apt.sh new file mode 100644 index 0000000..1ea0506 --- /dev/null +++ b/ressources/install_apt.sh @@ -0,0 +1,49 @@ +#!/bin/bash +PROGRESS_FILE=/tmp/jeedom/teleinfo/dependance +PROGRESS_FILE=$1 +touch ${PROGRESS_FILE} +echo 0 > ${PROGRESS_FILE} +function apt_install { + sudo apt-get -y install "$@" + if [ $? -ne 0 ]; then + echo "could not install $1 - abort" + rm ${PROGRESS_FILE} + exit 1 + fi +} + +function pip_install { + sudo pip install "$@" + if [ $? -ne 0 ]; then + echo "could not install $p - abort" + rm ${PROGRESS_FILE} + exit 1 + fi +} +#echo "Prérequis python3" +echo 10 > ${PROGRESS_FILE} +#apt_install python3 +#apt_install python3-pip +echo "Lancement de l'installation/mise à jour des dépendances Téléinfo" +sudo apt-get update +echo 20 > ${PROGRESS_FILE} +sudo apt-get -y install python-ftdi +sudo apt-get -y install python-ftdi1 +#pip_install pyftdi +pip_install pylibftdi +echo 30 > ${PROGRESS_FILE} +#pip_install python-ftdi1 +echo 40 > ${PROGRESS_FILE} +pip_install serial +echo 50 > ${PROGRESS_FILE} +if [ -e /dev/ttyAMA0 ]; then + sed -i 's/console=ttyAMA0,115200//; s/kgdboc=ttyAMA0,115200//' /boot/cmdline.txt + if [ -e /etc/inittab ]; then + sed -i 's|[^:]*:[^:]*:respawn:/sbin/getty[^:]*ttyAMA0[^:]*||' /etc/inittab + fi + sudo systemctl stop serial-getty@ttyAMA0.service + sudo systemctl disable serial-getty@ttyAMA0.service +fi +echo 100 > ${PROGRESS_FILE} +echo "Everything is successfully installed!" +rm ${PROGRESS_FILE} diff --git a/ressources/teleinfo_2_cpt.py b/ressources/teleinfo_2_cpt.py index 61409e2..8fa2251 100644 --- a/ressources/teleinfo_2_cpt.py +++ b/ressources/teleinfo_2_cpt.py @@ -238,9 +238,10 @@ class Teleinfo(object): def __init__(self, ftdi_): """ """ + self._log = MyLogger() + self._log.info("Initialisation de la teleinfo") if FTDI_TYPE == 0: - self._log = MyLogger() - self._log.info("Initialisation de la teleinfo") + self.context = "" super(Teleinfo, self).__init__() self.__ftdi = ftdi_ else: @@ -526,7 +527,7 @@ def main(): ftdi_.init() teleinfo = Teleinfo(ftdi_) else: - teleinfo = Teleinfo() + teleinfo = Teleinfo("") pid = str(os.getpid()) file("/tmp/teleinfo2cpt.pid", 'w').write("%s\n" % pid) signal.signal(signal.SIGTERM, teleinfo.exit_handler) From f251153ac7efc67bdd9fb057e57e9a39cf304bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Fri, 16 Mar 2018 19:45:24 -0400 Subject: [PATCH 16/16] Beta 2.7.0 --- core/class/teleinfo.class.php | 2 +- docs/fr_FR/changelog.md | 11 +++++++++-- ressources/install.sh | 23 ----------------------- 3 files changed, 10 insertions(+), 26 deletions(-) delete mode 100644 ressources/install.sh diff --git a/core/class/teleinfo.class.php b/core/class/teleinfo.class.php index 4bd1fd3..3d85c47 100644 --- a/core/class/teleinfo.class.php +++ b/core/class/teleinfo.class.php @@ -235,7 +235,7 @@ public static function runProductionDeamon($_debug = false, $type = 'prod') if ($twoCptCartelectronic == 1) { log::add('teleinfo', 'info', 'Fonctionnement en mode 2 compteur'); $teleinfoPath = $teleinfoPath . '/teleinfo_2_cpt.py'; - $cmd = 'sudo nice -n 19 /usr/bin/python3 ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -r ' . realpath(dirname(__FILE__)); + $cmd = 'sudo nice -n 19 /usr/bin/python ' . $teleinfoPath . ' -d ' . $_debug . ' -p ' . $port . ' -v ' . $modemVitesse . ' -e ' . $ip_interne . ' -c ' . config::byKey('api') . ' -f ' . $_force . ' -r ' . realpath(dirname(__FILE__)); } else { log::add('teleinfo', 'info', 'Fonctionnement en mode 1 compteur'); $teleinfoPath = $teleinfoPath . '/teleinfo.py'; diff --git a/docs/fr_FR/changelog.md b/docs/fr_FR/changelog.md index f7b602f..f47cfc8 100644 --- a/docs/fr_FR/changelog.md +++ b/docs/fr_FR/changelog.md @@ -5,14 +5,21 @@ Change log > Commit](https://github.com/Jeedom-Plugins-Extra/plugin-teleinfo/commits/master) -3.0.0 [![Stable](https://img.shields.io/badge/version-beta-yellow.svg?longCache=true&style=flat-square)](https://github.com/Jeedom-Plugins-Extra/plugin-teleinfo/milestone/1) +3.0.0 ===== - Docs au nouveau standard de la team (github pages) - Refaire fonctionner le mode 2 compteurs. - Noms des variables et fonctions - Compatibilité Linky -2.6.4 [![Stable](https://img.shields.io/badge/version-stable-brightgreen.svg?longCache=true&style=flat-square)](https://github.com/Jeedom-Plugins-Extra/plugin-teleinfo/releases) +2.7.0 Beta [![Beta](https://img.shields.io/badge/version-beta-yellow.svg?longCache=true&style=flat-square)](https://github.com/Jeedom-Plugins-Extra/plugin-teleinfo/milestone/1) +===== +- Issue du démon 2 compteurs et librairie ftdi. +- Reprise du processus des dépendances. +- Erreurs 500 sur le panel. +- Suppresion de fonctions dépréciés + +2.6.4 Stable [![Stable](https://img.shields.io/badge/version-stable-brightgreen.svg?longCache=true&style=flat-square)](https://github.com/Jeedom-Plugins-Extra/plugin-teleinfo/releases) ===== - Bugfix erreur lors de l'enregistrement diff --git a/ressources/install.sh b/ressources/install.sh deleted file mode 100644 index aeaf52f..0000000 --- a/ressources/install.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -touch /tmp/teleinfo_in_progress -echo 0 > /tmp/teleinfo_in_progress -sudo apt-get update -echo "Lancement de l'installation des dépendances Téléinfo" -echo 10 > /tmp/teleinfo_in_progress -sudo apt-get -y install python-ftdi -echo 20 > /tmp/teleinfo_in_progress -sudo apt-get -y install python-ftdi1 -echo 30 > /tmp/teleinfo_in_progress -sudo apt-get -y install python-serial -echo 50 > /tmp/teleinfo_in_progress -if [ -e /dev/ttyAMA0 ]; then - sudo sed -i 's/console=ttyAMA0,115200//; s/kgdboc=ttyAMA0,115200//' /boot/cmdline.txt - if [ -e /etc/inittab ]; then - sudo sed -i 's|[^:]*:[^:]*:respawn:/sbin/getty[^:]*ttyAMA0[^:]*||' /etc/inittab - fi - sudo systemctl stop serial-getty@ttyAMA0.service - sudo systemctl disable serial-getty@ttyAMA0.service -fi -echo 100 > /tmp/teleinfo_in_progress -echo "Everything is successfully installed!" -rm /tmp/teleinfo_in_progress