diff --git a/app/api/CronApi.php b/app/api/CronApi.php index 58a0404..ad4dcf2 100644 --- a/app/api/CronApi.php +++ b/app/api/CronApi.php @@ -12,6 +12,7 @@ class CronApi extends ApiController { echo (new Covid)->fetch(''); echo (new OpenWeatherMap)->fetch(''); echo (new UsaElection)->fetch(''); + echo (new AirQuality)->fetch(''); // Database Backup $filenames = []; diff --git a/app/models/managers/RecordManager.php b/app/models/managers/RecordManager.php index f9154f9..f6fe640 100644 --- a/app/models/managers/RecordManager.php +++ b/app/models/managers/RecordManager.php @@ -29,6 +29,7 @@ class RecordManager{ if (self::getLastRecord($subDeviceId, 1)['value'] === $value){ return false; } + try { $record = [ diff --git a/app/plugins/AirQuality.php b/app/plugins/AirQuality.php new file mode 100644 index 0000000..ce958ef --- /dev/null +++ b/app/plugins/AirQuality.php @@ -0,0 +1,32 @@ +virtual_device_name)) { + $deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id']; + if (!$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, $this->subdevice_type)) { + SubDeviceManager::create($deviceId, $this->subdevice_type, ''); + sleep(1); + } + + //if (!$this->fetchEnabled($deviceId,$subDevice['subdevice_id'])) die(); + + $finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id); + $json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true); + + RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi']); + } else { + DeviceManager::create($this->virtual_device_name, $this->virtual_device_name); + DeviceManager::approved($this->virtual_device_name); + } + } +}