< Summary - Jellyfin

Information
Class: Jellyfin.Api.Controllers.DevicesController
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/Controllers/DevicesController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 141
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 1/23/2026 - 12:11:06 AM Line coverage: 0% (0/16) Branch coverage: 0% (0/4) Total lines: 1404/19/2026 - 12:14:27 AM Line coverage: 0% (0/27) Branch coverage: 0% (0/8) Total lines: 1404/27/2026 - 12:15:04 AM Line coverage: 0% (0/27) Branch coverage: 0% (0/8) Total lines: 141 1/23/2026 - 12:11:06 AM Line coverage: 0% (0/16) Branch coverage: 0% (0/4) Total lines: 1404/19/2026 - 12:14:27 AM Line coverage: 0% (0/27) Branch coverage: 0% (0/8) Total lines: 1404/27/2026 - 12:15:04 AM Line coverage: 0% (0/27) Branch coverage: 0% (0/8) Total lines: 141

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetDevices(...)100%210%
GetDeviceInfo(...)0%620%
GetDeviceOptions(...)0%620%
UpdateDeviceOptions()100%210%
DeleteDevice()0%2040%

File(s)

/srv/git/jellyfin/Jellyfin.Api/Controllers/DevicesController.cs

#LineLine coverage
 1using System;
 2using System.ComponentModel.DataAnnotations;
 3using System.Threading.Tasks;
 4using Jellyfin.Api.Helpers;
 5using Jellyfin.Data.Dtos;
 6using Jellyfin.Data.Queries;
 7using MediaBrowser.Common.Api;
 8using MediaBrowser.Controller.Devices;
 9using MediaBrowser.Controller.Session;
 10using MediaBrowser.Model.Dto;
 11using MediaBrowser.Model.Querying;
 12using Microsoft.AspNetCore.Authorization;
 13using Microsoft.AspNetCore.Http;
 14using Microsoft.AspNetCore.Mvc;
 15
 16namespace Jellyfin.Api.Controllers;
 17
 18/// <summary>
 19/// Devices Controller.
 20/// </summary>
 21[Authorize(Policy = Policies.RequiresElevation)]
 22[Tags("Device")]
 23public class DevicesController : BaseJellyfinApiController
 24{
 25    private readonly IDeviceManager _deviceManager;
 26    private readonly ISessionManager _sessionManager;
 27
 28    /// <summary>
 29    /// Initializes a new instance of the <see cref="DevicesController"/> class.
 30    /// </summary>
 31    /// <param name="deviceManager">Instance of <see cref="IDeviceManager"/> interface.</param>
 32    /// <param name="sessionManager">Instance of <see cref="ISessionManager"/> interface.</param>
 033    public DevicesController(
 034        IDeviceManager deviceManager,
 035        ISessionManager sessionManager)
 36    {
 037        _deviceManager = deviceManager;
 038        _sessionManager = sessionManager;
 039    }
 40
 41    /// <summary>
 42    /// Get Devices.
 43    /// </summary>
 44    /// <param name="userId">Gets or sets the user identifier.</param>
 45    /// <response code="200">Devices retrieved.</response>
 46    /// <returns>An <see cref="OkResult"/> containing the list of devices.</returns>
 47    [HttpGet]
 48    [ProducesResponseType(StatusCodes.Status200OK)]
 49    public ActionResult<QueryResult<DeviceInfoDto>> GetDevices([FromQuery] Guid? userId)
 50    {
 051        userId = RequestHelpers.GetUserId(User, userId);
 052        return _deviceManager.GetDevicesForUser(userId);
 53    }
 54
 55    /// <summary>
 56    /// Get info for a device.
 57    /// </summary>
 58    /// <param name="id">Device Id.</param>
 59    /// <response code="200">Device info retrieved.</response>
 60    /// <response code="404">Device not found.</response>
 61    /// <returns>An <see cref="OkResult"/> containing the device info on success, or a <see cref="NotFoundResult"/> if t
 62    [HttpGet("Info")]
 63    [ProducesResponseType(StatusCodes.Status200OK)]
 64    [ProducesResponseType(StatusCodes.Status404NotFound)]
 65    public ActionResult<DeviceInfoDto> GetDeviceInfo([FromQuery, Required] string id)
 66    {
 067        var deviceInfo = _deviceManager.GetDevice(id);
 068        if (deviceInfo is null)
 69        {
 070            return NotFound();
 71        }
 72
 073        return deviceInfo;
 74    }
 75
 76    /// <summary>
 77    /// Get options for a device.
 78    /// </summary>
 79    /// <param name="id">Device Id.</param>
 80    /// <response code="200">Device options retrieved.</response>
 81    /// <response code="404">Device not found.</response>
 82    /// <returns>An <see cref="OkResult"/> containing the device info on success, or a <see cref="NotFoundResult"/> if t
 83    [HttpGet("Options")]
 84    [ProducesResponseType(StatusCodes.Status200OK)]
 85    [ProducesResponseType(StatusCodes.Status404NotFound)]
 86    public ActionResult<DeviceOptionsDto> GetDeviceOptions([FromQuery, Required] string id)
 87    {
 088        var deviceInfo = _deviceManager.GetDeviceOptions(id);
 089        if (deviceInfo is null)
 90        {
 091            return NotFound();
 92        }
 93
 094        return deviceInfo;
 95    }
 96
 97    /// <summary>
 98    /// Update device options.
 99    /// </summary>
 100    /// <param name="id">Device Id.</param>
 101    /// <param name="deviceOptions">Device Options.</param>
 102    /// <response code="204">Device options updated.</response>
 103    /// <returns>A <see cref="NoContentResult"/>.</returns>
 104    [HttpPost("Options")]
 105    [ProducesResponseType(StatusCodes.Status204NoContent)]
 106    public async Task<ActionResult> UpdateDeviceOptions(
 107        [FromQuery, Required] string id,
 108        [FromBody, Required] DeviceOptionsDto deviceOptions)
 109    {
 0110        await _deviceManager.UpdateDeviceOptions(id, deviceOptions.CustomName).ConfigureAwait(false);
 0111        return NoContent();
 0112    }
 113
 114    /// <summary>
 115    /// Deletes a device.
 116    /// </summary>
 117    /// <param name="id">Device Id.</param>
 118    /// <response code="204">Device deleted.</response>
 119    /// <response code="404">Device not found.</response>
 120    /// <returns>A <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if the device could not b
 121    [HttpDelete]
 122    [ProducesResponseType(StatusCodes.Status204NoContent)]
 123    [ProducesResponseType(StatusCodes.Status404NotFound)]
 124    public async Task<ActionResult> DeleteDevice([FromQuery, Required] string id)
 125    {
 0126        var existingDevice = _deviceManager.GetDevice(id);
 0127        if (existingDevice is null)
 128        {
 0129            return NotFound();
 130        }
 131
 0132        var sessions = _deviceManager.GetDevices(new DeviceQuery { DeviceId = id });
 133
 0134        foreach (var session in sessions.Items)
 135        {
 0136            await _sessionManager.Logout(session).ConfigureAwait(false);
 137        }
 138
 0139        return NoContent();
 0140    }
 141}