Automations Endpoint Detail + Cron Endpoint
This commit is contained in:
		@@ -41,23 +41,27 @@ $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');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$router->get('/api/automations', 'AutomationsApi@default');
 | 
					$router->get('/api/automations', 'AutomationsApi@default');
 | 
				
			||||||
 | 
					$router->get('/api/automations/{automationId}/detail', 'AutomationsApi@detail');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//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');
 | 
					$router->any('/api/users/subscribe', 'UsersApi@subscribe');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// examples
 | 
					// examples
 | 
				
			||||||
$router->any('/api/example', 'ExampleApi@example');
 | 
					$router->any('/api/example', 'ExampleApi@example');
 | 
				
			||||||
$router->any('/example', 'ExampleController@index');
 | 
					$router->any('/example', 'ExampleController@index');
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,9 +7,9 @@ class AutomationsApi extends ApiController
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		//$this->requireAuth();
 | 
							//$this->requireAuth();
 | 
				
			||||||
		$response = [];
 | 
							$response = [];
 | 
				
			||||||
		$automationData = AutomationManager::getAll();
 | 
							$automationsData = AutomationManager::getAll();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		foreach ($automationData as $automationKey => $automation) {
 | 
							foreach ($automationsData as $automationKey => $automation) {
 | 
				
			||||||
			$response[] = [
 | 
								$response[] = [
 | 
				
			||||||
				"automation_id" => $automation['automation_id'],
 | 
									"automation_id" => $automation['automation_id'],
 | 
				
			||||||
				"name" => $automation['name'],
 | 
									"name" => $automation['name'],
 | 
				
			||||||
@@ -19,4 +19,23 @@ class AutomationsApi extends ApiController
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		$this->response($response);
 | 
							$this->response($response);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function detail($automationId)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							//$this->requireAuth();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$response = null;
 | 
				
			||||||
 | 
							$automationData = AutomationManager::getById($automationId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$response = [
 | 
				
			||||||
 | 
								'automation_id' => $automationData['automation_id'],
 | 
				
			||||||
 | 
								'last_execution_time' => $automationData['last_execution_time'],
 | 
				
			||||||
 | 
								'owner' => $automationData['owner_id'],
 | 
				
			||||||
 | 
								'conditions' => $automationData['conditions'],
 | 
				
			||||||
 | 
								'tasks' => $automationData['tasks'],
 | 
				
			||||||
 | 
							];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$this->response($response);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,8 +20,7 @@ class CronApi extends ApiController
 | 
				
			|||||||
		$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/';
 | 
				
			||||||
@@ -60,4 +59,9 @@ class CronApi extends ApiController
 | 
				
			|||||||
		//Print Result
 | 
							//Print Result
 | 
				
			||||||
		$this->response($result);
 | 
							$this->response($result);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function automations(){
 | 
				
			||||||
 | 
							AutomationManager:executeAll();
 | 
				
			||||||
 | 
							$this->response(['Value' => 'OK']);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,10 +43,15 @@ class AutomationManager{
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public static function getById($automationId){
 | 
				
			||||||
 | 
							return Db::loadOne("SELECT * 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) {
 | 
				
			||||||
@@ -170,6 +175,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']));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}*/
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user