Compare commits
5 Commits
3.0
...
1d44bd62e2
Author | SHA1 | Date | |
---|---|---|---|
|
1d44bd62e2 | ||
|
75dab33c9a | ||
2410441b88 | |||
|
1f49391b36 | ||
|
c17e3090a8 |
11
README.md
11
README.md
@@ -136,6 +136,17 @@ Distributed under the MIT License. See `LICENSE` for more information.
|
|||||||
Project Link: [https://github.com/GamerClassN7/Smart_Home/](https://github.com/GamerClassN7/Smart_Home/) <br> <br>
|
Project Link: [https://github.com/GamerClassN7/Smart_Home/](https://github.com/GamerClassN7/Smart_Home/) <br> <br>
|
||||||
<sup><sub>Tags (ignore): ESP32 ESP12 ESP08 ESP01 ESP Smart Home Automation System PWA PHP HTML JS DHT11 DHT22
|
<sup><sub>Tags (ignore): ESP32 ESP12 ESP08 ESP01 ESP Smart Home Automation System PWA PHP HTML JS DHT11 DHT22
|
||||||
|
|
||||||
|
## Code Statistics
|
||||||
|
Type | Files | Lines
|
||||||
|
-----|-------|-----------
|
||||||
|
php | 2 | 2298 (89%)
|
||||||
|
md | 1 | 171 (7%)
|
||||||
|
js | 1 | 64 (2%)
|
||||||
|
sh | 1 | 34 (1%)
|
||||||
|
json | 1 | 10 (0.4%)
|
||||||
|
-----|-------|-----------
|
||||||
|
All | 6 | 2577
|
||||||
|
|
||||||
## Folder structure
|
## Folder structure
|
||||||
```
|
```
|
||||||
- /app # app specific files
|
- /app # app specific files
|
||||||
|
@@ -113,7 +113,7 @@ class EndpointsApi extends ApiController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$subDeviceLastReordValue[$key] = $value['value'];
|
$subDeviceLastReordValue[$key] = $value['value'];
|
||||||
RecordManager::create($device['device_id'], $key, round($value['value'],3));
|
RecordManager::create($device['device_id'], $key, round($value['value'],3), 'device');
|
||||||
$logManager->write("[API] Device_ID " . $device['device_id'] . " writed value " . $key . ' ' . $value['value'], LogRecordTypes::INFO);
|
$logManager->write("[API] Device_ID " . $device['device_id'] . " writed value " . $key . ' ' . $value['value'], LogRecordTypes::INFO);
|
||||||
|
|
||||||
//notification
|
//notification
|
||||||
|
@@ -14,7 +14,7 @@ class WidgetApi extends ApiController
|
|||||||
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
||||||
if ($subDeviceData['type'] == 'on/off') {
|
if ($subDeviceData['type'] == 'on/off') {
|
||||||
$lastValue = RecordManager::getLastRecord($subDeviceData['subdevice_id'])['value'];
|
$lastValue = RecordManager::getLastRecord($subDeviceData['subdevice_id'])['value'];
|
||||||
RecordManager::create($subDeviceData['device_id'], 'on/off', (int) !$lastValue);
|
RecordManager::create($subDeviceData['device_id'], 'on/off', (int) !$lastValue, "vue-app");
|
||||||
$response = !$lastValue;
|
$response = !$lastValue;
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Bad Request", 403);
|
throw new Exception("Bad Request", 403);
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
class GoogleHome {
|
class GoogleHome
|
||||||
static function sync($requestId){
|
{
|
||||||
|
static function sync($requestId)
|
||||||
|
{
|
||||||
$devices = [];
|
$devices = [];
|
||||||
$roomsData = RoomManager::getAllRooms();
|
$roomsData = RoomManager::getAllRooms();
|
||||||
foreach ($roomsData as $roomKey => $roomData) {
|
foreach ($roomsData as $roomKey => $roomData) {
|
||||||
@@ -64,19 +66,21 @@ class GoogleHome {
|
|||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function query($requestId, $payload){
|
static function query($requestId, $payload)
|
||||||
|
{
|
||||||
$devices = [];
|
$devices = [];
|
||||||
$num = 0;
|
$num = 0;
|
||||||
foreach ($payload['devices'] as $deviceId) {
|
foreach ($payload['devices'] as $deviceId) {
|
||||||
$subDevicesData = SubDeviceManager::getAllSubDevices($deviceId['id']);
|
|
||||||
|
|
||||||
$tempDevice[$deviceId['id']] = [
|
$tempDevice[$deviceId['id']] = [
|
||||||
'online' => false,
|
'online' => false,
|
||||||
'status' => 'OFFLINE',
|
'status' => 'OFFLINE',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($subDevicesData = SubDeviceManager::getAllSubDevices($deviceId['id'])) {
|
||||||
foreach ($subDevicesData as $key => $subDeviceData) {
|
foreach ($subDevicesData as $key => $subDeviceData) {
|
||||||
$lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']);
|
$lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']);
|
||||||
if ($lastRecord['execuded'] == 1){
|
if ($lastRecord != false && $lastRecord['execuded'] == 1) {
|
||||||
$tempDevice[$deviceId['id']]['online'] = true;
|
$tempDevice[$deviceId['id']]['online'] = true;
|
||||||
$tempDevice[$deviceId['id']]['status'] = "SUCCESS";
|
$tempDevice[$deviceId['id']]['status'] = "SUCCESS";
|
||||||
} else {
|
} else {
|
||||||
@@ -121,11 +125,14 @@ class GoogleHome {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($lastRecord['execuded'] == 1){
|
// $lastRecord = RecordManager::getLastRecord($deviceId['id']);
|
||||||
$online = true;
|
// //var_dump($lastRecord);
|
||||||
$status = 'SUCCESS';
|
// if ($lastRecord['execuded'] == 1) {
|
||||||
} else {
|
// $online = true;
|
||||||
|
// $status = 'SUCCESS';
|
||||||
|
// } else {
|
||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
||||||
@@ -135,15 +142,16 @@ class GoogleHome {
|
|||||||
$waiting++;
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($waiting < $executed) {
|
if ($waiting < $executed) {
|
||||||
$status = "PENDING";
|
$status = "PENDING";
|
||||||
$online = true;
|
$online = true;
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
$devices = $tempDevice;
|
$devices = $tempDevice;
|
||||||
/*if (count($devices)> 1){
|
if (count($devices)> 1){
|
||||||
$devices[] = $tempDevice;
|
$devices[] = $tempDevice;
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
$response = [
|
$response = [
|
||||||
'requestId' => $requestId,
|
'requestId' => $requestId,
|
||||||
@@ -157,7 +165,8 @@ class GoogleHome {
|
|||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function execute($requestId, $payload){
|
static function execute($requestId, $payload)
|
||||||
|
{
|
||||||
$commands = [];
|
$commands = [];
|
||||||
foreach ($payload['commands'] as $key => $command) {
|
foreach ($payload['commands'] as $key => $command) {
|
||||||
foreach ($command['devices'] as $key2 => $device) {
|
foreach ($command['devices'] as $key2 => $device) {
|
||||||
@@ -167,7 +176,8 @@ static function execute($requestId, $payload){
|
|||||||
}
|
}
|
||||||
|
|
||||||
$deviceType = GoogleHomeDeviceTypes::getType($executionCommand['command']);
|
$deviceType = GoogleHomeDeviceTypes::getType($executionCommand['command']);
|
||||||
$subDeviceId = SubDeviceManager::getSubDeviceByMasterAndType($device['id'], $deviceType)['subdevice_id'];
|
if ($subDeviceId = SubDeviceManager::getSubDeviceByMasterAndType($device['id'], $deviceType)) {
|
||||||
|
$subDeviceId = $subDeviceId['subdevice_id'];
|
||||||
switch ($executionCommand['command']) {
|
switch ($executionCommand['command']) {
|
||||||
case 'action.devices.commands.OnOff':
|
case 'action.devices.commands.OnOff':
|
||||||
$commands[] = self::executeSwitch($subDeviceId, $executionCommand);
|
$commands[] = self::executeSwitch($subDeviceId, $executionCommand);
|
||||||
@@ -212,9 +222,10 @@ static function execute($requestId, $payload){
|
|||||||
case 'action.devices.commands.mediaStop':
|
case 'action.devices.commands.mediaStop':
|
||||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$response = [
|
$response = [
|
||||||
'requestId' => $requestId,
|
'requestId' => $requestId,
|
||||||
@@ -230,14 +241,15 @@ static function execute($requestId, $payload){
|
|||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeSwitch($subDeviceId, $executionCommand){
|
static function executeSwitch($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
$value = 0;
|
$value = 0;
|
||||||
$status = 'OFFLINE';
|
$status = 'OFFLINE';
|
||||||
$online = false;
|
$online = false;
|
||||||
|
|
||||||
if ($executionCommand['params']['on']) $value = 1;
|
if ($executionCommand['params']['on']) $value = 1;
|
||||||
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $value);
|
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
||||||
|
|
||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
@@ -266,7 +278,8 @@ static function executeSwitch($subDeviceId, $executionCommand){
|
|||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeTermostatValue($subDeviceId, $executionCommand){
|
static function executeTermostatValue($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
$value = 0;
|
$value = 0;
|
||||||
$status = 'OFFLINE';
|
$status = 'OFFLINE';
|
||||||
$online = false;
|
$online = false;
|
||||||
@@ -275,7 +288,7 @@ static function executeTermostatValue($subDeviceId, $executionCommand){
|
|||||||
$value = $executionCommand['params']['thermostatTemperatureSetpoint'];
|
$value = $executionCommand['params']['thermostatTemperatureSetpoint'];
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $value);
|
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
||||||
|
|
||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
@@ -307,7 +320,8 @@ static function executeTermostatValue($subDeviceId, $executionCommand){
|
|||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeTermostatMode($subDeviceId, $executionCommand){
|
static function executeTermostatMode($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
$mode = "off";
|
$mode = "off";
|
||||||
$value = 0;
|
$value = 0;
|
||||||
$status = 'OFFLINE';
|
$status = 'OFFLINE';
|
||||||
@@ -318,7 +332,7 @@ static function executeTermostatMode($subDeviceId, $executionCommand){
|
|||||||
$value = RecordManager::getLastRecordNotNull($subDeviceId)['value'];
|
$value = RecordManager::getLastRecordNotNull($subDeviceId)['value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $value);
|
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
||||||
|
|
||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
@@ -348,7 +362,8 @@ static function executeTermostatMode($subDeviceId, $executionCommand){
|
|||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeVolume($subDeviceId, $executionCommand){
|
static function executeVolume($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
//echo $executionCommand['params']['volumeLevel'];
|
//echo $executionCommand['params']['volumeLevel'];
|
||||||
$status = 'OFFLINE';
|
$status = 'OFFLINE';
|
||||||
$online = false;
|
$online = false;
|
||||||
@@ -386,7 +401,8 @@ static function executeVolume($subDeviceId, $executionCommand){
|
|||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeApp($subDeviceId, $executionCommand){
|
static function executeApp($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
//echo $executionCommand['params']['newApplication'];
|
//echo $executionCommand['params']['newApplication'];
|
||||||
$status = 'OFFLINE';
|
$status = 'OFFLINE';
|
||||||
$online = false;
|
$online = false;
|
||||||
@@ -424,7 +440,8 @@ static function executeApp($subDeviceId, $executionCommand){
|
|||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeInput($subDeviceId, $executionCommand){
|
static function executeInput($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
//echo $executionCommand['params']['newInput'];
|
//echo $executionCommand['params']['newInput'];
|
||||||
$status = 'OFFLINE';
|
$status = 'OFFLINE';
|
||||||
$online = false;
|
$online = false;
|
||||||
@@ -462,7 +479,8 @@ static function executeInput($subDeviceId, $executionCommand){
|
|||||||
return $commandTemp;
|
return $commandTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function executeMediaCont($subDeviceId, $executionCommand){
|
static function executeMediaCont($subDeviceId, $executionCommand)
|
||||||
|
{
|
||||||
$status = 'SUCCESS';
|
$status = 'SUCCESS';
|
||||||
$online = true;
|
$online = true;
|
||||||
|
|
||||||
|
@@ -2,16 +2,21 @@
|
|||||||
class RecordManager{
|
class RecordManager{
|
||||||
public static $records;
|
public static $records;
|
||||||
|
|
||||||
public static function createWithSubId ($subDeviceId, $value) {
|
public static function createWithSubId ($subDeviceId, $value, $origin = false) {
|
||||||
try {
|
try {
|
||||||
$record = [
|
$record = [
|
||||||
'execuded' => 1,
|
'execuded' => 1,
|
||||||
];
|
];
|
||||||
|
|
||||||
Db::edit ('records', $record, 'WHERE subdevice_id = ?', array ($subDeviceId));
|
Db::edit ('records', $record, 'WHERE subdevice_id = ?', array ($subDeviceId));
|
||||||
$record = array (
|
$record = array (
|
||||||
'subdevice_id' => $subDeviceId,
|
'subdevice_id' => $subDeviceId,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($origin != false)
|
||||||
|
$record['Origin'] = $origin;
|
||||||
|
|
||||||
return Db::add ('records', $record);
|
return Db::add ('records', $record);
|
||||||
} catch(PDOException $error) {
|
} catch(PDOException $error) {
|
||||||
echo $error->getMessage();
|
echo $error->getMessage();
|
||||||
@@ -19,7 +24,7 @@ class RecordManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create ($deviceId, $type, $value) {
|
public static function create ($deviceId, $type, $value, $origin = false) {
|
||||||
$subDeviceId = Db::loadOne('SELECT * FROM subdevices WHERE device_id = ? AND type = ?;', array($deviceId, $type))['subdevice_id'];
|
$subDeviceId = Db::loadOne('SELECT * FROM subdevices WHERE device_id = ? AND type = ?;', array($deviceId, $type))['subdevice_id'];
|
||||||
if ($subDeviceId == '') {
|
if ($subDeviceId == '') {
|
||||||
return false;
|
return false;
|
||||||
@@ -28,7 +33,7 @@ class RecordManager{
|
|||||||
//Ochrana proti duplicitním hodnotám zapisují se jen změny
|
//Ochrana proti duplicitním hodnotám zapisují se jen změny
|
||||||
$lastRecord = self::getLastRecord($subDeviceId, 1);
|
$lastRecord = self::getLastRecord($subDeviceId, 1);
|
||||||
|
|
||||||
if ($lastRecord['value'] == $value){
|
if (isset($lastRecord['value']) && $lastRecord['value'] == $value){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +47,10 @@ class RecordManager{
|
|||||||
'subdevice_id' => $subDeviceId,
|
'subdevice_id' => $subDeviceId,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($origin != false)
|
||||||
|
$record['Origin'] = $origin;
|
||||||
|
|
||||||
return Db::add ('records', $record);
|
return Db::add ('records', $record);
|
||||||
} catch(PDOException $error) {
|
} catch(PDOException $error) {
|
||||||
echo $error->getMessage();
|
echo $error->getMessage();
|
||||||
|
@@ -22,7 +22,7 @@ class AirQuality extends VirtualDeviceManager
|
|||||||
|
|
||||||
$finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id);
|
$finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id);
|
||||||
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
|
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
|
||||||
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi']);
|
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi'], 'plugin');
|
||||||
} else {
|
} else {
|
||||||
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
||||||
DeviceManager::approved($this->virtual_device_name);
|
DeviceManager::approved($this->virtual_device_name);
|
||||||
|
@@ -30,7 +30,7 @@ class AirQuality extends VirtualDeviceManager
|
|||||||
|
|
||||||
$finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id);
|
$finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id);
|
||||||
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
|
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
|
||||||
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi']);
|
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi'], 'plugin');
|
||||||
} else {
|
} else {
|
||||||
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
||||||
DeviceManager::approved($this->virtual_device_name);
|
DeviceManager::approved($this->virtual_device_name);
|
||||||
|
@@ -31,7 +31,7 @@ class CovidV2 extends VirtualDeviceManager
|
|||||||
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true)['data'];
|
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true)['data'];
|
||||||
|
|
||||||
foreach ($dataItems as $dataItem) {
|
foreach ($dataItems as $dataItem) {
|
||||||
RecordManager::create($deviceId, strtolower($dataItem), end($json)[$this->name_index[$dataItem]]);
|
RecordManager::create($deviceId, strtolower($dataItem), end($json)[$this->name_index[$dataItem]], 'plugin');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, strtolower($this->virtual_device_name));
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, strtolower($this->virtual_device_name));
|
||||||
|
85
app/plugins/DameJidlo.php
Normal file
85
app/plugins/DameJidlo.php
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
class DameJidlo extends VirtualDeviceManager
|
||||||
|
{
|
||||||
|
private $virtual_device_name = "Dáme Jídlo";
|
||||||
|
private $device_type = "virtual-device";
|
||||||
|
private $subdevice_type = "dame-jidlo";
|
||||||
|
|
||||||
|
public function deliveryTime($token)
|
||||||
|
{
|
||||||
|
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_URL, 'https://cz.fd-api.com/api/v5/tracking/active-orders?time_variation=Variation2');
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
|
||||||
|
|
||||||
|
$headers = array();
|
||||||
|
$headers[] = 'Authority: cz.fd-api.com';
|
||||||
|
$headers[] = 'Sec-Ch-Ua: \"Chromium\";v=\"88\", \"Google Chrome\";v=\"88\", \";Not A Brand\";v=\"99\"';
|
||||||
|
$headers[] = 'Accept: application/json, text/plain, */*';
|
||||||
|
$headers[] = 'Authorization: Bearer ' . $token;
|
||||||
|
$headers[] = 'X-Pd-Language-Id: 2';
|
||||||
|
$headers[] = 'Sec-Ch-Ua-Mobile: ?0';
|
||||||
|
$headers[] = 'X-Fp-Api-Key: volo';
|
||||||
|
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36';
|
||||||
|
$headers[] = 'Origin: https://www.damejidlo.cz';
|
||||||
|
$headers[] = 'Sec-Fetch-Site: cross-site';
|
||||||
|
$headers[] = 'Sec-Fetch-Mode: cors';
|
||||||
|
$headers[] = 'Sec-Fetch-Dest: empty';
|
||||||
|
$headers[] = 'Referer: https://www.damejidlo.cz/';
|
||||||
|
$headers[] = 'Accept-Language: en-US,en;q=0.9,cs-CZ;q=0.8,cs;q=0.7';
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
echo 'Error:' . curl_error($ch);
|
||||||
|
}
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
return (isset(json_decode($result, true)['data']['active_orders'][0]['delivery']['time']['eta']) ? json_decode($result, true)['data']['active_orders'][0]['delivery']['time']['eta'] : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function make()
|
||||||
|
{
|
||||||
|
//Register the settings
|
||||||
|
$settingMng = new SettingsManager();
|
||||||
|
if (!($settingField = $settingMng->getByName("damejidlo_token","damejidlo"))) {
|
||||||
|
$settingMng->create("damejidlo_token", "", "damejidlo");
|
||||||
|
} else {
|
||||||
|
$bearer = $settingField['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (DeviceManager::registeret($this->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);
|
||||||
|
$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, strtolower($this->subdevice_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
//if (!$this->fetchEnabled($deviceId,$subDevice['subdevice_id'])) die();
|
||||||
|
|
||||||
|
RecordManager::create($deviceId, $this->subdevice_type, $this->deliveryTime($bearer), 'plugin');
|
||||||
|
} else {
|
||||||
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
||||||
|
DeviceManager::approved($this->virtual_device_name);
|
||||||
|
}
|
||||||
|
return 'sucessful';
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return 'exception: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function translate($value){
|
||||||
|
if ($value == 0) {
|
||||||
|
return " Delivered";
|
||||||
|
} else if ($value <= 1) {
|
||||||
|
return "less " . $value;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
@@ -29,7 +29,7 @@ class N7Day extends VirtualDeviceManager
|
|||||||
$datediff = $now - $your_date;
|
$datediff = $now - $your_date;
|
||||||
$daysUntilN7Day = round($datediff / (60 * 60 * 24));
|
$daysUntilN7Day = round($datediff / (60 * 60 * 24));
|
||||||
|
|
||||||
RecordManager::create($deviceId, $this->subdevice_type, $daysUntilN7Day);
|
RecordManager::create($deviceId, $this->subdevice_type, $daysUntilN7Day, 'plugin');
|
||||||
} else {
|
} else {
|
||||||
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, $this->device_type);
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, $this->device_type);
|
||||||
DeviceManager::approved($this->virtual_device_name);
|
DeviceManager::approved($this->virtual_device_name);
|
||||||
|
@@ -55,7 +55,7 @@ class OpenWeatherMap extends VirtualDeviceManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RecordManager::create($deviceId, $this->subdevice_type, $json['weather'][0]['id']);
|
RecordManager::create($deviceId, $this->subdevice_type, $json['weather'][0]['id'], 'plugin');
|
||||||
} else {
|
} else {
|
||||||
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
||||||
DeviceManager::approved($this->virtual_device_name);
|
DeviceManager::approved($this->virtual_device_name);
|
||||||
|
@@ -52,7 +52,7 @@ class UsaElection extends VirtualDeviceManager
|
|||||||
$OnePercent = ($Trump + $Biden + $Unknown) / 100;
|
$OnePercent = ($Trump + $Biden + $Unknown) / 100;
|
||||||
|
|
||||||
foreach ($dataItems as $Category) {
|
foreach ($dataItems as $Category) {
|
||||||
RecordManager::create($deviceId, strtolower($Category), round(($$Category / $OnePercent)));
|
RecordManager::create($deviceId, strtolower($Category), round(($$Category / $OnePercent)), 'plugin');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
|
||||||
|
Reference in New Issue
Block a user