diff --git a/core/ajax/mobile.ajax.php b/core/ajax/mobile.ajax.php index 378aca98..535bbbfb 100755 --- a/core/ajax/mobile.ajax.php +++ b/core/ajax/mobile.ajax.php @@ -59,7 +59,7 @@ } ajax::success($return); } - + if (init('action') == 'getNotificationsV2') { $return = ''; $iq = init('iq'); @@ -71,8 +71,8 @@ } if (init('action') == 'removeNotificationV2') { - ajax::success(mobile::removeNotificationV2(init('iq', ''), init('id', ''))); - } + ajax::success(mobile::removeNotificationV2(init('iq', ''), init('id', ''))); + } // APP V1 diff --git a/core/api/mobile.api.php b/core/api/mobile.api.php index 1a2f6076..169f93d0 100755 --- a/core/api/mobile.api.php +++ b/core/api/mobile.api.php @@ -26,17 +26,17 @@ } $params = $jsonrpc->getParams(); -log::add('mobile', 'debug', '┌──────────▶︎ :fg-warning: Appel API Mobile :/fg: ◀︎───────────'); -log::add('mobile', 'debug', '| Method > ' . $jsonrpc->getMethod()); +log::add('mobile', 'debug', '┌──────────▶︎ :fg-warning:Appel API Mobile:/fg: ◀︎─────────────'); +log::add('mobile', 'debug', '| Method ─▶︎ ' . $jsonrpc->getMethod()); $secureApikeyLog = $params; if (isset($secureApikeyLog['apikey'])) $secureApikeyLog['apikey'] = substr($secureApikeyLog['apikey'], 0, 10) . '...'; -log::add('mobile', 'debug', '| Paramètres passés > ' . json_encode($secureApikeyLog)); +log::add('mobile', 'debug', '| Paramètres passés ─▶︎ ' . json_encode($secureApikeyLog)); if ($params['Iq']) { if (mobile::whoIsIq($params['Iq']) == 'mobile non detecte') { //createMobile($params, 3); log::add('mobile', 'debug', '| [WARNING] mobile non detecté !'); } else { - log::add('mobile', 'debug', '| Mobile demandeur ' . mobile::whoIsIq($params['Iq'])); + log::add('mobile', 'debug', '| Mobile demandeur : ' . mobile::whoIsIq($params['Iq'])); } } else { log::add('mobile', 'debug', '| [WARNING] Paramètre Iq inexistant !'); @@ -123,14 +123,14 @@ function saveMenuFromAppV2($menu, $mobile) * @return string ok makeSuccess */ if ($jsonrpc->getMethod() == 'setConfigs') { - log::add('mobile', 'debug', '┌─────▶︎ AppV2 setConfigs ─────────────────'); + log::add('mobile', 'debug', '┌──────────▶︎ AppV2 setConfigs ──────────────'); $configs = $params['configs']; $geolocs = $params['geolocs']; $menu = $configs['menu']; $notification = $configs['notification']; - log::add('mobile', 'debug', '| [INFO] Configs > ' . json_encode($configs)); - log::add('mobile', 'debug', '| [INFO] Geolocs > ' . json_encode($geolocs)); - //log::add('mobile', 'debug', '| [INFO] Menu > ' . json_encode($menu)); + log::add('mobile', 'debug', '| [INFO] Configs ─▶︎ ' . json_encode($configs)); + log::add('mobile', 'debug', '| [INFO] Geolocs ─▶︎ ' . json_encode($geolocs)); + //log::add('mobile', 'debug', '| [INFO] Menu ─▶︎ ' . json_encode($menu)); log::add('mobile', 'debug', '| [INFO] Notification ─▶︎ ' . json_encode($notification)); $mobile = null; if (isset($params['Iq'])) { @@ -192,7 +192,7 @@ function saveMenuFromAppV2($menu, $mobile) * @return string ok makeSuccess */ if ($jsonrpc->getMethod() == 'setCustomMenu') { - log::add('mobile', 'debug', '┌─────▶︎ AppV2 setCustomMenu ─────────────────'); + log::add('mobile', 'debug', '┌──────────▶︎ AppV2 setCustomMenu ───────────'); $configs = $params['configs']; $menu = $configs['menu']; log::add('mobile', 'debug', '| [INFO] Configs ─▶︎ ' . json_encode($configs)); @@ -214,7 +214,7 @@ function saveMenuFromAppV2($menu, $mobile) * @return array makeSuccess */ if ($jsonrpc->getMethod() == 'getPlugins') { - log::add('mobile', 'debug', '┌─────◀︎ AppV2 getPlugins Infos ────────────────────'); + log::add('mobile', 'debug', '┌──────────◀︎ AppV2 getPlugins Infos ────────'); $idBox = jeedom::getHardwareKey(); $return = []; $arrayPlugins = []; @@ -267,7 +267,7 @@ function saveMenuFromAppV2($menu, $mobile) */ if ($jsonrpc->getMethod() == 'getJson') { - log::add('mobile', 'debug', '┌─────◀︎ AppV2 getJson ────────────────────'); + log::add('mobile', 'debug', '┌──────────◀︎ AppV2 getJson ──────────────────'); $registerDevice = $_USER_GLOBAL->getOptions('registerDevice', array()); if (!is_array($registerDevice)) { $registerDevice = array(); @@ -342,7 +342,7 @@ function saveMenuFromAppV2($menu, $mobile) $return[$idBox]['configs'] = array(); $return[$idBox]['miscellanousParams'] = array(); if (is_object($mobile)) { - log::add('mobile', 'debug', '| OK Mobile trouvé > ' . $mobile->getName()); + log::add('mobile', 'debug', '| OK Mobile trouvé ─▶︎ ' . $mobile->getName()); $return[$idBox]['configs']['menu'] = $mobile->configMenuCustom(); $return[$idBox]['miscellanousParams']['hideMenuCustom'] = intval($mobile->getConfiguration('hideMenuCustom', 0)); $return[$idBox]['miscellanousParams']['hideMenuGeoloc'] = intval($mobile->getConfiguration('hideMenuGeoloc', 0)); @@ -353,8 +353,8 @@ function saveMenuFromAppV2($menu, $mobile) $return[$idBox]['miscellanousParams']['hideMenuGeoloc'] = 0; $return[$idBox]['miscellanousParams']['sendNFCDirectly'] = 1; } - log::add('mobile', 'debug', '| [INFO] CustomENVOICONFIGSAPI GETJSON > ' . json_encode($return[$idBox]['configs'])); - log::add('mobile', 'debug', '| [INFO] Retour vers App > ' . json_encode($return)); + log::add('mobile', 'debug', '| [INFO] CustomENVOICONFIGSAPI GETJSON ─▶︎ ' . json_encode($return[$idBox]['configs'])); + log::add('mobile', 'debug', '| [INFO] Retour vers APP ─▶︎ ' . json_encode($return)); log::add('mobile', 'debug', '└───────────────────────────────────────────'); $jsonrpc->makeSuccess($return); @@ -366,8 +366,8 @@ function saveMenuFromAppV2($menu, $mobile) * @return array makeSuccess */ if ($jsonrpc->getMethod() == 'getCustomMenu') { - log::add('mobile', 'debug', '┌─────◀︎ AppV2 getCustomMenu ────────────────────'); - log::add('mobile', 'debug', '| Recherche du mobile via sont Iq ─▶︎ ' . $params['Iq']); + log::add('mobile', 'debug', '┌──────────◀︎ AppV2 getCustomMenu ───────────'); + log::add('mobile', 'debug', '| Recherche du mobile via sont Iq > ' . $params['Iq']); $mobile = eqLogic::byLogicalId($params['Iq'], 'mobile'); if (is_object($mobile)) { log::add('mobile', 'debug', '| OK Mobile trouvé ─▶︎ ' . $mobile->getName()); @@ -450,7 +450,7 @@ function saveMenuFromAppV2($menu, $mobile) * @return makeSuccess */ if ($jsonrpc->getMethod() == 'askText') { - log::add('mobile', 'debug', '┌─────▶︎ ASK ───────────────────────────────'); + log::add('mobile', 'debug', '┌──────────▶︎ ASK ───────────────────────────'); /*$configs = $params['configs']; $menu = $configs['menu']; $notification = $configs['notification'];*/ @@ -486,12 +486,12 @@ function saveMenuFromAppV2($menu, $mobile) * @return string ok */ if ($jsonrpc->getMethod() == 'getAskResponse') { - log::add('mobile', 'debug', '┌────▶︎ getAskResponse ────────────────────'); + log::add('mobile', 'debug', '┌──────────▶︎ getAskResponse ────────────────'); $Iq = $params['Iq']; $filePath = dirname(__FILE__) . '/../data/notifications/' . $Iq . '.json'; $idNotif = $params['idNotif']; $choiceAsk = $params['choiceAsk']; - log::add('mobile', 'debug', '| Réponse ASK ─▶︎ ' . $Iq . ' > ' . $idNotif . ' > ' . $choiceAsk); + log::add('mobile', 'debug', '| Réponse ASK ─▶︎ ' . $Iq . ' > ' . $idNotif . ' ─▶︎ ' . $choiceAsk); if (file_exists($filePath)) { $notifications = file_get_contents($filePath); $notificationsArray = json_decode($notifications, true); @@ -514,60 +514,63 @@ function saveMenuFromAppV2($menu, $mobile) * @return makeSuccess */ if ($jsonrpc->getMethod() == 'mobile::geoloc') { - log::add('mobile', 'debug', '┌─────▶︎ GeoLocV2 geofencing ───────────────'); + log::add('mobile', 'debug', '┌──────────▶︎ GeoLocV2 geofencing ───────────'); $mobile = eqLogic::byLogicalId($params['Iq'], 'mobile'); if (is_object($mobile)) { - if (isset($params['transmition']) && isset($params['transmition']['extras']) && isset($params['transmition']['extras']['method'])) { - if ($params['transmition']['extras']['method'] == 'getDeviceInformations') { - log::add('mobile', 'debug', '| ───:fg-success: methodeForSpecificChannel in Background :/fg: ───'); - $mobile->cmdForSpecificChannel($params, 'transmition'); - } - } else if (isset($params['transmition']) && isset($params['transmition']['event']) && $params['transmition']['event'] == 'geofence') { - log::add('mobile', 'debug', '| Event > ' . $params['transmition']['event']); - $geofence = $params['transmition']['geofence']; - log::add('mobile', 'debug', '| Event > ' . json_encode($geofence)); - log::add('mobile', 'debug', '| OK Mobile trouvé -> ' . $mobile->getName() . ' (' . $params['Iq'] . ')'); - $cmdgeoloc = cmd::byEqLogicIdAndLogicalId($mobile->getId(), 'geoloc_' . $geofence['identifier']); - if (is_object($cmdgeoloc)) { - if ($geofence['action'] == 'ENTER') { - log::add('mobile', 'debug', '| OK Commande "' . $cmdgeoloc->getName() . '" passée à 1'); - $cmdgeoloc->event(1); - } else if ($geofence['action'] == 'EXIT') { - log::add('mobile', 'debug', '| OK Commande "' . $cmdgeoloc->getName() . '" passée à 0'); - $cmdgeoloc->event(0); - } else { - log::add('mobile', 'debug', '| Event -> ' . $geofence['action']); + log::add('mobile', 'debug', '| OK Mobile trouvé ─▶︎ ' . $mobile->getName() . ' (' . $params['Iq'] . ')'); + if (isset($params['transmition'])) { + $mobile->cmdForSpecificChannel($params, 'transmition'); + if (isset($params['transmition']['event']) && $params['transmition']['event'] == 'geofence') { + log::add('mobile', 'debug', '| Event ─▶︎ ' . $params['transmition']['event']); + $geofence = $params['transmition']['geofence']; + log::add('mobile', 'debug', '| Event ─▶︎ ' . json_encode($geofence)); + $cmdgeoloc = cmd::byEqLogicIdAndLogicalId($mobile->getId(), 'geoloc_' . $geofence['identifier']); + if (is_object($cmdgeoloc)) { + if ($geofence['action'] == 'ENTER' || $geofence['action'] == 'EXIT') { + $eventAge = time() - intval(strtotime($geofence['timestamp'])); + if ($eventAge > 1800) { + log::add('mobile', 'debug', '| SKIP stale event (' . round($eventAge / 60) . 'min) ' . $geofence['action'] . ' geoloc_' . $geofence['identifier']); + } else { + $value = ($geofence['action'] == 'ENTER') ? 1 : 0; + log::add('mobile', 'debug', '| OK Commande "' . $cmdgeoloc->getName() . '" -> ' . $value); + $mobile->checkAndUpdateCmd('geoloc_' . $geofence['identifier'], $value); + } + } else { + log::add('mobile', 'debug', '| Event ─▶︎ ' . $geofence['action']); + } } - } - } else { - $transmitions = $params['transmition']; - $errorCount = 0; - foreach ($transmitions as $transmition) { - if (isset($transmition['event']) && $transmition['event'] == 'geofence') { - log::add('mobile', 'debug', '| Transmition :' . json_encode($params['transmition'])); - $geofence = $transmition['geofence']; - log::add('mobile', 'debug', '| Event > ' . json_encode($geofence)); - log::add('mobile', 'debug', '| OK Mobile trouvé -> ' . $mobile->getName() . ' (' . $params['Iq'] . ')'); - $cmdgeoloc = cmd::byEqLogicIdAndLogicalId($mobile->getId(), 'geoloc_' . $geofence['identifier']); - if (is_object($cmdgeoloc)) { - if ($geofence['action'] == 'ENTER') { - log::add('mobile', 'debug', '| OK Commande "' . $cmdgeoloc->getName() . '" passée à 1'); - $cmdgeoloc->event(1); - } else if ($geofence['action'] == 'EXIT') { - log::add('mobile', 'debug', '| OK Commande "' . $cmdgeoloc->getName() . '" passée à 0'); - $cmdgeoloc->event(0); + } else { + $transmitions = $params['transmition']; + $errorCount = 0; + foreach ($transmitions as $transmition) { + if (isset($transmition['event']) && $transmition['event'] == 'geofence') { + log::add('mobile', 'debug', '| Transmition : ' . json_encode($params['transmition'])); + $geofence = $transmition['geofence']; + log::add('mobile', 'debug', '| Event ─▶︎ ' . json_encode($geofence)); + $cmdgeoloc = cmd::byEqLogicIdAndLogicalId($mobile->getId(), 'geoloc_' . $geofence['identifier']); + if (is_object($cmdgeoloc)) {if ($geofence['action'] == 'ENTER' || $geofence['action'] == 'EXIT') { + $eventAge = time() - intval(strtotime($geofence['timestamp'])); + log::add('mobile', 'debug', '| $eventAge ─▶︎ ' . $eventAge); + if ($eventAge > 1800) { + log::add('mobile', 'debug', '| SKIP stale event (' . round($eventAge / 60) . 'min) ' . $geofence['action'] . ' geoloc_' . $geofence['identifier']); + } else { + $value = ($geofence['action'] == 'ENTER') ? 1 : 0; + log::add('mobile', 'debug', '| OK Commande "' . $cmdgeoloc->getName() . '" ─▶︎ ' . $value); + $mobile->checkAndUpdateCmd('geoloc_' . $geofence['identifier'], $value); + } + } else { + log::add('mobile', 'debug', '| [INFO] Event ─▶︎ ' . $geofence['action']); + } } else { - log::add('mobile', 'debug', '| [INFO] Event -> ' . $geofence['action']); + log::add('mobile', 'debug', '| [ERROR] Commande geoloc_' . $geofence['identifier'] . ' inexistante.'); } } else { - log::add('mobile', 'debug', '| [ERROR] Commande geoloc_' . $geofence['identifier'] . ' inexistante.'); + $errorCount++; } - } else { - $errorCount++; } - } - if ($errorCount > 0) { - log::add('mobile', 'debug', __('| Pas de paramètre de geofencing', __FILE__)); + if ($errorCount > 0) { + log::add('mobile', 'debug', __('| Pas de paramètre de geofencing', __FILE__)); + } } } } else { @@ -584,7 +587,7 @@ function saveMenuFromAppV2($menu, $mobile) * @return makeSuccess */ if ($jsonrpc->getMethod() == "qrcodemethod") { - log::add('mobile', 'debug', '┌─────▶︎ qrcodemethod ──────────────────────'); + log::add('mobile', 'debug', '┌──────────▶︎ qrcodemethod ──────────────────'); if ($params['appInfos']) { log::add('mobile', 'debug', '| [INFO] Valeur du QrCode > ' . json_encode($params['appInfos']['qrCode'])); if (isset($params['appInfos']['qrCode']['displayValue'])) { @@ -592,8 +595,8 @@ function saveMenuFromAppV2($menu, $mobile) } else { mobile::cmdForApi($params['Iq'], "qrcodemethod", json_encode($params['appInfos']['qrCode']), "QrCode"); } - log::add('mobile', 'debug', '└───────────────────────────────────────────'); } + log::add('mobile', 'debug', '└───────────────────────────────────────────'); $jsonrpc->makeSuccess(); } @@ -603,8 +606,8 @@ function saveMenuFromAppV2($menu, $mobile) * @return makeSuccess || makeError */ if ($jsonrpc->getMethod() == "methodeForSpecificChannel") { - log::add('mobile', 'debug', '┌─────▶︎ methodeForSpecificChannel ──────────────────────'); - log::add('mobile', 'debug', '| [INFO] params > ' . json_encode($params)); + log::add('mobile', 'debug', '┌──────────▶︎ methodeForSpecificChannel ──────────────────────'); + log::add('mobile', 'debug', '| [INFO] params ─▶︎ ' . json_encode($params)); $mobile = eqLogic::byLogicalId($params['Iq'], 'mobile'); if (is_object($mobile)) { $mobile->cmdForSpecificChannel($params, 'location'); @@ -617,7 +620,7 @@ function saveMenuFromAppV2($menu, $mobile) $jsonrpc->makeError('Paramètre Iq inexistant'); } } - log::add('mobile', 'debug', '└───────────────────────────────────────────'); + log::add('mobile', 'debug', '└─────────────────────────────────────────────────────────────'); $jsonrpc->makeSuccess(); } @@ -627,13 +630,13 @@ function saveMenuFromAppV2($menu, $mobile) * @return makeSuccess */ if ($jsonrpc->getMethod() == "nfc") { - log::add('mobile', 'debug', '┌─────▶︎ nfc ───────────────────────────────'); + log::add('mobile', 'debug', '┌──────────▶︎ NFC ───────────────────────────'); $id = (isset($params['appInfos']['payload']['id'])) ? $params['appInfos']['payload']['id'] : ""; $payload = (isset($params['appInfos']['payload']['payload'])) ? $params['appInfos']['payload']['payload'] : ""; mobile::cmdForApi($params['Iq'], "nfcId", $id, "Nfc Id"); mobile::cmdForApi($params['Iq'], "nfcPayload", json_encode($payload), "Nfc Payload"); - log::add('mobile', 'debug', '| [INFO] Id > ' . $id); - log::add('mobile', 'debug', '| [INFO] Payload > ' . $payload); + log::add('mobile', 'debug', '| [INFO] Id ─▶︎ ' . $id); + log::add('mobile', 'debug', '| [INFO] Payload ─▶︎ ' . $payload); log::add('mobile', 'debug', '└───────────────────────────────────────────'); $jsonrpc->makeSuccess(); } @@ -644,8 +647,8 @@ function saveMenuFromAppV2($menu, $mobile) * @return */ if ($jsonrpc->getMethod() == "syncBella") { - log::add('mobile', 'debug', '┌─────▶︎ syncBella ─────────────────────────'); - log::add('mobile', 'debug', '| JeedomApp > syncBella'); + log::add('mobile', 'debug', '┌──────────▶︎ syncBella ─────────────────────'); + log::add('mobile', 'debug', '| JeedomApp ─▶︎ syncBella'); log::add('mobile', 'debug', '└───────────────────────────────────────────'); } @@ -655,7 +658,7 @@ function saveMenuFromAppV2($menu, $mobile) * @return array */ if ($jsonrpc->getMethod() == 'getNotificationsFromFile') { - log::add('mobile', 'debug', '┌──────────▶︎ :fg-warning: Recuperation des Notifications :/fg: ──────────'); + log::add('mobile', 'debug', '┌──────────▶︎ :fg-warning:Recuperation des Notifications:/fg: ──────────'); $Iq = $params['Iq']; $filePath = dirname(__FILE__) . '/../data/notifications/' . $Iq . '.json'; $notifications = 'noNotifications'; @@ -665,8 +668,8 @@ function saveMenuFromAppV2($menu, $mobile) $notifications = 'noNotifications'; } } - log::add('mobile', 'debug', '| [INFO] Notifications > ' . $notifications); - log::add('mobile', 'debug', '└───────────────────────────────────────────'); + log::add('mobile', 'debug', '| [INFO] Notifications ─▶︎ ' . $notifications); + log::add('mobile', 'debug', '└─────────────────────────────────────────────────────'); $jsonrpc->makeSuccess($notifications); } @@ -676,7 +679,7 @@ function saveMenuFromAppV2($menu, $mobile) * @return string ok */ if ($jsonrpc->getMethod() == 'deleteNotificationInJsonFile') { - log::add('mobile', 'debug', '┌────▶︎ deleteNotificationInJsonFile ──────'); + log::add('mobile', 'debug', '┌──────────▶︎ deleteNotificationInJsonFile ──────'); $Iq = $params['Iq']; $filePath = dirname(__FILE__) . '/../data/notifications/' . $Iq . '.json'; $idNotif = $params['IdNotif']; @@ -692,7 +695,7 @@ function saveMenuFromAppV2($menu, $mobile) file_put_contents($filePath, $notifications); } } - log::add('mobile', 'debug', '└───────────────────────────────────────────'); + log::add('mobile', 'debug', '└───────────────────────────────────────────────'); $jsonrpc->makeSuccess('ok'); } @@ -702,7 +705,7 @@ function saveMenuFromAppV2($menu, $mobile) * @return string ok */ if ($jsonrpc->getMethod() == 'deleteGeolocCommand') { - log::add('mobile', 'debug', '┌────▶︎ Commande suppression GeoLoc ───────'); + log::add('mobile', 'debug', '┌──────────▶︎ Commande suppression GeoLoc ───────'); $geolocId = $params['geoloc_id']; $eqLogic = eqLogic::byLogicalId($params['Iq'], 'mobile'); if (is_object($eqLogic)) { @@ -714,7 +717,7 @@ function saveMenuFromAppV2($menu, $mobile) } else { log::add('mobile', 'debug', __('| [ERROR] EqLogic inconnu : ', __FILE__) . $params['Iq']); } - log::add('mobile', 'debug', '└───────────────────────────────────────────'); + log::add('mobile', 'debug', '└───────────────────────────────────────────────'); $jsonrpc->makeSuccess('ok'); } @@ -724,14 +727,14 @@ function saveMenuFromAppV2($menu, $mobile) * @return array */ if ($jsonrpc->getMethod() == 'getScenarios') { - log::add('mobile', 'debug', '┌────◀︎ Get Scénarios ─────────────────────'); + log::add('mobile', 'debug', '┌──────────◀︎ Get Scénarios ─────────────────'); $scenarios = array(); $hasScenario = false; $scenarioListGroup = scenario::listGroup(); $emptyListGroup = false; $emptyNoGroup = false; if (empty($scenarioListGroup)) { - log::add('mobile', 'debug', '| Scénarios > Aucun groupe de scénario'); + log::add('mobile', 'debug', '| Scénarios ─▶︎ Aucun groupe de scénario'); $emptyListGroup = true; } if (is_array($scenarioListGroup)) { @@ -745,15 +748,15 @@ function saveMenuFromAppV2($menu, $mobile) $scenarios['{{Aucun}}'] = $scenarioNoGroup; $hasScenario = true; } else { - log::add('mobile', 'debug', '| Scénarios > Aucun "sans groupe" de scénario'); + log::add('mobile', 'debug', '| Scénarios ─▶︎ Aucun "sans groupe" de scénario'); $emptyNoGroup = true; } - log::add('mobile', 'debug', '| Scénarios > ' . json_encode($scenarios)); + log::add('mobile', 'debug', '| Scénarios ─▶︎ ' . json_encode($scenarios)); $scenarioTemp = array(); foreach ($scenarios as $key => $scenario) { $scenarioTemp[$key][] = utils::o2a($scenario); } - log::add('mobile', 'debug', '| $scenarioTemp > ' . json_encode($scenarioTemp)); + log::add('mobile', 'debug', '| $scenarioTemp ─▶︎ ' . json_encode($scenarioTemp)); if ($emptyListGroup && $emptyNoGroup) { $return = 'noScenarios'; } else { @@ -766,7 +769,7 @@ function saveMenuFromAppV2($menu, $mobile) // APP V1 // if ($jsonrpc->getMethod() == 'sync') { - log::add('mobile', 'debug', '┌─────▶︎ Sync App V1 ───────────────'); + log::add('mobile', 'debug', '┌──────────▶︎ Sync App V1 ───────────────────'); if (jeedom::version() >= '3.2.0') { log::add('mobile', 'debug', '| Demande du RDK'); $registerDevice = $_USER_GLOBAL->getOptions('registerDevice', array()); @@ -780,7 +783,7 @@ function saveMenuFromAppV2($menu, $mobile) $registerDevice[sha512($rdk)]['session_id'] = session_id(); $_USER_GLOBAL->setOptions('registerDevice', $registerDevice); $_USER_GLOBAL->save(); - log::add('mobile', 'debug', '| RDK :' . $rdk); + log::add('mobile', 'debug', '| RDK : ' . $rdk); } $mobile = null; if (isset($params['Iq'])) { @@ -823,13 +826,13 @@ function saveMenuFromAppV2($menu, $mobile) $token = $mobile->getConfiguration('notificationRegistrationToken', 'nok'); $tokenMobile = $params['notificationRegistrationToken']; if ($token == 'nok') { - log::add('mobile', 'debug', '| notificationRegistrationToken null dans la configuration > ' . $token); + log::add('mobile', 'debug', '| notificationRegistrationToken null dans la configuration ─▶︎ ' . $token); $mobile->setConfiguration('notificationRegistrationToken', $tokenMobile); $mobile->save(); } else { log::add('mobile', 'debug', '| Token dans la configuration > ' . $token); if ($token != $tokenMobile) { - log::add('mobile', 'debug', '| Token config != Token mobile > ' . $token . ' != ' . $tokenMobile); + log::add('mobile', 'debug', '| Token config != Token mobile ─▶︎ ' . $token . ' != ' . $tokenMobile); $mobile->setConfiguration('notificationRegistrationToken', $tokenMobile); $mobile->save(); } @@ -848,13 +851,13 @@ function saveMenuFromAppV2($menu, $mobile) if (isset($rdk)) { $return['config']['rdk'] = $rdk; } - log::add('mobile', 'debug', '| Return $discovery_summaryValue > ' . json_encode($return['summaryValue'])); + log::add('mobile', 'debug', '| Return $discovery_summaryValue ─▶︎ ' . json_encode($return['summaryValue'])); log::add('mobile', 'debug', '└───────────────────────────────────────────'); $jsonrpc->makeSuccess($return); } if ($jsonrpc->getMethod() == 'cmdsbyEqlogicID') { - log::add('mobile', 'debug', 'Interogation du module id:' . $params['id'] . ' Pour les cmds'); + log::add('mobile', 'debug', 'Interogation du module id :' . $params['id'] . ' Pour les cmds'); $PluginToSend = mobile::PluginToSend(); $discover_eqLogic = mobile::discovery_eqLogic($PluginToSend); $sync_new = mobile::change_cmdAndeqLogic(mobile::discovery_cmd($PluginToSend, $discover_eqLogic, true), $discover_eqLogic); @@ -870,7 +873,7 @@ function saveMenuFromAppV2($menu, $mobile) } $i++; } - log::add('mobile', 'debug', 'Commande > ' . json_encode($cmdAPI)); + log::add('mobile', 'debug', 'Commande ─▶︎ ' . json_encode($cmdAPI)); $jsonrpc->makeSuccess($cmdAPI); } @@ -893,13 +896,13 @@ function saveMenuFromAppV2($menu, $mobile) } if ($jsonrpc->getMethod() == 'askText') { - log::add('mobile', 'debug', '┌──:fg-success: TESTAPIASK :/fg:──'); + log::add('mobile', 'debug', '┌──────────▶︎ :fg-success:TESTAPIASK:/fg: ────────────────────'); log::add('mobile', 'debug', '| Arrivée reponse ask Textuel depuis le mobile ─▶︎ ' . $params['Iq']); /*$configs = $params['configs']; $menu = $configs['menu']; $notification = $configs['notification'];*/ $mobile = eqLogic::byLogicalId($params['Iq'], 'mobile'); - log::add('mobile', 'debug', 'mobile >' . json_encode($mobile)); + log::add('mobile', 'debug', 'mobile ─▶︎ ' . json_encode($mobile)); if (is_object($mobile)) { $askCasse = config::byKey('askCasse', 'mobile', false); $textCasse = $params['text']; @@ -922,7 +925,7 @@ function saveMenuFromAppV2($menu, $mobile) $jsonrpc->makeSuccess(); } } - log::add('mobile', 'debug', '└────────────────────'); + log::add('mobile', 'debug', '└───────────────────────────────────────────'); } if ($jsonrpc->getMethod() == 'saveMobile') { @@ -933,12 +936,12 @@ function saveMenuFromAppV2($menu, $mobile) } if ($jsonrpc->getMethod() == 'getMobile') { - log::add('mobile', 'debug', ':fg-success: ─────▶︎ Demande de recuperation ::/fg: ' . $params['type'] . ' ─▶︎ ' . $params['Iq'] . '(' . mobile::whoIsIq($params['Iq']) . ') recuperation save du > ' . $params['IqRestore'] . ' (' . mobile::whoIsIq($params['IqRestore']) . ')'); + log::add('mobile', 'debug', ':fg-success: ─────▶︎ Demande de recuperation ::/fg: ' . $params['type'] . ' ─▶︎ ' . $params['Iq'] . '(' . mobile::whoIsIq($params['Iq']) . ') recuperation save du ─▶︎ ' . $params['IqRestore'] . ' (' . mobile::whoIsIq($params['IqRestore']) . ')'); $jsonrpc->makeSuccess(mobile::getSaveJson($params['IqRestore'], $params['type'])); } if ($jsonrpc->getMethod() == 'geoloc') { - log::add('mobile', 'debug', 'Geoloc ' . $params['id'] . ' > ' . $params['name'] . ' > ' . $params['value']); + log::add('mobile', 'debug', 'Geoloc ' . $params['id'] . ' > ' . $params['name'] . ' ─▶︎ ' . $params['value']); mobile::EventGeoloc($params); $jsonrpc->makeSuccess(); } @@ -954,7 +957,7 @@ function saveMenuFromAppV2($menu, $mobile) } if ($jsonrpc->getMethod() == 'geolocDel') { - log::add('mobile', 'debug', 'Geoloc DEL ' . $params['id'] . ' > ' . $params['name']); + log::add('mobile', 'debug', 'Geoloc DEL ' . $params['id'] . ' ─▶︎ ' . $params['name']); mobile::delGeoloc($params); $jsonrpc->makeSuccess(); } diff --git a/core/class/mobile.class.php b/core/class/mobile.class.php index 89dd8a4b..88d4aef2 100755 --- a/core/class/mobile.class.php +++ b/core/class/mobile.class.php @@ -145,7 +145,7 @@ public static function pluginToSend() public static function makeTemplateJson() { - log::add(__CLASS__, 'debug', '┌─────▶︎ makeTemplateJson ───────────────'); + log::add(__CLASS__, 'debug', '┌──────────▶︎ makeTemplateJson ──────────────'); $pluginToSend = mobile::pluginToSend(); $discover_eqLogic = mobile::discovery_eqLogic($pluginToSend); $sync_new = mobile::change_cmdAndeqLogic(mobile::discovery_cmd($pluginToSend, $discover_eqLogic), $discover_eqLogic); @@ -619,14 +619,14 @@ public static function SaveGeoloc($geoloc) public static function delGeoloc($geoloc) { - log::add('mobile', 'debug', '|┌──:fg-success: Lancement DEL du mobile- V1 :/fg:──'); - log::add('mobile', 'debug', '| Mobile ' . $geoloc['Iq'] . ' pour ' . $geoloc['id']); + log::add('mobile', 'debug', '|┌──:fg-success: Lancement DEL du mobile - V1 :/fg:──'); + log::add('mobile', 'debug', '|| Mobile ' . $geoloc['Iq'] . ' pour ' . $geoloc['id']); $eqLogicMobile = eqLogic::byLogicalId($geoloc['Iq'], 'mobile'); $cmdgeoloc = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(), 'geoId_' . $geoloc['id']); if (isset($cmdgeoloc)) { $cmdgeoloc->remove(); } - log::add('mobile', 'debug', '||└────────────────────'); + log::add('mobile', 'debug', '|└──────────────────────────────────'); } @@ -634,7 +634,7 @@ public static function EventGeoloc($geoloc) { /******************** APP V1 *************************/ log::add('mobile', 'debug', '|┌──:fg-success: jsonPublish :/fg:──'); - log::add('mobile', 'debug', '| Geoloc Event du mobile ─▶︎ ' . $geoloc['Iq'] . ' pour ' . $geoloc['id']); + log::add('mobile', 'debug', '|| Geoloc Event du mobile ─▶︎ ' . $geoloc['Iq'] . ' pour ' . $geoloc['id']); $eqLogicMobile = eqLogic::byLogicalId($geoloc['Iq'], 'mobile'); $cmdgeoloc = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(), 'geoId_' . $geoloc['id']); $cmdgeolocv2 = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(), 'geoloc_' . $geoloc['id']); @@ -656,7 +656,7 @@ public static function EventGeoloc($geoloc) log::add('mobile', 'debug', '| Valeur identique ─▶︎ ' . $geoloc['value'] . ' / ' . $cmdgeolocv2->execCmd()); } } - log::add('mobile', 'debug', '|└────────────────────'); + log::add('mobile', 'debug', '|└─────────────────'); } @@ -694,8 +694,8 @@ public static function deleteFileImg() public static function jsonPublish($os, $titre, $message, $type, $idNotif, $answer, $timeout, $token, $photo, $version, $optionsNotif = [], $critical = false, $Iq = null, $specific = false, $silent = false) { log::add('mobile', 'debug', '||┌──:fg-success: jsonPublish :/fg:──'); - log::add('mobile', 'debug', '||┌──:fg-success: PARAMS :/fg:──' . $silent); - if (isset($Iq)) log::add('mobile', 'debug', '||| IQ for jsonPublish > ' . $Iq); + if ($silent) log::add('mobile', 'debug', '||| Silent notification'); + if (isset($Iq)) log::add('mobile', 'debug', '||| IQ for jsonPublish ─▶︎ ' . $Iq); $dateNotif = date("Y-m-d H:i:s"); $newDate = date("Y-m-d"); @@ -934,8 +934,8 @@ public static function jsonPublish($os, $titre, $message, $type, $idNotif, $answ } } } - log::add('mobile', 'debug', '||| [INFO] JSON publish > ' . json_encode($publish)); - log::add('mobile', 'debug', '||└────────────────────'); + log::add('mobile', 'debug', '||| [INFO] JSON publish ─▶︎ ' . json_encode($publish)); + log::add('mobile', 'debug', '||└─────────────────'); return $publish; } @@ -1009,7 +1009,7 @@ public static function notification($arn, $os, $titre, $message, $type, $idNotif //} else { //log::add('mobile', 'error', __("Échec de l'envoi de notification : la version 1 de l'app n'est plus prise en charge !", __FILE__)); //} - log::add('mobile', 'debug', '|└────────────────────'); + log::add('mobile', 'debug', '|└─────────────────────────────'); } /** @@ -1027,7 +1027,7 @@ public static function getNotificationsV2($Iq) } return $return; } - + /** * remove notification from Id into filepath id * Call by ajax removeNotificationV2 @@ -1060,20 +1060,42 @@ public static function removeNotificationV2($_iq, $_id) */ public static function createCmdGeoLocV2($Iq, $geolocs) { - log::add('mobile', 'debug', '|┌──:fg-success: GeoLocV2 :/fg:──'); + log::add('mobile', 'debug', '|┌──:fg-success: createCmdGeoLocV2 :/fg:──'); $mobile = eqLogic::byLogicalId($Iq, 'mobile'); if (is_object($mobile)) { - log::add('mobile', 'debug', '|| OK Mobile existant > ' . $mobile->getName()); - log::add('mobile', 'debug', '|| [INFO] GEOLOCS > ' . $geolocs); + log::add('mobile', 'debug', '|| OK Mobile existant ─▶︎ ' . $mobile->getName()); + log::add('mobile', 'debug', '|| [INFO] GEOLOCS ─▶︎ ' . $geolocs); $order = count($mobile->getCmd()); $noExistCmd = 0; $decodedGeolocs = json_decode($geolocs, true); foreach ($decodedGeolocs as $index => $geoloc) { if (!isset($geoloc['name'])) continue; - log::add('mobile', 'debug', '|| geoloc_' . $index . ' > ' . $geoloc['name']); + log::add('mobile', 'debug', '|| geoloc_' . $index . ' ─▶︎ ' . $geoloc['name']); $cmd = cmd::byEqLogicIdAndLogicalId($mobile->getId(), 'geoloc_' . $index); $logicalId = 'geoloc_' . $index; + /* PR Migrate geoloc logicalId by name + When creating geoloc_X commands, add a migration step to handle cases where the command UUID/logicalId changed: + if no command is found by the expected logicalId, iterate existing commands to find one with a geoloc_N pattern and the same name, + rename its logicalId to the expected value, save it and reuse it. This prevents duplicate geoloc commands after UUID/ID changes. + */ + if (!is_object($cmd)) { + if (!preg_match('/^geoloc_\d+$/', $logicalId)) { + foreach ($mobile->getCmd() as $existing) { + if ( + preg_match('/^geoloc_\d+$/', $existing->getLogicalId()) + && $existing->getName() === $geoloc['name'] + ) { + log::add('mobile', 'debug', '|| Migration UUID : renommage ' . $existing->getLogicalId() . ' ─▶︎ ' . $logicalId); + $existing->setLogicalId($logicalId); + $existing->save(); + $cmd = $existing; + break; + } + } + } + } + /* End PR Migrate */ if (!is_object($cmd)) { $noExistCmd = 1; $cmd = new mobileCmd(); @@ -1088,7 +1110,7 @@ public static function createCmdGeoLocV2($Iq, $geolocs) $cmd->setIsHistorized(1); $cmd->setOrder($order); $order++; - log::add('mobile', 'debug', '|| Ajout geofencing > ' . $geoloc['name']); + log::add('mobile', 'debug', '|| Ajout geofencing ─▶︎ ' . $geoloc['name']); } $cmd->setName($geoloc['name']); $cmd->setType('info'); @@ -1099,14 +1121,14 @@ public static function createCmdGeoLocV2($Iq, $geolocs) if ($cmd->getChanged() === true) $cmd->save(); if ($noExistCmd == 1) { $mobile->checkAndUpdateCmd($logicalId, $geoloc['value']); - log::add('mobile', 'debug', '|| Valeur enregistrée > ' . $geoloc['value']); + log::add('mobile', 'debug', '|| Valeur enregistrée ─▶︎ ' . $geoloc['value']); } $noExistCmd = 0; } } else { log::add('mobile', 'debug', '| [ERROR] Mobile inexistant !'); } - log::add('mobile', 'debug', '|└────────────────────'); + log::add('mobile', 'debug', '|└──────────────'); } /** @@ -1381,7 +1403,7 @@ public function configMenuCustom() //$objectId = isset($menuCustomArray[$i]['selectNameMenu']) ? $menuCustomArray[$i]['selectNameMenu'] : ''; $isActive = true; //$webviewUrl = 'd'; - //if (!empty($objectId)) log::add('mobile', 'debug', '|| - objectId > ' . $objectId); + //if (!empty($objectId)) log::add('mobile', 'debug', '|| - objectId ─▶︎ ' . $objectId); // GENERATE URLS FOR MENU CUSTOM //$result = self::generateTypeObject($objectId, $i, $webviewUrl, $pluginPanelMobile); @@ -1414,7 +1436,7 @@ public function configMenuCustom() $j++; $count++; } - log::add('mobile', 'debug', '|| [INFO] arrayElements > ' . json_encode($arrayElements)); + log::add('mobile', 'debug', '|| [INFO] arrayElements ─▶︎ ' . json_encode($arrayElements)); log::add('mobile', 'debug', '|└────────────────────'); return $arrayElements; } @@ -1504,86 +1526,137 @@ public function cmdForSpecificChannel($params = array(), $_trigger = 'location') if (isset($params['Iq'])) { if (isset($params[$_trigger])) { $order = count($this->getCmd()); - // Battery - if (isset($params[$_trigger]['battery'])) { - // level - if (isset($params[$_trigger]['battery']['level'])) { - $cmd = $this->getCmd(null, 'phoneBattery'); - if (!is_object($cmd)) { - $cmd = new mobileCmd(); - $cmd->setLogicalId('phoneBattery'); - $cmd->setName(__('Batterie du téléphone', __FILE__)); - $cmd->setDisplay('icon', ''); - $cmd->setDisplay('showIconAndNamedashboard', 1); - $cmd->setDisplay('showIconAndNamemobile', 1); - $cmd->setDisplay('forceReturnLineAfter', 1); - $cmd->setConfiguration('historizeRound', 2); - $cmd->setConfiguration('minValue', 0); - $cmd->setConfiguration('maxValue', 100); - $cmd->setUnite('%'); - $cmd->setIsVisible(0); - $cmd->setOrder($order); - $order++; - log::add('mobile', 'debug', 'Creation commande Batterie du téléphone'); + $getDeviceInformations = (isset($params[$_trigger]['extras']) && isset($params[$_trigger]['extras']['method']) && $params[$_trigger]['extras']['method'] == 'getDeviceInformations'); + $eventAge = time() - intval(strtotime($params[$_trigger]['timestamp'])); + if ($eventAge > 1800) { + log::add('mobile', 'debug', '| SKIP stale specific event (' . round($eventAge / 60) . 'min) '); + } else { + log::add('mobile', 'debug', '| eventAge = ' . $eventAge . ' s'); + // Battery + if (isset($params[$_trigger]['battery'])) { + // level + if (isset($params[$_trigger]['battery']['level'])) { + if ($getDeviceInformations) { + $cmd = $this->getCmd(null, 'battery::level'); + if (!is_object($cmd)) { + $cmd = new mobileCmd(); + $cmd->setLogicalId('battery::level'); + $cmd->setName(__('Batterie du téléphone', __FILE__)); + $cmd->setDisplay('icon', ''); + $cmd->setDisplay('showIconAndNamedashboard', 1); + $cmd->setDisplay('showIconAndNamemobile', 1); + $cmd->setDisplay('forceReturnLineAfter', 1); + $cmd->setConfiguration('historizeRound', 2); + $cmd->setConfiguration('minValue', 0); + $cmd->setConfiguration('maxValue', 100); + $cmd->setUnite('%'); + $cmd->setIsVisible(0); + $cmd->setOrder($order); + $order++; + log::add('mobile', 'debug', '| Création de la commande Batterie du téléphone'); + } + $cmd->setEqLogic_id($this->getId()); + $cmd->setType('info'); + $cmd->setConfiguration('calculValueOffset', '#value# * 100'); + $cmd->setSubType('numeric'); + if ($cmd->getChanged() === true) $cmd->save(); + } + if ($params[$_trigger]['battery']['level'] != -1) { + if ($this->checkAndUpdateCmd('battery::level', $params[$_trigger]['battery']['level'])) { + log::add('mobile', 'debug', '| ' . (__('Batterie du téléphone', __FILE__)) . ' = ' . $params[$_trigger]['battery']['level'] * 100 . '%'); + } + } else { + log::add('mobile', 'debug', '| ' . (__('Batterie du téléphone', __FILE__)) . ' : ' . 'Absence de donnée ─▶︎ ' . $params[$_trigger]['battery']['level']); + } } - $cmd->setEqLogic_id($this->getId()); - $cmd->setType('info'); - $cmd->setSubType('numeric'); - if ($cmd->getChanged() === true) $cmd->save(); - log::add('mobile', 'debug', '| OK phoneBattery = ' . $params[$_trigger]['battery']['level'] * 100); - $this->checkAndUpdateCmd('phoneBattery', $params[$_trigger]['battery']['level'] * 100); - } - // charging - if (isset($params[$_trigger]['battery']['is_charging'])) { - $cmd = $this->getCmd(null, 'phoneCharging'); - if (!is_object($cmd)) { - $cmd = new mobileCmd(); - $cmd->setLogicalId('phoneCharging'); - $cmd->setName(__('En charge', __FILE__)); - $cmd->setDisplay('icon', ''); - $cmd->setDisplay('showIconAndNamedashboard', 1); - $cmd->setDisplay('showIconAndNamemobile', 1); - $cmd->setDisplay('forceReturnLineAfter', 1); - $cmd->setTemplate('dashboard', 'core::line'); - $cmd->setTemplate('mobile', 'core::line'); - $cmd->setIsVisible(0); - $cmd->setOrder($order); - $order++; - log::add('mobile', 'debug', 'Creation commande En charge'); + // charging + if (isset($params[$_trigger]['battery']['is_charging'])) { + if ($getDeviceInformations) { + $cmd = $this->getCmd(null, 'battery::isCharging'); + if (!is_object($cmd)) { + $cmd = new mobileCmd(); + $cmd->setLogicalId('battery::isCharging'); + $cmd->setName(__('En charge', __FILE__)); + $cmd->setDisplay('icon', ''); + $cmd->setDisplay('showIconAndNamedashboard', 1); + $cmd->setDisplay('showIconAndNamemobile', 1); + $cmd->setDisplay('forceReturnLineAfter', 1); + $cmd->setTemplate('dashboard', 'core::line'); + $cmd->setTemplate('mobile', 'core::line'); + $cmd->setIsVisible(0); + $cmd->setOrder($order); + $order++; + log::add('mobile', 'debug', '| ' . __('Création de la commande', __FILE__) . ' > ' . __('En charge', __FILE__)); + } + $cmd->setEqLogic_id($this->getId()); + $cmd->setType('info'); + $cmd->setSubType('binary'); + if ($cmd->getChanged() === true) $cmd->save(); + } + if ($this->checkAndUpdateCmd('battery::isCharging', intval($params[$_trigger]['battery']['is_charging']))) { + log::add('mobile', 'debug', '| ' . (__('En charge', __FILE__)) . ' = ' . intval($params[$_trigger]['battery']['is_charging'])); + } } - $cmd->setEqLogic_id($this->getId()); - $cmd->setType('info'); - $cmd->setSubType('binary'); - if ($cmd->getChanged() === true) $cmd->save(); - log::add('mobile', 'debug', '| OK phoneCharging = ' . intval($params[$_trigger]['battery']['is_charging'])); - $this->checkAndUpdateCmd('phoneCharging', intval($params[$_trigger]['battery']['is_charging'])); } - } - // coords - if (isset($params[$_trigger]['coords'])) { - if (isset($params[$_trigger]['coords']['latitude']) && isset($params[$_trigger]['coords']['longitude'])) { - $cmd = $this->getCmd(null, 'coords'); - if (!is_object($cmd)) { - $cmd = new mobileCmd(); - $cmd->setLogicalId('coords'); - $cmd->setName(__('Coordonnées', __FILE__)); - $cmd->setDisplay('icon', ''); - $cmd->setDisplay('showIconAndNamedashboard', 1); - $cmd->setDisplay('showIconAndNamemobile', 1); - $cmd->setDisplay('forceReturnLineAfter', 1); - $cmd->setTemplate('dashboard', 'core::line'); - $cmd->setTemplate('mobile', 'core::line'); - $cmd->setIsVisible(0); - $cmd->setOrder($order); - $order++; - log::add('mobile', 'debug', 'Create cmd for coords'); + // coords + if (isset($params[$_trigger]['coords'])) { + if (isset($params[$_trigger]['coords']['latitude']) && isset($params[$_trigger]['coords']['longitude'])) { + if ($getDeviceInformations) { + $cmd = $this->getCmd(null, 'coords'); + if (!is_object($cmd)) { + $cmd = new mobileCmd(); + $cmd->setLogicalId('coords'); + $cmd->setName(__('Coordonnées', __FILE__)); + $cmd->setDisplay('icon', ''); + $cmd->setDisplay('showIconAndNamedashboard', 1); + $cmd->setDisplay('showIconAndNamemobile', 1); + $cmd->setDisplay('forceReturnLineAfter', 1); + $cmd->setTemplate('dashboard', 'core::line'); + $cmd->setTemplate('mobile', 'core::line'); + $cmd->setIsVisible(0); + $cmd->setOrder($order); + $order++; + log::add('mobile', 'debug', '| ' . __('Création de la commande', __FILE__) . ' > ' . __('Coordonnées', __FILE__)); + } + $cmd->setEqLogic_id($this->getId()); + $cmd->setType('info'); + $cmd->setSubType('string'); + if ($cmd->getChanged() === true) $cmd->save(); + } + $coord = $params[$_trigger]['coords']['latitude'] . ',' . $params[$_trigger]['coords']['longitude']; + if ($this->checkAndUpdateCmd('coords', $coord)) { + log::add('mobile', 'debug', '| ' . (__('Coordonnées', __FILE__)) . ' = ' . $coord); + } + + } + if (isset($params[$_trigger]['coords']['altitude'])) { + if ($getDeviceInformations) { + $cmd = $this->getCmd(null, 'altitude'); + if (!is_object($cmd)) { + $cmd = new mobileCmd(); + $cmd->setLogicalId('altitude'); + $cmd->setName(__('Altitude', __FILE__)); + $cmd->setDisplay('icon', ''); + $cmd->setDisplay('showIconAndNamedashboard', 1); + $cmd->setDisplay('showIconAndNamemobile', 1); + $cmd->setDisplay('forceReturnLineAfter', 1); + $cmd->setTemplate('dashboard', 'core::line'); + $cmd->setTemplate('mobile', 'core::line'); + $cmd->setIsVisible(0); + $cmd->setUnite('m'); + $cmd->setOrder($order); + $order++; + log::add('mobile', 'debug', '| ' . __('Création de la commande', __FILE__) . ' > ' . __('Altitude', __FILE__)); + } + $cmd->setEqLogic_id($this->getId()); + $cmd->setType('info'); + $cmd->setSubType('string'); + if ($cmd->getChanged() === true) $cmd->save(); + } + if ($this->checkAndUpdateCmd('altitude', $params[$_trigger]['coords']['altitude'])) { + log::add('mobile', 'debug', '| ' . (__('Altitude', __FILE__)) . ' = ' . $params[$_trigger]['coords']['altitude'] . 'm'); + } } - $cmd->setEqLogic_id($this->getId()); - $cmd->setType('info'); - $cmd->setSubType('string'); - if ($cmd->getChanged() === true) $cmd->save(); - log::add('mobile', 'debug', '| OK coords = ' . $params[$_trigger]['coords']['latitude'] . ',' . $params[$_trigger]['coords']['longitude']); - $this->checkAndUpdateCmd('coords', $params[$_trigger]['coords']['latitude'] . ',' . $params[$_trigger]['coords']['longitude']); } } } @@ -1598,7 +1671,7 @@ public function cleaningNotifications() { $notifsTime = $this->getConfiguration('notifsTime', 30); log::add('mobile', 'debug', '┌──────────▶︎ :fg-warning: Nettoyage des Notifications et Images :/fg: ──────────'); - log::add('mobile', 'debug', '| Durée de retention actuelle : ' . $notifsTime . ' jours'); + log::add('mobile', 'debug', '| Durée de rétention actuelle : ' . $notifsTime . ' jours'); // Images $retentionSeconds = intVal($notifsTime) * 24 * 60 * 60; $currentTime = time(); @@ -1610,9 +1683,9 @@ public function cleaningNotifications() $fileCreationTime = filemtime($image); if ($fileCreationTime < ($currentTime - $retentionSeconds)) { if (!unlink($image)) { - log::add('mobile', 'error', 'Erreur lors de la suppression de: ' . $image); + log::add('mobile', 'error', 'Erreur lors de la suppression de : ' . $image); } else { - log::add('mobile', 'debug', '| ─▶︎ :fg-danger:suppression image:/fg: > ' . $image); + log::add('mobile', 'debug', '| ─▶︎ :fg-danger:suppression image:/fg: ─▶︎ ' . $image); } } } @@ -1634,7 +1707,7 @@ public function cleaningNotifications() foreach ($notifications as $id => $value) { $notificationDate = strtotime($value['data']['date']); if (($currentTime - $notificationDate) > $retentionSeconds) { - log::add('mobile', 'debug', '| ─▶︎ :fg-danger:suppression notification:/fg: > N°' . $id); + log::add('mobile', 'debug', '| ─▶︎ :fg-danger:suppression notification:/fg: ─▶︎ N°' . $id); unset($notifications[$id]); $notificationsModified = true; } @@ -1856,10 +1929,10 @@ public static function fileInMessage($data) if (json_last_error() === JSON_ERROR_NONE) { log::add('mobile', 'DEBUG', '|| [INFO] Message : ' . $decodedMessage); } else { - log::add('mobile', 'DEBUG', '|| [INFO] Message : ' . $result['message']); + log::add('mobile', 'DEBUG', '|| [INFO] Message : ' . str_replace(["\r", "\n"], "", $result['message'])); } if (array_key_exists('file', $result)) { - log::add('mobile', 'debug', '|| file > ' . $result['file']); + log::add('mobile', 'debug', '|| file ─▶︎ ' . $result['file']); log::add('mobile', 'debug', '|└────────────────────'); return $result; } else { @@ -1885,7 +1958,7 @@ public function execute($_options = array()) switch ($valueUser) { case 1: file_put_contents($filePath, ''); - log::add('mobile', 'info', '| Suppression des notifications effectuée'); + log::add('mobile', 'info', '| Suppression des notifications réalisée'); break; case 2: $notifs = json_decode(file_get_contents($filePath), true); @@ -1897,7 +1970,7 @@ public function execute($_options = array()) return $notif['data']['askVariable'] == 'rien' || ($currentTime - $notifTime) < $timeout; }); file_put_contents($filePath, json_encode($notifs)); - log::add('mobile', 'info', '| Suppression des asks expirés effectuée'); + log::add('mobile', 'info', '| Suppression des asks expirés réalisée'); break; case 3: $notifs = json_decode(file_get_contents($filePath), true); @@ -1905,7 +1978,7 @@ public function execute($_options = array()) return !isset($notif['data']['choiceAsk']) || $notif['data']['choiceAsk'] == ''; }); file_put_contents($filePath, json_encode($notifs)); - log::add('mobile', 'info', '| Suppression des asks répondus effectuée'); + log::add('mobile', 'info', '| Suppression des asks répondus réalisée'); break; } @@ -1937,7 +2010,7 @@ public function execute($_options = array()) log::add('mobile', 'debug', '| file detected ' . json_encode($file)); } log::add('mobile', 'DEBUG', '| [INFO] Title : ' . $_options['title']); - log::add('mobile', 'DEBUG', '| [INFO] Message : ' . $_options['message']); + log::add('mobile', 'DEBUG', '| [INFO] Message : ' . str_replace(["\r", "\n"], "", $_options['message'])); if ($eqLogic->getConfiguration('type_mobile') == 'android') $_options['message'] = nl2br($_options['message']); $answer = (isset($_options['answer']) && $_options['answer']) ? join(';', $_options['answer']) : null; $askVariable = isset($_options['variable']) ? $_options['variable'] : null; @@ -1945,7 +2018,6 @@ public function execute($_options = array()) if ($askType == 'ask_Text') $_options['title'] = $defaultName; $timeout = isset($_options['timeout']) && $_options['timeout'] ? $_options['timeout'] : 'nok'; $optionsNotif['askVariable'] = $askVariable; - //log::add('mobile', 'debug', '|-----------------------------------'); log::add('mobile', 'debug', '| Commande de notification : ' . $askType); if (($eqLogic->getConfiguration('notificationArn', null) != null || $eqLogic->getConfiguration('notificationRegistrationToken', null) != null) && $eqLogic->getConfiguration('type_mobile', null) != null) { $idNotif = $eqLogic->getConfiguration('idNotif', 0); @@ -1953,8 +2025,8 @@ public function execute($_options = array()) $eqLogic->setConfiguration('idNotif', $idNotif); $eqLogic->save(); - log::add('mobile', 'debug', '| [INFO] Notif > ' . json_encode($_options)); - log::add('mobile', 'debug', '| eqLogic > ' . $eqLogic->getId() . ' | LogicalId > ' . $this->getLogicalId() . ' | idNotif > ' . $idNotif); + log::add('mobile', 'debug', '| [INFO] Notif ─▶︎ ' . json_encode($_options)); + log::add('mobile', 'debug', '| eqLogic ─▶︎ ' . $eqLogic->getId() . ' | LogicalId ─▶︎ ' . $this->getLogicalId() . ' | idNotif ─▶︎ ' . $idNotif); if (isset($options['file'])) { //log::add('mobile', 'debug', '| [NOTICE] FILE'); //unset($data['file']); @@ -1968,7 +2040,7 @@ public function execute($_options = array()) continue; } $ext = pathinfo($file, PATHINFO_EXTENSION); - log::add('mobile', 'debug', '| ' . $ext . ' pour > ' . $file); + log::add('mobile', 'debug', '| ' . $ext . ' pour ─▶︎ ' . $file); if (in_array($ext, array('gif', 'jpeg', 'jpg', 'png'))) { log::add('mobile', 'debug', '| type photo !'); if ($ext == "gif") { @@ -1988,7 +2060,7 @@ public function execute($_options = array()) $nameFile = $Iq . '__' . base64_encode($file) . '.' . $ext; $path = dirname(__FILE__) . '/../../data/images'; $newfile = $path . '/' . $nameFile; - log::add('mobile', 'debug', '| copie sur > ' . $newfile); + log::add('mobile', 'debug', '| copie sur ─▶︎ ' . $newfile); if (!file_exists($path)) { mkdir($path); } @@ -1997,7 +2069,7 @@ public function execute($_options = array()) } $keyFile = md5_file($newfile); $url .= 'key=' . $keyFile . '&name=' . $nameFile; - log::add('mobile', 'debug', '| url > ' . $url); + log::add('mobile', 'debug', '| url ─▶︎ ' . $url); mobile::notification($eqLogic->getConfiguration('notificationArn', null), $eqLogic->getConfiguration('type_mobile', null), $_options['title'], $_options['message'], $askType, $idNotif, $answer, $timeout, $eqLogic->getConfiguration('notificationRegistrationToken', null), $url, $eqLogic->getConfiguration('appVersion', 1), $optionsNotif, $critical, $eqLogic->getLogicalId(), $specific, $silent); } else { mobile::notification($eqLogic->getConfiguration('notificationArn', null), $eqLogic->getConfiguration('type_mobile', null), $_options['title'], $_options['message'], $askType, $idNotif, $answer, $timeout, $eqLogic->getConfiguration('notificationRegistrationToken', null), null, $eqLogic->getConfiguration('appVersion', 1), $optionsNotif, $critical, $eqLogic->getLogicalId(), $specific, $silent); diff --git a/desktop/php/mobile.php b/desktop/php/mobile.php index cf288f8f..36f4bfeb 100755 --- a/desktop/php/mobile.php +++ b/desktop/php/mobile.php @@ -15,17 +15,16 @@ } } $isApi = config::byKey('api::mobile::mode'); -if($isApi == 'whiteip' || $isApi == 'disable'){ +if ($isApi == 'whiteip' || $isApi == 'disable') { message::add('mobile', 'L\'API mobile est désactivée ou en mode whitelist IP'); } $isCoreApi = config::byKey('api::core::mode'); -if($isCoreApi == 'whiteip' || $isCoreApi == 'disable'){ +if ($isCoreApi == 'whiteip' || $isCoreApi == 'disable') { message::add('mobile', 'L\'API core est désactivée ou en mode whitelist IP'); } ?>
-
{{App V2}} @@ -94,7 +93,7 @@ echo '
'; echo '{{Pour ajouter un téléphone, il y a 2 méthodes possible :}}
{{Sur le premier écran de l\'application, il vous est proposé de connecter votre compte market, et ainsi de retrouver toutes les boxs associées à ce compte, ou bien simplement ajouter une box.}}'; echo '
'; - } + } ?>
@@ -125,6 +124,9 @@ {{Mes Téléphones Mobiles}} +
+ {{Attention, l'APP V1 ne sera plus mise à jour}} +
= 0) { // AppV1 @@ -237,13 +239,13 @@
- +
- +