Skip to content

Commit 58f1e6d

Browse files
authored
improve code
1 parent 3e44c85 commit 58f1e6d

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

core/class/ajaxSystem.class.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,15 @@ public static function sync() {
174174
$devices = self::request('/user/{userId}/hubs/' . $hub['hubId'] . '/devices');
175175
log::add('ajaxSystem', 'debug', json_encode($devices));
176176
foreach ($devices as $device) {
177+
if (!isset($device['id'])) {
178+
continue;
179+
}
180+
$eqLogic = eqLogic::byLogicalId($device['id'], 'ajaxSystem');
177181
$device_info = self::request('/user/{userId}/hubs/' . $hub['hubId'] . '/devices/' . $device['id']);
178-
if($device_info['deviceName'] == ''){
182+
usleep(200000);
183+
if(!isset($device_info['deviceName']) || $device_info['deviceName'] == ''){
179184
continue;
180185
}
181-
$eqLogic = eqLogic::byLogicalId($device['id'], 'ajaxSystem');
182186
if (!is_object($eqLogic)) {
183187
$eqLogic = new ajaxSystem();
184188
$eqLogic->setEqType_name('ajaxSystem');
@@ -194,7 +198,7 @@ public static function sync() {
194198
$eqLogic->setConfiguration('firmware', $device_info['firmwareVersion']);
195199
$eqLogic->setLogicalId($device['id']);
196200
$eqLogic->save();
197-
$eqLogic->refreshData();
201+
$eqLogic->refreshData($device_info);
198202
}
199203

200204
$groups = self::request('/user/{userId}/hubs/' . $hub['hubId'] . '/groups');
@@ -217,7 +221,7 @@ public static function sync() {
217221
$eqLogic->setConfiguration('device', 'group');
218222
$eqLogic->setLogicalId($group['id']);
219223
$eqLogic->save();
220-
$eqLogic->refreshData();
224+
$eqLogic->refreshData($group);
221225
}
222226
}
223227
}
@@ -283,12 +287,16 @@ public function getImage() {
283287
return false;
284288
}
285289

286-
public function refreshData() {
287-
if ($this->getConfiguration('type') == 'hub') {
288-
$datas = self::request('/user/{userId}/hubs/' . $this->getLogicalId());
289-
}
290-
if ($this->getConfiguration('type') == 'device') {
291-
$datas = self::request('/user/{userId}/hubs/' . $this->getConfiguration('hub_id') . '/devices/' . $this->getLogicalId());
290+
public function refreshData($_data = null) {
291+
if($_data == null){
292+
if ($this->getConfiguration('type') == 'hub') {
293+
$datas = self::request('/user/{userId}/hubs/' . $this->getLogicalId());
294+
}
295+
if ($this->getConfiguration('type') == 'device') {
296+
$datas = self::request('/user/{userId}/hubs/' . $this->getConfiguration('hub_id') . '/devices/' . $this->getLogicalId());
297+
}
298+
}else{
299+
$datas = $_data;
292300
}
293301
if (isset($datas['firmwareVersion']) && $datas['firmwareVersion'] != $this->getConfiguration('firmware')) {
294302
$this->setConfiguration('firmware', $datas['firmwareVersion']);

0 commit comments

Comments
 (0)