diff --git a/modules/api/controllers/ItemController.php b/modules/api/controllers/ItemController.php index 196ed82..10ba9b0 100644 --- a/modules/api/controllers/ItemController.php +++ b/modules/api/controllers/ItemController.php @@ -70,6 +70,43 @@ class ItemController extends Controller ]; } + /** + * @param int $item_id + * @return array + * @throws BadRequestHttpException + * @throws NotSupportedException + */ + public function actionTurnOff($item_id) + { + $item = $this->findItem($item_id); + + if ($item->type !== Item::TYPE_SWITCH) { + throw new BadRequestHttpException(); + } + + $board = $item->board; + + switch ($board->type) { + case Board::TYPE_AREST: + throw new NotSupportedException(); + break; + case Board::TYPE_WEBSOCKET: + $api = new WebSocketAPI(Yii::$app->user->identity); + + if (!$api->turnOff($item_id)) { + return [ + 'success' => false, + ]; + } + + break; + } + + return [ + 'success' => true, + ]; + } + /** * @param int $id * @return Item diff --git a/servers/Panel.php b/servers/Panel.php index 8ac703a..e58c5d7 100644 --- a/servers/Panel.php +++ b/servers/Panel.php @@ -7,7 +7,6 @@ use app\models\Task; use app\models\Trigger; use app\models\History; use app\models\Item; -use app\models\TaskAction; use app\models\User; use Ratchet\ConnectionInterface; use Ratchet\MessageComponentInterface;