using System; using System.Collections; using System.Collections.Generic; using Newtonsoft.Json.Linq; namespace HDL_ON.Entity { public class AC : Function { /* * 空调:trait: [switch, mode, fan, temperature, swing, lock] * 属性 描述 * on_off on/off * mode mode: auto, cool, heat, dry, fan * fan high, medium, low, auto * temperature up,down,value * swing up/down/left/right * lock boolean (Lock锁定控制) */ public AC() { } /// /// 当前温度模式 /// 0:摄氏度 /// 1:华氏度 /// [Newtonsoft.Json.JsonIgnore] public int curTempType = 0; /// /// 当前温度模式字符 /// public string curTempTypeString { get { if (curTempType == 0) { return "°C"; } else { return "°F"; } } } /// /// 当前模式索引 /// bus控制命令使用 /// [Newtonsoft.Json.JsonIgnore] public byte curModeIndex { get { try { byte index = 0; switch (trait_mode.curValues.ToString()) { case "auto": index = 3; break; case "cool": index = 0; break; case "heat": index = 1; break; case "dry": index = 4; break; case "fan": index = 2; break; default: index = 0; break; } return index; } catch (Exception ex) { MainPage.Log($"get curModeIndex error : {ex.Message}"); return 0; } } set { switch (value) { case 0: trait_mode.curValues = "cool"; break; case 1: trait_mode.curValues = "heat"; break; case 2: trait_mode.curValues = "fan"; break; case 3: trait_mode.curValues = "auto"; break; case 4: trait_mode.curValues = "dry"; break; default: trait_mode.curValues = "cool"; break; } } } /// /// 当前风速索引 /// bus控制命令使用 /// [Newtonsoft.Json.JsonIgnore] public byte curFanIndex { get { try { byte index = 0; switch (trait_fan.curValues.ToString()) { case "high": index = 1; break; case "medium": index = 2; break; case "low": index = 3; break; case "auto": index = 0; break; default: index = 0; break; } return index; } catch (Exception ex) { MainPage.Log($"get curFanIndex error : {ex.Message}"); return 0; } } set { switch (value) { case 0: trait_fan.curValues = "auto"; break; case 1: trait_fan.curValues = "high"; break; case 2: trait_fan.curValues = "medium"; break; case 3: trait_fan.curValues = "low"; break; default: trait_fan.curValues = "high"; break; } } } Trait _trait_mode; /// /// 模式属性 /// [Newtonsoft.Json.JsonIgnore] public Trait trait_mode { get { if (_trait_mode == null) { _trait_mode = function.Find((obj) => obj.attri == "mode"); //找不到属性需要声明一个,防止报错闪退 if (_trait_mode == null) { _trait_mode = new Trait() { attri = "mode", value = new List { "auto", "cool", "heat", "dry", "fan" }, max = 4, min = 0, }; } _trait_mode.curValues = _trait_mode.value.Count > 0 ? _trait_mode.value[0] : ""; } return _trait_mode; } } /// /// 空调模式 /// [Newtonsoft.Json.JsonIgnore] public List modeList { get { try { return trait_mode.value; } catch (Exception ex) { MainPage.Log($"ac get mode error : {ex.Message}"); return new List { "auto", "cool", "heat", "dry", "fan" }; } } } Trait _trait_fan; [Newtonsoft.Json.JsonIgnore] public Trait trait_fan { get { if (_trait_fan == null) { _trait_fan = function.Find((obj) => obj.attri == "fan"); //找不到属性需要声明一个,防止报错闪退 if (_trait_fan == null) { _trait_fan = new Trait() { attri = "fan", value = new List { "high", "medium", "low", "auto" }, max = 3, min = 0, }; } _trait_fan.curValues = _trait_fan.value.Count > 0 ? _trait_fan.value[0] : ""; } return _trait_fan; } } /// /// 空调风速模式 /// [Newtonsoft.Json.JsonIgnore] public List fan_List { get { try { return trait_fan.value; } catch (Exception ex) { MainPage.Log($"ac get fan error : {ex.Message}"); return new List { "high", "medium", "low", "auto" }; } } } /// /// 当前空调温度 /// [Newtonsoft.Json.JsonIgnore] public int curTemp = 20; // temperature up, down, value // swing up/down/left/right Trait _trait_swting; [Newtonsoft.Json.JsonIgnore] public Trait trait_swting { get { if (_trait_swting == null) { _trait_swting = function.Find((obj) => obj.attri == "swting"); //找不到属性需要声明一个,防止报错闪退 if (_trait_swting == null) { _trait_swting = new Trait() { attri = "swting", value = new List { "up", "down", "left", "right" }, max = 3, min = 0, }; } _trait_swting.curValues = _trait_swting.value.Count > 0 ? _trait_swting.value[trait_mode.min] : ""; } return _trait_swting; } } /// /// 空调扫风模式列表 /// [Newtonsoft.Json.JsonIgnore] public List swting { get { try { return trait_swting.value; } catch (Exception ex) { MainPage.Log($"ac get swting error : {ex.Message}"); return new List { "up", "down", "left", "right" }; } } } /// /// 室内温度 /// [Newtonsoft.Json.JsonIgnore] public int indoorTemp = 20; /// /// 当前模式的icon路径 /// [Newtonsoft.Json.JsonIgnore] public string curModeImage { get { try { var imagePath = "FunctionIcon/AC/CoolIcon.png"; switch (trait_mode.curValues.ToString()) { case "auto": imagePath = "FunctionIcon/AC/AutoIcon.png"; break; case "cool": imagePath = "FunctionIcon/AC/CoolIcon.png"; break; case "heat": imagePath = "FunctionIcon/AC/HeatingIcon.png"; break; case "dry": imagePath = "FunctionIcon/AC/DehumidificationIcon.png"; break; case "fan": imagePath = "FunctionIcon/AC/AirSupplyIcon.png"; break; default: imagePath = "FunctionIcon/AC/CoolIcon.png"; break; } return imagePath; } catch (Exception ex) { MainPage.Log($"ac ge curModeImage error : {ex.Message}"); return "FunctionIcon/AC/CoolIcon.png"; } } } /// /// 当前风速的icon路径 /// [Newtonsoft.Json.JsonIgnore] public string curFanImage { get { try { var imagePath = "FunctionIcon/AC/WindHighIcon.png"; switch (trait_fan.curValues.ToString()) { case "high": imagePath = "FunctionIcon/AC/WindHighIcon.png"; break; case "medium": imagePath = "FunctionIcon/AC/WindMediumIcon.png"; break; case "low": imagePath = "FunctionIcon/AC/WindLowIcon.png"; break; case "auto": imagePath = "FunctionIcon/AC/AutoIcon.png"; break; default: imagePath = "FunctionIcon/AC/WindHighIcon.png"; break; } return imagePath; }catch (Exception ex) { MainPage.Log($"ac get curFanImage error : {ex.Message}"); return "FunctionIcon/AC/WindHighIcon.png"; } } } /// /// 拼接、获取A协议操作数据 /// public override JObject GetSendJObject(CommandType_A command) { var sendJob = new JObject(); if (command == CommandType_A.write) { sendJob = new JObject { { "Namespace", vendor_code }, { "Command", command.ToString() }, { "Type", "device" } }; JObject data = new JObject { { "sid", sid } }; sendJob.Add("objects", data); List controlData = new List(); controlData.Add(new ControlData() { name = "on_off", data_type = "Bool", value = on_off }); } else if (command == CommandType_A.read) { sendJob = new JObject { { "Namespace", vendor_code }, { "Command", command.ToString() }, { "Type", "device" } }; var data = new JObject { { "sid", sid } }; sendJob.Add("objects", data); } return sendJob; } } }