Former-commit-id: c11741eee04b8f029ab1b80365d3f58c319d60ff
TangShanKaiPing
wanggang 6 years ago
parent 284912bfd8
commit 6cd75eb04b

@ -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("版本")]

@ -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", "关");
});
}
}
}

@ -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<IRepository<Device>>();
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<Device> deviceRepo, string sn, string ieee)
{
return deviceRepo.Table()

@ -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)

@ -389,9 +389,9 @@
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch2/Off')">全关</a>
</div>
<div class="row">
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch2/L1On')" v-if="getData(device,'状态4')==='关'"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch2/L1On')" v-if="getData(device,'L1状态')==='关'"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch2/L1Off')" v-else></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch2/L2On')" v-if="getData(device,'状态5')==='关'"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch2/L2On')" v-if="getData(device,'L2状态')==='关'"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch2/L2Off')" v-else></a>
</div>
</div>
@ -427,11 +427,11 @@
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch3/Off')">全关</a>
</div>
<div class="row">
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch3/L1On')" v-if="getData(device,'状态4')==='关'"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch3/L1On')" v-if="getData(device,'L1状态')==='关'"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch3/L1Off')" v-else></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch3/L2On')" v-if="getData(device,'状态5')==='关'"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch3/L2On')" v-if="getData(device,'L2状态')==='关'"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch3/L2Off')" v-else></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch3/L3On')" v-if="getData(device,'状态6')==='关'"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch3/L3On')" v-if="getData(device,'L3状态')==='关'"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Switch3/L3Off')" v-else></a>
</div>
</div>
@ -459,8 +459,8 @@
</ul>
</div>
<div class="row">
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/ColorLight/On')"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/ColorLight/Off')"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/ColorLight/On')" v-if="getData(device,'状态')==='关'"></a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/ColorLight/Off')" v-else></a>
</div>
<div class="row">
<form class="ajax" method="get" :action="vm.IoTServer+'/App/Exec'">
@ -498,9 +498,9 @@
<i class="f7-icons">info</i>
</div>
<div class="item-inner">
<div class="item-title item-label"></div>
<div class="item-title item-label"></div>
<div class="item-input-wrap">
<input class="ajax" type="range" min="0" step="1" max="255" name="Hue" :value="getValue(device,'色')" />
<input class="ajax" type="range" min="0" step="1" max="255" name="Hue" :value="getValue(device,'色')" />
</div>
</div>
</li>
@ -546,6 +546,49 @@
</div>
</div>
</template>
<template v-if="getDevices('红外转发器').length">
<div class="block-title">红外转发器</div>
<div class="block block-strong">
<div class="row">
<div class="col-100 tablet-50 desktop-25" v-for="device in getDevices('红外转发器')">
<div class="list">
<ul>
<li>
<a class="item-link item-content"
:href="'/device/'+device.Number+'/name/'+device.Name">
<div class="item-media"> <img :src="'images/'+device.Icon+'.png'" /></div>
<div class="item-inner">
<div class="item-title">{{device.DisplayName||device.Name}}</div>
<div class="item-after"></div>
</div>
</a>
</li>
</ul>
</div>
<div class="row">
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Ir/KeyCodeType1On')" v-if="getData(device,'空调')==='关'">启用空调</a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Ir/KeyCodeType1Off')" v-else>禁用空调</a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Ir/KeyCodeType2On')" v-if="getData(device,'电视')==='关'">启用电视</a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Ir/KeyCodeType2Off')" v-else>禁用电视</a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Ir/KeyCodeType5On')" v-if="getData(device,'电视')==='关'">启用自定义</a>
<a class="button button-large button-raised button-fill" href="javascript: ;" v-on:click="call(device.GatewayNumber,device.Number,'/Ir/KeyCodeType5Off')" v-else>禁用自定义</a>
</div>
<div class="row" v-if="getData(device,'空调')==='开'">
<form class="ajax" method="get" :action="vm.IoTServer+'/App/Exec'">
<input type="hidden" name="ConnectionId" :value="vm.ConnectionId" />
<input type="hidden" name="Gateway" :value="device.GatewayNumber" />
<input type="hidden" name="Number" :value="device.Number" />
<input type="hidden" name="Type" value="1" />
<div class="row">
<input name="power" type="button" value="2" class="ajax" />
</div>
</form>
</div>
</div>
</div>
</div>
</template>
</f7-page>
</template>
<template id="page-device">

Loading…
Cancel
Save