Skip to content

Commit

Permalink
Merge pull request #203 from NextDom/develop
Browse files Browse the repository at this point in the history
4.8.3
  • Loading branch information
noyax authored Feb 29, 2024
2 parents 4db6388 + 036396e commit cc68552
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ ressources/teleinfo - Copie.py
.project

.travis.yml

ressources/venv/
34 changes: 23 additions & 11 deletions core/class/teleinfo.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public static function cronHourly()
log::add('teleinfo', 'debug', 'cronhourly ');
}

// Fonction pour exclure un sous répertoire de la sauvegarde
public static function backupExclude() {
return ['ressources/venv'];
}

public static function changeLogLive($level)
{
$activation_Modem = (config::byKey('activation_Modem', 'teleinfo') == "") ? 1 : config::byKey('activation_Modem', 'teleinfo');
Expand Down Expand Up @@ -305,6 +310,7 @@ public static function findModemType(string $port, string $type)
public static function runDeamon($debug = false, $type = 'conso', $mqtt = false)
{
$teleinfoPath = realpath(dirname(__FILE__) . '/../../ressources');
$activation_Modem = (config::byKey('activation_Modem', 'teleinfo') == "") ? 1 : config::byKey('activation_Modem', 'teleinfo');
if ($activation_Modem==''){
$activation_Modem = 1;
log::add('teleinfo', 'info', '---------- Activation Modem 1---------');
Expand All @@ -326,9 +332,11 @@ public static function runDeamon($debug = false, $type = 'conso', $mqtt = false)
if ($twoCptCartelectronic == 1) {
$port = '/dev/ttyUSB1';
} else {
if (!file_exists($port)) {
log::add('teleinfo', 'error', '[TELEINFO]-----[' . $type . '] Le port1 '. $port . ' n\'existe pas');
return false;
if (is_string($port)) {
if (!file_exists($port)) {
log::add('teleinfo', 'error', '[TELEINFO]-----[' . $type . '] Le port1 '. $port . ' n\'existe pas');
return false;
}
}
}
}
Expand All @@ -345,9 +353,11 @@ public static function runDeamon($debug = false, $type = 'conso', $mqtt = false)
if ($twoCptCartelectronic == 1) {
$port = '/dev/ttyUSB1';
} else {
if (!file_exists($port)) {
log::add('teleinfo', 'error', '[TELEINFO]-----[' . $type . '] Le port2 '. $port . ' n\'existe pas');
return false;
if (is_string($port)) {
if (!file_exists($port)) {
log::add('teleinfo', 'error', '[TELEINFO]-----[' . $type . '] Le port2 '. $port . ' n\'existe pas');
return false;
}
}
}
}
Expand Down Expand Up @@ -376,11 +386,13 @@ public static function runDeamon($debug = false, $type = 'conso', $mqtt = false)

if ($twoCptCartelectronic == 1) {
log::add('teleinfo', 'info', '[' . $type . '] Fonctionnement en mode 2 compteur');
$cmd = 'sudo nice -n 19 /usr/bin/python3 ' . $teleinfoPath . '/teleinfo_2_cpt.py';
$cmd = 'sudo nice -n 19 ' . $teleinfoPath . '/venv/bin/python3 ' . $teleinfoPath . '/teleinfo_2_cpt.py';
//$cmd = 'sudo nice -n 19 /usr/bin/python3 ' . $teleinfoPath . '/teleinfo_2_cpt.py';
}
else {
log::add('teleinfo', 'info', '[' . $type . '] Fonctionnement en mode 1 compteur');
$cmd = 'nice -n 19 /usr/bin/python3 ' . $teleinfoPath . '/teleinfo.py';
$cmd = 'nice -n 19 ' . $teleinfoPath . '/venv/bin/python3 ' . $teleinfoPath . '/teleinfo.py';
//$cmd = 'nice -n 19 /usr/bin/python3 ' . $teleinfoPath . '/teleinfo.py';
$cmd .= ' --type ' . $type;
}
$cmd .= ' --port ' . $port;
Expand Down Expand Up @@ -415,7 +427,7 @@ public static function runDeamon($debug = false, $type = 'conso', $mqtt = false)
}

public static function runDeamonMqtt($debug = false, $type = 'mqtt'){

$teleinfoPath = realpath(dirname(__FILE__) . '/../../ressources');
$socketPort = config::byKey('socketport', 'teleinfo', '55062') + 2;
$socketHost = config::byKey('socketHost', 'teleinfo', '127.0.0.1');
Expand All @@ -433,7 +445,7 @@ public static function runDeamonMqtt($debug = false, $type = 'mqtt'){
log::add('teleinfo', 'info', "Port du Broker : " . $mqtt_port);
log::add('teleinfo', 'info', "topic : " . '"' . $mqtt_topic . '"');
log::add('teleinfo', 'info', '---------------------------------------------');
$cmd = 'nice -n 19 /usr/bin/python3 ' . $teleinfoPath . '/teleinfo_mqtt.py';
$cmd = 'nice -n 19 ' . $teleinfoPath . '/venv/bin/python3 ' . $teleinfoPath . '/teleinfo_mqtt.py';
$cmd .= ' --socketport ' . $socketPort;
$cmd .= ' --mqtt True';
$cmd .= ' --mqtt_broker ' . $mqtt_broker;
Expand Down Expand Up @@ -729,7 +741,7 @@ public static function deamon_stop()
}
}
}
if ($deamonInfo['deamon_conso'] == 'ok') {
if ($deamonInfo['deamon_modem'] == 'ok') {
$pidFile = jeedom::getTmpFolder('teleinfo') . '/teleinfo_conso.pid';
if (file_exists($pidFile)) {
$pid = intval(trim(file_get_contents($pidFile)));
Expand Down
7 changes: 1 addition & 6 deletions desktop/js/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ function loadData(){
if(compteurProd||prodEtConso){
stackGraph = 0
if (datacmd.name == 'STAT_YESTERDAY_PROD'){
datacmd.name = 'Index Prod';
datacmd.name = 'Prod ';
}
serie = 14;
console.log("[loadData][STAT_YESTERDAY_PROD] " + datacmd.id);
Expand Down Expand Up @@ -1815,11 +1815,6 @@ function teleinfoDrawChart(_params) {
dailyHistoryChart[_params.el].color = 0;
}

var extremes = dailyHistoryChart[_params.el].chart.xAxis[0].getExtremes();
var plotband = jeedom.history.generatePlotBand(extremes.min,extremes.max);
for(var i in plotband){
dailyHistoryChart[_params.el].chart.xAxis[0].addPlotBand(plotband[i]);
}
$.hideLoading();
if (typeof (init(_params.success)) == 'function') {
_params.success(data.result);
Expand Down
58 changes: 41 additions & 17 deletions desktop/modal/info_daemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
$jeeNetwork = jeeNetwork::byId(init('slave_id'));
//$deamon_info = $jeeNetwork->sendRawRequest('plugin::deamonInfo', array('plugin_id' => init('plugin_id')));
}
// uniquement si on est en version 4.4 ou supérieur
$jeedomVersion = jeedom::version() ?? '0';
$displayInfoValue = version_compare($jeedomVersion, '4.4.0', '>=');

sendVarToJS('versionsup', json_encode($displayInfoValue));
sendVarToJs('logfile', init('plugin_id'));
sendVarToJs('slave_id', init('slave_id'));
?>
Expand All @@ -25,21 +29,41 @@
<br/><br/><br/>
<pre id='pre_pluginDeamonLogUpdate' style='overflow: auto; height: 90%;with:90%;'></pre>


<script>
if(slave_id == 0){
jeedom.log.autoupdate({
log : logfile,
display : $('#pre_pluginDeamonLogUpdate'),
search : $('#in_pluginDeamonLogSearch'),
control : $('#bt_pluginDeamonLogStopStart'),
});
}else{
jeedom.log.autoupdate({
log : logfile,
slaveId :slave_id,
display : $('#pre_pluginDeamonLogUpdate'),
search : $('#in_pluginDeamonLogSearch'),
control : $('#bt_pluginDeamonLogStopStart'),
});
}
</script>
if (versionsup == "true"){
if(slave_id == 0){
jeedom.log.autoUpdateDelta({
log : logfile,
display : $('#pre_pluginDeamonLogUpdate'),
search : $('#in_pluginDeamonLogSearch'),
control : $('#bt_pluginDeamonLogStopStart'),
});
}else{
jeedom.log.autoUpdateDelta({
log : logfile,
slaveId :slave_id,
display : $('#pre_pluginDeamonLogUpdate'),
search : $('#in_pluginDeamonLogSearch'),
control : $('#bt_pluginDeamonLogStopStart'),
});
};
} else {
if(slave_id == 0){
jeedom.log.autoupdate({
log : logfile,
display : $('#pre_pluginDeamonLogUpdate'),
search : $('#in_pluginDeamonLogSearch'),
control : $('#bt_pluginDeamonLogStopStart'),
});
}else{
jeedom.log.autoupdate({
log : logfile,
slaveId :slave_id,
display : $('#pre_pluginDeamonLogUpdate'),
search : $('#in_pluginDeamonLogSearch'),
control : $('#bt_pluginDeamonLogStopStart'),
});
};
};
</script>
5 changes: 5 additions & 0 deletions docs/fr_FR/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Pour toutes demandes :
- [Changelog version stable](https://nextdom.github.io/plugin-teleinfo/fr_FR/changelog.md)
- [Changelog version bêta](https://noyax.github.io/plugin-teleinfo/fr_FR/changelog.md)

## 4.8.3 (**-**-2024)
- Adapatation du plugin à jeedom V4.4 + Debian 12 + php 8.2.7 (merci @Typher)
- Adaptation au passage à paho-mqtt v2
- Passage en environnement virtuel

## 4.8.2c (09-09-2023) => version stable ET bêta
- Pour les deux versions: résolution d'un problème de redémarrage intempestif du démon

Expand Down
6 changes: 3 additions & 3 deletions plugin_info/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"changelog" : "https://NextDom.github.io/plugin-teleinfo/fr_FR/changelog",
"documentation" : "https://NextDom.github.io/plugin-teleinfo/fr_FR/",
"changelog_beta" : "https://Noyax.github.io/plugin-teleinfo/fr_FR/changelog",
"documentation_beta" : "https://Noyax.github.io/plugin-teleinfo/fr_FR/",
"pluginVersion" : "4.8.2c"
"changelog_beta" : "https://noyax-37.github.io/plugin-teleinfo/fr_FR/changelog",
"documentation_beta" : "https://noyax-37.github.io/plugin-teleinfo/fr_FR/",
"pluginVersion" : "4.8.3"
}
10 changes: 3 additions & 7 deletions plugin_info/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
"python3-ftdi1" : {}
},
"pip3" :{
"pylibftdi" : {},
"six" : {},
"pyserial" : {},
"setuptools" : {},
"requests" : {},
"pyudev" : {},
"paho-mqtt" : {}
},
"post-install" : {
"script" : "plugins/teleinfo/ressources/post-install.sh"
}
}
58 changes: 58 additions & 0 deletions ressources/post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# post-install script for Jeedom plugin teleinfo
#!/bin/bash
PROGRESS_FILE=/tmp/jeedom_install_in_progress_teleinfo
if [ ! -z $1 ]; then
PROGRESS_FILE=$1
fi
date
touch ${PROGRESS_FILE}
echo 0 > ${PROGRESS_FILE}
echo "**********************************"
echo "* Installation des dépendances *"
echo "**********************************"
BASEDIR=/var/www/html/plugins/teleinfo/ressources

echo 5 > ${PROGRESS_FILE}
sudo apt-get update
sudo apt-get upgrade
date
#echo 10 > ${PROGRESS_FILE}
#sudo apt remove -y python3-serial

echo 10 > ${PROGRESS_FILE}
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y libxml2-dev libxslt-dev

echo 15 > ${PROGRESS_FILE}
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python3
date

echo 20 > ${PROGRESS_FILE}
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python3-venv python3-pip python3-dev
date

echo 25 > ${PROGRESS_FILE}
sudo -u www-data python3 -m venv $BASEDIR/venv
date

sudo -u www-data $BASEDIR/venv/bin/python3 -m pip install --upgrade pip wheel

echo 30 > ${PROGRESS_FILE}
sudo -u www-data $BASEDIR/venv/bin/pip3 install --no-cache-dir pylibftdi
echo 35 > ${PROGRESS_FILE}
sudo -u www-data $BASEDIR/venv/bin/pip3 install --no-cache-dir six
echo 40 > ${PROGRESS_FILE}
sudo -u www-data $BASEDIR/venv/bin/pip3 install --no-cache-dir pyserial
echo 45 > ${PROGRESS_FILE}
sudo -u www-data $BASEDIR/venv/bin/pip3 install --no-cache-dir setuptools
echo 50 > ${PROGRESS_FILE}
sudo -u www-data $BASEDIR/venv/bin/pip3 install --no-cache-dir requests
echo 55 > ${PROGRESS_FILE}
sudo -u www-data $BASEDIR/venv/bin/pip3 install --no-cache-dir pyudev
echo 60 > ${PROGRESS_FILE}
sudo -u www-data $BASEDIR/venv/bin/pip3 install --no-cache-dir paho-mqtt==1.6.1

date
rm ${PROGRESS_FILE}
echo "*************************************"
echo "* Installation des dépendances OK *"
echo "*************************************"

0 comments on commit cc68552

Please sign in to comment.