Skip to content

Commit f1b66a6

Browse files
authored
Merge pull request #22 from Jezza34000/beta
add IA detection type
2 parents 6a5e776 + cf9ded8 commit f1b66a6

File tree

5 files changed

+41
-46
lines changed

5 files changed

+41
-46
lines changed

3rdparty/reolinkapi.class.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,17 @@ public function __construct(array $cnxinfo) {
160160
$this->cnxtype = strtolower($cnxinfo['cnxtype']);
161161
}
162162

163-
if ($this->cnxtype == "http") {
164-
($cnxinfo['port'] == "" || !is_numeric($cnxinfo['port'])) ? $this->port = 80 : $this->port = trim($cnxinfo['port']);
163+
if ($cnxinfo['port'] == "" || !is_numeric($cnxinfo['port'])) {
164+
if ($this->cnxtype == "http") {
165+
$this->port = 80;
166+
} else {
167+
$this->port = 443;
168+
}
165169
} else {
166-
($cnxinfo['port'] == "" || !is_numeric($cnxinfo['port'])) ? $this->port = 443 : $this->port = trim($cnxinfo['port']);
170+
$this->port = trim($cnxinfo['port']);
167171
}
168172

173+
169174
$this->user = trim($cnxinfo['username']);
170175
$this->password = trim($cnxinfo['password']);
171176
$this->tagtoken = str_replace(".", "", $this->ip);

core/ajax/reolink.ajax.php

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030
*/
3131
ajax::init();
3232

33+
$camera = reolink::byId(init('id'));
34+
if (!is_object($camera)) {
35+
throw new Exception(__('Impossible de trouver la caméra : ' . init('id'), __FILE__));
36+
}
37+
38+
3339
if (init('action') == 'CreateCMD') {
34-
$camera = reolink::byId(init('id'));
35-
if (!is_object($camera)) {
36-
throw new Exception(__('Impossible de trouver la caméra : ' . init('id'), __FILE__));
37-
}
3840
$camera->GetCamNFO(init('id'));
3941
$res = $camera->loadCmdFromConf(init('id'));
4042

@@ -46,10 +48,6 @@
4648
}
4749

4850
if (init('action') == 'CheckConnexion') {
49-
$camera = reolink::byId(init('id'));
50-
if (!is_object($camera)) {
51-
throw new Exception(__('Impossible de trouver la caméra : ' . init('id'), __FILE__));
52-
}
5351
$res = $camera->TryConnect(init('id'));
5452
if ($res === true) {
5553
ajax::success();
@@ -59,43 +57,15 @@
5957
}
6058

6159
if (init('action') == 'CheckDeviceInfo') {
62-
$camera = reolink::byId(init('id'));
63-
if (!is_object($camera)) {
64-
throw new Exception(__('Impossible de trouver la caméra : ' . init('id'), __FILE__));
65-
}
6660
$res = $camera->GetCamNFO(init('id'));
6761
if ($res === true) {
6862
ajax::success();
6963
} else {
70-
throw new Exception(__('Impossible de se connecter à la caméra ('.$res.')', __FILE__));
64+
throw new Exception(__('Impossible d\'obtenir les informations de la caméra ('.$res.')', __FILE__));
7165
}
7266
}
7367

74-
if (init('action') == 'SetCAMConfig') {
75-
$camera = reolink::byId(init('id'));
76-
if (!is_object($camera)) {
77-
throw new Exception(__('Impossible de trouver la caméra : ' . init('id'), __FILE__));
78-
}
79-
$cfgGroup = init('group');
80-
if ($cfgGroup == 'EMAIL'){
81-
$res = reolink::setEmail(init('id'));
82-
}
83-
if ($cfgGroup == 'FTP'){
84-
$res = reolink::setFTP(init('id'));
85-
}
86-
87-
if ($res == 200) {
88-
ajax::success();
89-
} else {
90-
throw new Exception(__('Echec du paramétrage de la caméra (consultez le log pour plus de détails)', __FILE__));
91-
}
92-
}
93-
9468
if (init('action') == 'GetCAMConfig') {
95-
$camera = reolink::byId(init('id'));
96-
if (!is_object($camera)) {
97-
throw new Exception(__('Impossible de trouver la caméra : ' . init('id'), __FILE__));
98-
}
9969
$res = reolink::refreshNFO(init('id'));
10070
ajax::success();
10171
}

core/class/reolink.class.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,14 +467,16 @@ public static function refreshNFO($id) {
467467
case reolinkAPI::CAM_GET_AIALARM:
468468
switch ($json_data['value']['AiAlarm']['ai_type']) {
469469
case "people":
470-
$camcmd->checkAndUpdateCmd('SetSdSensitivityPeopleState', $json_data['value']['AiAlarm']['sensitivity']);
471-
$camcmd->checkAndUpdateCmd('SetAlarmDelayPeopleState', $json_data['value']['AiAlarm']['stay_time']);
470+
$s1 = 'SetSdSensitivityPeopleState';
471+
$s2 = 'SetAlarmDelayPeopleState';
472472
break;
473473
case "vehicle":
474-
$camcmd->checkAndUpdateCmd('SetSdSensitivityVehicleState', $json_data['value']['AiAlarm']['sensitivity']);
475-
$camcmd->checkAndUpdateCmd('SetAlarmDelayVehicleState', $json_data['value']['AiAlarm']['stay_time']);
474+
$s1 = 'SetSdSensitivityVehicleState';
475+
$s2 = 'SetAlarmDelayVehicleState';
476476
break;
477477
}
478+
$camcmd->checkAndUpdateCmd($s1, $json_data['value']['AiAlarm']['sensitivity']);
479+
$camcmd->checkAndUpdateCmd($s2, $json_data['value']['AiAlarm']['stay_time']);
478480
log::add('reolink', 'debug', 'ai_type check : '. $json_data['value']['AiAlarm']['ai_type']);
479481
break;
480482

core/php/jeeReolink.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,28 @@
2222

2323
foreach ($eqLogics as $eqLogic) {
2424
$camera_contact_point = $eqLogic->getConfiguration('adresseip');
25+
$camera_AI = $eqLogic->getConfiguration('supportai');
26+
2527
if (filter_var($camera_contact_point, FILTER_VALIDATE_IP)) {
2628
$camera_ip = $camera_contact_point;
2729
} else {
2830
$camera_ip = gethostbyname($camera_contact_point);
2931
}
32+
3033
if ($camera_ip == $result['ip']) {
31-
log::add('reolink', 'debug', 'Evènement MotionState reçu depuis le daemon. Cam IP='.$result['ip'].' état='.$result['motionstate']);
32-
$eqLogic->checkAndUpdateCmd('MdState', $result['motionstate']);
34+
log::add('reolink', 'debug', 'Evènement MotionState reçu depuis le daemon. Cam IP='.$result['ip'].' état='.$result['motionstate']);
35+
$eqLogic->checkAndUpdateCmd('MdState', $result['motionstate']);
36+
#log::add('reolink', 'debug', 'IP : ' . $camera_contact_point . ' / IsCamAI : ' . $camera_AI . ' / EqId : ' . $EqId . ' / Channel : ' . $channel);
37+
if ($camera_AI == "Oui") {
38+
$camcnx = reolink::getReolinkConnection($eqLogic->getId());
39+
$channel = $eqLogic->getConfiguration('channelNum') - 1;
40+
$res = $camcnx->SendCMD('[{"cmd":"GetAiState","action":0,"param":{"channel":'.$channel.'}}]');
41+
if (isset($res[0]['value'])) {
42+
$eqLogic->checkAndUpdateCmd('MdPersonState', $res[0]['value']['people']['alarm_state']);
43+
$eqLogic->checkAndUpdateCmd('MdVehicleState', $res[0]['value']['vehicle']['alarm_state']);
44+
}
45+
log::add('reolink', 'debug', 'Cam AI : Evènements Motion | Personne : ' . $res[0]['value']['people']['alarm_state'] . ' / Vehicule : ' . $res[0]['value']['vehicle']['alarm_state']);
46+
}
3347
}
3448
}
3549
} elseif (isset($result['message']) && $result['message'] == "subscription") {

plugin_info/install.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ function reolink_install() {
2525

2626
// Fonction exécutée automatiquement après la mise à jour du plugin
2727
function reolink_update() {
28+
$plugin = plugin::byId('reolink');
29+
$eqLogics = eqLogic::byType($plugin->getId());
30+
foreach ($eqLogics as $eqLogic) {
2831

32+
}
2933
}
3034

3135
// Fonction exécutée automatiquement après la suppression du plugin

0 commit comments

Comments
 (0)