From 3069c032027eeea7a14fa9f462440bb2d802d9a9 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期一, 11 一月 2021 14:25:09 +0800
Subject: [PATCH] 20210111-合并代码
---
HDL_ON/Entity/Function/Function.cs | 1054 +++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 820 insertions(+), 234 deletions(-)
diff --git a/HDL_ON/Entity/Function/Function.cs b/HDL_ON/Entity/Function/Function.cs
index 64225a0..7b241c6 100644
--- a/HDL_ON/Entity/Function/Function.cs
+++ b/HDL_ON/Entity/Function/Function.cs
@@ -1,270 +1,250 @@
锘縰sing System;
using System.Collections.Generic;
-using System.Linq;
-using Newtonsoft.Json.Linq;
-using HDL_ON;
+using HDL_ON.Common;
+using HDL_ON.DAL.Server;
+using HDL_ON.DriverLayer;
+using Shared;
namespace HDL_ON.Entity
{
/// <summary>
- /// 鍔熻兘灞炴��
- /// 灞炴�у瓧娈佃В鏋愶細attri :灞炴�у唴瀹癸紝value 灞炴�х殑鍊硷紝max 鏈�澶у�� min 鏈�灏忓��
+ /// 璇诲彇鏈嶅姟鍣ㄧ┖闂翠俊鎭繑鍥炲埌鏁版嵁鍖�
/// </summary>
- public class Trait
+ public class DevcieApiPack
{
- /// <summary>
- /// 灞炴�у唴瀹�
- /// </summary>
- public string attri;
- /// <summary>
- /// 灞炴�х殑鍊�
- /// </summary>
- public List<string> value;
- /// <summary>
- /// 鏈�澶у��
- /// </summary>
- public int max;
- /// <summary>
- /// 鏈�灏忓��
- /// </summary>
- public int min;
+ public List<Function> list = new List<Function>();
- /// <summary>
- ///
- /// </summary>
- public string data_type = "";
+ public string totalCount = "0";
- /// <summary>
- /// 褰撳墠鍊�
- /// app杞欢鑷畾涔夊睘鎬�
- /// 鐢ㄦ潵璁板綍褰撳墠鐘舵��
- /// </summary>
- public object curValues;
+ public string totalPage = "0";
+
+ public string pageNo = "0";
+
+ public string pageSize = "0";
+
}
+ /// <summary>
+ /// 鍔熻兘绫昏兘婊¤冻鏁版嵁浣跨敤瑕佹眰锛屽瓙绫诲彧鏄负浜嗘柟渚夸娇鐢ㄥ睘鎬�
+ /// </summary>
public class Function
{
- /*
- HDL缁熶竴鍗忚鏍煎紡锛�16bytes
- 鍘傚晢浠e彿锛�2bytes
- 閫氳鏂瑰紡锛氭湁绾�/鏃犵嚎/ZIGBEE绛�1bytes
- 浜у搧璇嗗埆鐮侊細浠ユ坊鍔犺澶囩殑骞存湀鏃ユ椂鍒嗙 + 闅忔満鏁� 8bytes Category
- 鍔熻兘绫诲埆锛�1bytes
- 鏁版嵁琛ㄧ储寮曞湴鍧�锛�2bytes
- 鍥炶矾锛�2bytes
- 涓句緥锛� 0001-00-2019101209001234-01-0001-0001
- 0001-01-14051D0A300C92C9-02-0202-0001-0001
- */
public Function()
{
- //dicPropert = new Dictionary<string, string>();
- //if (propertList == null || propertList.Count == 0)
- //{
- // foreach (var t in propertList)
- // {
- // dicPropert.TryAdd(t.attri,t.min.ToString());
- // }
- //}
}
+
#region base info
/// <summary>
- /// 鍔熻兘ID
- /// 鍘傚晢浠g爜 2bytes; 01 HDL
- /// 閫氳鏂瑰紡 1byte ; 01 HDL Bus; 02 Zigbee;03 KNX;04 Z-Wave
- /// 浜у搧GUID 8bytes
- /// 浜у搧绫诲埆 1byte ; 01 璋冨厜鍣�;02缁х數鍣�;03骞叉帴鐐规ā鍧�;04浼犳劅鍣�;05闈㈡澘
- /// 鐗╂ā鍨嬬被鍨�2bytes 01 寮�鍏崇被 --01寮�鍏�;02鎻掑骇
- /// 02 鐓ф槑 --01寮�鍏崇被;02璋冨厜绫�;03鑹叉俯;04LED
- /// 03 閬槼 --01绐楀笜鐢垫満;02鐧惧彾绐�;03寮�鍚堝笜;04鍗峰笜
- /// 04 鎭掓俯鍣� --01绌鸿皟;02鍦版殩;03姣涚粏绌鸿皟
- /// 05 鏂伴
- /// 06 褰遍煶
- /// 07 闊充箰
- /// 08 鑳芥簮
- /// 09 瀹夐槻
- /// 閫氶亾鍙� 2bytes
- /// Key_id 2bytes
+ /// HDL缁熶竴鍗忚鏍煎紡锛�14bytes
+ /// 涓句緥锛� 鏉ユ簮 鍘傚晢浠g爜 閫氳鏂瑰紡 浜у搧鏃堕棿鎴� 浜у搧绫诲埆 鐗╂ā鍨嬬被 閫氶亾鍙� 澶у皬绫诲埆
+ /// 1byte 1byte 1byte 4byte 1byte 2byte 2byte 2byte
+ /// 鏉ユ簮锛�00 榛樿鍘熺敓鎬佺郴缁熸暟鎹� 銆�01 缃戝叧鎴栬�呭叾浠朅璁惧銆�02 璋冭瘯杞欢銆�03 APP搴旂敤绋嬪簭銆�04 绗笁鏂圭綉鍏虫垨鑰呭钩鍙�
+ /// 鍘傚晢浠g爜锛�01 HDL
+ /// 閫氳鏂瑰紡锛�01 HDL Bus銆�02 Zigbee銆�03 KNX銆�04 Z-Wave
+ /// 浜у搧鏃堕棿鎴筹細4bytes 浠�2020骞�1鏈�1鏃ョ畻鍑虹殑鏃堕棿鎴�0.1s涓哄崟浣�
+ /// 浜у搧绫诲埆锛�01 璋冨厜鍣ㄣ��02 缁х數鍣ㄣ��03 骞叉帴鐐规ā鍧椼��04 浼犳劅鍣ㄣ��05 闈㈡澘
+ /// 鐗╂ā鍨嬬被鍨嬶細
+ /// 01 寮�鍏崇被锛�01 寮�鍏炽��02 鎻掑骇銆�03
+ /// 02 鐓ф槑锛� 01 寮�鍏炽��02 璋冨厜銆�03 鑹叉俯銆�04 LED
+ /// 03 閬槼锛� 01 绐楀笜鐢垫満銆�02 鐧惧彾绐椼��03 寮�鍚堝笜銆�04 鍗峰笜
+ /// 04 鎭掓俯鍣細01 绌鸿皟銆�02 鍦版殩銆�03 姣涚粏绌鸿皟
+ /// 05 鏂伴
+ /// 06 褰遍煶
+ /// 07 闊充箰
+ /// 08 鑳芥簮
+ /// 09 瀹夐槻
+ /// 澶х被鍒� 1bytes 锛堥鐣欙級
+ /// 灏忕被鍒� 1byte 锛堥鐣欙級
/// </summary>
- public string sid = "00010112345678901234560101230123AABB";
+ public string sid = "0301011234567801012301230123";
+ /// <summary>
+ /// 澶囨敞
+ /// </summary>
+ public string name;
+ /// <summary>
+ /// 璁惧ID
+ /// 浜戠璐熻矗鐢熸垚
+ /// </summary>
+ public string deviceId = "0";
+ /// <summary>
+ /// 璁惧spk
+ /// </summary>
+ public string spk = "";
+ ///// <summary>
+ ///// 鍔熻兘绫诲埆
+ ///// 濡傦細绌鸿皟绫汇�佺伅鍏夌被銆佺獥甯樼被
+ ///// </summary>
+ //public FunctionCategory Spk_Prefix
+ //{
+ // get
+ // {
+ // try
+ // {
+ // var _functionCategoryString = sid.Substring(16, 2);
+ // var _functionCategory = Convert.ToInt32(_functionCategoryString, 16);
+ // return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), _functionCategory);
+ // }
+ // catch (Exception ex)
+ // {
+ // MainPage.Log($"get FunctionCategory error : {ex.Message}");
+ // return FunctionCategory.UnKown;
+ // }
+ // }
+ //}
+
+ ///// <summary>
+ ///// 鍔熻兘绫诲瀷
+ ///// </summary>
+ //public FunctionType spk
+ //{
+ // get
+ // {
+ // var _functionTypeString = sid.Substring(16, 4);
+ // return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16));
+ // }
+ //}
+
+ string spk_Prefix;
+ /// <summary>
+ /// spk鍓嶇紑
+ /// 澶х被
+ /// 鍔熻兘绫诲埆
+ /// 濡傦細绌鸿皟绫汇�佺伅鍏夌被銆佺獥甯樼被
+ /// </summary>
+ public string Spk_Prefix
+ {
+ get
+ {
+ if (string.IsNullOrEmpty(spk_Prefix))
+ {
+ spk_Prefix = spk.Split(".")[0];
+ }
+ return spk_Prefix;
+ }
+ }
+ string spk_Suffix;
+ ///// <summary>
+ ///// spk鍚庣紑
+ ///// 灏忕被
+ ///// 鍔熻兘绫诲瀷
+ ///// </summary>
+ //public string spk
+ //{
+ // get
+ // {
+ // if (string.IsNullOrEmpty(spk_Suffix))
+ // {
+ // try
+ // {
+ // spk_Suffix = spk.Split(".")[1];
+ // }
+ // catch
+ // {
+ // spk_Suffix = "";
+ // }
+ // }
+ // return spk_Suffix;
+ // }
+ //}
/// <summary>
/// A鍗忚鍔熻兘鐨勭壒鎬�
/// 濡傦細鏄疉C鍔熻兘锛氱壒鎬э細on_off,mode,fan,temperature
/// attri
/// </summary>
- public List<Trait> function = new List<Trait>();
+ public List<FunctionAttributes> attributes = new List<FunctionAttributes>();
/// <summary>
/// 鎴块棿ID鍒楄〃
/// 璇ュ姛鑳芥坊鍔犲埌鍒版埧闂村垪琛�
/// </summary>
- public List<string> roomIdList = new List<string>();
+ public List<string> roomIds = new List<string>();
/// <summary>
/// bus鍗忚鏁版嵁鏍煎紡
/// 浣跨敤A鍗忚鎺у埗鏃讹紝鏀瑰睘鎬т负绌�
/// </summary>
- public BusData bus_Data;
- #endregion
-
-
- ///// <summary>
- ///// 鍔熻兘闄勫甫鐨勫睘鎬т笌鍊肩殑鍒楄〃
- ///// </summary>
- //public Dictionary<string, string> dicPropert;
-
- /// <summary>
- /// 鍔熻兘绫诲埆
- /// 濡傦細绌鸿皟绫汇�佺伅鍏夌被銆佺獥甯樼被
- /// </summary>
- public FunctionCategory functionCategory
- {
- get
- {
- try
- {
- var _functionCategoryString = sid.Substring(24, 2);
- var _functionCategory = Convert.ToInt32(_functionCategoryString, 16);
- return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), _functionCategory);
- }
- catch (Exception ex)
- {
- MainPage.Log($"get FunctionCategory error : {ex.Message}");
- return FunctionCategory.UnKown;
- }
- }
- }
-
- public FunctionType functionType
- {
- get
- {
- var _functionTypeString = sid.Substring(24, 4);
- return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16));
- }
- }
-
- /// <summary>
- /// 澶囨敞
- /// </summary>
- public string name;
- /// <summary>
- /// A鍗忚鍘傚晢浠g爜
- /// </summary>
- public string vendor_code
- {
- get
- {
- string vendorCode = "HDL";
- var code = sid.Substring(0, 4);
- if (code == "0001")
- vendorCode = "HDL";
- return vendorCode;
- }
- }
-
- /// <summary>
- /// 鏈�鍚庢帶鍒剁殑涓�娆$姸鎬�
- /// </summary>
- public string lastState = "";
-
- [Newtonsoft.Json.JsonIgnore]
- public Trait trait_on_off;
- /// <summary>
- /// 寮�鍏崇姸鎬�
- /// 0:鍏�
- /// 1:寮�
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public string on_off
- {
- get
- {
- try
- {
- if (trait_on_off == null)
- {
- trait_on_off = function.Find((obj) => obj.attri == "on_off");
- //鎵句笉鍒板睘鎬ч渶瑕佸0鏄庝竴涓紝闃叉鎶ラ敊闂��
- if (trait_on_off == null)
- {
- trait_on_off = new Trait()
- {
- attri = "on_off",
- value = new List<string> { "on", "off" },
- max = 1,
- min = 0,
- };
- }
- trait_on_off.curValues = trait_on_off.value[trait_on_off.min];
- }
- return trait_on_off.curValues.ToString();
- }
- catch
- {
- MainPage.Log("on_off 鏁版嵁鑾峰彇澶辫触.");
- function.Add( new Trait()
- {
- attri = "on_off",
- value = new List<string> { "on", "off" },
- max = 1,
- min = 0,
- });
- return "off";
- }
- }
- set
- {
- try
- {
- if (trait_on_off == null)
- {
- trait_on_off = function.Find((obj) => obj.attri == "on_off");
- //鎵句笉鍒板睘鎬ч渶瑕佸0鏄庝竴涓紝闃叉鎶ラ敊闂��
- if (trait_on_off == null)
- {
- trait_on_off = new Trait()
- {
- attri = "on_off",
- value = new List<string> { "on", "off" },
- max = 1,
- min = 0,
- };
- }
- trait_on_off.curValues = trait_on_off.min;
- }
- trait_on_off.curValues = value;
- }
- catch (Exception ex)
- {
- MainPage.Log($"on_off 鏁版嵁鍒锋柊澶辫触: {ex.Message}");
- function.Add(new Trait()
- {
- attri = "on_off",
- value = new List<string> { "on", "off" },
- max = 1,
- min = 0,
- });
- }
- }
- }
-
+ public BusData bus;
/// <summary>
/// 鏄惁鏀惰棌
/// </summary>
- public bool collection = false;
+ public bool collect = false;
+ /// <summary>
+ /// 鏄惁鍦ㄧ嚎
+ /// </summary>
+ public bool online = true;
+ /// <summary>
+ /// 浜戠鏁版嵁鍒涘缓鐨勬椂闂�
+ /// </summary>
+ public string createTime = "";
+ /// <summary>
+ /// 浜戠鏁版嵁淇敼鐨勬渶鍚庢椂闂�
+ /// </summary>
+ public string modifyTime = "";
+ /// <summary>
+ /// 鍒犻櫎鏍囪
+ /// 闇�瑕佸垹闄ゆ暟鎹椂锛屾爣璁颁负锛歵rue
+ /// 鐢变簯绔垹闄ゆ垚鍔熶箣鍚庯紝杩斿洖鏁版嵁鍐嶆竻闄ゆ湰鍦版暟鎹�
+ /// </summary>
+ public bool DeleteSign = false;
+
+ #endregion
+ /// <summary>
+ /// 寤舵椂
+ /// </summary>
+ public int delay = 0;
+ /// <summary>
+ /// 鏈�鍚庢帶鍒剁殑涓�娆$姸鎬�
+ /// </summary>
+ [Newtonsoft.Json.JsonIgnore]
+ public string lastState = "";
+
+ FunctionAttributes _trait_on_off;
+ [Newtonsoft.Json.JsonIgnore]
+ public FunctionAttributes trait_on_off
+ {
+ get
+ {
+ if (_trait_on_off == null)
+ {
+ _trait_on_off = attributes.Find((obj) => obj.key == FunctionAttributeKey.OnOff);
+ //鎵句笉鍒板睘鎬ч渶瑕佸0鏄庝竴涓紝闃叉鎶ラ敊闂��
+ if (_trait_on_off == null)
+ {
+ _trait_on_off = new FunctionAttributes()
+ {
+ key = "on_off",
+ value = new List<string> { "on", "off" },
+ max = 1,
+ min = 0,
+ };
+ _trait_on_off.curValue = "off";
+ }
+ }
+ if(_trait_on_off.curValue.ToString() != "on"&& _trait_on_off.curValue.ToString() != "off")
+ {
+ _trait_on_off.curValue = "off";
+ }
+ return _trait_on_off;
+ }
+ //set
+ //{
+ // _trait_on_off = value;
+ //}
+ }
/// <summary>
/// 浣跨敤娆℃暟
/// </summary>
- public double usageCount = 0;
+ public double controlCounter = 0;
/// <summary>
/// 浣跨敤棰戠巼
/// </summary>
- public double usageFrequency {
+ public double usageFrequency
+ {
get
{
- return usageCount / 7;
+ return controlCounter / 7;
}
}
/// <summary>
@@ -273,24 +253,71 @@
public int fixedSerialNumber = int.MaxValue;
/// <summary>
- /// 鑾峰彇A鍗忚鎺у埗瀛楃涓�
+ /// 鏀惰棌鍔熻兘
/// </summary>
- /// <param name="command">鎺у埗鍛戒护锛歸rite锛宺ead</param>
- /// <returns></returns>
- public virtual JObject GetSendJObject(CommandType_A command)
+ public void CollectFunction()
{
- var sendJob = new JObject { { "vendor_code", vendor_code }, { "Command", command.ToString() }, { "Type", "device" }, };
- var data = new JObject { { "sid", sid } };
- sendJob.Add("objects", data);
- return sendJob;
+ 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 ()
+ public string GetBusId()
{
string busId = "";
- if (bus_Data != null)
+ if (bus != null)
{
- busId = bus_Data.SubnetID + "_" + bus_Data.DeviceID + "_" + bus_Data.LoopID;
+ busId = bus.SubnetID + "_" + bus.DeviceID + "_" + bus.LoopId;
}
return busId;
}
@@ -302,23 +329,582 @@
public string GetRoomListName()
{
string roomNameList = "";
- foreach(var roomId in roomIdList)
+ foreach (var roomId in roomIds)
{
- var findRoom = DB_ResidenceData.residenceData.rooms.Find(obj => obj.sid == roomId);
+ var findRoom = SpatialInfo.CurrentSpatial.RoomList.Find(obj => obj.roomId == roomId);
if (findRoom == null)
+ {
continue;
- if(roomNameList != "")
+ }
+ if (roomNameList != "")
{
roomNameList += ",";
}
- roomNameList += findRoom.floor + "路" + findRoom.name;
+ roomNameList += findRoom.floorName +"-"+ findRoom.roomName;
+ }
+ if (roomNameList == "" )
+ {
+ roomNameList = Language.StringByID(StringId.WholeZone);
}
return roomNameList;
+ }
+ /// <summary>
+ /// 鏁版嵁瀛樺偍鏂囦欢鍚�
+ /// </summary>
+ [Newtonsoft.Json.JsonIgnore]
+ public string savePath
+ {
+ get
+ {
+ return "FunctionData_" + sid;
+ }
+ }
+
+ /// <summary>
+ /// 淇濆瓨鍔熻兘鏂囦欢
+ /// </summary>
+ public void SaveFunctionFile()
+ {
+ 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 pack = ApiUtlis.Ins.HttpRequest.UpdataDevcieBindRoomInfo(this);
+ //鐩存帴淇濆瓨鏈湴锛�
+ SaveFunctionFile();
+ if (pack.Code == StateCode.SUCCESS)
+ {
+ }
+ else
+ {
+ IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
+ }
+ })
+ { 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>
+ /// 杞崲鎴愬満鏅姛鑳藉璞�
+ /// </summary>
+ /// <returns></returns>
+ public SceneFunction ConvertSceneFunction()
+ {
+ var sFunc = new SceneFunction();
+ foreach (var attr in attributes)
+ {
+ switch (attr.key)
+ {
+ 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;
+ return sFunc;
}
/// <summary>
/// 鏇存柊鏃堕棿
/// </summary>
public DateTime refreshTime = DateTime.MinValue;
+
+ /// <summary>
+ /// 鑾峰彇鏈湴鎺у埗鏁版嵁
+ /// </summary>
+ public AlinkFunctionStatusObj GetGatewayAlinkControlData(Dictionary<string, string> commandDictionary)
+ {
+ var sendDataObj = new AlinkFunctionStatusObj();
+ sendDataObj.id = Control.Ins.msg_id.ToString();
+ sendDataObj.time_stamp = Control.Ins.Get_TimeStamp();
+
+
+ var acd = new AlinkControlData();
+ acd.sid = sid;
+ foreach (var dic in commandDictionary)
+ {
+ var aca = new AlinkControlAttributes();
+ aca.key = dic.Key;
+ aca.value = dic.Value;
+ acd.status.Add(aca);
+ }
+
+ sendDataObj.objects.Add(acd);
+
+ return sendDataObj;
+ }
+ /// <summary>
+ /// 鑾峰彇Api鎺у埗鏁版嵁
+ /// </summary>
+ /// <returns></returns>
+ public ApiAlinkControlActionObj GetApiControlData(Dictionary<string, string> keyValues)
+ {
+ 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()
+ {
+ key = kv.Key,
+ value = kv.Value,
+ });
+ }
+ return aaao;
+ }
}
+
+ /// <summary>
+ /// 杩滅▼鎺у埗
+ /// api a鍗忚鎺у埗鍔ㄤ綔瀵硅薄
+ /// </summary>
+ public class ApiAlinkControlActionObj
+ {
+ /// <summary>
+ /// 璁惧ID
+ /// </summary>
+ public string deviceId = "0";
+ /// <summary>
+ /// spk
+ /// 鍒�:light.switch
+ /// </summary>
+ public string spk = "";
+
+ public List<AlinkControlAttributes> attributes = new List<AlinkControlAttributes>();
+ //[Newtonsoft.Json.JsonIgnore]
+ public BusData bus = new BusData();
+ }
+
+ /// <summary>
+ /// A鍗忚鎺у埗鏁版嵁鐨勫璞�
+ /// </summary>
+ public class AlinkFunctionStatusObj
+ {
+ public List<AlinkControlData> objects = new List<AlinkControlData>();
+
+ public string time_stamp = "";
+ public string id = "";
+ }
+ /// <summary>
+ /// 鏈湴鐘舵�佽鍙�
+ /// A鍗忚鐘舵�佽鍙栨牸寮忓璞�
+ /// </summary>
+ public class AlinkReadFunctionStatusObj
+ {
+ public string id = "0";
+ public List<Dictionary<string, string>> objects = new List<Dictionary<string, string>>();
+ public string time_stamp = "";
+ }
+ /// <summary>
+ /// A鍗忚鎺у埗鏁版嵁
+ /// </summary>
+ public class AlinkControlData
+ {
+ public string sid = "";
+ public List<AlinkControlAttributes> status = new List<AlinkControlAttributes>();
+ }
+ /// <summary>
+ /// a鍗忚鎺у埗鍔ㄤ綔鏁版嵁
+ /// </summary>
+ public class AlinkControlAttributes
+ {
+ /// <summary>
+ /// 灞炴�у悕
+ /// 鍒�:on_off
+ /// </summary>
+ public string key = "";
+ /// <summary>
+ /// 灞炴�у��
+ /// 鍒�:on
+ /// </summary>
+ public string value = "";
+ }
+
+ /// <summary>
+ /// 鍔熻兘灞炴��
+ /// 灞炴�у瓧娈佃В鏋愶細attri :灞炴�у唴瀹癸紝value 灞炴�х殑鍊硷紝max 鏈�澶у�� min 鏈�灏忓��
+ /// </summary>
+ [System.Serializable]
+ public class FunctionAttributes
+ {
+ /// <summary>
+ /// 灞炴�ч敭鍚�
+ /// </summary>
+ public string key;
+ /// <summary>
+ /// 灞炴�х殑鍊煎垪琛�
+ /// </summary>
+ public List<string> value = new List<string>();
+ /// <summary>
+ /// 鏈�澶у��
+ /// </summary>
+ public int max = 100;
+ /// <summary>
+ /// 鏈�灏忓��
+ /// </summary>
+ public int min = 0;
+ /// <summary>
+ /// 鏁版嵁绫诲瀷
+ /// </summary>
+ public string data_type = "";
+ /// <summary>
+ /// 褰撳墠鍊�
+ /// </summary>
+ public object curValue = new object();
+
+ }
+ /// <summary>
+ /// 鍔熻兘灞炴�ч敭鍚嶅垪琛�
+ /// </summary>
+ public static class FunctionAttributeKey
+ {
+ /// <summary>
+ /// 寮�鍏�
+ /// </summary>
+ public const string OnOff = "on_off";
+ /// <summary>
+ /// 浜害
+ /// </summary>
+ public const string Brightness = "brightness";
+ /// <summary>
+ /// 棰滆壊
+ /// </summary>
+ public const string RGB = "rgb";
+ /// <summary>
+ /// 娓愬彉鏃堕棿
+ /// </summary>
+ public const string FadeTime = "fade_time";
+ /// <summary>
+ /// 妯″紡
+ /// </summary>
+ public const string Mode = "mode";
+ /// <summary>
+ /// 椋庨��
+ /// </summary>
+ public const string FanSpeed = "fan";
+ /// <summary>
+ /// 璁剧疆娓╁害
+ /// </summary>
+ public const string SetTemp = "set_temp";
+ /// <summary>
+ /// 寤舵椂
+ /// </summary>
+ public const string Delay = "delay";
+ /// <summary>
+ /// 鑹叉俯
+ /// </summary>
+ public const string CCT = "cct";
+ /// <summary>
+ /// 鐧惧垎姣�
+ /// </summary>
+ public const string Percent = "percent";
+ /// <summary>
+ /// 瀹ゅ唴娓╁害
+ /// </summary>
+ public const string IndoorTemp = "room_temp";
+ /// <summary>
+ /// value
+ /// </summary>
+ public const string Value = "value";
+ }
+ /// <summary>
+ /// 璁惧鍔熻兘oid
+ /// </summary>
+ public class FunctionOid
+ {
+ public string oid;
+ public string name;
+ public string machine_id;
+ public string net_id;
+ public string dev_id;
+ public string channels;
+ }
+
+ /// <summary>
+ /// 鍏煎鏃у崗璁帶鍒�
+ /// </summary>
+ public class BusData
+ {
+ public string addresses = "FFFF";
+ [Newtonsoft.Json.JsonIgnore]
+ public byte SubnetID
+ {
+ get
+ {
+ return Convert.ToByte(addresses.Substring(0, 2), 16);
+ }
+ }
+ [Newtonsoft.Json.JsonIgnore]
+ public byte DeviceID
+ {
+ get
+ {
+ return Convert.ToByte(addresses.Substring(2, 2), 16);
+ }
+ }
+ public byte LoopId
+ {
+ get
+ {
+ return Convert.ToByte(loopId, 16);
+ }
+ }
+
+ public string loopId;
+ }
+
+ public static class SPK
+ {
+ /// <summary>
+ /// 锛堝紑鍏崇伅锛�
+ /// </summary>
+ public const string LightSwitch = "light.switch";
+ /// <summary>
+ /// 锛堣皟鍏夌伅锛�
+ /// </summary>
+ public const string LightDimming = "light.dimming";
+ /// <summary>
+ /// 锛圧GB鐏級
+ /// </summary>
+ public const string LightRGB = "light.rgb";
+ /// <summary>
+ /// 锛圧GBW鐏級
+ /// </summary>
+ public const string LightRGBW = "light.rgbw";
+ /// <summary>
+ /// 锛圕CT鐏級
+ /// </summary>
+ public const string LightCCT = "light.cct";
+ /// <summary>
+ /// 锛堝紑鍏崇獥甯橈級
+ /// </summary>
+ public const string CurtainSwitch = "curtain.switch";
+ /// <summary>
+ /// 锛堝紑鍚堝笜锛�
+ /// </summary>
+ public const string CurtainTrietex = "curtain.trietex";
+ /// <summary>
+ /// 锛堢櫨鍙跺笜锛�
+ /// </summary>
+ public const string CurtainShades = "curtain.shades";
+ /// <summary>
+ /// 锛堝嵎甯橈級
+ /// </summary>
+ public const string CurtainRoller = "curtain.roller";
+ /// <summary>
+ /// 锛堢┖璋冿級
+ /// </summary>
+ public const string AcStandard = "ac.standard";
+ /// <summary>
+ /// 锛堝湴鐑級
+ /// </summary>
+ public const string FloorHeatStandard = "floorHeat.standard";
+ /// <summary>
+ /// 锛堟柊椋庯級
+ /// </summary>
+ public const string AirFreshStandard = "airFresh.standard";
+ /// <summary>
+ /// 锛堥煶涔愶級
+ /// </summary>
+ public const string MusicStandard = "music.standard";
+ /// <summary>
+ /// 锛堜寒搴︿紶鎰熷櫒锛�
+ /// </summary>
+ public const string SensorLight = "sensor.light";
+ /// <summary>
+ /// 锛堟俯搴︿紶鎰熷櫒锛�
+ /// </summary>
+ public const string SensorTemperature = "sensor.temperature";
+ /// <summary>
+ /// (绾㈠绉诲姩浼犳劅鍣�)
+ /// </summary>
+ public const string SensorPir = "sensor.pir";
+ /// <summary>
+ /// 锛堥棬绐椾紶鎰熷櫒锛�
+ /// </summary>
+ public const string SensorDoorWindow = "sensor.doorwindow";
+ /// <summary>
+ /// 锛圥M2.5浼犳劅鍣級
+ /// </summary>
+ public const string SensorPm25 = "sensor.pm25";
+ /// <summary>
+ /// co2浼犳劅鍣�
+ /// </summary>
+ public const string SensorCO2 = "sensor.co2";
+ /// <summary>
+ /// tvoc浼犳劅鍣�
+ /// </summary>
+ public const string SensorTVOC = "sensor.tvoc";
+ /// <summary>
+ /// 婀垮害浼犳劅鍣�
+ /// </summary>
+ public const string SensorHumidity = "sensor.humidity";
+ /// <summary>
+ /// 锛堝共鎺ョ偣锛�
+ /// </summary>
+ public const string DryContact = "dryContact.standard";
+ /// <summary>
+ /// 瀹剁數銆佹彃搴�
+ /// </summary>
+ public const string ElectricSocket = "electrical.socket";
+ /// <summary>
+ /// 瀹剁數銆佺數瑙�
+ /// </summary>
+ public const string ElectricTV = "electrical.tv";
+ /// <summary>
+ /// 瀹剁數銆侀鎵�
+ /// </summary>
+ public const string ElectricFan = "electrical.fan";
+
+ }
+
+
+ /// <summary>
+ /// 鍔熻兘绫诲埆
+ /// </summary>
+ public static class FunctionCategory
+ {
+ /// <summary>
+ ///锛堢伅锛�
+ /// </summary>
+ public const string Light = "light";
+ /// <summary>
+ /// 锛堢獥甯橈級
+ /// </summary>
+ public const string Curtain = "curtain";
+ /// <summary>
+ /// 锛堢┖璋冿級
+ /// </summary>
+ public const string AC = "ac";
+ /// <summary>
+ /// 锛堝湴鐑級
+ /// </summary>
+ public const string FloorHeat = "floorHeat";
+ /// <summary>
+ /// 锛堟柊椋庯級
+ /// </summary>
+ public const string AirFresh = "airFresh";
+ /// <summary>
+ /// 锛堥煶涔愶級
+ /// </summary>
+ public const string Music = "music";
+ /// <summary>
+ /// 锛堜紶鎰熷櫒锛�
+ /// </summary>
+ public const string Sensor = "sensor";
+ /// <summary>
+ /// 锛堝共鎺ョ偣锛�
+ /// </summary>
+ public const string DryContact = "dryContact";
+ /// <summary>
+ /// 瀹剁數
+ /// </summary>
+ public const string Electric = "electrical";
+
+ //Music = 0x09,
+ }
+
+
}
--
Gitblit v1.8.0