Compare commits
2 Commits
9d9304d30e
...
feature/co
Author | SHA1 | Date | |
---|---|---|---|
a7380841cf | |||
28dd69e3a5 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,7 +2,6 @@
|
|||||||
.ftpconfig
|
.ftpconfig
|
||||||
.ftpconfig2
|
.ftpconfig2
|
||||||
*.log
|
*.log
|
||||||
*.bin
|
|
||||||
config.php
|
config.php
|
||||||
|
|
||||||
_nemazat/index.html
|
_nemazat/index.html
|
||||||
|
11
README.md
11
README.md
@@ -136,17 +136,6 @@ 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
|
||||||
|
@@ -19,58 +19,40 @@ $router->any('/logout', 'Logout');
|
|||||||
$router->any('/automation', 'Automation');
|
$router->any('/automation', 'Automation');
|
||||||
$router->any('/setting', 'Setting');
|
$router->any('/setting', 'Setting');
|
||||||
$router->any('/device', 'Device');
|
$router->any('/device', 'Device');
|
||||||
$router->any('/device/{sortBy}/{sortType}', 'Device');
|
$router->get('/device/{sortBy}/{sortType}', 'Device');
|
||||||
$router->any('/plugins', 'Plugins');
|
$router->any('/plugins', 'Plugins');
|
||||||
$router->any('/ajax', 'Ajax');
|
$router->any('/ajax', 'Ajax');
|
||||||
$router->any('/oauth', 'Oauth');
|
$router->any('/oauth', 'Oauth');
|
||||||
|
|
||||||
//Vue APP - Authentication
|
//Vue APP
|
||||||
$router->post('/api/login', 'AuthApi@login');
|
$router->post('/api/login', 'AuthApi@login');
|
||||||
$router->post('/api/logout', 'AuthApi@logout');
|
$router->post('/api/logout', 'AuthApi@logout');
|
||||||
|
|
||||||
//Vue APP - Rooms
|
|
||||||
$router->get('/api/rooms', 'RoomsApi@default');
|
$router->get('/api/rooms', 'RoomsApi@default');
|
||||||
$router->get('/api/rooms/{roomId}/update', 'RoomsApi@update');
|
$router->get('/api/rooms/{roomId}/update', 'RoomsApi@update');
|
||||||
|
|
||||||
$router->get('/api/devices', 'DevicesApi@default');
|
$router->get('/api/devices', 'DevicesApi@default');
|
||||||
|
|
||||||
$router->get('/api/plugins', 'PluginsApi@default');
|
$router->get('/api/plugins', 'PluginsApi@default');
|
||||||
|
|
||||||
$router->get('/api/users', 'UsersApi@default');
|
$router->get('/api/users', 'UsersApi@default');
|
||||||
|
|
||||||
//Vue APP - Server Info
|
|
||||||
$router->get('/api/server', 'ServerApi@default');
|
$router->get('/api/server', 'ServerApi@default');
|
||||||
$router->get('/api/server/log', 'ServerApi@logStatus');
|
$router->get('/api/server/log', 'ServerApi@logStatus');
|
||||||
|
|
||||||
//Vue APP - Widgets
|
|
||||||
$router->post('/api/widgets/{widgetId}/run', 'WidgetApi@run');
|
$router->post('/api/widgets/{widgetId}/run', 'WidgetApi@run');
|
||||||
$router->get('/api/widgets/{widgetId}/detail', 'WidgetApi@detail');
|
$router->get('/api/widgets/{widgetId}/detail', 'WidgetApi@detail');
|
||||||
$router->get('/api/widgets/{widgetId}/detail/{period}', 'WidgetApi@detail');
|
$router->get('/api/widgets/{widgetId}/detail/{period}', 'WidgetApi@detail');
|
||||||
|
|
||||||
//Vue APP - Automations Endpoints
|
|
||||||
$router->get('/api/automations', 'AutomationsApi@default');
|
|
||||||
$router->get('/api/automations/{automationId}/detail', 'AutomationsApi@detail');
|
|
||||||
$router->post('/api/automations/create', 'AutomationsApi@create');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//cron
|
//cron
|
||||||
$router->post('/cron/clean', 'CronApi@clean');
|
$router->post('/cron/clean', 'CronApi@clean');
|
||||||
$router->post('/cron/fetch', 'CronApi@fetch');
|
$router->post('/cron/fetch', 'CronApi@fetch');
|
||||||
$router->post('/cron/automations', 'CronApi@automations');
|
|
||||||
|
|
||||||
|
|
||||||
//Google Home - API
|
//Google Home - API
|
||||||
$router->any('/api/HA/auth', 'Oauth');
|
$router->any('/api/HA/auth', 'Oauth');
|
||||||
$router->any('/api/HA', 'GoogleHomeApi@response');
|
$router->any('/api/HA', 'GoogleHomeApi@response');
|
||||||
|
|
||||||
|
|
||||||
//Endpoints API
|
//Endpoints API
|
||||||
$router->post('/api/endpoint/', 'EndpointsApi@default');
|
$router->post('/api/endpoint/', 'EndpointsApi@default');
|
||||||
$router->any('/api/update/', 'UpdatesApi@default');
|
$router->any('/api/update/', 'UpdatesApi@default');
|
||||||
$router->any('/api/users/status', 'UsersApi@status');
|
$router->any('/api/users/status', 'UsersApi@status');
|
||||||
$router->any('/api/users/subscribe', 'UsersApi@subscribe');
|
|
||||||
|
|
||||||
|
|
||||||
// examples
|
// examples
|
||||||
$router->any('/api/example', 'ExampleApi@example');
|
$router->any('/api/example', 'ExampleApi@example');
|
||||||
|
@@ -1,44 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class AutomationsApi extends ApiController
|
|
||||||
{
|
|
||||||
|
|
||||||
public function default()
|
|
||||||
{
|
|
||||||
//$this->requireAuth();
|
|
||||||
$response = [];
|
|
||||||
$response = AutomationManager::getAll(["automation_id","name","enabled"]);
|
|
||||||
|
|
||||||
$this->response($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function detail($automationId)
|
|
||||||
{
|
|
||||||
//$this->requireAuth();
|
|
||||||
$response = [];
|
|
||||||
$response = AutomationManager::getById($automationId, ["automation_id", "last_execution_time", "owner_id", "conditions", "tasks"]);
|
|
||||||
|
|
||||||
$this->response($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create()
|
|
||||||
{
|
|
||||||
$this->requireAuth();
|
|
||||||
$obj = $this->input;
|
|
||||||
|
|
||||||
if (
|
|
||||||
empty($obj['name']) ||
|
|
||||||
!isset($obj['name']) ||
|
|
||||||
!isset($obj['conditions']) ||
|
|
||||||
!isset($obj['tasks']) ||
|
|
||||||
!isset($obj['days'])
|
|
||||||
) {
|
|
||||||
throw new Exception("Invalid request payload", 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = [];
|
|
||||||
$response = AutomationManager::create($obj['name'],json_encode($obj['days']), json_encode($obj['tasks']), json_encode($obj['conditions']));
|
|
||||||
|
|
||||||
$this->response(['value'=>'OK']);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -12,15 +12,11 @@ class CronApi extends ApiController
|
|||||||
$backupWorker = new DatabaseBackup();
|
$backupWorker = new DatabaseBackup();
|
||||||
$backupWorker->purge(5);
|
$backupWorker->purge(5);
|
||||||
|
|
||||||
//Old Records Cleanup
|
|
||||||
foreach (SubDeviceManager::getAllSubDevices() as $key => $value) {
|
|
||||||
RecordManager::setHistory($value['subdevice_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->response(['Value' => 'OK']);
|
$this->response(['Value' => 'OK']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetch(){
|
public function fetch()
|
||||||
|
{
|
||||||
//Run Plugins
|
//Run Plugins
|
||||||
$result = [];
|
$result = [];
|
||||||
$dir = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/';
|
$dir = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/';
|
||||||
@@ -59,9 +55,4 @@ class CronApi extends ApiController
|
|||||||
//Print Result
|
//Print Result
|
||||||
$this->response($result);
|
$this->response($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function automations(){
|
|
||||||
AutomationManager:executeAll();
|
|
||||||
$this->response(['Value' => 'OK']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -7,9 +7,11 @@ class DevicesApi extends ApiController{
|
|||||||
$response = [];
|
$response = [];
|
||||||
|
|
||||||
// TODO: process the request
|
// TODO: process the request
|
||||||
|
|
||||||
$this->response($response);
|
$this->response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDevicesByRoom($roomId){
|
public function getDevicesByRoom($roomId){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -62,7 +62,6 @@ class EndpointsApi extends ApiController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$device = DeviceManager::getDeviceByToken($obj['token']);
|
$device = DeviceManager::getDeviceByToken($obj['token']);
|
||||||
DeviceManager::setHeartbeat($device['device_id']);
|
|
||||||
|
|
||||||
//Diagnostic
|
//Diagnostic
|
||||||
if (isset($obj['settings'])){
|
if (isset($obj['settings'])){
|
||||||
@@ -78,9 +77,7 @@ class EndpointsApi extends ApiController{
|
|||||||
foreach ($obj['logs'] as $log) {
|
foreach ($obj['logs'] as $log) {
|
||||||
$deviceLogManager = new LogManager('../logs/devices/'. date("Y-m-d").'.log');
|
$deviceLogManager = new LogManager('../logs/devices/'. date("Y-m-d").'.log');
|
||||||
$deviceLogManager->setLevel(LOGLEVEL);
|
$deviceLogManager->setLevel(LOGLEVEL);
|
||||||
if ($log != 'HTTP_UPDATE_FAILD code-102 messageFile Not Found (404)'){
|
$deviceLogManager->write("[Device Log Msg] Device_ID " . $device['device_id'] . "->" . $log, LogRecordTypes::ERROR);
|
||||||
$deviceLogManager->write("[Device Log Msg] Device_ID " . $device['device_id'] . "->" . $log, LogRecordTypes::ERROR);
|
|
||||||
}
|
|
||||||
unset($deviceLogManager);
|
unset($deviceLogManager);
|
||||||
}
|
}
|
||||||
$this->response([
|
$this->response([
|
||||||
@@ -113,9 +110,9 @@ class EndpointsApi extends ApiController{
|
|||||||
if (!SubDeviceManager::getSubDeviceByMaster($device['device_id'], $key)) {
|
if (!SubDeviceManager::getSubDeviceByMaster($device['device_id'], $key)) {
|
||||||
SubDeviceManager::create($device['device_id'], $key, UNITS[$key]);
|
SubDeviceManager::create($device['device_id'], $key, UNITS[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$subDeviceLastReordValue[$key] = $value['value'];
|
$subDeviceLastReordValue[$key] = $value['value'];
|
||||||
RecordManager::create($device['device_id'], $key, round($value['value'],3), 'device');
|
RecordManager::create($device['device_id'], $key, round($value['value'],3));
|
||||||
$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
|
||||||
|
@@ -54,7 +54,6 @@ class RoomsApi extends ApiController
|
|||||||
foreach ($roomsData as $roomKey => $roomData) {
|
foreach ($roomsData as $roomKey => $roomData) {
|
||||||
if ($roomData['device_count'] == 0) continue;
|
if ($roomData['device_count'] == 0) continue;
|
||||||
$subDevicesSorted = isset($subDevicesData[$roomData['room_id']]) ? Utilities::sortArrayByKey($subDevicesData[$roomData['room_id']], 'connection_error', 'asc') : [];
|
$subDevicesSorted = isset($subDevicesData[$roomData['room_id']]) ? Utilities::sortArrayByKey($subDevicesData[$roomData['room_id']], 'connection_error', 'asc') : [];
|
||||||
if (count($subDevicesSorted) == 0) continue;
|
|
||||||
$response[] = [
|
$response[] = [
|
||||||
'room_id' => $roomData['room_id'],
|
'room_id' => $roomData['room_id'],
|
||||||
'name' => $roomData['name'],
|
'name' => $roomData['name'],
|
||||||
|
@@ -34,14 +34,4 @@ class UsersApi extends ApiController{
|
|||||||
}
|
}
|
||||||
$this->response(['value'=>'OK']);
|
$this->response(['value'=>'OK']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function subscribe(){
|
|
||||||
//$this->requireAuth();
|
|
||||||
$bearer = $_SERVER['HTTP_AUTHORIZATION'];
|
|
||||||
$authManager = new AuthManager();
|
|
||||||
$userId = $authManager->getUserId($bearer);
|
|
||||||
|
|
||||||
NotificationManager::addSubscriber($userId, $this->input['pushtoken']);
|
|
||||||
$this->response(['value'=>'OK']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -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, "vue-app");
|
RecordManager::create($subDeviceData['device_id'], 'on/off', (int) !$lastValue);
|
||||||
$response = !$lastValue;
|
$response = !$lastValue;
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Bad Request", 403);
|
throw new Exception("Bad Request", 403);
|
||||||
@@ -46,7 +46,7 @@ class WidgetApi extends ApiController
|
|||||||
$response = null;
|
$response = null;
|
||||||
$subDeviceData = SubDeviceManager::getSubdeviceDetailById($subDeviceId);
|
$subDeviceData = SubDeviceManager::getSubdeviceDetailById($subDeviceId);
|
||||||
|
|
||||||
|
|
||||||
//TODO: zeptat se @Patrik Je Graf Dobře Seřazený na DESC ?
|
//TODO: zeptat se @Patrik Je Graf Dobře Seřazený na DESC ?
|
||||||
$events = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy[$period]);
|
$events = RecordManager::getAllRecordForGraph($subDeviceId, $period, $groupBy[$period]);
|
||||||
if ( count($events) == 0){
|
if ( count($events) == 0){
|
||||||
@@ -114,7 +114,7 @@ class WidgetApi extends ApiController
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
//TODO: Make Cleaner
|
//TODO: Make Cleaner
|
||||||
if (isset(RANGES[$subDeviceData['type']])){
|
if (isset(RANGES[$subDeviceData['type']])){
|
||||||
$response['graph']['options']['scales']['yAxes'] = [[
|
$response['graph']['options']['scales']['yAxes'] = [[
|
||||||
'ticks' => [
|
'ticks' => [
|
||||||
@@ -124,7 +124,7 @@ class WidgetApi extends ApiController
|
|||||||
]
|
]
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->response($response);
|
$this->response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
if (!empty ($_POST)){
|
if (!empty ($_POST)){
|
||||||
$deviceManager = new DeviceManager ();
|
$deviceManager = new DeviceManager ();
|
||||||
$subDeviceManager = new SubDeviceManager ();
|
|
||||||
if (!empty ($_FILES['deviceFirmware']) && !empty ($_FILES['deviceFirmware']['tmp_name']) && !empty ($_POST['deviceId'])) {
|
if (!empty ($_FILES['deviceFirmware']) && !empty ($_FILES['deviceFirmware']['tmp_name']) && !empty ($_POST['deviceId'])) {
|
||||||
$file = $_FILES['deviceFirmware'];
|
$file = $_FILES['deviceFirmware'];
|
||||||
$deviceMac = $deviceManager->getDeviceById ($_POST['deviceId'])['mac'];
|
$deviceMac = $deviceManager->getDeviceById ($_POST['deviceId'])['mac'];
|
||||||
@@ -28,9 +27,6 @@ if (!empty ($_POST)){
|
|||||||
if (!empty ($_POST['deviceName']) && !empty ($_POST['deviceId'])) {
|
if (!empty ($_POST['deviceName']) && !empty ($_POST['deviceId'])) {
|
||||||
$deviceManager->edit ($_POST['deviceId'], array ('name' => $_POST['deviceName']));
|
$deviceManager->edit ($_POST['deviceId'], array ('name' => $_POST['deviceName']));
|
||||||
}
|
}
|
||||||
if (isset ($_POST['deviceHistory']) && !empty ($_POST['deviceId'])) {
|
header('Location: ./device');
|
||||||
$subDeviceManager->editSubDevicesByDevice($_POST['deviceId'], array ('history' => $_POST['deviceHistory']));
|
|
||||||
}
|
|
||||||
header('Location: ' . BASEURL . str_replace(BASEDIR, "", $_SERVER['REQUEST_URI']));
|
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
@@ -21,24 +21,13 @@ if (isset($_POST) && !empty($_POST)){
|
|||||||
|
|
||||||
$ga = new PHPGangsta_GoogleAuthenticator();
|
$ga = new PHPGangsta_GoogleAuthenticator();
|
||||||
$checkResult = $ga->verifyCode($otaSecret, $otaCode, 2); // 2 = 2*30sec clock tolerance
|
$checkResult = $ga->verifyCode($otaSecret, $otaCode, 2); // 2 = 2*30sec clock tolerance
|
||||||
if ($checkResult) {
|
if ($checkResult) {
|
||||||
$userManager->setOta($otaCode, $otaSecret);
|
$userManager->setOta($otaCode, $otaSecret);
|
||||||
}
|
}
|
||||||
header('Location: ' . BASEURL . 'setting');
|
header('Location: ' . BASEURL . 'setting');
|
||||||
die();
|
die();
|
||||||
} else if (isset ($_POST['userPermission']) && !empty ($_POST['userID'])) {
|
} else if (isset ($_POST['userPermission']) && !empty ($_POST['userID'])) {
|
||||||
$userManager->setUserDataAdmin("permission", $_POST['userPermission'], $_POST['userID']);
|
$userManager->setUserDataAdmin("permission", $_POST['userPermission'], $_POST['userID']);
|
||||||
header('Location: ' . BASEURL . 'setting');
|
|
||||||
die();
|
|
||||||
} else {
|
|
||||||
foreach ($_POST as $key => $value) {
|
|
||||||
if ($key == 'submit') continue;
|
|
||||||
$settingMng = new SettingsManager();
|
|
||||||
if ($settingMng->getByName($key)) {
|
|
||||||
$settingMng->update($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
header('Location: ' . BASEURL . 'setting');
|
header('Location: ' . BASEURL . 'setting');
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
<?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) {
|
||||||
@@ -28,7 +26,7 @@ class GoogleHome
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($traids < 1) {
|
if ($traids < 0){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,444 +53,428 @@ class GoogleHome
|
|||||||
$response = [
|
$response = [
|
||||||
'requestId' => $requestId,
|
'requestId' => $requestId,
|
||||||
'payload' => [
|
'payload' => [
|
||||||
'agentUserId' => '651351531531',
|
'agentUserId'=>'651351531531',
|
||||||
'devices' => array_values($devices),
|
'devices' => array_values( $devices ),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$apiLogManager = new LogManager('../logs/google-home/' . date("Y-m-d") . '.log');
|
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
|
||||||
$apiLogManager->setLevel(LOGLEVEL);
|
$apiLogManager->setLevel(LOGLEVEL);
|
||||||
$apiLogManager->write("[API][$requestId] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
$apiLogManager->write("[API][$requestId] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
||||||
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',
|
||||||
];
|
];
|
||||||
|
foreach ($subDevicesData as $key => $subDeviceData) {
|
||||||
if ($subDevicesData = SubDeviceManager::getAllSubDevices($deviceId['id'])) {
|
$lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']);
|
||||||
foreach ($subDevicesData as $key => $subDeviceData) {
|
if ($lastRecord['execuded'] == 1){
|
||||||
$lastRecord = RecordManager::getLastRecord($subDeviceData['subdevice_id']);
|
$tempDevice[$deviceId['id']]['online'] = true;
|
||||||
if ($lastRecord != false && $lastRecord['execuded'] == 1) {
|
$tempDevice[$deviceId['id']]['status'] = "SUCCESS";
|
||||||
|
} else {
|
||||||
|
$executed = 0;
|
||||||
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
||||||
|
if ($value['execuded'] == 1){
|
||||||
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($waiting < $executed){
|
||||||
$tempDevice[$deviceId['id']]['online'] = true;
|
$tempDevice[$deviceId['id']]['online'] = true;
|
||||||
$tempDevice[$deviceId['id']]['status'] = "SUCCESS";
|
}
|
||||||
} else {
|
}
|
||||||
$executed = 0;
|
|
||||||
$waiting = 0;
|
switch ($subDeviceData['type']) {
|
||||||
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
case 'temp_cont':
|
||||||
if ($value['execuded'] == 1) {
|
$tempDevice[$deviceId['id']]['thermostatMode'] = 'off';
|
||||||
$executed++;
|
if ($lastRecord['value'] != 0) {
|
||||||
} else {
|
$tempDevice[$deviceId['id']]['thermostatMode'] = 'heat';
|
||||||
$waiting++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($waiting < $executed) {
|
$tempDevice[$deviceId['id']]['thermostatTemperatureAmbient'] = $lastRecord['value'];
|
||||||
$tempDevice[$deviceId['id']]['online'] = true;
|
$tempDevice[$deviceId['id']]['thermostatTemperatureSetpoint'] = $lastRecord['value'];
|
||||||
}
|
break;
|
||||||
}
|
case 'vol_cont':
|
||||||
|
$tempDevice[$deviceId['id']]['currentVolume'] = $lastRecord['value'];
|
||||||
switch ($subDeviceData['type']) {
|
break;
|
||||||
case 'temp_cont':
|
case 'media_apps':
|
||||||
$tempDevice[$deviceId['id']]['thermostatMode'] = 'off';
|
$tempDevice[$deviceId['id']]['currentApplication'] = "kodi";
|
||||||
if ($lastRecord['value'] != 0) {
|
break;
|
||||||
$tempDevice[$deviceId['id']]['thermostatMode'] = 'heat';
|
case 'media_input':
|
||||||
}
|
$tempDevice[$deviceId['id']]['currentInput'] = "pc";
|
||||||
$tempDevice[$deviceId['id']]['thermostatTemperatureAmbient'] = $lastRecord['value'];
|
break;
|
||||||
$tempDevice[$deviceId['id']]['thermostatTemperatureSetpoint'] = $lastRecord['value'];
|
case 'media_status':
|
||||||
break;
|
$tempDevice[$deviceId['id']]['activityState'] = "ACTIVE";
|
||||||
case 'vol_cont':
|
$tempDevice[$deviceId['id']]['playbackState'] = "PLAYING";
|
||||||
$tempDevice[$deviceId['id']]['currentVolume'] = $lastRecord['value'];
|
break;
|
||||||
break;
|
case 'on/off':
|
||||||
case 'media_apps':
|
$tempDevice[$deviceId['id']]['on'] = ($lastRecord['value'] == 1 ? true : false);
|
||||||
$tempDevice[$deviceId['id']]['currentApplication'] = "kodi";
|
break;
|
||||||
break;
|
|
||||||
case 'media_input':
|
|
||||||
$tempDevice[$deviceId['id']]['currentInput'] = "pc";
|
|
||||||
break;
|
|
||||||
case 'media_status':
|
|
||||||
$tempDevice[$deviceId['id']]['activityState'] = "ACTIVE";
|
|
||||||
$tempDevice[$deviceId['id']]['playbackState'] = "PLAYING";
|
|
||||||
break;
|
|
||||||
case 'on/off':
|
|
||||||
$tempDevice[$deviceId['id']]['on'] = ($lastRecord['value'] == 1 ? true : false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// $lastRecord = RecordManager::getLastRecord($deviceId['id']);
|
|
||||||
// //var_dump($lastRecord);
|
|
||||||
// if ($lastRecord['execuded'] == 1) {
|
|
||||||
// $online = true;
|
|
||||||
// $status = 'SUCCESS';
|
|
||||||
// } else {
|
|
||||||
$executed = 0;
|
|
||||||
$waiting = 0;
|
|
||||||
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
|
||||||
if ($value['execuded'] == 1) {
|
|
||||||
$executed++;
|
|
||||||
} else {
|
|
||||||
$waiting++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($waiting < $executed) {
|
|
||||||
$status = "PENDING";
|
|
||||||
$online = true;
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
$devices = $tempDevice;
|
|
||||||
if (count($devices)> 1){
|
|
||||||
$devices[] = $tempDevice;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$response = [
|
|
||||||
'requestId' => $requestId,
|
|
||||||
'payload' => [
|
|
||||||
'devices' => $devices,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
$apiLogManager = new LogManager('../logs/google-home/' . date("Y-m-d") . '.log');
|
|
||||||
$apiLogManager->write("[API][$requestId] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
|
||||||
$apiLogManager->setLevel(LOGLEVEL);
|
|
||||||
echo json_encode($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
static function execute($requestId, $payload)
|
|
||||||
{
|
|
||||||
$commands = [];
|
|
||||||
foreach ($payload['commands'] as $key => $command) {
|
|
||||||
foreach ($command['devices'] as $key2 => $device) {
|
|
||||||
$executionCommand = $command['execution'][0];
|
|
||||||
if (isset($command['execution'][$key])) {
|
|
||||||
$executionCommand = $command['execution'][$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
$deviceType = GoogleHomeDeviceTypes::getType($executionCommand['command']);
|
|
||||||
if ($subDeviceId = SubDeviceManager::getSubDeviceByMasterAndType($device['id'], $deviceType)) {
|
|
||||||
$subDeviceId = $subDeviceId['subdevice_id'];
|
|
||||||
switch ($executionCommand['command']) {
|
|
||||||
case 'action.devices.commands.OnOff':
|
|
||||||
$commands[] = self::executeSwitch($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.ThermostatTemperatureSetpoint':
|
|
||||||
$commands[] = self::executeTermostatValue($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.ThermostatSetMode':
|
|
||||||
$commands[] = self::executeTermostatMode($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.setVolume':
|
|
||||||
$commands[] = self::executeVolume($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.appSelect':
|
|
||||||
$commands[] = self::executeApp($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.SetInput':
|
|
||||||
$commands[] = self::executeInput($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.mediaNext':
|
|
||||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.mediaPrevious':
|
|
||||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.mediaPause':
|
|
||||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.mediaResume':
|
|
||||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'action.devices.commands.mediaStop':
|
|
||||||
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$response = [
|
|
||||||
'requestId' => $requestId,
|
|
||||||
'payload' => [
|
|
||||||
'commands' => $commands,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
$apiLogManager = new LogManager('../logs/google-home/' . date("Y-m-d") . '.log');
|
|
||||||
$apiLogManager->setLevel(LOGLEVEL);
|
|
||||||
$apiLogManager->write("[API][EXECUTE][$requestId]\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
|
||||||
|
|
||||||
echo json_encode($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
static function executeSwitch($subDeviceId, $executionCommand)
|
|
||||||
{
|
|
||||||
$value = 0;
|
|
||||||
$status = 'OFFLINE';
|
|
||||||
$online = false;
|
|
||||||
|
|
||||||
if ($executionCommand['params']['on']) $value = 1;
|
|
||||||
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
|
||||||
|
|
||||||
$executed = 0;
|
|
||||||
$waiting = 0;
|
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
|
||||||
if ($value['execuded'] == 1) {
|
|
||||||
$executed++;
|
|
||||||
} else {
|
|
||||||
$waiting++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($waiting < $executed) {
|
if ($lastRecord['execuded'] == 1){
|
||||||
$status = "PENDING";
|
|
||||||
$online = true;
|
$online = true;
|
||||||
}
|
$status = 'SUCCESS';
|
||||||
|
} else {
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
|
||||||
$commandTemp = [
|
|
||||||
'ids' => [(string) $deviceId],
|
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'on' => $executionCommand['params']['on'],
|
|
||||||
'online' => $online,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function executeTermostatValue($subDeviceId, $executionCommand)
|
|
||||||
{
|
|
||||||
$value = 0;
|
|
||||||
$status = 'OFFLINE';
|
|
||||||
$online = false;
|
|
||||||
|
|
||||||
if (isset($executionCommand['params']['thermostatTemperatureSetpoint'])) {
|
|
||||||
$value = $executionCommand['params']['thermostatTemperatureSetpoint'];
|
|
||||||
}
|
|
||||||
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
|
||||||
|
|
||||||
$executed = 0;
|
|
||||||
$waiting = 0;
|
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $lastValue) {
|
|
||||||
if ($lastValue['execuded'] == 1) {
|
|
||||||
$executed++;
|
|
||||||
} else {
|
|
||||||
$waiting++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($waiting < $executed) {
|
|
||||||
$status = "PENDING";
|
|
||||||
$online = true;;
|
|
||||||
}
|
|
||||||
|
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
|
||||||
$commandTemp = [
|
|
||||||
'ids' => [(string) $deviceId],
|
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'thermostatMode' => 'heat',
|
|
||||||
'thermostatTemperatureSetpoint' => $value,
|
|
||||||
'thermostatTemperatureAmbient' => $value,
|
|
||||||
'online' => $online,
|
|
||||||
//ambient z dalšího zenzoru v roomu
|
|
||||||
],
|
|
||||||
];
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function executeTermostatMode($subDeviceId, $executionCommand)
|
|
||||||
{
|
|
||||||
$mode = "off";
|
|
||||||
$value = 0;
|
|
||||||
$status = 'OFFLINE';
|
|
||||||
$online = false;
|
|
||||||
|
|
||||||
if (isset($executionCommand['params']['thermostatMode']) && $executionCommand['params']['thermostatMode'] != 'off') {
|
|
||||||
$mode = $executionCommand['params']['thermostatMode'];
|
|
||||||
$value = RecordManager::getLastRecordNotNull($subDeviceId)['value'];
|
|
||||||
}
|
|
||||||
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $value, 'google');
|
|
||||||
|
|
||||||
$executed = 0;
|
|
||||||
$waiting = 0;
|
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
|
||||||
if ($value['execuded'] == 1) {
|
|
||||||
$executed++;
|
|
||||||
} else {
|
|
||||||
$waiting++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($waiting < $executed) {
|
|
||||||
$status = "PENDING";
|
|
||||||
$online = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
|
||||||
$commandTemp = [
|
|
||||||
'ids' => [(string) $deviceId],
|
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'thermostatMode' => $mode,
|
|
||||||
'online' => $online,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function executeVolume($subDeviceId, $executionCommand)
|
|
||||||
{
|
|
||||||
//echo $executionCommand['params']['volumeLevel'];
|
|
||||||
$status = 'OFFLINE';
|
|
||||||
$online = false;
|
|
||||||
|
|
||||||
$currentVolume = RecordManager::getLastRecord($subDeviceId)['value'];
|
|
||||||
|
|
||||||
if (isset($executionCommand['params']['volumeLevel'])) {
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $executionCommand['params']['volumeLevel']);
|
|
||||||
$executed = 0;
|
$executed = 0;
|
||||||
$waiting = 0;
|
$waiting = 0;
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
foreach (RecordManager::getLastRecord($deviceId['id'], 6) as $key => $value) {
|
||||||
if ($value['execuded'] == 1) {
|
if ($value['execuded'] == 1){
|
||||||
$executed++;
|
$executed++;
|
||||||
} else {
|
} else {
|
||||||
$waiting++;
|
$waiting++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($waiting < $executed) {
|
if ($waiting < $executed){
|
||||||
$status = "PENDING";
|
$status = "PENDING";
|
||||||
$online = true;
|
$online = true;
|
||||||
$currentVolume = $executionCommand['params']['volumeLevel'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$devices = $tempDevice;
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
/*if (count($devices)> 1){
|
||||||
$commandTemp = [
|
$devices[] = $tempDevice;
|
||||||
'ids' => [(string) $deviceId],
|
}*/
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'currentVolume' => $currentVolume,
|
|
||||||
'online' => $online,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function executeApp($subDeviceId, $executionCommand)
|
|
||||||
{
|
|
||||||
//echo $executionCommand['params']['newApplication'];
|
|
||||||
$status = 'OFFLINE';
|
|
||||||
$online = false;
|
|
||||||
|
|
||||||
$currentApplication = RecordManager::getLastRecord($subDeviceId)['value'];
|
|
||||||
|
|
||||||
if (isset($executionCommand['params']['newApplication'])) {
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $executionCommand['params']['newApplication']);
|
|
||||||
$executed = 0;
|
|
||||||
$waiting = 0;
|
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
|
||||||
if ($value['execuded'] == 1) {
|
|
||||||
$executed++;
|
|
||||||
} else {
|
|
||||||
$waiting++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($waiting < $executed) {
|
|
||||||
$status = "PENDING";
|
|
||||||
$online = true;
|
|
||||||
$currentApplication = $executionCommand['params']['newApplication'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
|
||||||
$commandTemp = [
|
|
||||||
'ids' => [(string) $deviceId],
|
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'currentApplication' => $currentApplication,
|
|
||||||
'online' => $online,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function executeInput($subDeviceId, $executionCommand)
|
|
||||||
{
|
|
||||||
//echo $executionCommand['params']['newInput'];
|
|
||||||
$status = 'OFFLINE';
|
|
||||||
$online = false;
|
|
||||||
|
|
||||||
$currentInput = RecordManager::getLastRecord($subDeviceId)['value'];
|
|
||||||
|
|
||||||
if (isset($executionCommand['params']['newInput'])) {
|
|
||||||
RecordManager::createWithSubId($subDeviceId, $executionCommand['params']['newInput']);
|
|
||||||
$executed = 0;
|
|
||||||
$waiting = 0;
|
|
||||||
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
|
||||||
if ($value['execuded'] == 1) {
|
|
||||||
$executed++;
|
|
||||||
} else {
|
|
||||||
$waiting++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($waiting < $executed) {
|
|
||||||
$status = "PENDING";
|
|
||||||
$online = true;
|
|
||||||
$currentInput = $executionCommand['params']['newInput'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
|
||||||
$commandTemp = [
|
|
||||||
'ids' => [(string) $deviceId],
|
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'currentInput' => $currentInput,
|
|
||||||
'online' => $online,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static function executeMediaCont($subDeviceId, $executionCommand)
|
|
||||||
{
|
|
||||||
$status = 'SUCCESS';
|
|
||||||
$online = true;
|
|
||||||
|
|
||||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
|
||||||
$commandTemp = [
|
|
||||||
'ids' => [(string) $deviceId],
|
|
||||||
'status' => $status,
|
|
||||||
'states' => [
|
|
||||||
'online' => $online,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $commandTemp;
|
|
||||||
}
|
}
|
||||||
|
$response = [
|
||||||
|
'requestId' => $requestId,
|
||||||
|
'payload' => [
|
||||||
|
'devices' => $devices,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
|
||||||
|
$apiLogManager->write("[API][$requestId] request response\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
||||||
|
$apiLogManager->setLevel(LOGLEVEL);
|
||||||
|
echo json_encode($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function execute($requestId, $payload){
|
||||||
|
$commands = [];
|
||||||
|
foreach ($payload['commands'] as $key => $command) {
|
||||||
|
foreach ($command['devices'] as $key2 => $device) {
|
||||||
|
$executionCommand = $command['execution'][0];
|
||||||
|
if (isset($command['execution'][$key])) {
|
||||||
|
$executionCommand = $command['execution'][$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
$deviceType = GoogleHomeDeviceTypes::getType($executionCommand['command']);
|
||||||
|
$subDeviceId = SubDeviceManager::getSubDeviceByMasterAndType($device['id'], $deviceType)['subdevice_id'];
|
||||||
|
switch ($executionCommand['command']) {
|
||||||
|
case 'action.devices.commands.OnOff':
|
||||||
|
$commands[] = self::executeSwitch($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.ThermostatTemperatureSetpoint':
|
||||||
|
$commands[] = self::executeTermostatValue($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.ThermostatSetMode':
|
||||||
|
$commands[] = self::executeTermostatMode($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.setVolume':
|
||||||
|
$commands[] = self::executeVolume($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.appSelect':
|
||||||
|
$commands[] = self::executeApp($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.SetInput':
|
||||||
|
$commands[] = self::executeInput($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.mediaNext':
|
||||||
|
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.mediaPrevious':
|
||||||
|
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.mediaPause':
|
||||||
|
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.mediaResume':
|
||||||
|
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'action.devices.commands.mediaStop':
|
||||||
|
$commands[] = self::executeMediaCont($subDeviceId, $executionCommand);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$response = [
|
||||||
|
'requestId' => $requestId,
|
||||||
|
'payload' => [
|
||||||
|
'commands' => $commands,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$apiLogManager = new LogManager('../logs/google-home/'. date("Y-m-d").'.log');
|
||||||
|
$apiLogManager->setLevel(LOGLEVEL);
|
||||||
|
$apiLogManager->write("[API][EXECUTE][$requestId]\n" . json_encode($response, JSON_PRETTY_PRINT), LogRecordTypes::INFO);
|
||||||
|
|
||||||
|
echo json_encode($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function executeSwitch($subDeviceId, $executionCommand){
|
||||||
|
$value = 0;
|
||||||
|
$status = 'OFFLINE';
|
||||||
|
$online = false;
|
||||||
|
|
||||||
|
if ($executionCommand['params']['on']) $value = 1;
|
||||||
|
|
||||||
|
RecordManager::createWithSubId($subDeviceId, $value);
|
||||||
|
|
||||||
|
$executed = 0;
|
||||||
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
|
if ($value['execuded'] == 1){
|
||||||
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($waiting < $executed){
|
||||||
|
$status = "PENDING";
|
||||||
|
$online = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
|
$commandTemp = [
|
||||||
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'on' => $executionCommand['params']['on'],
|
||||||
|
'online' => $online,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
return $commandTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function executeTermostatValue($subDeviceId, $executionCommand){
|
||||||
|
$value = 0;
|
||||||
|
$status = 'OFFLINE';
|
||||||
|
$online = false;
|
||||||
|
|
||||||
|
if (isset($executionCommand['params']['thermostatTemperatureSetpoint'])) {
|
||||||
|
$value = $executionCommand['params']['thermostatTemperatureSetpoint'];
|
||||||
|
}
|
||||||
|
|
||||||
|
RecordManager::createWithSubId($subDeviceId, $value);
|
||||||
|
|
||||||
|
$executed = 0;
|
||||||
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $lastValue) {
|
||||||
|
if ($lastValue['execuded'] == 1){
|
||||||
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($waiting < $executed){
|
||||||
|
$status = "PENDING";
|
||||||
|
$online = true;;
|
||||||
|
}
|
||||||
|
|
||||||
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
|
$commandTemp = [
|
||||||
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'thermostatMode' => 'heat',
|
||||||
|
'thermostatTemperatureSetpoint' => $value,
|
||||||
|
'thermostatTemperatureAmbient' => $value,
|
||||||
|
'online' => $online,
|
||||||
|
//ambient z dalšího zenzoru v roomu
|
||||||
|
],
|
||||||
|
];
|
||||||
|
return $commandTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function executeTermostatMode($subDeviceId, $executionCommand){
|
||||||
|
$mode = "off";
|
||||||
|
$value = 0;
|
||||||
|
$status = 'OFFLINE';
|
||||||
|
$online = false;
|
||||||
|
|
||||||
|
if (isset($executionCommand['params']['thermostatMode']) && $executionCommand['params']['thermostatMode'] != 'off') {
|
||||||
|
$mode = $executionCommand['params']['thermostatMode'];
|
||||||
|
$value = RecordManager::getLastRecordNotNull($subDeviceId)['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
RecordManager::createWithSubId($subDeviceId, $value);
|
||||||
|
|
||||||
|
$executed = 0;
|
||||||
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
|
if ($value['execuded'] == 1){
|
||||||
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($waiting < $executed){
|
||||||
|
$status = "PENDING";
|
||||||
|
$online = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
|
$commandTemp = [
|
||||||
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'thermostatMode' => $mode,
|
||||||
|
'online' => $online,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $commandTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function executeVolume($subDeviceId, $executionCommand){
|
||||||
|
//echo $executionCommand['params']['volumeLevel'];
|
||||||
|
$status = 'OFFLINE';
|
||||||
|
$online = false;
|
||||||
|
|
||||||
|
$currentVolume = RecordManager::getLastRecord($subDeviceId)['value'];
|
||||||
|
|
||||||
|
if (isset($executionCommand['params']['volumeLevel'])) {
|
||||||
|
RecordManager::createWithSubId($subDeviceId, $executionCommand['params']['volumeLevel']);
|
||||||
|
$executed = 0;
|
||||||
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
|
if ($value['execuded'] == 1){
|
||||||
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($waiting < $executed){
|
||||||
|
$status = "PENDING";
|
||||||
|
$online = true;
|
||||||
|
$currentVolume = $executionCommand['params']['volumeLevel'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
|
$commandTemp = [
|
||||||
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'currentVolume' => $currentVolume,
|
||||||
|
'online' => $online,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $commandTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function executeApp($subDeviceId, $executionCommand){
|
||||||
|
//echo $executionCommand['params']['newApplication'];
|
||||||
|
$status = 'OFFLINE';
|
||||||
|
$online = false;
|
||||||
|
|
||||||
|
$currentApplication = RecordManager::getLastRecord($subDeviceId)['value'];
|
||||||
|
|
||||||
|
if (isset($executionCommand['params']['newApplication'])) {
|
||||||
|
RecordManager::createWithSubId($subDeviceId, $executionCommand['params']['newApplication']);
|
||||||
|
$executed = 0;
|
||||||
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
|
if ($value['execuded'] == 1){
|
||||||
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($waiting < $executed){
|
||||||
|
$status = "PENDING";
|
||||||
|
$online = true;
|
||||||
|
$currentApplication = $executionCommand['params']['newApplication'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
|
$commandTemp = [
|
||||||
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'currentApplication' => $currentApplication,
|
||||||
|
'online' => $online,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $commandTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function executeInput($subDeviceId, $executionCommand){
|
||||||
|
//echo $executionCommand['params']['newInput'];
|
||||||
|
$status = 'OFFLINE';
|
||||||
|
$online = false;
|
||||||
|
|
||||||
|
$currentInput = RecordManager::getLastRecord($subDeviceId)['value'];
|
||||||
|
|
||||||
|
if (isset($executionCommand['params']['newInput'])) {
|
||||||
|
RecordManager::createWithSubId($subDeviceId, $executionCommand['params']['newInput']);
|
||||||
|
$executed = 0;
|
||||||
|
$waiting = 0;
|
||||||
|
foreach (RecordManager::getLastRecord($subDeviceId, 4) as $key => $value) {
|
||||||
|
if ($value['execuded'] == 1){
|
||||||
|
$executed++;
|
||||||
|
} else {
|
||||||
|
$waiting++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($waiting < $executed){
|
||||||
|
$status = "PENDING";
|
||||||
|
$online = true;
|
||||||
|
$currentInput = $executionCommand['params']['newInput'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
|
$commandTemp = [
|
||||||
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'currentInput' => $currentInput,
|
||||||
|
'online' => $online,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $commandTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function executeMediaCont($subDeviceId, $executionCommand){
|
||||||
|
$status = 'SUCCESS';
|
||||||
|
$online = true;
|
||||||
|
|
||||||
|
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||||
|
$commandTemp = [
|
||||||
|
'ids' => [(string) $deviceId],
|
||||||
|
'status' => $status,
|
||||||
|
'states' => [
|
||||||
|
'online' => $online,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $commandTemp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -187,31 +187,20 @@ class Utilities
|
|||||||
* @param string $operator ('asc'/'desc')
|
* @param string $operator ('asc'/'desc')
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
static function sortArrayByKey($data = [], $key, $operator = "asc")
|
static function sortArrayByKey($data = [], $key, $operator = "asc"){
|
||||||
{
|
if ($operator == "asc")
|
||||||
if ($operator == "asc") {
|
{
|
||||||
uasort($data, function ($a, $b) use ($key) {
|
uasort($data, function($a, $b) use ($key){
|
||||||
$SortA = $a[$key];
|
if ($a[$key] == $b[$key]) return 0;
|
||||||
$SortB = $b[$key];
|
return ($a[$key] < $b[$key]) ? -1 : 1;
|
||||||
if ($key == "room_id") {
|
|
||||||
$SortA = RoomManager::getRoomName($SortA);
|
|
||||||
$SortB = RoomManager::getRoomName($SortB);
|
|
||||||
}
|
|
||||||
if ($SortA == $SortB) return 0;
|
|
||||||
return ($SortA < $SortB) ? -1 : 1;
|
|
||||||
});
|
});
|
||||||
} else {
|
} else{
|
||||||
uasort($data, function ($a, $b) use ($key) {
|
uasort($data, function($a, $b) use ($key){
|
||||||
$SortA = $a[$key];
|
if ($a[$key] == $b[$key]) return 0;
|
||||||
$SortB = $b[$key];
|
return ($a[$key] > $b[$key]) ? -1 : 1;
|
||||||
if ($key == "room_id") {
|
|
||||||
$SortA = RoomManager::getRoomName($SortA);
|
|
||||||
$SortB = RoomManager::getRoomName($SortB);
|
|
||||||
}
|
|
||||||
if ($SortA == $SortB) return 0;
|
|
||||||
return ($SortA > $SortB) ? -1 : 1;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -61,10 +61,4 @@ class AuthManager {
|
|||||||
};
|
};
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUserId($bearer){
|
|
||||||
$token = explode(' ', $bearer)[1];
|
|
||||||
$userid = Db::loadOne('SELECT user_id FROM tokens WHERE token = ? AND expire >= CURRENT_TIMESTAMP AND blocked = 0;', array($token))['user_id'];
|
|
||||||
return $userid;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -8,23 +8,23 @@ class AutomationManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function deactive($automationId) {
|
public static function deactive($automationId) {
|
||||||
$automation = self::getById($automationId,["enabled"]);
|
$automation = Db::loadOne ("SELECT * FROM automation WHERE automation_id=?" , array ($automationId));
|
||||||
$flipedValue = ($automation['enabled'] == 1 ? 0 : 1);
|
$flipedValue = ($automation['active'] == 1 ? 0 : 1);
|
||||||
return Db::command ('UPDATE automation SET enabled = ? WHERE automation_id=?', array ($flipedValue,$automationId));
|
return Db::command ('UPDATE automation SET active = ? WHERE automation_id=?', array ($flipedValue,$automationId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function restart($automationId) {
|
public static function restart($automationId) {
|
||||||
return Db::command ('UPDATE automation SET executed = 0 WHERE automation_id=?', array ($automationId));
|
return Db::command ('UPDATE automation SET executed = 0 WHERE automation_id=?', array ($automationId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create ($name, $onDays, $doCode, $ifCode, $userId = 1, $automationId = "") {
|
public static function create ($name, $onDays, $doCode, $ifCode, $automationId = "") {
|
||||||
$userId = UserManager::getUserData('user_id', $userId);
|
$userId = UserManager::getUserData('user_id');
|
||||||
$scene = array (
|
$scene = array (
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'owner_id' => $userId,
|
'owner_id' => $userId,
|
||||||
'on_days' => $onDays,
|
'on_days' => $onDays,
|
||||||
'conditions' => $ifCode,
|
'if_something' => $ifCode,
|
||||||
'tasks' => $doCode,
|
'do_something' => $doCode,
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
if ($automationId == "") {
|
if ($automationId == "") {
|
||||||
@@ -34,24 +34,19 @@ class AutomationManager{
|
|||||||
}
|
}
|
||||||
} catch(PDOException $error) {
|
} catch(PDOException $error) {
|
||||||
echo $error->getMessage();
|
echo $error->getMessage();
|
||||||
return false;
|
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAll($collums = ['*']){
|
public static function getAll(){
|
||||||
return Db::loadAll ("SELECT ". implode("," , $collums)." FROM automation");
|
return Db::loadAll ("SELECT * FROM automation");
|
||||||
}
|
|
||||||
|
|
||||||
public static function getById($automationId, $collums = ['*']){
|
|
||||||
return Db::loadOne("SELECT ". implode("," , $collums)." FROM automation WHERE automation_id = ?", [$automationId]);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function executeAll(){
|
public static function executeAll(){
|
||||||
global $logManager;
|
global $logManager;
|
||||||
|
|
||||||
/*$automations = Db::loadAll ("SELECT * FROM automation");
|
$automations = Db::loadAll ("SELECT * FROM automation");
|
||||||
$dayNameNow = strtolower (date('D', time()));
|
$dayNameNow = strtolower (date('D', time()));
|
||||||
|
|
||||||
foreach ($automations as $automation) {
|
foreach ($automations as $automation) {
|
||||||
@@ -175,6 +170,6 @@ class AutomationManager{
|
|||||||
Db::edit('automation', array('locked' => 0), 'WHERE automation_id = ?', array($automation['automation_id']));
|
Db::edit('automation', array('locked' => 0), 'WHERE automation_id = ?', array($automation['automation_id']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,9 +7,7 @@ class DeviceManager{
|
|||||||
WHERE approved != ?", Array(2));
|
WHERE approved != ?", Array(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
static function setHeartbeat($deviceId){
|
|
||||||
self::edit($deviceId, ['heartbeat' => date("Y-m-d H:i:s", time())]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static function getAllDevicesInRoom ($roomId = "") {
|
static function getAllDevicesInRoom ($roomId = "") {
|
||||||
return Db::loadAll ("SELECT * FROM devices WHERE room_id = ? AND approved != ?", Array($roomId, 2));
|
return Db::loadAll ("SELECT * FROM devices WHERE room_id = ? AND approved != ?", Array($roomId, 2));
|
||||||
|
@@ -2,21 +2,16 @@
|
|||||||
class RecordManager{
|
class RecordManager{
|
||||||
public static $records;
|
public static $records;
|
||||||
|
|
||||||
public static function createWithSubId ($subDeviceId, $value, $origin = false) {
|
public static function createWithSubId ($subDeviceId, $value) {
|
||||||
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();
|
||||||
@@ -24,7 +19,7 @@ class RecordManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create ($deviceId, $type, $value, $origin = false) {
|
public static function create ($deviceId, $type, $value) {
|
||||||
$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;
|
||||||
@@ -33,7 +28,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 (isset($lastRecord['value']) && $lastRecord['value'] == $value){
|
if ($lastRecord['value'] == $value){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,10 +42,6 @@ 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();
|
||||||
@@ -96,7 +87,7 @@ class RecordManager{
|
|||||||
$dateTime = $dateTime->modify($periodLocal);
|
$dateTime = $dateTime->modify($periodLocal);
|
||||||
$dateTime = $dateTime->format('Y-m-d H:i:s');
|
$dateTime = $dateTime->format('Y-m-d H:i:s');
|
||||||
$groupBy = strtoupper($groupBy).'(time)';
|
$groupBy = strtoupper($groupBy).'(time)';
|
||||||
$sql = 'SELECT value, time, execuded, origin FROM records
|
$sql = 'SELECT value, time, execuded FROM records
|
||||||
WHERE
|
WHERE
|
||||||
subdevice_id = ?
|
subdevice_id = ?
|
||||||
AND
|
AND
|
||||||
@@ -111,7 +102,7 @@ class RecordManager{
|
|||||||
|
|
||||||
public static function clean ($day) {
|
public static function clean ($day) {
|
||||||
if (isset($day)) {
|
if (isset($day)) {
|
||||||
Db::command ('DELETE FROM records WHERE `time` < ADDDATE(NOW(), INTERVAL ? DAY);', array($day));
|
Db::command ('DELETE FROM records WHERE `time` < ADDDATE(NOW(), INTERVAL -? DAY);', array($day));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,10 +110,5 @@ class RecordManager{
|
|||||||
public static function cleanSubdeviceRecords ($subDeviceId) {
|
public static function cleanSubdeviceRecords ($subDeviceId) {
|
||||||
Db::command ('DELETE FROM records WHERE subdevice_id = ?);', array($subDeviceId));
|
Db::command ('DELETE FROM records WHERE subdevice_id = ?);', array($subDeviceId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setHistory($subDeviceId){
|
|
||||||
$history = SubDeviceManager::getSubDevice($subDeviceId)['history'];
|
|
||||||
if ($history > 0) self::clean(-abs($history));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@@ -19,12 +19,6 @@ class RoomManager{
|
|||||||
return $allRoom;
|
return $allRoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getRoomName ($room_id) {
|
|
||||||
//TODO: ignore Widgets withoud data
|
|
||||||
$allRoom = Db::loadAlone ("SELECT name FROM rooms WHERE room_id=?", array ($room_id));
|
|
||||||
return $allRoom;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function create ($name) {
|
public static function create ($name) {
|
||||||
$room = array (
|
$room = array (
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
|
@@ -14,23 +14,21 @@ class SettingsManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function create ($name, $value, $type = '') {
|
public static function create ($name, $value, $type = '') {
|
||||||
if (!self::getByName($name)){
|
$setting = array (
|
||||||
$setting = array (
|
'name' => $name,
|
||||||
'name' => $name,
|
'value' => $value,
|
||||||
'value' => $value,
|
'type' => $type,
|
||||||
'type' => $type,
|
);
|
||||||
);
|
try {
|
||||||
try {
|
Db::add ('settings', $setting);
|
||||||
Db::add ('settings', $setting);
|
} catch(PDOException $error) {
|
||||||
} catch(PDOException $error) {
|
echo $error->getMessage();
|
||||||
echo $error->getMessage();
|
die();
|
||||||
die();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function update ($name, $value, $type = '') {
|
public static function update ($name, $value, $type = '') {
|
||||||
if (!self::getByName($name)){
|
if (self::getByName($name)){
|
||||||
self::create($name, $value, $type);
|
self::create($name, $value, $type);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
@@ -50,7 +50,7 @@ class SubDeviceManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check if dubdevice exist
|
//check if dubdevice exist
|
||||||
//Add History to be set in Creation
|
|
||||||
public static function create($deviceId, $type, $unit)
|
public static function create($deviceId, $type, $unit)
|
||||||
{
|
{
|
||||||
$record = array(
|
$record = array(
|
||||||
@@ -66,10 +66,6 @@ class SubDeviceManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function editSubDevicesByDevice ($deviceId, $subDeviceParameters) {
|
|
||||||
DB::edit('subdevices', $subDeviceParameters, 'WHERE device_id=?', array ($deviceId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function remove($subDeviceId)
|
public static function remove($subDeviceId)
|
||||||
{
|
{
|
||||||
RecordManager::cleanSubdeviceRecords($subDeviceId);
|
RecordManager::cleanSubdeviceRecords($subDeviceId);
|
||||||
@@ -107,7 +103,7 @@ class SubDeviceManager
|
|||||||
public static function getSubdeviceDetailById($subDeviceId){
|
public static function getSubdeviceDetailById($subDeviceId){
|
||||||
if (empty($subDeviceId)) return NULL;
|
if (empty($subDeviceId)) return NULL;
|
||||||
|
|
||||||
$rows = Db::loadOne("SELECT d.room_id, d.sleep_time, sd.subdevice_id, sd.type, sd.device_id FROM subdevices sd
|
$rows = Db::loadOne("SELECT d.room_id, d.sleep_time, sd.subdevice_id, sd.type, sd.device_id FROM subdevices sd
|
||||||
JOIN devices d ON sd.device_id = d.device_id
|
JOIN devices d ON sd.device_id = d.device_id
|
||||||
WHERE sd.subdevice_id = ? ", [$subDeviceId]);
|
WHERE sd.subdevice_id = ? ", [$subDeviceId]);
|
||||||
|
|
||||||
|
@@ -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'], 'plugin');
|
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi']);
|
||||||
} 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);
|
||||||
|
@@ -9,14 +9,6 @@ class AirQuality extends VirtualDeviceManager
|
|||||||
|
|
||||||
function make()
|
function make()
|
||||||
{
|
{
|
||||||
//Register the settings
|
|
||||||
$settingMng = new SettingsManager();
|
|
||||||
if (!($settingField = $settingMng->getByName("airquality"))) {
|
|
||||||
$settingMng->create("token", "", "airquality");
|
|
||||||
} else {
|
|
||||||
$app_id = $settingField['value'];
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (DeviceManager::registeret($this->virtual_device_name)) {
|
if (DeviceManager::registeret($this->virtual_device_name)) {
|
||||||
$deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id'];
|
$deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id'];
|
||||||
@@ -25,12 +17,12 @@ class AirQuality extends VirtualDeviceManager
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, strtolower($this->subdevice_type));
|
$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, strtolower($this->subdevice_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (!$this->fetchEnabled($deviceId,$subDevice['subdevice_id'])) die();
|
//if (!$this->fetchEnabled($deviceId,$subDevice['subdevice_id'])) die();
|
||||||
|
|
||||||
$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'], 'plugin');
|
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi']);
|
||||||
} 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]], 'plugin');
|
RecordManager::create($deviceId, strtolower($dataItem), end($json)[$this->name_index[$dataItem]]);
|
||||||
}
|
}
|
||||||
} 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));
|
||||||
|
@@ -1,85 +0,0 @@
|
|||||||
<?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);
|
|
||||||
var_dump(isset(json_decode($result, true)['data']['active_orders'][0]['delivery']['time']['eta']) ? json_decode($result, true)['data']['active_orders'][0]['delivery']['time']['eta'] : 0);
|
|
||||||
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 $value;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -3,45 +3,30 @@ class DatabaseBackup
|
|||||||
{
|
{
|
||||||
public function make()
|
public function make()
|
||||||
{
|
{
|
||||||
//Register the settings
|
|
||||||
$time = '00:00';
|
|
||||||
$settingMng = new SettingsManager();
|
|
||||||
if (!($settingField = $settingMng->getByName("backup_time","db_backup"))) {
|
|
||||||
$settingMng->create("backup_time", $time, "db_backup");
|
|
||||||
} else {
|
|
||||||
$time = $settingField['value'];
|
|
||||||
}
|
|
||||||
|
|
||||||
//Time to Backup ?
|
|
||||||
if (date("H:i",time()) != $time)
|
|
||||||
return 'pending';
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$filenames = [];
|
$filenames = [];
|
||||||
$backupWorker = new DatabaseBackup;
|
$backupWorker = new DatabaseBackup;
|
||||||
$filenames[] = $backupWorker->scheme(); //Backup Database scheme
|
$filenames[] = $backupWorker->scheme(); //Backup Database scheme
|
||||||
$filenames[] = $backupWorker->data(); //Backup Database Data
|
$filenames[] = $backupWorker->data(); //Backup Database Data
|
||||||
//$filenames[] = $_SERVER['DOCUMENT_ROOT'] . '/config/config.php'; //Backup Configuration File
|
//$filenames[] = $_SERVER['DOCUMENT_ROOT'] . '/config/config.php'; //Backup Configuration File
|
||||||
$backupWorker->compress($_SERVER['DOCUMENT_ROOT'] . BASEDIR . '/backup/' . date("Y-m-d", time()) . '.zip', $filenames);
|
$backupWorker->compress($_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'backup/' . date("Y-m-d", time()) . '.zip', $filenames);
|
||||||
return 'sucessful';
|
return 'sucessful';
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return 'exception: ' . $e->getMessage();
|
return 'exception: ' . $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function data()
|
private function scheme()
|
||||||
{
|
{
|
||||||
$backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "/backup/" . DBNAME . '_data_' . date("Y-m-d", time()) . '.sql';
|
$backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "backup/" . DBNAME . '_scheme_' . date("Y-m-d", time()) . '.sql';
|
||||||
if (file_exists($backupfile)) return null;
|
|
||||||
$command = "mysqldump --skip-comments --no-create-info -h localhost -u " . DBUSER . " -p" . DBPASS . " " . DBNAME . " -r $backupfile 2>&1";
|
$command = "mysqldump --skip-comments --no-create-info -h localhost -u " . DBUSER . " -p" . DBPASS . " " . DBNAME . " -r $backupfile 2>&1";
|
||||||
$this->executeCommand($command);
|
$this->executeCommand($command);
|
||||||
return $backupfile;
|
return $backupfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function scheme()
|
private function data()
|
||||||
{
|
{
|
||||||
$backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "/backup/" . DBNAME . '_scheme_' . date("Y-m-d", time()) . '.sql';
|
$backupfile = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . "backup/" . DBNAME . '_data_' . date("Y-m-d", time()) . '.sql';
|
||||||
if (file_exists($backupfile)) return null;
|
|
||||||
$command = "mysqldump --skip-comments --no-data -h localhost -u " . DBUSER . " -p" . DBPASS . " " . DBNAME . " -r $backupfile 2>&1";
|
$command = "mysqldump --skip-comments --no-data -h localhost -u " . DBUSER . " -p" . DBPASS . " " . DBNAME . " -r $backupfile 2>&1";
|
||||||
$this->executeCommand($command);
|
$this->executeCommand($command);
|
||||||
return $backupfile;
|
return $backupfile;
|
||||||
@@ -58,7 +43,9 @@ class DatabaseBackup
|
|||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
if ($zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
|
if ($zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$zip->addFile($file);
|
$filename = explode('/', $file);
|
||||||
|
$filename = end($filename);
|
||||||
|
$zip->addFile($file, $filename);
|
||||||
}
|
}
|
||||||
$zip->close();
|
$zip->close();
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
@@ -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, 'plugin');
|
RecordManager::create($deviceId, $this->subdevice_type, $daysUntilN7Day);
|
||||||
} 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);
|
||||||
|
@@ -23,39 +23,7 @@ class OpenWeatherMap 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['weather'][0]['id']);
|
||||||
//Notification data setup
|
|
||||||
$notificationMng = new NotificationManager;
|
|
||||||
if ($json['weather'][0]['id'] >= 500 && $json['weather'][0]['id'] < 600) {
|
|
||||||
// $notificationData = [
|
|
||||||
// 'title' => 'Weather',
|
|
||||||
// 'body' => 'It Will be rainy outhere, Take Umbrela :)',
|
|
||||||
// 'icon' => 'http://dev.steelants.cz/projekty/simplehome-client/img/icons/favicon-16x16.png',
|
|
||||||
// ];
|
|
||||||
// //Notification for newly added Device
|
|
||||||
// if ($notificationData != []) {
|
|
||||||
// $subscribers = $notificationMng::getSubscription();
|
|
||||||
// foreach ($subscribers as $key => $subscriber) {
|
|
||||||
// $notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
} else if ($json['weather'][0]['id'] >= 600 && $json['weather'][0]['id'] < 700) {
|
|
||||||
// $notificationData = [
|
|
||||||
// 'title' => 'Weather',
|
|
||||||
// 'body' => 'It is white out there :)',
|
|
||||||
// 'icon' => 'http://dev.steelants.cz/projekty/simplehome-client/img/icons/favicon-16x16.png',
|
|
||||||
// ];
|
|
||||||
// //Notification for newly added Device
|
|
||||||
// if ($notificationData != []) {
|
|
||||||
// $subscribers = $notificationMng::getSubscription();
|
|
||||||
// foreach ($subscribers as $key => $subscriber) {
|
|
||||||
// $notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -65,8 +33,4 @@ class OpenWeatherMap extends VirtualDeviceManager
|
|||||||
return 'exception: ' . $e->getMessage();
|
return 'exception: ' . $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function enable(){
|
|
||||||
(new SettingsManager)->create('open_weather_api_token', '', 'open_weather');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -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)), 'plugin');
|
RecordManager::create($deviceId, strtolower($Category), round(($$Category / $OnePercent)));
|
||||||
}
|
}
|
||||||
} 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');
|
||||||
|
@@ -5,21 +5,6 @@ class Device extends Template
|
|||||||
{
|
{
|
||||||
function __construct($sortBy = null, $sortType = null)
|
function __construct($sortBy = null, $sortType = null)
|
||||||
{
|
{
|
||||||
// //Notification data setup
|
|
||||||
// $notificationMng = new NotificationManager;
|
|
||||||
// $notificationData = [
|
|
||||||
// 'title' => 'Info',
|
|
||||||
// 'body' => 'New device Detected Found',
|
|
||||||
// 'icon' => 'http://dev.steelants.cz/projekty/simplehome-client/img/icons/favicon-16x16.png',
|
|
||||||
// ];
|
|
||||||
// //Notification for newly added Device
|
|
||||||
// if ($notificationData != []) {
|
|
||||||
// $subscribers = $notificationMng::getSubscription();
|
|
||||||
// foreach ($subscribers as $key => $subscriber) {
|
|
||||||
// $notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
$userManager = new UserManager();
|
$userManager = new UserManager();
|
||||||
$deviceManager = new DeviceManager();
|
$deviceManager = new DeviceManager();
|
||||||
$subDeviceManager = new SubDeviceManager();
|
$subDeviceManager = new SubDeviceManager();
|
||||||
@@ -43,8 +28,7 @@ class Device extends Template
|
|||||||
"token" => "token",
|
"token" => "token",
|
||||||
"signal" => "signal",
|
"signal" => "signal",
|
||||||
"firmware" => "firmware_hash",
|
"firmware" => "firmware_hash",
|
||||||
"icon" => "icon",
|
"icon" => "icon"
|
||||||
"history" => "history",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$sortIcons = [
|
$sortIcons = [
|
||||||
@@ -63,23 +47,18 @@ class Device extends Template
|
|||||||
$sortBy = "id";
|
$sortBy = "id";
|
||||||
$sortType = "DESC";
|
$sortType = "DESC";
|
||||||
}
|
}
|
||||||
|
|
||||||
$template->prepare('sortIcon', [$sortBy => $sortIcons[$sortType]]);
|
$template->prepare('sortIcon', [$sortBy => $sortIcons[$sortType]]);
|
||||||
|
|
||||||
foreach ($devices as $key => $device) {
|
foreach ($devices as $key => $device) {
|
||||||
//Signal Stenght
|
//Signal Stenght
|
||||||
$subdevice = $subDeviceManager->getSubDeviceByMasterAndType($device['device_id'], "wifi");
|
$subdevice = $subDeviceManager->getSubDeviceByMasterAndType($device['device_id'], "wifi");
|
||||||
$subdeviceLocal = $subDeviceManager->getSubDeviceByMaster($device['device_id']);
|
|
||||||
if (!empty($subdeviceLocal)) {
|
|
||||||
$devices[$key]['history'] = (!empty($subdeviceLocal['history']) ? $subdeviceLocal['history'] : 0);
|
|
||||||
} else {
|
|
||||||
$devices[$key]['history'] = "null";
|
|
||||||
}
|
|
||||||
$devices[$key]['signal'] = "";
|
$devices[$key]['signal'] = "";
|
||||||
if (!empty($subdevice['subdevice_id'])) {
|
if (!empty($subdevice['subdevice_id'])) {
|
||||||
$record = $recordManager->getLastRecord($subdevice['subdevice_id']);
|
$record = $recordManager->getLastRecord($subdevice['subdevice_id']);
|
||||||
if (!empty($record)) {
|
if (!empty($record)) {
|
||||||
$devices[$key]['signal'] = $record['value'] . " " . $subdevice['unit'];
|
$devices[$key]['signal'] = $record['value'] . " " . $subdevice['unit'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Firmware Status
|
//Firmware Status
|
||||||
|
@@ -70,8 +70,6 @@ class Setting extends Template
|
|||||||
$result = $settingsManager->getSettingGroup($plugins[$key]['slug']);
|
$result = $settingsManager->getSettingGroup($plugins[$key]['slug']);
|
||||||
if (count ($result) > 0) {
|
if (count ($result) > 0) {
|
||||||
$plugins[$key]['settings'] = $result;
|
$plugins[$key]['settings'] = $result;
|
||||||
} else {
|
|
||||||
unset($plugins[$key]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,6 @@
|
|||||||
<a href="device/mac/<?php echo $SORTTYPE; ?>">(Mac)</a><i class="fa"><?php echo (!empty($SORTICON['mac']) ? $SORTICON['mac'] : ""); ?></i><br>
|
<a href="device/mac/<?php echo $SORTTYPE; ?>">(Mac)</a><i class="fa"><?php echo (!empty($SORTICON['mac']) ? $SORTICON['mac'] : ""); ?></i><br>
|
||||||
<a href="device/token/<?php echo $SORTTYPE; ?>">Token</a><i class="fa"><?php echo (!empty($SORTICON['token']) ? $SORTICON['token'] : ""); ?></i>
|
<a href="device/token/<?php echo $SORTTYPE; ?>">Token</a><i class="fa"><?php echo (!empty($SORTICON['token']) ? $SORTICON['token'] : ""); ?></i>
|
||||||
</th>
|
</th>
|
||||||
<th><a href="device/history/<?php echo $SORTTYPE; ?>">Historie</a><i class="fa"><?php echo (!empty($SORTICON['history']) ? $SORTICON['history'] : ""); ?></i></th>
|
|
||||||
<th>Action
|
<th>Action
|
||||||
<form method="post" action="">
|
<form method="post" action="">
|
||||||
<button class="fa custom-file-input" type="submit" name="deviceCommand" value="reset" title="Reset All"><b></b></button>
|
<button class="fa custom-file-input" type="submit" name="deviceCommand" value="reset" title="Reset All"><b></b></button>
|
||||||
@@ -101,14 +100,6 @@
|
|||||||
<td><?php echo (!empty($device['mac']) ? $device['mac'] : ""); ?><br>
|
<td><?php echo (!empty($device['mac']) ? $device['mac'] : ""); ?><br>
|
||||||
<?php echo (!empty($device['ip_address']) ? $device['ip_address'] : ""); ?><br>
|
<?php echo (!empty($device['ip_address']) ? $device['ip_address'] : ""); ?><br>
|
||||||
<?php echo (!empty($device['token']) ? $device['token'] : ""); ?></td>
|
<?php echo (!empty($device['token']) ? $device['token'] : ""); ?></td>
|
||||||
<td>
|
|
||||||
<?php if (isset($device['history']) && $device['history'] != "null"): ?>
|
|
||||||
<form method="post" action="">
|
|
||||||
<input type="hidden" name="deviceId" value="<?php echo (!empty($device['device_id']) ? $device['device_id'] : ""); ?>">
|
|
||||||
<input class="input" type="number" onchange="this.form.submit();" name="deviceHistory" value="<?php echo (!empty($device['history']) ? $device['history'] : 0); ?>">
|
|
||||||
</form>
|
|
||||||
<?php endif; ?>
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
<?php if (!empty($device['mac'])) : ?>
|
<?php if (!empty($device['mac'])) : ?>
|
||||||
<form method="post" action="">
|
<form method="post" action="">
|
||||||
@@ -131,6 +122,12 @@
|
|||||||
$partial->render();
|
$partial->render();
|
||||||
//TODO js do main.js
|
//TODO js do main.js
|
||||||
?>
|
?>
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$("#sortable").sortable();
|
||||||
|
$("#sortable").disableSelection();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@@ -202,23 +202,7 @@ $partial = new Partial('head');
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--Plugins Settings-->
|
|
||||||
<?php foreach ($PLUGINSSETTINGS as $key => $pluginSeting) { ?>
|
|
||||||
<div class="col-12 col-sm-9 mx-auto mt-4">
|
|
||||||
<h4 class="mb-4"><?php echo $pluginSeting['name'] ?></h4>
|
|
||||||
<form method="post">
|
|
||||||
<?php foreach ($pluginSeting['settings'] as $key => $pluginSetingField) { ?>
|
|
||||||
<div class="field">
|
|
||||||
<div class="label"><?php echo $pluginSetingField['name'] ?>:</div>
|
|
||||||
<input type="text" class="input" name="<?php echo $pluginSetingField['name'] ?>" value="<?php echo $pluginSetingField['value'] ?>">
|
|
||||||
</div>
|
|
||||||
<?php } ?>
|
|
||||||
<div class="field">
|
|
||||||
<input type="submit" name="submitPlugins<?php echo $pluginSeting['name'] ?>Settings" class="button" value="<?php $LANGMNG->echo('b_save') ?>">
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<?php } ?>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title><?php echo $this->title; ?></title>
|
<title><?php echo $this->title ?></title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<?php echo $this->content(); ?>
|
<?php echo $this->content(); ?>
|
||||||
|
@@ -60,6 +60,7 @@ const UNITS = [
|
|||||||
|
|
||||||
//Notifications
|
//Notifications
|
||||||
define('SERVERKEY','');
|
define('SERVERKEY','');
|
||||||
|
define('SERVERVAIPKEY','');
|
||||||
|
|
||||||
//TODO: Po registraci vzít výchozí hodnoty
|
//TODO: Po registraci vzít výchozí hodnoty
|
||||||
//Default network Setting
|
//Default network Setting
|
||||||
|
24
core/Configuration/ConfigurationLoader.php
Normal file
24
core/Configuration/ConfigurationLoader.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Core\Configuration;
|
||||||
|
|
||||||
|
class ConfigurationLoader
|
||||||
|
{
|
||||||
|
private const CONFIGURATIONS_DIRECTORY = __DIR__ . DIRECTORY_SEPARATOR
|
||||||
|
. '..' . DIRECTORY_SEPARATOR
|
||||||
|
. '..' . DIRECTORY_SEPARATOR . 'config'
|
||||||
|
. DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
|
public function load(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Concerns
|
||||||
|
* -> Loading configuration files
|
||||||
|
* - Scan directory for files.
|
||||||
|
* - Filtering none config / php files.
|
||||||
|
* - Creating assoc array.
|
||||||
|
*/
|
||||||
|
}
|
@@ -8,4 +8,18 @@ namespace Core\Configuration;
|
|||||||
* @author Romano Schoonheim https://github.com/romano1996
|
* @author Romano Schoonheim https://github.com/romano1996
|
||||||
*/
|
*/
|
||||||
class Configurations
|
class Configurations
|
||||||
{}
|
{
|
||||||
|
/** @var array */
|
||||||
|
private $configurations;
|
||||||
|
|
||||||
|
public function __construct(ConfigurationLoader $configurationLoader)
|
||||||
|
{
|
||||||
|
// Concern: Storing assoc array to this object.
|
||||||
|
$this->configurations = $configurationLoader->load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get(string $path)
|
||||||
|
{
|
||||||
|
// Concern: Accessing configurations based on "paths" application.something For example.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1,2 +0,0 @@
|
|||||||
$lines = (ls -r|sls '^\s*(#|$)' -a -n).Count
|
|
||||||
write-host $lines" of code"
|
|
@@ -2660,19 +2660,19 @@ html {
|
|||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'Metropolis';
|
font-family: 'Metropolis';
|
||||||
/*src: url("../fonts/Metropolis-Regular.ttf");*/
|
src: url("../fonts/Metropolis-Regular.ttf");
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
}
|
}
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'Metropolis';
|
font-family: 'Metropolis';
|
||||||
/*src: url("../fonts/Metropolis-Medium.ttf");*/
|
src: url("../fonts/Metropolis-Medium.ttf");
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'Metropolis';
|
font-family: 'Metropolis';
|
||||||
/*src: url("../fonts/Metropolis-SemiBold.ttf");*/
|
src: url("../fonts/Metropolis-SemiBold.ttf");
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user