PHP_SMART_HOME_V3/app/api/AutomationsApi.php

45 lines
985 B
PHP
Raw Normal View History

2021-02-16 13:28:31 +00:00
<?php
class AutomationsApi extends ApiController
{
public function default()
{
//$this->requireAuth();
$response = [];
2021-02-17 07:37:08 +00:00
$response = AutomationManager::getAll(["automation_id","name","enabled"]);
2021-02-16 13:28:31 +00:00
$this->response($response);
}
public function detail($automationId)
{
//$this->requireAuth();
2021-02-17 07:37:08 +00:00
$response = [];
$response = AutomationManager::getById($automationId, ["automation_id", "last_execution_time", "owner_id", "conditions", "tasks"]);
$this->response($response);
}
2021-02-23 11:41:34 +00:00
public function create()
{
2021-02-23 11:41:48 +00:00
$this->requireAuth();
2021-02-23 11:41:34 +00:00
$obj = $this->input;
2021-02-24 16:20:49 +00:00
if (
empty($obj['name']) ||
!isset($obj['name']) ||
!isset($obj['conditions']) ||
!isset($obj['tasks']) ||
!isset($obj['days'])
) {
throw new Exception("Invalid request payload", 400);
}
2021-02-23 11:41:34 +00:00
$response = [];
2021-02-24 16:20:49 +00:00
$response = AutomationManager::create($obj['name'],json_encode($obj['days']), json_encode($obj['tasks']), json_encode($obj['conditions']));
2021-02-23 11:41:34 +00:00
$this->response(['value'=>'OK']);
}
2021-02-16 13:28:31 +00:00
}