using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json.Linq; namespace HDL_ON.Entity { public class Function : A_Protocol_FunctionInfo { /// /// 功能附带的属性与值的列表 /// public Dictionary dicPropert = new Dictionary(); /// /// 是否收藏 /// public bool collection = false; /// /// 房间ID列表 /// 该功能添加到到房间列表 /// public List roomIdList = new List(); /// /// 最后控制的一次状态 /// public string lastState = ""; /// /// 功能类型: /// 如:灯下面的继电器/调光器/RGB属于同一种功能不同类型的灯 /// public string functionType { get { return GetFunctionType(); } } /// /// bus协议数据格式 /// public BusData bus_Data; /// /// 使用次数 /// public double usageCount = 0; /// /// 使用频率 /// public double usageFrequency = 0; /// /// 固定的序号 /// public int fixedSerialNumber = int.MaxValue; /// /// A协议数据 /// public List PropertyArray { get { var proArr = trait.Split(',').ToList(); foreach(var pro in proArr) { if (!dicPropert.ContainsKey(pro)) { dicPropert.TryAdd(pro, 0); } } return proArr; } } /// /// 获取A协议控制字符串 /// /// 控制命令:write,read /// public virtual JObject GetSendJObject(string command) { var sendJob = new JObject { { "Namespace", a_Protocol_Namespace }, { "Command", command }, { "Type", "device" }, }; var data = new JObject { { "sid", sid } }; sendJob.Add("objects", data); return sendJob; } /// /// 返回功能类型 /// protected virtual string GetFunctionType() { return functionCategory.ToString(); } public string GetBusId () { string busId = ""; if(bus_Data!=null) { busId = bus_Data.SubnetID + "_" + bus_Data.DeviceID + "_" + bus_Data.LoopID; } return busId; } /// /// 获取设备添加到房间的房间名称 /// /// public string GetRoomListName() { string roomNameList = ""; foreach(var roomId in roomIdList) { var findRoom = DB_ResidenceData.residenceData.rooms.Find(obj => obj.sid == roomId); if(roomNameList != "") { roomNameList += ","; } roomNameList += findRoom.floor + "·" + findRoom.name; } return roomNameList; } } }