diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/HomeController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/HomeController.cs index 75f76c85..16ec72d8 100644 --- a/projects/IoT/IoTServices/FBeeService/Controllers/HomeController.cs +++ b/projects/IoT/IoTServices/FBeeService/Controllers/HomeController.cs @@ -54,175 +54,6 @@ namespace FBeeService.Controllers #endregion ui - #region api - - [ApiExplorerSettings(IgnoreApi = true)] - [SwaggerOperation("设备开关")] - [HttpGet] - [Route("/api/x82")] - public ApiResponse X82(string sn, string ieee, byte status) - { - try - { - this._deviceService.X82(sn, ieee, status); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - [ApiExplorerSettings(IgnoreApi = true)] - [SwaggerOperation("设置亮度")] - [HttpGet] - [Route("/api/x83")] - public ApiResponse X83(string sn, string ieee, [Range(0, 255)]byte brightness) - { - try - { - this._deviceService.X83(sn, ieee, brightness); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - [ApiExplorerSettings(IgnoreApi = true)] - [SwaggerOperation("设置颜色")] - [HttpGet] - [Route("/api/x84")] - public ApiResponse X84(string sn, string ieee, [Range(0, 255)]byte hue, [Range(0, 255)]byte saturation) - { - try - { - this._deviceService.X84(sn, ieee, hue, saturation); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - #endregion api - - #region smart plug - - [HttpGet] - [Route("/smartplug/api")] - [SwaggerOperation("API")] - [ApiExplorerSettings(IgnoreApi = true)] - public string Switch2Api() - { - return GetApiJson("/smartplug/"); - } - - [SwaggerOperation("开")] - [HttpGet] - [Route("/smartplug/21on")] - public ApiResponse SmartPlugOn([SwaggerParameter("设备Id")]string id) - { - try - { - this._deviceService.X82(null, id, 1); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - [SwaggerOperation("关")] - [HttpGet] - [Route("/smartplug/22off")] - public ApiResponse SmartPlugOff([SwaggerParameter("设备Id")]string id) - { - try - { - this._deviceService.X82(null, id, 0); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - #endregion smart plug - - #region colorlight - - [HttpGet] - [Route("/colorlight/api")] - [SwaggerOperation("API")] - [ApiExplorerSettings(IgnoreApi = true)] - public string ColorLightApi() - { - return GetApiJson("/colorlight/"); - } - - [SwaggerOperation("亮度")] - [HttpGet] - [Route("/colorlight/23setbrightness")] - public ApiResponse SetBrightness([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, [SwaggerParameter("亮度")][Range(0, 255)]int brightness) - { - try - { - this._deviceService.X83(sn, id, (byte)brightness); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - [SwaggerOperation("颜色")] - [HttpGet] - [Route("/colorlight/24setcolor")] - public ApiResponse SetColor([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, [SwaggerParameter("色度")][Range(0, 255)]int hue, [SwaggerParameter("饱和度")][Range(0, 255)]int saturation) - { - try - { - this._deviceService.X84(sn, id, (byte)hue, (byte)saturation); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - [SwaggerOperation("色温")] - [HttpGet] - [Route("/colorlight/25setcolortemperature")] - public ApiResponse SetColorTemperature([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, [SwaggerParameter("色温")][Range(2700, 6500)]int colorTemperature) - { - try - { - this._deviceService.XA8(sn, id, (ushort)colorTemperature); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - #endregion colorlight - #region IR [SwaggerOperation("版本")] diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/IrController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/IrController.cs index 00f0a6f6..d68ac407 100644 --- a/projects/IoT/IoTServices/FBeeService/Controllers/IrController.cs +++ b/projects/IoT/IoTServices/FBeeService/Controllers/IrController.cs @@ -34,5 +34,95 @@ namespace FBeeService.Controllers this._deviceService.XA70083(gateway, number, type, code); }); } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("启用空调")] + public ApiResponse KeyCodeType1On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) + { + return this.AsyncAction(() => + { + this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType1", "开"); + }); + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("禁用空调")] + public ApiResponse KeyCodeType1Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) + { + return this.AsyncAction(() => + { + this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType1", "关"); + }); + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("启用电视")] + public ApiResponse KeyCodeType2On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) + { + return this.AsyncAction(() => + { + this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType2", "开"); + }); + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("禁用电视")] + public ApiResponse KeyCodeType2Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) + { + return this.AsyncAction(() => + { + this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType2", "关"); + }); + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("启用图影仪")] + public ApiResponse KeyCodeType3On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) + { + return this.AsyncAction(() => + { + this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType3", "开"); + }); + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("禁用图影仪")] + public ApiResponse KeyCodeType3Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) + { + return this.AsyncAction(() => + { + this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType3", "关"); + }); + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("启用机顶盒")] + public ApiResponse KeyCodeType4On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) + { + return this.AsyncAction(() => + { + this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType4", "开"); + }); + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("禁用机顶盒")] + public ApiResponse KeyCodeType4Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) + { + return this.AsyncAction(() => + { + this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType4", "关"); + }); + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("启用自定义")] + public ApiResponse KeyCodeType5On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) + { + return this.AsyncAction(() => + { + this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType5", "开"); + }); + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("禁用自定义")] + public ApiResponse KeyCodeType5Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) + { + return this.AsyncAction(() => + { + this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType5", "关"); + }); + } } } \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Infrastructure/DeviceService.cs b/projects/IoT/IoTServices/FBeeService/Infrastructure/DeviceService.cs index 5b452a80..fb4615ce 100644 --- a/projects/IoT/IoTServices/FBeeService/Infrastructure/DeviceService.cs +++ b/projects/IoT/IoTServices/FBeeService/Infrastructure/DeviceService.cs @@ -528,6 +528,14 @@ namespace FBeeService InfoNumber = infoNumber, InfoId = deviceInfo.Id }; + if (deviceName == "红外转发器") + { + device.AddorUpdateData("KeyCodeType1", "关", DeviceDataType.String, "空调"); + device.AddorUpdateData("KeyCodeType2", "关", DeviceDataType.String, "电视"); + device.AddorUpdateData("KeyCodeType3", "关", DeviceDataType.String, "图影仪"); + device.AddorUpdateData("KeyCodeType4", "关", DeviceDataType.String, "机顶盒"); + device.AddorUpdateData("KeyCodeType5", "关", DeviceDataType.String, "自定义"); + } deviceRepo.Add(device); } device.IsOnline = isOnline != 0x00; @@ -1238,6 +1246,22 @@ namespace FBeeService #endregion api + public void SetKeyCodeType(string sn, string ieee, string keyType, string value) + { + using (var scope = _applicationServices.CreateScope()) + { + var repo = scope.ServiceProvider.GetService>(); + var device = repo.Table().Include(o => o.Data).FirstOrDefault(o => o.GatewayNumber == sn && o.Number == ieee); + var data = device.Data.FirstOrDefault(o => o.Key == keyType); + if (data != null) + { + data.Value = value; + } + repo.SaveChanges(); + this.SendDevice(device); + } + } + private Device GetDevice(IRepository deviceRepo, string sn, string ieee) { return deviceRepo.Table() diff --git a/projects/IoTCenter/Services/PageHub.cs b/projects/IoTCenter/Services/PageHub.cs index cf871b7b..b17c9898 100644 --- a/projects/IoTCenter/Services/PageHub.cs +++ b/projects/IoTCenter/Services/PageHub.cs @@ -2,6 +2,7 @@ using Infrastructure.Data; using Infrastructure.Extensions; using Infrastructure.Web.SignalR; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Readers; @@ -126,6 +127,7 @@ namespace IoTCenter.Services } } deviceRepo.SaveChanges(); + this.Clients.Group("page").SendAsync("UpdateDevice", device.ToJson()); } } catch (Exception ex) diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html b/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html index 8773495e..14dc32be 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html @@ -389,9 +389,9 @@ 全关
- + - +
@@ -427,11 +427,11 @@ 全关
- + - + - +
@@ -459,8 +459,8 @@
- - + +
@@ -498,9 +498,9 @@ info
-
色度
+
色调
- +
@@ -546,6 +546,49 @@ + +