diff --git a/core/class/frigate.class.php b/core/class/frigate.class.php index 58b76c30..fcdade39 100644 --- a/core/class/frigate.class.php +++ b/core/class/frigate.class.php @@ -84,6 +84,23 @@ private static function configSave(array $array = []): void } } } + + public static function setConfigEqlogic() + { + $eqLogics = self::byType('frigate'); + foreach ($eqLogics as $eqLogic) { + $refresh = config::byKey('refresh_snapshot', 'frigate', 5); + if ($eqLogic->getConfiguration('normal::refresh') === null) { + $eqLogic->setConfiguration('normal::refresh', $refresh); + $eqLogic->save(); + } + if ($eqLogic->getConfiguration('normal::mobilerefresh') === null) { + $eqLogic->setConfiguration('normal::mobilerefresh', $refresh); + $eqLogic->save(); + } + } + } + private static function execCron($frequence) { log::add(__CLASS__, 'debug', "╔════════════════════════ :fg-success:START CRON:/fg: ════════════════════════"); @@ -407,8 +424,18 @@ public function toHtml($_version = 'dashboard') $replace['#cameraEqlogicId#'] = $this->getLogicalId(); $replace['#cameraName#'] = $this->getConfiguration("name"); $replace['#imgUrl#'] = $this->getConfiguration("img"); - $replace['#enabled#'] = $this->getCmd('info', 'info_enabled') ? $this->getCmd('info', 'info_enabled')->execCmd() : 1; - $replace['#refresh#'] = (float)(config::byKey('refresh_snapshot', 'frigate')) * 1000; + $enabledCmd = $this->getCmd('info', 'info_enabled'); + if ($enabledCmd) { + $value = $enabledCmd->execCmd(); + $replace['#enabled#'] = ($value !== null && $value !== '') ? $value : 1; + } else { + $replace['#enabled#'] = 1; + } + if ($this->getConfiguration('normal::refresh') != '') { + $replace['#refresh#'] = (float)$this->getConfiguration('normal::refresh') * 1000; + } else { + $replace['#refresh#'] = (float)(config::byKey('refresh_snapshot', 'frigate', 5)) * 1000; + } $replace['#actions#'] = $this->buildActions(); $replace['#iaActions#'] = $this->buildIaActions(); @@ -714,8 +741,19 @@ private static function getcURL($function, $url, $params = null, $decodeJson = t curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); } + // log de la commande curl + $curl_cmd = "curl -k -X " . $method; + if ($method !== 'DELETE') { + $curl_cmd .= " -H 'Content-Type: application/json'"; + $curl_cmd .= " -d '" . json_encode($params) . "'"; + } + $curl_cmd .= " '" . $url . "'"; + log::add(__CLASS__, 'debug', "║ Commande exécutée : " . $curl_cmd); + // Fin du log + $data = curl_exec($ch); + log::add(__CLASS__, 'debug', "║ Réponse reçue : " . $data); if (curl_errno($ch)) { log::add(__CLASS__, "error", "║ Erreur getcURL (" . $method . "): " . curl_error($ch)); return null; @@ -733,6 +771,9 @@ private static function postcURL($function, $url, $params = null, $decodeJson = private static function putcURL($function, $url, $params = null, $decodeJson = true) { + if (empty($params)) { + $params = new stdClass(); + } return self::getcURL($function, $url, $params, $decodeJson, 'PUT'); } @@ -1519,8 +1560,8 @@ public static function getFolderSize() } catch (Exception $e) { return 0; } - $t1 = microtime(true); - log::add(__CLASS__, 'debug', "║ Taille du dossier calculée via PHP : " . round($size / (1024 * 1024), 2) . " Mo en " . round($t1 - $t0, 2) . "s"); + $t1 = microtime(true); + log::add(__CLASS__, 'debug', "║ Taille du dossier calculée via PHP : " . round($size / (1024 * 1024), 2) . " Mo en " . round($t1 - $t0, 2) . "s"); return round($size / (1024 * 1024), 2); } @@ -2021,33 +2062,33 @@ private static function updateCommands($eqlogicId, $type, $frigateEvent) { log::add(__CLASS__, 'debug', "║ MAJ Commandes pour le type : $type"); - $update = function ($label, $subtype, $unit, $logicalId, $value) use ($eqlogicId) { - $cmd = self::createCmd($eqlogicId, $label, $subtype, $unit, $logicalId, "", 0, null, 0); + $update = function ($label, $subtype, $unit, $logicalId, $genericType, $value) use ($eqlogicId) { + $cmd = self::createCmd($eqlogicId, $label, $subtype, $unit, $logicalId, $genericType, 0, null, 0); $cmd->save(); $cmd->event($value ?? ''); $cmd->save(); }; - $update("Reconnaissance - Type", "string", "", "info_detection_type", $type); + $update("Reconnaissance - Type", "string", "", "info_detection_type", "", $type); $withNameScore = ['face', 'lpr', 'classification']; if (in_array($type, $withNameScore)) { - $update("Reconnaissance - Nom", "string", "", "info_detection_name", $frigateEvent->getRecognition_name()); - $update("Reconnaissance - Score", "numeric", "%", "info_detection_score", $frigateEvent->getRecognition_score()); + $update("Reconnaissance - Nom", "string", "", "info_detection_name", "", $frigateEvent->getRecognition_name()); + $update("Reconnaissance - Score", "numeric", "%", "info_detection_score", "", $frigateEvent->getRecognition_score()); } if ($type === 'description') { log::add(__CLASS__, 'debug', "║ Mise à jour de la description : " . $frigateEvent->getRecognition_description()); - $update("Reconnaissance - Description", "string", "", "info_description", $frigateEvent->getRecognition_description()); + $update("Reconnaissance - Description", "string", "", "info_description", "", $frigateEvent->getRecognition_description()); } if ($type === 'lpr') { - $update("Reconnaissance - Plaque d'immatriculation", "string", "", "info_plate", $frigateEvent->getRecognition_plate()); + $update("Reconnaissance - Plaque d'immatriculation", "string", "", "info_plate", "", $frigateEvent->getRecognition_plate()); } if ($type === 'classification') { - $update("Reconnaissance - Label", "string", "", "info_detection_subname", $frigateEvent->getRecognition_subname()); - $update("Reconnaissance - Attributs", "string", "", "info_detection_attributes", $frigateEvent->getRecognition_attributes()); + $update("Reconnaissance - Label", "string", "", "info_detection_subname", "", $frigateEvent->getRecognition_subname()); + $update("Reconnaissance - Attributs", "string", "", "info_detection_attributes", "", $frigateEvent->getRecognition_attributes()); } } @@ -3164,7 +3205,7 @@ public static function handleMqttMessage($_message) if (version_compare($version, "0.14", "<")) { log::add("frigate_MQTT", 'info', ' => Traitement mqtt events <0.14'); log::add("frigate_MQTT", 'warning', ' => Version < 0.14, mettre à jour votre serveur frigate !'); - message::add("frigate",__("Version de Frigate détectée : " . $version . ", certaines fonctionnalités du plugin peuvent ne pas fonctionner correctement. Veuillez mettre à jour votre serveur Frigate pour une expérience optimale.", __FILE__)); + message::add("frigate", __("Version de Frigate détectée : " . $version . ", certaines fonctionnalités du plugin peuvent ne pas fonctionner correctement. Veuillez mettre à jour votre serveur Frigate pour une expérience optimale.", __FILE__)); self::getEvents(true, [$value['after']], $value['type']); event::add('frigate::events', array('message' => 'mqtt_update', 'type' => 'event')); } diff --git a/core/template/dashboard/widgetCamera.html b/core/template/dashboard/widgetCamera.html index 8489a2b0..779c2a22 100644 --- a/core/template/dashboard/widgetCamera.html +++ b/core/template/dashboard/widgetCamera.html @@ -112,6 +112,7 @@ function startImageFetchInterval() { if (!intervalId) { intervalId = setInterval(refreshImage, #refresh#); + console.log('Interval started for camera #id# with refresh rate: ' + #refresh# + ' ms'); } } diff --git a/core/template/dashboard/widgetPanel.html b/core/template/dashboard/widgetPanel.html index 35e82fed..b026c790 100644 --- a/core/template/dashboard/widgetPanel.html +++ b/core/template/dashboard/widgetPanel.html @@ -108,7 +108,8 @@ function startImageFetchInterval() { if (!intervalId) { - intervalId = setInterval(refreshImage, #refresh#); + intervalId = setInterval(refreshImage, #refresh#); + console.log('Interval started for camera #id# with refresh rate: ' + #refresh# + ' ms'); } } diff --git a/desktop/js/frigate.js b/desktop/js/frigate.js index 4d73ab36..d643b026 100644 --- a/desktop/js/frigate.js +++ b/desktop/js/frigate.js @@ -528,9 +528,24 @@ function printEqLogic(_eqLogic) { observer.observe(imgElement); function startImageFetchInterval() { - if (!intervalId) { - intervalId = setInterval(refreshImage, refresh); + const eqRefresh = $('.eqLogicAttr[data-l1key="configuration"]') + .filter(function () { + return $(this).attr('data-l2key') === 'normal::refresh'; + }) + .val(); + refreshSnap = refresh; + if (eqRefresh && !isNaN(eqRefresh) && eqRefresh > 0) { + refreshSnap = eqRefresh * 1000; } + + // On arrête toujours l'intervalle existant avant d'en créer un nouveau + if (intervalId) { + clearInterval(intervalId); + intervalId = null; + } + + console.log('Refresh interval in milliseconds: ' + refreshSnap); + intervalId = setInterval(refreshImage, refreshSnap); } function stopImageFetchInterval() { @@ -657,12 +672,12 @@ document.getElementById('addCmdHttp').addEventListener('click', function () { }, dataType: 'json', - error: function (error) { - jeedomUtils.showAlert({ - message: error.message, - level: 'danger' - }); - }, + error: function (error) { + jeedomUtils.showAlert({ + message: error.message, + level: 'danger' + }); + }, success: function (data) { jeedomUtils.showAlert({ message: '{{Création de la commande réussie.}}', @@ -698,12 +713,12 @@ function editHTTP(cmd) { }, dataType: 'json', - error: function (error) { - jeedomUtils.showAlert({ - message: error.message, - level: 'danger' - }); - }, + error: function (error) { + jeedomUtils.showAlert({ + message: error.message, + level: 'danger' + }); + }, success: function (data) { jeedomUtils.showAlert({ message: '{{Modification de la commande réussie.}}', diff --git a/desktop/php/frigate.php b/desktop/php/frigate.php index 5f5aacd9..229f7da6 100644 --- a/desktop/php/frigate.php +++ b/desktop/php/frigate.php @@ -13,7 +13,6 @@ sendVarToJS('frigateURL', $urlFrigate); $urlExterne = config::byKey('URLexterne', 'frigate'); sendVarToJS('frigateURLexterne', $urlExterne); - $refresh = (float)(config::byKey('refresh_snapshot', 'frigate')) * 1000; sendVarToJS('refresh', $refresh); ?> @@ -209,6 +208,17 @@ +