You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/IoTNode/Controllers/FBee/WarmLightController.cs

87 lines
3.3 KiB

using Application.Models;
using Infrastructure.Extensions;
using IoTNode.DeviceServices.FBee;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System;
using System.ComponentModel.DataAnnotations;
namespace IoTNode.Controllers
{
[SwaggerTag("色暖灯")]
public class WarmLightController : SwitchController
{
internal readonly FBeeService _deviceService;
public WarmLightController(IServiceProvider applicationServices, FBeeService deviceService) : base(applicationServices, deviceService)
{
this._deviceService = deviceService;
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")]
public ApiResponse SetBrightness([SwaggerParameter("设备编号")]string number, [SwaggerParameter("亮度")][Range(0, 255)]int brightness)
{
if (number is null)
{
throw new ArgumentNullException(nameof(number));
}
try
{
var values = number.Split('-');
this._deviceService.X83(values[0], values[1], (byte)brightness);
}
catch (Exception ex)
{
ex.PrintStack();
return ApiResponse.Error(ex.Message);
}
return ApiResponse.AsyncSuccess();
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")]
public ApiResponse SetColor([SwaggerParameter("设备编号")]string number, [SwaggerParameter("色调")][Range(0, 255)]int hue, [SwaggerParameter("饱和度")][Range(0, 255)]int saturation)
{
if (number is null)
{
throw new ArgumentNullException(nameof(number));
}
try
{
var values = number.Split('-');
this._deviceService.X84(values[0], values[1], (byte)hue, (byte)saturation);
}
catch (Exception ex)
{
ex.PrintStack();
return ApiResponse.Error(ex.Message);
}
return ApiResponse.AsyncSuccess();
}
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")]
public ApiResponse SetColorTemperature([SwaggerParameter("设备编号")]string number, [SwaggerParameter("色温")][Range(2700, 6500)]int colorTemperature)
{
if (number is null)
{
throw new ArgumentNullException(nameof(number));
}
try
{
var values = number.Split('-');
this._deviceService.XA8(values[0], values[1], (ushort)colorTemperature);
}
catch (Exception ex)
{
ex.PrintStack();
return ApiResponse.Error(ex.Message);
}
return ApiResponse.AsyncSuccess();
}
}
}