Skip to content

Commit

Permalink
Update cmd.class.php
Browse files Browse the repository at this point in the history
BugFix:  update normaly static function to static function to prevent error
  • Loading branch information
limad authored Nov 23, 2024
1 parent 30bc076 commit 4143e5b
Showing 1 changed file with 40 additions and 48 deletions.
88 changes: 40 additions & 48 deletions core/class/cmd.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

class cmd {
/* * *************************Attributs****************************** */
/* * *************************Attributs****************************** */

protected $id;
protected $logicalId;
Expand Down Expand Up @@ -64,7 +64,7 @@ class cmd {
'Hz' => array(1000, 'Hz', 'kHz', 'MHz', 'GHz'),
'l' => array(1000, 'l', 'm<sup>3</sup>')
);
/* * ***********************Méthodes statiques*************************** */
/* * ***********************Méthodes statiques*************************** */

private static function cast($_inputs, $_eqLogic = null) {
if (is_object($_inputs) && class_exists($_inputs->getEqType() . 'Cmd')) {
Expand Down Expand Up @@ -983,7 +983,7 @@ public static function cmdAlert($_options) {
$cmd->executeAlertCmdAction();
}

/* * *********************Méthodes d'instance************************* */
/* * *********************Méthodes d'instance************************* */
public function formatValue($_value, $_quote = false) {
if (is_array($_value) || is_object($_value)) {
return '';
Expand Down Expand Up @@ -2273,60 +2273,39 @@ public function computeInfluxData($_value, $_timestamp = '') {
return $point;
}

public function getInflux($_cmdId = null) {
try {
if ($_cmdId) {
public static function getInflux($_cmdId = null) {
if ($_cmdId) {
$cmd = cmd::byId($_cmdId);
$enabled = $cmd->getConfiguration('influx::enable');
if (!$enabled) {
return;
}
}
$url = config::byKey('cmdInfluxURL');
$port = config::byKey('cmdInfluxPort');
$base = config::byKey('cmdInfluxTable');
$user = config::byKey('cmdInfluxUser', 'core', '');
$pass = config::byKey('cmdInfluxPass', 'core', '');
if ($url == '' || $port == '') {
$url = config::byKey('cmdInfluxURL');
$port = config::byKey('cmdInfluxPort');
$base = config::byKey('cmdInfluxTable');
$user = config::byKey('cmdInfluxUser', 'core', '');
$pass = config::byKey('cmdInfluxPass', 'core', '');
if ($url == '' || $port == '') {
return;
}
if ($base == '') {
if ($base == '') {
$base = 'Jeedom';
}
if ($user == '') {
if ($user == '') {
$client = new InfluxDB\Client($url, $port);
} else {
$client = new InfluxDB\Client($url, $port, $user, $pass);
}
$database = $client->selectDB($base);
if (!$database->exists()) {
$database = $client->selectDB($base);
if (!$database->exists()) {
$database->create();
}
return $database;
} catch (Exception $e) {
log::add('cmd', 'error', __('Erreur get influx database :', __FILE__) . ' ' . ' => ' . log::exception($e));
}
return $database;
return '';
}

public function pushInflux($_value = null) {
try {
$database = cmd::getInflux($this->getId());
if ($database == '') {
return;
}
if ($_value === null) {
$_value = $this->execCmd();
}
$point = $this->computeInfluxData($_value);
$result = $database->writePoints(array($point), 's');
} catch (Exception $e) {
log::add('cmd', 'error', __('Erreur push influx sur :', __FILE__) . ' ' . ' commande : ' . $this->getHumanName() . ' => ' . log::exception($e));
}
return;
}

public function dropInfluxDatabase() {
public static function dropInfluxDatabase() {
try {
$database = cmd::getInflux();
if ($database == '') {
Expand Down Expand Up @@ -2354,11 +2333,24 @@ public function dropInflux() {
return;
}

public function historyInfluxAll() {
cmd::historyInflux('all');
public static function historyInfluxAll() {
try {
$cron = new cron();
$cron->setClass('cmd');
$cron->setFunction('sendHistoryInflux');
$cron->setOption(array('cmd_id' => 'all'));
$cron->setLastRun(date('Y-m-d H:i:s'));
$cron->setOnce(1);
$cron->setSchedule(cron::convertDateToCron(strtotime("now") + 60));
$cron->save();
return;
}
catch (Exception $e) {
log::add('cmd', 'error', __('historyInfluxAll w :', __FILE__) . ' '. $e->getMessage());
}
}

public function sendHistoryInflux($_params) {
public static function sendHistoryInflux($_params) {
$cmds = array();
if ($_params['cmd_id'] == 'all') {
foreach (cmd::byTypeSubType('info') as $cmd) {
Expand Down Expand Up @@ -2401,19 +2393,19 @@ public function sendHistoryInflux($_params) {
}
} catch (Exception $e) {
log::add('cmd', 'error', __('Erreur history influx sur :', __FILE__) . ' ' . ' commande : ' . $cmd->getHumanName() . ' => ' . log::exception($e));

}
}

public function historyInflux($_type = '') {
if ($_type == 'all') {
return cmd::historyInfluxAll();
}
$cron = new cron();
$cron->setClass('cmd');
$cron->setFunction('sendHistoryInflux');
if ($_type == 'all') {
$cron->setOption(array('cmd_id' => 'all'));
} else {
$cron->setOption(array('cmd_id' => intval($this->getId())));
}
$cron->setLastRun(date('Y-m-d H:i:s'));
$cron->setOption(array('cmd_id' => intval($this->getId())));
$cron->setLastRun(date('Y-m-d H:i:s'));
$cron->setOnce(1);
$cron->setSchedule(cron::convertDateToCron(strtotime("now") + 60));
$cron->save();
Expand Down Expand Up @@ -2898,7 +2890,7 @@ public function hasRight($_user = null) {
}
}

/* * **********************Getteur Setteur*************************** */
/* * **********************Getteur Setteur*************************** */

public function getId() {
return $this->id;
Expand Down

0 comments on commit 4143e5b

Please sign in to comment.