Skip to content

Commit 75b4e54

Browse files
authored
Merge pull request #42 from jeedom/beta
To Stable
2 parents e59f01b + 1ca93ad commit 75b4e54

6 files changed

Lines changed: 225 additions & 139 deletions

File tree

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ nbproject/
22
test.php
33
core/config/common.config.php
44
plugins
5-
sftp-config.json
6-
.project
5+
deployment-config.json
6+
.project

core/ajax/mobile.ajax.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@
4444
mobile::makeTemplateJson();
4545
ajax::success();
4646
}
47+
48+
if (init('action') == 'getSaveDashboard'){
49+
$iq = init('iq');
50+
$jsonDashboard = mobile::getSaveJson($iq, 'dashboard');
51+
if ($jsonDashboard == ""){
52+
$reponse = false;
53+
}else{
54+
$reponse = true;
55+
}
56+
ajax::success($reponse);
57+
}
58+
59+
if (init('action') == 'getSaveFavDash'){
60+
$iq = init('iq');
61+
$jsonFavDash = mobile::getSaveJson($iq, 'favdash');
62+
if ($jsonFavDash == ""){
63+
$reponse = false;
64+
}else{
65+
$reponse = true;
66+
}
67+
ajax::success($reponse);
68+
}
4769

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

core/api/mobile.api.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
$params = $jsonrpc->getParams();
2929

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

3233
if ($jsonrpc->getMethod() == 'sync') {
3334
if (jeedom::version() >= '3.2.0') {
@@ -174,17 +175,22 @@
174175
}
175176

176177
if ($jsonrpc->getMethod() == 'geolocSave'){
177-
log::add('mobile', 'debug', 'Geoloc ADD '. $params['id'] .' > ' . $params['name']);
178-
mobile::SaveGeoloc($params);
179-
$jsonrpc->makeSuccess();
178+
log::add('mobile', 'debug', 'Geoloc SAVE '. $params['id'] .' > ' . $params['name']);
179+
if($params['id'] != '' || $params['id'] != null){
180+
mobile::SaveGeoloc($params);
181+
$jsonrpc->makeSuccess();
182+
}else{
183+
throw new Exception(__('pas d\'id : ', __FILE__) . $params['name']);
184+
}
180185
}
181186

182187
if ($jsonrpc->getMethod() == 'geolocDel'){
183188
log::add('mobile', 'debug', 'Geoloc DEL '. $params['id'] .' > ' . $params['name']);
184-
mobile::DelGeoloc($params);
189+
mobile::delGeoloc($params);
185190
$jsonrpc->makeSuccess();
186191
}
187192

188193

189194
throw new Exception(__('Aucune demande', __FILE__));
190195
?>
196+

core/class/mobile.class.php

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
class mobile extends eqLogic {
2323
/* * *************************Attributs****************************** */
2424

25-
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');
25+
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');
2626

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

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

@@ -97,26 +97,26 @@ public static function getTemplateJson() {
9797
}
9898
return json_decode(cmd::cmdToValue(file_get_contents(dirname(__FILE__) . '/../../data/mobile.json')), true);
9999
}
100-
101-
public static function makeSaveJson($data = '',$mobileID, $type = 'dashboard') {
102-
$path = dirname(__FILE__) . '/../../data/'.$mobileID.'/'.$type.'.json';
100+
101+
public static function makeSaveJson($data = array(), $mobileID, $type = 'dashboard') {
102+
$path = dirname(__FILE__) . '/../../data/' . $mobileID . '/' . $type . '.json';
103103
if (!file_exists(dirname(__FILE__) . '/../../data')) {
104104
mkdir(dirname(__FILE__) . '/../../data');
105105
}
106-
if (!file_exists(dirname(__FILE__) . '/../../data/'.$mobileID)) {
107-
mkdir(dirname(__FILE__) . '/../../data/'.$mobileID);
106+
if (!file_exists(dirname(__FILE__) . '/../../data/' . $mobileID)) {
107+
mkdir(dirname(__FILE__) . '/../../data/' . $mobileID);
108108
}
109-
if (file_exists(dirname(__FILE__) . '/../../data/'.$mobileID.'/'.$type.'.json')) {
110-
unlink(dirname(__FILE__) . '/../../data/'.$mobileID.'/'.$type.'.json');
109+
if (file_exists(dirname(__FILE__) . '/../../data/' . $mobileID . '/' . $type . '.json')) {
110+
unlink(dirname(__FILE__) . '/../../data/' . $mobileID . '/' . $type . '.json');
111111
}
112-
file_put_contents(dirname(__FILE__) . '/../../data/'.$mobileID.'/'.$type.'.json', json_encode($data));
112+
file_put_contents(dirname(__FILE__) . '/../../data/' . $mobileID . '/' . $type . '.json', json_encode($data));
113113
}
114-
115-
public static function getSaveJson($mobileID,$type = 'dashboard') {
116-
if (!file_exists(dirname(__FILE__) . '/../../data/'.$mobileID.'/'.$type.'.json')) {
117-
self::makeSaveJson();
114+
115+
public static function getSaveJson($mobileID, $type = 'dashboard') {
116+
if (!file_exists(dirname(__FILE__) . '/../../data/' . $mobileID . '/' . $type . '.json')) {
117+
self::makeSaveJson(array(), $mobileID, $type);
118118
}
119-
return json_decode(file_get_contents(dirname(__FILE__) . '/../../data/'.$mobileID.'/'.$type.'.json'), true);
119+
return json_decode(file_get_contents(dirname(__FILE__) . '/../../data/' . $mobileID . '/' . $type . '.json'), true);
120120
}
121121

122122
public static function discovery_eqLogic($plugin = array(), $hash = null) {
@@ -127,7 +127,7 @@ public static function discovery_eqLogic($plugin = array(), $hash = null) {
127127
continue;
128128
}
129129
foreach ($eqLogics as $eqLogic) {
130-
if ($eqLogic->getEqType_name() != 'mobile'){
130+
if ($eqLogic->getEqType_name() != 'mobile') {
131131
if ($eqLogic->getIsEnable() != 1) {
132132
continue;
133133
}
@@ -139,7 +139,7 @@ public static function discovery_eqLogic($plugin = array(), $hash = null) {
139139
}
140140
}
141141
$eqLogic_array = utils::o2a($eqLogic);
142-
if ($eqLogic->getEqType_name() == 'mobile'){
142+
if ($eqLogic->getEqType_name() == 'mobile') {
143143
if (isset($eqLogic_array["logicalId"])) {
144144
$eqLogic_array["localApiKey"] = $eqLogic_array["logicalId"];
145145
}
@@ -182,6 +182,9 @@ public static function discovery_cmd($plugin = array(), $eqLogics = null, $_with
182182
if (in_array($cmd->getGeneric_type(), ['GENERIC_ERROR', 'DONT'])) {
183183
continue;
184184
}
185+
if (!isset($eqLogic['eqType_name'])) {
186+
$eqLogic['eqType_name'] = '';
187+
}
185188
if ($cmd->getIsVisible() != 1 && !in_array($cmd->getGeneric_type(), $genericisvisible) && !in_array($eqLogic['eqType_name'], self::$_pluginWidget)) {
186189
continue;
187190
}
@@ -429,7 +432,7 @@ public function getQrCode() {
429432
public static function jsonPublish($os, $titre, $message, $badge = 'null', $type, $idNotif, $answer, $timeout) {
430433
$dateNotif = date("Y-m-d H:i:s");
431434
$badge = '+1';
432-
$message = preg_replace("# {2,}#"," ",preg_replace("#(\r\n|\n\r|\n|\r)#","\\\\\\n",$message));
435+
$message = preg_replace("# {2,}#", " ", preg_replace("#(\r\n|\n\r|\n|\r)#", "\\\\\\n", $message));
433436
if ($timeout != 'nok') {
434437
$timeout = date('Y-m-d H:i:s', strtotime("$dateNotif + $timeout SECONDS"));
435438
}
@@ -470,48 +473,56 @@ public static function notification($arn, $os, $titre, $message, $badge = 'null'
470473
curl_close($ch);
471474
log::add('mobile', 'debug', 'notification resultat > ' . $server_output);
472475
}
473-
474-
public function SaveGeoloc($geoloc){
475-
log::add('mobile', 'debug', '|-----------------------------------');
476-
log::add('mobile', 'debug', '|--debut de la fonction SaveGeoLoc--');
477-
log::add('mobile', 'debug', '|-----------------------------------');
478-
log::add('mobile', 'debug', '|');
479-
$eqLogicMobile = eqLogic::byLogicalId($geoloc['iQ'], 'mobile');
480-
log::add('mobile', 'debug', '| iQ = '.$geoloc['iQ']);
481-
if(isset($eqLogicMobile)){
482-
log::add('mobile', 'debug', '| Mobile bien trouvé dans cette Jeedom');
483-
log::add('mobile', 'debug', '| Objet > '.$eqLogicMobile->getId());
484-
}
485-
$cmdgeoloc = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(),'geoId_'.$geoloc['id']);
486-
if(!is_object($cmdgeoloc)){
476+
477+
public function SaveGeoloc($geoloc) {
478+
log::add('mobile', 'debug', '|-----------------------------------');
479+
log::add('mobile', 'debug', '|--debut de la fonction SaveGeoLoc--');
480+
log::add('mobile', 'debug', '|-----------------------------------');
481+
log::add('mobile', 'debug', '|');
482+
$eqLogicMobile = eqLogic::byLogicalId($geoloc['Iq'], 'mobile');
483+
log::add('mobile', 'debug', '| Iq = ' . $geoloc['Iq']);
484+
if (isset($eqLogicMobile)) {
485+
log::add('mobile', 'debug', '| Mobile bien trouvé dans cette Jeedom');
486+
log::add('mobile', 'debug', '| Objet > ' . $eqLogicMobile->getId());
487+
}
488+
$cmdgeoloc = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(), 'geoId_' . $geoloc['id']);
489+
if (!is_object($cmdgeoloc)) {
487490
$cmdgeoloc = new mobileCmd();
488-
$cmdgeoloc->setLogicalId('geoId_'.$geoloc['id']);
491+
$cmdgeoloc->setLogicalId('geoId_' . $geoloc['id']);
489492
$cmdgeoloc->setEqLogic_id($eqLogicMobile->getId());
490493
$cmdgeoloc->setType('info');
491494
$cmdgeoloc->setSubType('binary');
492495
$cmdgeoloc->setIsVisible(1);
493496
}
494-
$cmdgeoloc->setName(__($geoloc['name'], __FILE__));
495-
$cmdgeoloc->setConfiguration('latitude', $geoloc['latitude']);
496-
$cmdgeoloc->setConfiguration('longitude', $geoloc['longitude']);
497-
$cmdgeoloc->setConfiguration('subtitle', $geoloc['subtitle']);
498-
$cmdgeoloc->setConfiguration('radius', $geoloc['radius']);
499-
$cmdgeoloc->save();
497+
$cmdgeoloc->setName(__($geoloc['id'].'-'.$geoloc['name'], __FILE__));
498+
$cmdgeoloc->setConfiguration('latitude', $geoloc['latitude']);
499+
$cmdgeoloc->setConfiguration('longitude', $geoloc['longitude']);
500+
$cmdgeoloc->setConfiguration('subtitle', $geoloc['subtitle']);
501+
$cmdgeoloc->setConfiguration('radius', $geoloc['radius']);
502+
$cmdgeoloc->save();
500503
}
501-
502-
public function DelGeoloc($geoloc){
503-
$eqLogicMobile = eqLogic::byLogicalId($geoloc['iQ'], 'mobile');
504-
$cmdgeoloc = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(),'geoId_'.$geoloc['id']);
505-
if(isset($cmdgeoloc)){
504+
505+
public function delGeoloc($geoloc) {
506+
log::add('mobile', 'debug', 'Geoloc lancement DEL du mobile > '.$geoloc['Iq'].' pour '.$geoloc['id']);
507+
$eqLogicMobile = eqLogic::byLogicalId($geoloc['Iq'], 'mobile');
508+
$cmdgeoloc = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(), 'geoId_' . $geoloc['id']);
509+
if(isset($cmdgeoloc)) {
506510
$cmdgeoloc->remove();
507511
}
508512
}
509-
510-
public function EventGeoloc($geoloc){
511-
$eqLogicMobile = eqLogic::byLogicalId($geoloc['iQ'], 'mobile');
512-
$cmdgeoloc = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(),'geoId_'.$geoloc['id']);
513-
if(isset($cmdgeoloc)){
514-
$cmdgeoloc->event($geoloc['value']);
513+
514+
public function EventGeoloc($geoloc) {
515+
log::add('mobile', 'debug', 'Geoloc Event du mobile > '.$geoloc['Iq'].' pour '.$geoloc['id']);
516+
$eqLogicMobile = eqLogic::byLogicalId($geoloc['Iq'], 'mobile');
517+
$cmdgeoloc = cmd::byEqLogicIdAndLogicalId($eqLogicMobile->getId(), 'geoId_' . $geoloc['id']);
518+
if (isset($cmdgeoloc)) {
519+
log::add('mobile', 'debug', 'commande trouvé');
520+
if(geoloc['value'] !== $cmdgeoloc->execCmd()){
521+
log::add('mobile', 'debug', 'Valeur non pareil.');
522+
$cmdgeoloc->event($geoloc['value']);
523+
}else{
524+
log::add('mobile', 'debug', 'Valeur pareil. >'.geoloc['value'].' / '.$cmdgeoloc->execCmd());
525+
}
515526
}
516527
}
517528

@@ -557,7 +568,7 @@ class mobileCmd extends cmd {
557568
/* * ***********************Methode static*************************** */
558569

559570
/* * *********************Methode d'instance************************* */
560-
571+
561572
public function dontRemoveCmd() {
562573
return true;
563574
}
@@ -593,3 +604,4 @@ public function execute($_options = array()) {
593604
}
594605

595606
?>
607+

desktop/js/mobile.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,58 @@ $('.nav-tabs a').on('shown.bs.tab', function (e) {
8282
}
8383
}
8484
});
85+
$.ajax({
86+
type: "POST",
87+
url: "plugins/mobile/core/ajax/mobile.ajax.php",
88+
data: {
89+
action: "getSaveDashboard",
90+
iq: _eqLogic.logicalId,
91+
},
92+
dataType: 'json',
93+
global: false,
94+
error: function (request, status, error) {
95+
handleAjaxError(request, status, error);
96+
},
97+
success: function (data) {
98+
if (data.state != 'ok') {
99+
$('#div_alert').showAlert({message: data.result, level: 'danger'});
100+
return;
101+
}
102+
if (data.result == true) {
103+
$('#SaveDash').addClass('badge-success');
104+
$('#SaveDash').text('OK');
105+
}else if(data.result == false){
106+
$('#SaveDash').addClass('badge-danger');
107+
$('#SaveDash').text('NOK');
108+
}
109+
}
110+
});
111+
$.ajax({
112+
type: "POST",
113+
url: "plugins/mobile/core/ajax/mobile.ajax.php",
114+
data: {
115+
action: "getSaveFavDash",
116+
iq: _eqLogic.logicalId,
117+
},
118+
dataType: 'json',
119+
global: false,
120+
error: function (request, status, error) {
121+
handleAjaxError(request, status, error);
122+
},
123+
success: function (data) {
124+
if (data.state != 'ok') {
125+
$('#div_alert').showAlert({message: data.result, level: 'danger'});
126+
return;
127+
}
128+
if (data.result == true) {
129+
$('#SaveFav').addClass('badge-success');
130+
$('#SaveFav').text('OK');
131+
}else if(data.result == false){
132+
$('#SaveFav').addClass('badge-danger');
133+
$('#SaveFav').text('NOK');
134+
}
135+
}
136+
});
85137
}
86138

87139

0 commit comments

Comments
 (0)