This commit is contained in:
Alex Solomaha
2016-12-10 01:38:21 +02:00
parent deb7055032
commit b500d71335
2 changed files with 37 additions and 1 deletions

View File

@@ -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

View File

@@ -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;