Merge pull request #820 from chme/outputs_toggle
New JSON API endpoint for toggling outputs
This commit is contained in:
commit
a08e08c63a
|
@ -310,6 +310,7 @@ curl -X PUT "http://localhost:3689/api/player/seek?position_ms=2000"
|
|||
| PUT | [/api/outputs/set](#set-enabled-outputs) | Set enabled outputs |
|
||||
| GET | [/api/outputs/{id}](#get-an-output) | Get an output |
|
||||
| PUT | [/api/outputs/{id}](#change-an-output) | Change an output (enable/disable or volume) |
|
||||
| PUT | [/api/outputs/{id}/toggle](#toggle-an-output) | Enable or disable an output, depending on the current state |
|
||||
|
||||
|
||||
|
||||
|
@ -484,6 +485,32 @@ On success returns the HTTP `204 No Content` success status response code.
|
|||
curl -X PUT "http://localhost:3689/api/outputs/0" --data "{\"selected\":true, \"volume\": 50}"
|
||||
```
|
||||
|
||||
### Toggle an output
|
||||
|
||||
Enable or disable an output, depending on its current state
|
||||
|
||||
**Endpoint**
|
||||
|
||||
```http
|
||||
PUT /api/outputs/{id}/toggle
|
||||
```
|
||||
|
||||
**Path parameters**
|
||||
|
||||
| Parameter | Value |
|
||||
| --------------- | -------------------- |
|
||||
| id | Output id |
|
||||
|
||||
**Response**
|
||||
|
||||
On success returns the HTTP `204 No Content` success status response code.
|
||||
|
||||
**Example**
|
||||
|
||||
```shell
|
||||
curl -X PUT "http://localhost:3689/api/outputs/0/toggle"
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Queue
|
||||
|
|
|
@ -1502,6 +1502,42 @@ jsonapi_reply_outputs_put_byid(struct httpd_request *hreq)
|
|||
return HTTP_NOCONTENT;
|
||||
}
|
||||
|
||||
/*
|
||||
* PUT /api/outputs/[output_id]/toggle
|
||||
*/
|
||||
static int
|
||||
jsonapi_reply_outputs_toggle_byid(struct httpd_request *hreq)
|
||||
{
|
||||
uint64_t output_id;
|
||||
struct player_speaker_info spk;
|
||||
int ret;
|
||||
|
||||
ret = safe_atou64(hreq->uri_parsed->path_parts[2], &output_id);
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_WEB, "No valid output id given to outputs endpoint '%s'\n", hreq->uri_parsed->path);
|
||||
|
||||
return HTTP_BADREQUEST;
|
||||
}
|
||||
|
||||
ret = player_speaker_get_byid(output_id, &spk);
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_WEB, "No output found for the given output id, toggle failed for '%s'\n", hreq->uri_parsed->path);
|
||||
return HTTP_BADREQUEST;
|
||||
}
|
||||
|
||||
if (spk.selected)
|
||||
ret = player_speaker_disable(output_id);
|
||||
else
|
||||
ret = player_speaker_enable(output_id);
|
||||
|
||||
if (ret < 0)
|
||||
return HTTP_INTERNAL;
|
||||
|
||||
return HTTP_NOCONTENT;
|
||||
}
|
||||
|
||||
/*
|
||||
* Endpoint "/api/outputs"
|
||||
*/
|
||||
|
@ -3817,6 +3853,7 @@ static struct httpd_uri_map adm_handlers[] =
|
|||
{ EVHTTP_REQ_POST, "^/api/select-outputs$", jsonapi_reply_outputs_set }, // deprecated: use "/api/outputs/set"
|
||||
{ EVHTTP_REQ_GET, "^/api/outputs/[[:digit:]]+$", jsonapi_reply_outputs_get_byid },
|
||||
{ EVHTTP_REQ_PUT, "^/api/outputs/[[:digit:]]+$", jsonapi_reply_outputs_put_byid },
|
||||
{ EVHTTP_REQ_PUT, "^/api/outputs/[[:digit:]]+/toggle$", jsonapi_reply_outputs_toggle_byid },
|
||||
|
||||
{ EVHTTP_REQ_GET, "^/api/player$", jsonapi_reply_player },
|
||||
{ EVHTTP_REQ_PUT, "^/api/player/play$", jsonapi_reply_player_play },
|
||||
|
|
Loading…
Reference in New Issue