From 271faaf6664166dc368639b9f2e577f63f901be5 Mon Sep 17 00:00:00 2001 From: wei <kaede@kaededeMacBook-Air.local> Date: 星期三, 23 十二月 2020 22:23:57 +0800 Subject: [PATCH] 20201223-99 --- HDL_ON/Entity/Function/Function.cs | 228 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 195 insertions(+), 33 deletions(-) diff --git a/HDL_ON/Entity/Function/Function.cs b/HDL_ON/Entity/Function/Function.cs index ddafe50..26c6ff3 100644 --- a/HDL_ON/Entity/Function/Function.cs +++ b/HDL_ON/Entity/Function/Function.cs @@ -1,5 +1,7 @@ 锘縰sing System; using System.Collections.Generic; +using HDL_ON.Common; +using HDL_ON.DAL.Server; using HDL_ON.DriverLayer; using Shared; @@ -162,7 +164,7 @@ { if (_trait_on_off == null) { - _trait_on_off = attributes.Find((obj) => obj.key == "on_off"); + _trait_on_off = attributes.Find((obj) => obj.key == FunctionAttributeKey.OnOff); //鎵句笉鍒板睘鎬ч渶瑕佸0鏄庝竴涓紝闃叉鎶ラ敊闂�� if (_trait_on_off == null) { @@ -173,8 +175,12 @@ max = 1, min = 0, }; + _trait_on_off.curValue = "off"; } - _trait_on_off.curValue = "on"; + } + if(_trait_on_off.curValue.ToString() != "on"&& _trait_on_off.curValue.ToString() != "off") + { + _trait_on_off.curValue = "off"; } return _trait_on_off; } @@ -187,7 +193,7 @@ /// <summary> /// 浣跨敤娆℃暟 /// </summary> - public double usageCount = 0; + public double controlCounter = 0; /// <summary> /// 浣跨敤棰戠巼 /// </summary> @@ -195,13 +201,73 @@ { get { - return usageCount / 7; + return controlCounter / 7; } } /// <summary> /// 鍥哄畾鐨勫簭鍙� /// </summary> public int fixedSerialNumber = int.MaxValue; + + /// <summary> + /// 鏀惰棌鍔熻兘 + /// </summary> + public void CollectFunction() + { + var result = ""; + //var waitPage = new Loading(); + + new System.Threading.Thread(() => + { + if (collect) + { + result = ApiUtlis.Ins.HttpRequest.CollectDevice(deviceId).Code; + } + else + { + result = ApiUtlis.Ins.HttpRequest.CancelCollectDevice(deviceId).Code; + } + //鎻愮ず閿欒 + if (result != StateCode.SUCCESS) + { + Application.RunOnMainThread(() => + { + collect = !collect; + IMessageCommon.Current.ShowErrorInfoAlter(result); + }); + } + }) + { IsBackground = true }.Start(); + } + /// <summary> + /// 缂栬緫鍔熻兘缁戝畾鎴块棿淇℃伅 + /// </summary> + public void EditBindRoomInfo(string roomId) + { + var result = ""; + + new System.Threading.Thread(() => + { + if (collect) + { + result = ApiUtlis.Ins.HttpRequest.BindDeviceToRoom(new List<string>() { deviceId }, new List<string>() { roomId }).Code; + } + else + { + result = ApiUtlis.Ins.HttpRequest.UnbindDeviceToRoom(deviceId,roomId); + } + //鎻愮ず閿欒 + if (result != StateCode.SUCCESS) + { + Application.RunOnMainThread(() => + { + collect = !collect; + IMessageCommon.Current.ShowErrorInfoAlter(result); + }); + } + }) + { IsBackground = true }.Start(); + } public string GetBusId() { @@ -231,11 +297,11 @@ { roomNameList += ","; } - roomNameList += findRoom.floorName + findRoom.roomName; + roomNameList += findRoom.floorName +"-"+ findRoom.roomName; } if (roomNameList == "" && functionType == FunctionType.Scene) { - roomNameList = Language.StringByID(StringId.WholeHouseScene); + roomNameList = Language.StringByID(StringId.WholeZone); } return roomNameList; } @@ -250,31 +316,104 @@ return "FunctionData_" + sid; } } + /// <summary> - /// 淇濆瓨鍔熻兘鏁版嵁 + /// 淇濆瓨鍔熻兘鏂囦欢 /// </summary> - public void SaveFunctionData(bool upSevser) + public void SaveFunctionFile() { - if (upSevser) + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); + FileUtlis.Files.WriteFileByBytes(savePath, ssd); + } + /// <summary> + /// 淇濆瓨鎴块棿缁戝畾淇℃伅 + /// </summary> + public void UpdataRoomIds() + { + new System.Threading.Thread(() => { - var pm = new DAL.Server.HttpServerRequest(); - var pack = pm.UpdataDevcieInfo(this); - if (pack.Code == DAL.Server.StateCode.SUCCESS) + var pack = ApiUtlis.Ins.HttpRequest.UpdataDevcieBindRoomInfo(this); + //鐩存帴淇濆瓨鏈湴锛� + SaveFunctionFile(); + if (pack.Code == StateCode.SUCCESS) { - var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); - Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); } else { - Utlis.ShowTip(Language.StringByID(StringId.EditFunctionInfoFail) + "\r\nCode:" + pack.Code); + IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); } - } - else - { - var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); - Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); - } + }) + { IsBackground = true }.Start(); } + /// <summary> + /// 鏇存柊鍔熻兘淇℃伅 + /// </summary> + public void UpdataFuncitonInfo() + { + new System.Threading.Thread(() => + { + var pm = new HttpServerRequest(); + var pack = pm.UpdataDevcieInfo(this); + SaveFunctionFile(); + if (pack.Code == StateCode.SUCCESS) + { + } + else + { + IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); + } + }) + { IsBackground = true }.Start(); + } + /// <summary> + /// 鏇存柊鍔熻兘鍚嶇О + /// </summary> + public void UpdataFunctionName() + { + new System.Threading.Thread(() => + { + var pm = new HttpServerRequest(); + var pack = pm.UpdataDevcieInfo(this); + SaveFunctionFile(); + if (pack.Code == StateCode.SUCCESS) + { + } + else + { + IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); + } + }) + { IsBackground = true }.Start(); + } + /// <summary> + /// 淇濆瓨鍔熻兘鏁版嵁 + /// </summary> + //public void SaveFunctionData(bool upSevser) + //{ + // if (upSevser) + // { + // new System.Threading.Thread(() => + // { + // var pm = new HttpServerRequest(); + // var pack = pm.UpdataDevcieInfo(this); + // if (pack.Code == StateCode.SUCCESS) + // { + // var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); + // FileUtlis.Files.WriteFileByBytes(savePath, ssd); + // } + // else + // { + // IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); + // } + // }) + // { IsBackground = true }.Start(); + // } + // else + // { + // var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); + // FileUtlis.Files.WriteFileByBytes(savePath, ssd); + // } + //} /// <summary> @@ -286,19 +425,37 @@ var sFunc = new SceneFunction(); foreach (var attr in attributes) { - if (attr.curValue.ToString() == "{}") + switch (attr.key) { - attr.curValue = "0"; - } - if (attr.key == FunctionAttributeKey.SetTemp) - { - double vv = 16; - Double.TryParse(attr.curValue.ToString(),out vv); - sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = Convert.ToInt32(vv).ToString() }); - } - else - { - sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = attr.curValue.ToString() }); + case FunctionAttributeKey.OnOff: + case FunctionAttributeKey.Brightness: + case FunctionAttributeKey.Mode: + case FunctionAttributeKey.SetTemp: + case FunctionAttributeKey.FanSpeed: + case FunctionAttributeKey.Percent: + //case FunctionAttributeKey.FadeTime: + if (attr.curValue.ToString() == "{}") + { + if (attr.key == FunctionAttributeKey.OnOff) + { + attr.curValue = "off"; + } + else + { + attr.curValue = "0"; + } + } + if (attr.key == FunctionAttributeKey.SetTemp) + { + double vv = 16; + Double.TryParse(attr.curValue.ToString(), out vv); + sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = Convert.ToInt32(vv).ToString() }); + } + else + { + sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = attr.curValue.ToString() }); + } + break; } } sFunc.sid = this.sid; @@ -343,6 +500,7 @@ ApiAlinkControlActionObj aaao = new ApiAlinkControlActionObj(); aaao.deviceId = this.deviceId; aaao.spk = this.spk; + aaao.bus = this.bus; foreach (var kv in keyValues) { aaao.attributes.Add(new AlinkControlAttributes() @@ -503,6 +661,10 @@ /// 瀹ゅ唴娓╁害 /// </summary> public const string IndoorTemp = "room_temp"; + /// <summary> + /// value + /// </summary> + public const string Value = "value"; } /// <summary> /// 璁惧鍔熻兘oid -- Gitblit v1.8.0