Skip to content

Commit f1bd5aa

Browse files
committed
Fix miniature panel
1 parent 2b5709d commit f1bd5aa

File tree

1 file changed

+44
-41
lines changed

1 file changed

+44
-41
lines changed

core/class/frigate.class.php

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private static function isFrigateServerAvailable()
192192
public static function cron()
193193
{
194194
if (!self::isFrigateServerAvailable()) {
195-
log::add(__CLASS__, 'warning', "Le serveur Frigate n'est pas disponible. Cron non exécuté.");
195+
log::add(__CLASS__, "warning", "Le serveur Frigate n'est pas disponible. Cron non exécuté.");
196196
return;
197197
}
198198
self::checkFrigateStatus();
@@ -202,7 +202,7 @@ public static function cron()
202202
public static function cron5()
203203
{
204204
if (!self::isFrigateServerAvailable()) {
205-
log::add(__CLASS__, 'warning', "Le serveur Frigate n'est pas disponible. Cron5 non exécuté.");
205+
log::add(__CLASS__, "warning", "Le serveur Frigate n'est pas disponible. Cron5 non exécuté.");
206206
return;
207207
}
208208
self::checkFrigateStatus();
@@ -212,7 +212,7 @@ public static function cron5()
212212
public static function cron10()
213213
{
214214
if (!self::isFrigateServerAvailable()) {
215-
log::add(__CLASS__, 'warning', "Le serveur Frigate n'est pas disponible. Cron10 non exécuté.");
215+
log::add(__CLASS__, "warning", "Le serveur Frigate n'est pas disponible. Cron10 non exécuté.");
216216
return;
217217
}
218218
self::checkFrigateStatus();
@@ -222,7 +222,7 @@ public static function cron10()
222222
public static function cron15()
223223
{
224224
if (!self::isFrigateServerAvailable()) {
225-
log::add(__CLASS__, 'warning', "Le serveur Frigate n'est pas disponible. Cron15 non exécuté.");
225+
log::add(__CLASS__, "warning", "Le serveur Frigate n'est pas disponible. Cron15 non exécuté.");
226226
return;
227227
}
228228
self::checkFrigateStatus();
@@ -232,7 +232,7 @@ public static function cron15()
232232
public static function cron30()
233233
{
234234
if (!self::isFrigateServerAvailable()) {
235-
log::add(__CLASS__, 'warning', "Le serveur Frigate n'est pas disponible. Cron30 non exécuté.");
235+
log::add(__CLASS__, "warning", "Le serveur Frigate n'est pas disponible. Cron30 non exécuté.");
236236
return;
237237
}
238238
self::checkFrigateStatus();
@@ -242,7 +242,7 @@ public static function cron30()
242242
public static function cronHourly()
243243
{
244244
if (!self::isFrigateServerAvailable()) {
245-
log::add(__CLASS__, 'warning', "Le serveur Frigate n'est pas disponible. CronHourly non exécuté.");
245+
log::add(__CLASS__, "warning", "Le serveur Frigate n'est pas disponible. CronHourly non exécuté.");
246246
return;
247247
}
248248
self::checkFrigateStatus();
@@ -252,7 +252,7 @@ public static function cronHourly()
252252
public static function cronDaily()
253253
{
254254
if (!self::isFrigateServerAvailable()) {
255-
log::add(__CLASS__, 'warning', "Le serveur Frigate n'est pas disponible. CronDaily non exécuté.");
255+
log::add(__CLASS__, "warning", "Le serveur Frigate n'est pas disponible. CronDaily non exécuté.");
256256
return;
257257
}
258258
self::checkFrigateStatus();
@@ -785,12 +785,12 @@ public static function getUrlFrigate()
785785
{
786786
$url = config::byKey('URL', 'frigate');
787787
if ($url == "") {
788-
log::add(__CLASS__, 'error', "║ Erreur: L'URL ne peut être vide.");
788+
log::add(__CLASS__, "error", "║ Erreur: L'URL ne peut être vide.");
789789
return false;
790790
}
791791
$port = config::byKey('port', 'frigate');
792792
if ($port == "") {
793-
log::add(__CLASS__, 'error', "║ Erreur: Le port ne peut être vide");
793+
log::add(__CLASS__, "error", "║ Erreur: Le port ne peut être vide");
794794
return false;
795795
}
796796
$urlFrigate = $url . ":" . $port;
@@ -844,7 +844,7 @@ private static function getcURL($function, $url, $params = null, $decodeJson = t
844844
$data = curl_exec($ch);
845845

846846
if (curl_errno($ch)) {
847-
log::add(__CLASS__, 'error', "║ Erreur getcURL (" . $method . "): " . curl_error($ch));
847+
log::add(__CLASS__, "error", "║ Erreur getcURL (" . $method . "): " . curl_error($ch));
848848
return null;
849849
}
850850
curl_close($ch);
@@ -873,7 +873,7 @@ private static function deletecURL($url)
873873
$data = curl_exec($ch);
874874

875875
if (curl_errno($ch)) {
876-
log::add(__CLASS__, 'error', "║ Erreur: deletecURL" . curl_error($ch));
876+
log::add(__CLASS__, "error", "║ Erreur: deletecURL" . curl_error($ch));
877877
die();
878878
}
879879
curl_close($ch);
@@ -1123,6 +1123,7 @@ public static function getEvents($mqtt = false, $events = array(), $type = 'end'
11231123
$updated = false;
11241124

11251125
$fieldsToUpdate = [
1126+
'StartTime' => $infos["startTime"] ?? $infos['endTime'],
11261127
'EndTime' => $infos["endTime"],
11271128
'HasClip' => $infos["hasClip"],
11281129
'Clip' => $infos["clip"],
@@ -1135,6 +1136,7 @@ public static function getEvents($mqtt = false, $events = array(), $type = 'end'
11351136
'PlusId' => $event['plus_id'],
11361137
'SubLabel' => $event['sub_label'],
11371138
'Thumbnail' => $infos["thumbnail"],
1139+
'Lasted' => $infos["image"],
11381140
'Type' => $type,
11391141
'TopScore' => $infos["topScore"],
11401142
'Score' => $infos["score"],
@@ -1251,10 +1253,10 @@ public static function getEventInfos($mqtt, $event, $force = false, $type = "end
12511253
// Fonction de vérification et téléchargement
12521254
sleep($sleep);
12531255
$img = self::processImage($dir, $event, true, $force);
1254-
log::add(__CLASS__, 'warning', "║ Thumbnail: " . json_encode($img));
1256+
log::add(__CLASS__, "debug", "║ Thumbnail: " . json_encode($img));
12551257

12561258
$snapshot = self::processImage($dir, $event, false, $force);
1257-
log::add(__CLASS__, 'warning', "║ Snapshot: " . json_encode($snapshot));
1259+
log::add(__CLASS__, "debug", "║ Snapshot: " . json_encode($snapshot));
12581260

12591261
$clip = self::processClip($dir, $event, $type, $force);
12601262
self::processPreview($dir, $event);
@@ -1491,14 +1493,14 @@ public static function cleanFolderData()
14911493
if (unlink($path)) {
14921494
log::add(__CLASS__, 'debug', "║ Suppresion reussie: " . $path);
14931495
} else {
1494-
log::add(__CLASS__, 'error', "║ Suppresion echouée: " . $path);
1496+
log::add(__CLASS__, "error", "║ Suppresion echouée: " . $path);
14951497
}
14961498
}
14971499
}
14981500
}
14991501
}
15001502
} else {
1501-
log::add(__CLASS__, 'error', "║ Dossier inexistant: " . $folder);
1503+
log::add(__CLASS__, "error", "║ Dossier inexistant: " . $folder);
15021504
}
15031505
}
15041506

@@ -1510,11 +1512,11 @@ public static function cleanAllOldestFiles()
15101512
$days = config::byKey('remove_days', 'frigate', "7");
15111513
$recoveryDays = config::byKey('recovery_days', 'frigate', "7");
15121514
if (!is_numeric($days) || $days <= 0) {
1513-
log::add(__CLASS__, 'error', "║ Configuration invalide pour 'remove_days': " . $days . " Cela doit être un nombre positif.");
1515+
log::add(__CLASS__, "error", "║ Configuration invalide pour 'remove_days': " . $days . " Cela doit être un nombre positif.");
15141516
return;
15151517
}
15161518
if ($days < $recoveryDays) {
1517-
log::add(__CLASS__, 'warning', "║ 'remove_days' doit être supérieur à 'recovery_days'");
1519+
log::add(__CLASS__, "warning", "║ 'remove_days' doit être supérieur à 'recovery_days'");
15181520
$days = $recoveryDays;
15191521
}
15201522
log::add(__CLASS__, 'info', "║ Nettoyage des fichiers datant de plus de " . $days . " jours.");
@@ -1532,7 +1534,7 @@ public static function cleanAllOldestFiles()
15321534
if ($result) {
15331535
log::add(__CLASS__, 'info', "║ Événement ID: " . $eventId . " nettoyé avec succès.");
15341536
} else {
1535-
log::add(__CLASS__, 'error', "║ Échec du nettoyage de l'événement ID: " . $eventId);
1537+
log::add(__CLASS__, "error", "║ Échec du nettoyage de l'événement ID: " . $eventId);
15361538
}
15371539
}
15381540
} else {
@@ -1555,7 +1557,7 @@ public static function cleanByType($type = "new")
15551557
if ($result) {
15561558
log::add(__CLASS__, 'info', "║ Événement ID: " . $eventId . " nettoyé avec succès.");
15571559
} else {
1558-
log::add(__CLASS__, 'error', "║ Échec du nettoyage de l'événement ID: " . $eventId);
1560+
log::add(__CLASS__, "error", "║ Échec du nettoyage de l'événement ID: " . $eventId);
15591561
}
15601562
}
15611563
}
@@ -1773,14 +1775,14 @@ public static function generateAllEqs()
17731775
log::add(__CLASS__, 'debug', "╔════════════════════════ :fg-success:CREATION DES EQUIPEMENTS:/fg: ═══════════════════");
17741776
$urlfrigate = self::getUrlFrigate();
17751777
if (empty($urlfrigate)) {
1776-
log::add(__CLASS__, 'error', "║ Impossible de récupérer l'URL de Frigate.");
1778+
log::add(__CLASS__, "error", "║ Impossible de récupérer l'URL de Frigate.");
17771779
log::add(__CLASS__, 'debug', "╚════════════════════════ :fg-warning:ERREURS DANS LA CONFIGURATION:/fg: ═══════════════════");
17781780
return false;
17791781
}
17801782
// récupérer le json de configuration
17811783
$configurationArray = self::jsonFromUrl("http://" . $urlfrigate . "/api/config");
17821784
if ($configurationArray == null) {
1783-
log::add(__CLASS__, 'error', "║ Impossible de récupérer le fichier de configuration de Frigate.");
1785+
log::add(__CLASS__, "error", "║ Impossible de récupérer le fichier de configuration de Frigate.");
17841786
log::add(__CLASS__, 'debug', "╚════════════════════════ :fg-warning:ERREURS DANS LA CONFIGURATION:/fg: ═══════════════════");
17851787
return false;
17861788
}
@@ -1996,7 +1998,7 @@ public static function updateTrackedObjects($trackedObjects)
19961998
// Vérification équipement Frigate
19971999
$frigate = frigate::byLogicalId("eqFrigateCamera_" . $camera, 'frigate');
19982000
if (!is_object($frigate)) {
1999-
log::add(__CLASS__, 'error', "║ Équipement introuvable pour la caméra : $camera");
2001+
log::add(__CLASS__, "error", "║ Équipement introuvable pour la caméra : $camera");
20002002
return;
20012003
}
20022004

@@ -2019,11 +2021,12 @@ public static function updateTrackedObjects($trackedObjects)
20192021

20202022
private static function updateDatabase($frigateEvent, $type, $trackedObjects)
20212023
{
2024+
$id = $trackedObjects['id'] ?? null;
20222025
if (!is_object($frigateEvent)) {
2023-
log::add(__CLASS__, 'error', "║ Événement introuvable pour l'ID : $id, il est créé dans la DB.");
2026+
log::add(__CLASS__, "error", "║ Événement introuvable (id: $id), il sera est créé dans la DB.");
20242027
$frigateEvent = new frigate_events();
20252028
$frigateEvent->setCamera($trackedObjects['camera']);
2026-
$frigateEvent->setEventId($trackedObjects['id']);
2029+
$frigateEvent->setEventId($id);
20272030
}
20282031

20292032
switch ($type) {
@@ -3156,7 +3159,7 @@ public static function getConfig()
31563159
log::add(__CLASS__, 'debug', "╚════════════════════════ :fg-warning:ERREURS:/fg: ═══════════════════");
31573160
return false;
31583161
} else if ($config == null) {
3159-
log::add(__CLASS__, 'error', "║Erreur: Impossible de récupérer la configuration de Frigate.");
3162+
log::add(__CLASS__, "error", "║Erreur: Impossible de récupérer la configuration de Frigate.");
31603163
log::add(__CLASS__, 'debug', "╚════════════════════════ :fg-warning:ERREURS:/fg: ═══════════════════");
31613164
return false;
31623165
} else {
@@ -3513,7 +3516,7 @@ public static function getFrigateConfiguration()
35133516
if ($curlResponse === false) {
35143517
$error = 'Erreur cURL : ' . curl_error($ch);
35153518
curl_close($ch);
3516-
log::add(__CLASS__, 'error', '║ getFrigateConfiguration :: ' . $error);
3519+
log::add(__CLASS__, "error", '║ getFrigateConfiguration :: ' . $error);
35173520
$response = array(
35183521
'status' => 'error',
35193522
'message' => $error
@@ -3526,7 +3529,7 @@ public static function getFrigateConfiguration()
35263529
if ($httpCode != 200) {
35273530
$error = 'Erreur : Impossible de récupérer la configuration. Code de statut : ' . $httpCode;
35283531
curl_close($ch);
3529-
log::add(__CLASS__, 'error', '║ getFrigateConfiguration :: ' . $error);
3532+
log::add(__CLASS__, "error", '║ getFrigateConfiguration :: ' . $error);
35303533
$response = array(
35313534
'status' => 'error',
35323535
'message' => $error
@@ -3571,7 +3574,7 @@ public static function sendFrigateConfiguration($frigateConfiguration, $restart
35713574
if ($curlResponse === false) {
35723575
$error = 'Erreur cURL : ' . curl_error($ch);
35733576
curl_close($ch);
3574-
log::add(__CLASS__, 'error', '║ sendFrigateConfiguration :: ' . $error);
3577+
log::add(__CLASS__, "error", '║ sendFrigateConfiguration :: ' . $error);
35753578
$response = array(
35763579
'status' => 'error',
35773580
'message' => $error
@@ -3584,7 +3587,7 @@ public static function sendFrigateConfiguration($frigateConfiguration, $restart
35843587
if ($httpCode != 200) {
35853588
$error = 'Erreur : Impossible de sauvegarder la configuration. Code de statut : ' . $httpCode;
35863589
curl_close($ch);
3587-
log::add(__CLASS__, 'error', '║ sendFrigateConfiguration :: ' . $error);
3590+
log::add(__CLASS__, "error", '║ sendFrigateConfiguration :: ' . $error);
35883591
$response = array(
35893592
'status' => 'error',
35903593
'message' => $error
@@ -3612,12 +3615,12 @@ private static function jsonFromUrl($jsonUrl)
36123615
$jsonContent = file_get_contents($jsonUrl);
36133616
} else {
36143617
$jsonContent = false;
3615-
log::add(__CLASS__, 'error', "║ jsonFromUrl : HTTP Error $code lors du téléchargement de $jsonUrl");
3618+
log::add(__CLASS__, "error", "║ jsonFromUrl : HTTP Error $code lors du téléchargement de $jsonUrl");
36163619
}
36173620

36183621
// Vérifier si le téléchargement a réussi
36193622
if ($jsonContent === false) {
3620-
log::add(__CLASS__, 'error', "║ jsonFromUrl : Failed to retrieve JSON from URL");
3623+
log::add(__CLASS__, "error", "║ jsonFromUrl : Failed to retrieve JSON from URL");
36213624
return null;
36223625
}
36233626

@@ -3626,7 +3629,7 @@ private static function jsonFromUrl($jsonUrl)
36263629

36273630
// Vérifier si la conversion a réussi
36283631
if ($jsonArray === null && json_last_error() !== JSON_ERROR_NONE) {
3629-
log::add(__CLASS__, 'error', "║ jsonFromUrl : Failed to decode JSON content");
3632+
log::add(__CLASS__, "error", "║ jsonFromUrl : Failed to decode JSON content");
36303633
return null;
36313634
}
36323635

@@ -3639,14 +3642,14 @@ private static function jsonFromUrl($jsonUrl)
36393642
$yamlContent = file_get_contents($yamlUrl);
36403643
// Vérifier si le téléchargement a réussi
36413644
if ($yamlContent === false) {
3642-
log::add(__CLASS__, 'error', "yamlToJsonFromUrl : Failed to retrieve YAML from URL");
3645+
log::add(__CLASS__, "error", "yamlToJsonFromUrl : Failed to retrieve YAML from URL");
36433646
return json_encode(["error" => "Failed to retrieve YAML from URL: $yamlUrl"]);
36443647
}
36453648
// Parser le contenu YAML
36463649
$yamlArray = yaml_parse($yamlContent);
36473650
// Vérifier si le parsing est réussi
36483651
if ($yamlArray === false) {
3649-
log::add(__CLASS__, 'error', "yamlToJsonFromUrl : Invalid YAML content or file not found");
3652+
log::add(__CLASS__, "error", "yamlToJsonFromUrl : Invalid YAML content or file not found");
36503653
return json_encode(["error" => "Invalid YAML content or file not found"]);
36513654
}
36523655
// Convertir le tableau PHP en JSON
@@ -3691,7 +3694,7 @@ private static function checkFrigateVersion()
36913694
$resultURL = $urlfrigate . "/api/stats";
36923695
$stats = self::getcURL("Stats", $resultURL);
36933696
if ($stats == null) {
3694-
log::add(__CLASS__, 'error', "║ Erreur: Impossible de récupérer les stats de Frigate.");
3697+
log::add(__CLASS__, "error", "║ Erreur: Impossible de récupérer les stats de Frigate.");
36953698
log::add(__CLASS__, 'debug', "╚════════════════════════ :fg-warning:ERREURS:/fg: ═══════════════════");
36963699
return;
36973700
}
@@ -3709,16 +3712,16 @@ public static function getPluginVersion()
37093712
$pluginVersion = '0.0.0';
37103713
try {
37113714
if (!file_exists(dirname(__FILE__) . '/../../plugin_info/info.json')) {
3712-
log::add('frigate', 'warning', '[Plugin-Version] fichier info.json manquant');
3715+
log::add('frigate', "warning", '[Plugin-Version] fichier info.json manquant');
37133716
}
37143717
$data = json_decode(file_get_contents(dirname(__FILE__) . '/../../plugin_info/info.json'), true);
37153718
if (!is_array($data)) {
3716-
log::add('frigate', 'warning', '[Plugin-Version] Impossible de décoder le fichier info.json');
3719+
log::add('frigate', "warning", '[Plugin-Version] Impossible de décoder le fichier info.json');
37173720
}
37183721
try {
37193722
$pluginVersion = $data['pluginVersion'];
37203723
} catch (\Exception $e) {
3721-
log::add('frigate', 'warning', '[Plugin-Version] Impossible de récupérer la version du plugin');
3724+
log::add('frigate', "warning", '[Plugin-Version] Impossible de récupérer la version du plugin');
37223725
}
37233726
} catch (\Exception $e) {
37243727
log::add('frigate', 'debug', '[Plugin-Version] Get ERROR :: ' . $e->getMessage());
@@ -3973,7 +3976,7 @@ public function execute($_options = array())
39733976
if ($response !== false) {
39743977
$frigate->getCmd(null, 'info_http')->event($response);
39753978
} else {
3976-
log::add('frigate', 'error', "Erreur lors de l'appel HTTP: $link");
3979+
log::add('frigate', "error", "Erreur lors de l'appel HTTP: $link");
39773980
}
39783981
break;
39793982
default:
@@ -3983,7 +3986,7 @@ public function execute($_options = array())
39833986
if ($response !== false) {
39843987
$frigate->getCmd(null, 'info_http')->event($response);
39853988
} else {
3986-
log::add('frigate', 'error', "Erreur lors de l'appel HTTP: $link");
3989+
log::add('frigate', "error", "Erreur lors de l'appel HTTP: $link");
39873990
}
39883991
}
39893992
}
@@ -4005,7 +4008,7 @@ private function getCurlcmd($link, $username, $password)
40054008
$response = curl_exec($ch);
40064009

40074010
if (curl_errno($ch)) {
4008-
log::add('frigate', 'error', "Erreur cURL: " . curl_error($ch));
4011+
log::add('frigate', "error", "Erreur cURL: " . curl_error($ch));
40094012
} else {
40104013
log::add('frigate', 'debug', "║ Resultat de la commande HTTP : " . $response);
40114014
}

0 commit comments

Comments
 (0)