Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ nbproject/
test.php
core/config/common.config.php
plugins
sftp-config.json
.project
deployment-config.json
.project
22 changes: 22 additions & 0 deletions core/ajax/mobile.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@
mobile::makeTemplateJson();
ajax::success();
}

if (init('action') == 'getSaveDashboard'){
$iq = init('iq');
$jsonDashboard = mobile::getSaveJson($iq, 'dashboard');
if ($jsonDashboard == ""){
$reponse = false;
}else{
$reponse = true;
}
ajax::success($reponse);
}

if (init('action') == 'getSaveFavDash'){
$iq = init('iq');
$jsonFavDash = mobile::getSaveJson($iq, 'favdash');
if ($jsonFavDash == ""){
$reponse = false;
}else{
$reponse = true;
}
ajax::success($reponse);
}

throw new Exception(__('Aucune methode correspondante à : ', __FILE__) . init('action'));

Expand Down
14 changes: 10 additions & 4 deletions core/api/mobile.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
$params = $jsonrpc->getParams();

log::add('mobile', 'debug', 'Appel API Mobile > ' . $jsonrpc->getMethod());
log::add('mobile', 'debug', 'paramettres passés > ' . json_encode($params));

if ($jsonrpc->getMethod() == 'sync') {
if (jeedom::version() >= '3.2.0') {
Expand Down Expand Up @@ -174,17 +175,22 @@
}

if ($jsonrpc->getMethod() == 'geolocSave'){
log::add('mobile', 'debug', 'Geoloc ADD '. $params['id'] .' > ' . $params['name']);
mobile::SaveGeoloc($params);
$jsonrpc->makeSuccess();
log::add('mobile', 'debug', 'Geoloc SAVE '. $params['id'] .' > ' . $params['name']);
if($params['id'] != '' || $params['id'] != null){
mobile::SaveGeoloc($params);
$jsonrpc->makeSuccess();
}else{
throw new Exception(__('pas d\'id : ', __FILE__) . $params['name']);
}
}

if ($jsonrpc->getMethod() == 'geolocDel'){
log::add('mobile', 'debug', 'Geoloc DEL '. $params['id'] .' > ' . $params['name']);
mobile::DelGeoloc($params);
mobile::delGeoloc($params);
$jsonrpc->makeSuccess();
}


throw new Exception(__('Aucune demande', __FILE__));
?>

114 changes: 63 additions & 51 deletions core/class/mobile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
class mobile extends eqLogic {
/* * *************************Attributs****************************** */

public static $_pluginSuported = array('mobile', 'openzwave', 'rfxcom', 'edisio', 'mpower', 'mySensors', 'Zibasedom', 'virtual', 'camera', 'weather', 'philipsHue', 'enocean', 'wifipower', 'alarm', 'mode', 'apcupsd', 'btsniffer', 'dsc', 'rflink', 'mysensors', 'relaynet', 'remora', 'unipi', 'eibd', 'thermostat', 'netatmoThermostat', 'espeasy', 'jeelink', 'teleinfo', 'tahoma', 'protexiom', 'lifx', 'wattlet', 'rfplayer', 'openenocean','netatmoWeather','Volets');
public static $_pluginSuported = array('mobile', 'openzwave', 'rfxcom', 'edisio', 'mpower', 'mySensors', 'Zibasedom', 'virtual', 'camera', 'weather', 'philipsHue', 'enocean', 'wifipower', 'alarm', 'mode', 'apcupsd', 'btsniffer', 'dsc', 'rflink', 'mysensors', 'relaynet', 'remora', 'unipi', 'eibd', 'thermostat', 'netatmoThermostat', 'espeasy', 'jeelink', 'teleinfo', 'tahoma', 'protexiom', 'lifx', 'wattlet', 'rfplayer', 'openenocean', 'netatmoWeather', 'Volets');

public static $_pluginWidget = array('alarm', 'camera', 'thermostat', 'netatmoThermostat', 'weather', 'mode','mobile');
public static $_pluginWidget = array('alarm', 'camera', 'thermostat', 'netatmoThermostat', 'weather', 'mode', 'mobile');

public static $_pluginMulti = array('LIGHT_STATE', 'ENERGY_STATE', 'FLAP_STATE', 'HEATING_STATE', 'SIREN_STATE', 'LOCK_STATE');

Expand Down Expand Up @@ -97,26 +97,26 @@ public static function getTemplateJson() {
}
return json_decode(cmd::cmdToValue(file_get_contents(dirname(__FILE__) . '/../../data/mobile.json')), true);
}
public static function makeSaveJson($data = '',$mobileID, $type = 'dashboard') {
$path = dirname(__FILE__) . '/../../data/'.$mobileID.'/'.$type.'.json';

public static function makeSaveJson($data = array(), $mobileID, $type = 'dashboard') {
$path = dirname(__FILE__) . '/../../data/' . $mobileID . '/' . $type . '.json';
if (!file_exists(dirname(__FILE__) . '/../../data')) {
mkdir(dirname(__FILE__) . '/../../data');
}
if (!file_exists(dirname(__FILE__) . '/../../data/'.$mobileID)) {
mkdir(dirname(__FILE__) . '/../../data/'.$mobileID);
if (!file_exists(dirname(__FILE__) . '/../../data/' . $mobileID)) {
mkdir(dirname(__FILE__) . '/../../data/' . $mobileID);
}
if (file_exists(dirname(__FILE__) . '/../../data/'.$mobileID.'/'.$type.'.json')) {
unlink(dirname(__FILE__) . '/../../data/'.$mobileID.'/'.$type.'.json');
if (file_exists(dirname(__FILE__) . '/../../data/' . $mobileID . '/' . $type . '.json')) {
unlink(dirname(__FILE__) . '/../../data/' . $mobileID . '/' . $type . '.json');
}
file_put_contents(dirname(__FILE__) . '/../../data/'.$mobileID.'/'.$type.'.json', json_encode($data));
file_put_contents(dirname(__FILE__) . '/../../data/' . $mobileID . '/' . $type . '.json', json_encode($data));
}
public static function getSaveJson($mobileID,$type = 'dashboard') {
if (!file_exists(dirname(__FILE__) . '/../../data/'.$mobileID.'/'.$type.'.json')) {
self::makeSaveJson();

public static function getSaveJson($mobileID, $type = 'dashboard') {
if (!file_exists(dirname(__FILE__) . '/../../data/' . $mobileID . '/' . $type . '.json')) {
self::makeSaveJson(array(), $mobileID, $type);
}
return json_decode(file_get_contents(dirname(__FILE__) . '/../../data/'.$mobileID.'/'.$type.'.json'), true);
return json_decode(file_get_contents(dirname(__FILE__) . '/../../data/' . $mobileID . '/' . $type . '.json'), true);
}

public static function discovery_eqLogic($plugin = array(), $hash = null) {
Expand All @@ -127,7 +127,7 @@ public static function discovery_eqLogic($plugin = array(), $hash = null) {
continue;
}
foreach ($eqLogics as $eqLogic) {
if ($eqLogic->getEqType_name() != 'mobile'){
if ($eqLogic->getEqType_name() != 'mobile') {
if ($eqLogic->getIsEnable() != 1) {
continue;
}
Expand All @@ -139,7 +139,7 @@ public static function discovery_eqLogic($plugin = array(), $hash = null) {
}
}
$eqLogic_array = utils::o2a($eqLogic);
if ($eqLogic->getEqType_name() == 'mobile'){
if ($eqLogic->getEqType_name() == 'mobile') {
if (isset($eqLogic_array["logicalId"])) {
$eqLogic_array["localApiKey"] = $eqLogic_array["logicalId"];
}
Expand Down Expand Up @@ -182,6 +182,9 @@ public static function discovery_cmd($plugin = array(), $eqLogics = null, $_with
if (in_array($cmd->getGeneric_type(), ['GENERIC_ERROR', 'DONT'])) {
continue;
}
if (!isset($eqLogic['eqType_name'])) {
$eqLogic['eqType_name'] = '';
}
if ($cmd->getIsVisible() != 1 && !in_array($cmd->getGeneric_type(), $genericisvisible) && !in_array($eqLogic['eqType_name'], self::$_pluginWidget)) {
continue;
}
Expand Down Expand Up @@ -429,7 +432,7 @@ public function getQrCode() {
public static function jsonPublish($os, $titre, $message, $badge = 'null', $type, $idNotif, $answer, $timeout) {
$dateNotif = date("Y-m-d H:i:s");
$badge = '+1';
$message = preg_replace("# {2,}#"," ",preg_replace("#(\r\n|\n\r|\n|\r)#","\\\\\\n",$message));
$message = preg_replace("# {2,}#", " ", preg_replace("#(\r\n|\n\r|\n|\r)#", "\\\\\\n", $message));
if ($timeout != 'nok') {
$timeout = date('Y-m-d H:i:s', strtotime("$dateNotif + $timeout SECONDS"));
}
Expand Down Expand Up @@ -470,48 +473,56 @@ public static function notification($arn, $os, $titre, $message, $badge = 'null'
curl_close($ch);
log::add('mobile', 'debug', 'notification resultat > ' . $server_output);
}
public function SaveGeoloc($geoloc){
log::add('mobile', 'debug', '|-----------------------------------');
log::add('mobile', 'debug', '|--debut de la fonction SaveGeoLoc--');
log::add('mobile', 'debug', '|-----------------------------------');
log::add('mobile', 'debug', '|');
$eqLogicMobile = eqLogic::byLogicalId($geoloc['iQ'], 'mobile');
log::add('mobile', 'debug', '| iQ = '.$geoloc['iQ']);
if(isset($eqLogicMobile)){
log::add('mobile', 'debug', '| Mobile bien trouvé dans cette Jeedom');
log::add('mobile', 'debug', '| Objet > '.$eqLogicMobile->getId());
}
$cmdgeoloc = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(),'geoId_'.$geoloc['id']);
if(!is_object($cmdgeoloc)){

public function SaveGeoloc($geoloc) {
log::add('mobile', 'debug', '|-----------------------------------');
log::add('mobile', 'debug', '|--debut de la fonction SaveGeoLoc--');
log::add('mobile', 'debug', '|-----------------------------------');
log::add('mobile', 'debug', '|');
$eqLogicMobile = eqLogic::byLogicalId($geoloc['Iq'], 'mobile');
log::add('mobile', 'debug', '| Iq = ' . $geoloc['Iq']);
if (isset($eqLogicMobile)) {
log::add('mobile', 'debug', '| Mobile bien trouvé dans cette Jeedom');
log::add('mobile', 'debug', '| Objet > ' . $eqLogicMobile->getId());
}
$cmdgeoloc = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(), 'geoId_' . $geoloc['id']);
if (!is_object($cmdgeoloc)) {
$cmdgeoloc = new mobileCmd();
$cmdgeoloc->setLogicalId('geoId_'.$geoloc['id']);
$cmdgeoloc->setLogicalId('geoId_' . $geoloc['id']);
$cmdgeoloc->setEqLogic_id($eqLogicMobile->getId());
$cmdgeoloc->setType('info');
$cmdgeoloc->setSubType('binary');
$cmdgeoloc->setIsVisible(1);
}
$cmdgeoloc->setName(__($geoloc['name'], __FILE__));
$cmdgeoloc->setConfiguration('latitude', $geoloc['latitude']);
$cmdgeoloc->setConfiguration('longitude', $geoloc['longitude']);
$cmdgeoloc->setConfiguration('subtitle', $geoloc['subtitle']);
$cmdgeoloc->setConfiguration('radius', $geoloc['radius']);
$cmdgeoloc->save();
$cmdgeoloc->setName(__($geoloc['id'].'-'.$geoloc['name'], __FILE__));
$cmdgeoloc->setConfiguration('latitude', $geoloc['latitude']);
$cmdgeoloc->setConfiguration('longitude', $geoloc['longitude']);
$cmdgeoloc->setConfiguration('subtitle', $geoloc['subtitle']);
$cmdgeoloc->setConfiguration('radius', $geoloc['radius']);
$cmdgeoloc->save();
}

public function DelGeoloc($geoloc){
$eqLogicMobile = eqLogic::byLogicalId($geoloc['iQ'], 'mobile');
$cmdgeoloc = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(),'geoId_'.$geoloc['id']);
if(isset($cmdgeoloc)){

public function delGeoloc($geoloc) {
log::add('mobile', 'debug', 'Geoloc lancement DEL du 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();
}
}

public function EventGeoloc($geoloc){
$eqLogicMobile = eqLogic::byLogicalId($geoloc['iQ'], 'mobile');
$cmdgeoloc = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(),'geoId_'.$geoloc['id']);
if(isset($cmdgeoloc)){
$cmdgeoloc->event($geoloc['value']);

public function EventGeoloc($geoloc) {
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']);
if (isset($cmdgeoloc)) {
log::add('mobile', 'debug', 'commande trouvé');
if(geoloc['value'] !== $cmdgeoloc->execCmd()){
log::add('mobile', 'debug', 'Valeur non pareil.');
$cmdgeoloc->event($geoloc['value']);
}else{
log::add('mobile', 'debug', 'Valeur pareil. >'.geoloc['value'].' / '.$cmdgeoloc->execCmd());
}
}
}

Expand Down Expand Up @@ -557,7 +568,7 @@ class mobileCmd extends cmd {
/* * ***********************Methode static*************************** */

/* * *********************Methode d'instance************************* */

public function dontRemoveCmd() {
return true;
}
Expand Down Expand Up @@ -593,3 +604,4 @@ public function execute($_options = array()) {
}

?>

52 changes: 52 additions & 0 deletions desktop/js/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,58 @@ $('.nav-tabs a').on('shown.bs.tab', function (e) {
}
}
});
$.ajax({
type: "POST",
url: "plugins/mobile/core/ajax/mobile.ajax.php",
data: {
action: "getSaveDashboard",
iq: _eqLogic.logicalId,
},
dataType: 'json',
global: false,
error: function (request, status, error) {
handleAjaxError(request, status, error);
},
success: function (data) {
if (data.state != 'ok') {
$('#div_alert').showAlert({message: data.result, level: 'danger'});
return;
}
if (data.result == true) {
$('#SaveDash').addClass('badge-success');
$('#SaveDash').text('OK');
}else if(data.result == false){
$('#SaveDash').addClass('badge-danger');
$('#SaveDash').text('NOK');
}
}
});
$.ajax({
type: "POST",
url: "plugins/mobile/core/ajax/mobile.ajax.php",
data: {
action: "getSaveFavDash",
iq: _eqLogic.logicalId,
},
dataType: 'json',
global: false,
error: function (request, status, error) {
handleAjaxError(request, status, error);
},
success: function (data) {
if (data.state != 'ok') {
$('#div_alert').showAlert({message: data.result, level: 'danger'});
return;
}
if (data.result == true) {
$('#SaveFav').addClass('badge-success');
$('#SaveFav').text('OK');
}else if(data.result == false){
$('#SaveFav').addClass('badge-danger');
$('#SaveFav').text('NOK');
}
}
});
}


Expand Down
Loading