|
|
|
@ -1,87 +1,14 @@
|
|
|
|
|
using Application.Models;
|
|
|
|
|
using Infrastructure.Extensions;
|
|
|
|
|
using IoTNode.DeviceServices.FBee;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using IoTNode.DeviceServices.FBee;
|
|
|
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
|
|
|
|
namespace IoTNode.Controllers
|
|
|
|
|
{
|
|
|
|
|
[SwaggerTag("调色灯")]
|
|
|
|
|
public class ColorLightController : SwitchController
|
|
|
|
|
public class ColorLightController : WarmLightController
|
|
|
|
|
{
|
|
|
|
|
internal readonly FBeeService _deviceService;
|
|
|
|
|
|
|
|
|
|
public ColorLightController(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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|