From 66a9965c44ecc32a6696abca876ab9d1cd091584 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期五, 28 二月 2020 15:25:13 +0800
Subject: [PATCH] 2020.2.28

---
 ZigbeeApp/Shared/Common/DeviceUI.cs |  459 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 321 insertions(+), 138 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/DeviceUI.cs b/ZigbeeApp/Shared/Common/DeviceUI.cs
index cb57e47..88c0ada 100644
--- a/ZigbeeApp/Shared/Common/DeviceUI.cs
+++ b/ZigbeeApp/Shared/Common/DeviceUI.cs
@@ -15,27 +15,13 @@
         #region 鈼� 鍙橀噺____________________________
 
         /// <summary>
-        /// 鏄惁鏄嚜瀹氫箟鍥剧墖
+        /// 璁惧MAC鍦板潃
         /// </summary>
-        public bool IsCustomizeImage = false;
-
-        //DeviceUI_DeviceFilePath
-        public override bool Equals(object obj)
-        {
-            var other= obj as DeviceUI;
-            if (CommonDevice.DeviceAddr==other.CommonDevice.DeviceAddr && CommonDevice.DeviceEpoint==other.CommonDevice.DeviceEpoint)
-            {
-                return true;
-            }
-            return false;
-            //CommonDevice.DeviceEpoint.Equals(other.CommonDevice.DeviceEpoint) && CommonDevice.DeviceAddr.Equals(other.CommonDevice.DeviceAddr);
-
-        }
-
-        public override int GetHashCode()
-        {
-            return base.GetHashCode();
-        }
+        public string DeviceAddr = string.Empty;
+        /// <summary>
+        /// 璁惧绔偣
+        /// </summary>
+        public int DeviceEpoint = 0;
 
         /// <summary>
         /// 璁惧鏂囦欢
@@ -45,20 +31,58 @@
         public string FileName
         {
             get
-            {
-                return $"DeviceUI_{DeviceFileName}";
+            {
+                var myDevice = Common.LocalDevice.Current.GetDevice(DeviceAddr, DeviceEpoint);
+                if (myDevice != null)
+                {
+                    return myDevice.FilePath;
+                }
+                return $"Device_Unkwon";
             }
         }
-        /// <summary>
-        /// 璁惧鏂囦欢鍚嶏紙骞堕潪deviceUI璁惧鏂囦欢鍚嶏紝鎸囩殑鏄痙evice锛�
-        /// </summary>
-        public string DeviceFileName = string.Empty;
 
-        /// <summary>
-        /// 鍥剧墖
-        /// </summary>
-        public string IconPath = string.Empty;
 
+        [Newtonsoft.Json.JsonIgnore]
+        public ZigBee.Device.CommonDevice CommonDevice
+        {
+            get
+            {
+                return Common.LocalDevice.Current.GetDevice(DeviceAddr, DeviceEpoint);
+            }
+        }
+
+        /// <summary>
+        /// 鏄惁鏄嚜瀹氫箟鍥剧墖
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public bool IsCustomizeImage
+        {
+            get
+            {
+                var myDevice = Common.LocalDevice.Current.GetDevice(DeviceAddr, DeviceEpoint);
+                if (myDevice != null)
+                {
+                    return myDevice.IsCustomizeImage;
+                }
+                return false;
+            }
+        }
+        /// <summary>
+        /// 璁惧鍥剧墖
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public string IconPath
+        {
+            get
+            {
+                var myDevice = Common.LocalDevice.Current.GetDevice(DeviceAddr, DeviceEpoint);
+                if (myDevice != null)
+                {
+                    return myDevice.IconPath;
+                }
+                return string.Empty;
+            }
+        }
         /// <summary>
         /// 璁惧鍥剧墖--鍦ㄧ嚎鎴栬�呴�変腑鐘舵��
         /// </summary>
@@ -68,51 +92,14 @@
         {
             get
             {
-                if (string.IsNullOrEmpty(IconPath))
-                {
-                    return string.Empty;
-                }
-                var pathArr = IconPath.Split('.');
-                if (pathArr == null || string.IsNullOrEmpty(pathArr[0]))
-                {
-                    return string.Empty;
-                }
-                return $"{pathArr[0]}Selected.png";
+                var myDevice = Common.LocalDevice.Current.GetDevice(DeviceAddr, DeviceEpoint);
+                if (myDevice != null)
+                {
+                    return myDevice.OnlineIconPath;
+                }
+                return string.Empty;
             }
         }
-        //[Newtonsoft.Json.JsonIgnore]
-        //ZigBee.Device.CommonDevice commonDevice;
-        [Newtonsoft.Json.JsonIgnore]
-        public ZigBee.Device.CommonDevice CommonDevice
-        {
-            get
-            {
-                //commonDevice = ZigBee.Device.CommonDevice.CommonDeviceByFilePath(DeviceFilePath);
-                //return commonDevice;
-                //if (commonDevice == null)
-                //{
-                //    return ReCommonDevice;
-                //}
-                //else{
-                //return commonDevice;
-                if (DeviceFileName.Split('_').Length < 4)
-                {
-                    return null;
-                }
-                return Common.LocalDevice.Current.GetDevice(DeviceFileName.Split('_')[2], int.Parse(DeviceFileName.Split('_')[3]));
-                //}
-            }
-        }
-
-        //[Newtonsoft.Json.JsonIgnore]
-        //public ZigBee.Device.CommonDevice ReCommonDevice
-        //{
-        //    get
-        //    {
-        //commonDevice= ZigBee.Device.CommonDevice.CommonDeviceByFilePath(DeviceFilePath);
-        //return commonDevice;
-        //    }
-        //}
 
         /// <summary>
         /// 鎺у埗寤舵椂榛樿鍙嶉鐨勭嚎绋嬪垪琛�
@@ -169,64 +156,9 @@
             Application.RunOnMainThread(() =>
             {
                 string msg = Language.StringByID(r);
-                var tip = new Phone.UserCenter.TipViewControl(msg, 1000, 1);
-                tip.ShowView();
+                var tip = new Phone.UserCenter.ShowMsgControl(Phone.UserCenter.ShowMsgType.Tip, msg);
+                tip.Show();
             });
-        }
-
-        #endregion
-
-        #region 鈼� 淇濆瓨____________________________
-
-        /// <summary>
-        /// 淇濆瓨
-        /// </summary>
-        public void Save()
-        {
-            if (Global.IsExistsByHomeId(FileName))
-            {
-                return;
-            }
-            ReSave();
-        }
-
-        /// <summary>
-        /// 閲嶆柊淇濆瓨
-        /// </summary>
-        public void ReSave()
-        {
-            var paths = DeviceFileName.Split('_');
-            if (paths.Length < 3)
-            {
-                return;
-            }
-            if (IconPath == string.Empty)
-            {
-                //鎺у埗闈㈡澘鏄竴涓偣
-                if (paths[1] == ZigBee.Device.DeviceType.OnOffSwitch.ToString())
-                {
-                    IconPath = "Device/DryContact.png";
-                }
-                else if (paths[1] == ZigBee.Device.DeviceType.ColorDimmableLight.ToString())
-                {
-                    //褰╃伅
-                    IconPath = "Device/ColorDimmableLight.png";
-                }
-                else if (paths[1] == ZigBee.Device.DeviceType.DimmableLight.ToString())
-                {
-                    //璋冨厜鍣�
-                    IconPath = "Device/DimmableLight.png";
-                }
-                else if (CommonDevice != null)
-                {
-                    //鍏朵粬鐨勫浘鏍囨湁鐐圭壒娈�
-                    string unSelectPic = string.Empty;
-                    string selectPic = string.Empty;
-                    LocalDevice.Current.GetDeviceBeloneIcon(new List<CommonDevice> { CommonDevice }, ref unSelectPic, ref selectPic);
-                    IconPath = unSelectPic;
-                }
-            }
-            Global.WriteFileByBytesByHomeId(FileName, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
         }
 
         #endregion
@@ -246,38 +178,42 @@
             {
                 case DeviceType.OnOffSwitch:
                     //鎺у埗闈㈡澘
-                    ImagePath= "Device/DryContact.png";
+                    ImagePath = "Device/DryContact.png";
                     break;
                 case DeviceType.OnOffOutput:
                     //缁х數鍣�
-                    ImagePath= "Device/Relay.png";
+                    ImagePath = "Device/Relay.png";
                     break;
                 case DeviceType.DimmableLight:
                     //璋冨厜鐏�
-                    ImagePath= "Device/DimmableLight.png";
+                    ImagePath = "Device/DimmableLight.png";
                     break;
                 case DeviceType.WindowCoveringDevice:
                     //绐楀笜
-                    ImagePath= "Device/Curtain.png";
+                    ImagePath = "Device/Curtain.png";
                     break;
                 case DeviceType.Thermostat:
                     //绌鸿皟
-                    ImagePath= "Device/AirConditioner.png";
+                    ImagePath = "Device/AirConditioner.png";
                     break;
                 case DeviceType.IASZone:
                     //浼犳劅鍣�
-                    ImagePath= "Device/Sensor.png";
+                    ImagePath = "Device/Sensor.png";
                     break;
                 case DeviceType.AirSwitch:
                     //绌烘皵寮�鍏�
-                    ImagePath= "Device/AirSwitch.png";
+                    ImagePath = "Device/AirSwitch.png";
                     break;
                 case DeviceType.Repeater:
                     //涓户鍣�
                     ImagePath = "Device/AirSwitch.png";
                     break;
+                case DeviceType.TemperatureSensor:
+                    //娓╂箍搴︿紶鎰熷櫒
+                    ImagePath = "Device/Sensor.png";
+                    break;
                 default:
-                    ImagePath= "Device/Relay.png";
+                    ImagePath = "Device/Relay.png";
                     break;
             }
             return ImagePath;
@@ -372,6 +308,15 @@
                     //涓户鍣�
                     deviceTypeR = R.MyInternationalizationString.Repeater;
                     break;
+                case DeviceType.DoorLock:
+                    //闂ㄩ攣
+                    deviceTypeR = R.MyInternationalizationString.DoorLock;
+                    break;
+
+                case DeviceType.TemperatureSensor:
+                    //娓╁害浼犳劅鍣�
+                    deviceTypeR = R.MyInternationalizationString.TemperatureAndHumiditySensor;
+                    break;
                 default:
                     deviceTypeR = R.MyInternationalizationString.UnknowDevice;
                     break;
@@ -380,5 +325,243 @@
         }
 
         #endregion
+
+        #region 鈼� 閫氳繃id鑾峰彇璁惧鍖哄煙_____________
+
+        /// <summary>
+        /// GetZone
+        /// </summary>
+        /// <returns></returns>
+        public string GetZone()
+        {
+            var room = Room.CurrentRoom.GetRoomByDevice(CommonDevice);
+            if (room == null)
+            {
+                return Language.StringByID(R.MyInternationalizationString.UnallocatedArea);
+            }
+            if(string.IsNullOrEmpty(room.FloorId))
+            {
+                return room.Name;
+            }
+            var floorName = Config.Instance.Home.GetFloorNameById(room.FloorId);
+            if (floorName == null)
+            {
+                return room.Name;
+            }
+            return $"{floorName},{room.Name}";
+        }
+
+        #endregion
+
+        /// <summary>
+        /// GetDeviceStatu
+        /// </summary>
+        /// <returns></returns>
+        public string GetDeviceStatu()
+        {
+            var device = CommonDevice;
+            if (device.Type == DeviceType.OnOffOutput)
+            {
+                if ((device as ToggleLight).OnOffStatus == 1)
+                {
+                    return Language.StringByID(R.MyInternationalizationString.Open);
+                }
+                return Language.StringByID(R.MyInternationalizationString.Shut);
+            }
+            else if (device.Type == DeviceType.AirSwitch)
+            {
+                if ((device as ZigBee.Device.AirSwitch).OnOffStatus == 1)
+                {
+                    return Language.StringByID(R.MyInternationalizationString.Open);
+                }
+                return Language.StringByID(R.MyInternationalizationString.Shut);
+            }
+            else if (device.Type == DeviceType.DimmableLight)
+            {
+                if ((device as DimmableLight).OnOffStatus == 0 || (device as DimmableLight).Level == 0)
+                {
+                    return Language.StringByID(R.MyInternationalizationString.Shut);
+                }
+                return $"{(int)((device as DimmableLight).Level * 1.0 / 254 * 100)}%";
+            }
+            else if (device.Type == DeviceType.WindowCoveringDevice)
+            {
+                if ((device as Rollershade).WcdCurrentPositionLiftPercentage == 0)
+                {
+                    return Language.StringByID(R.MyInternationalizationString.Shut);
+                }
+                return $"{(device as Rollershade).WcdCurrentPositionLiftPercentage}%";
+            }
+            else if (device.Type == DeviceType.Thermostat)
+            {
+                //娓╁害锛屾ā寮忥紝椋庨��
+                string tempareture = string.Empty;
+                string model = string.Empty;
+                string wind = string.Empty;
+
+                var ac = CommonDevice as AC;
+
+                if (ac.currentSystemMode == 0)
+                {
+                    return Language.StringByID(R.MyInternationalizationString.Shut);
+                }
+                else if (ac.currentSystemMode == 1)
+                {
+                    model = Language.StringByID(R.MyInternationalizationString.Mode_Auto);
+                    tempareture = $"{ac.currentCoolingSetpoint} 鈩�";
+                }
+                else if (ac.currentSystemMode == 3)
+                {
+                    model = Language.StringByID(R.MyInternationalizationString.Mode_Cool);
+                    tempareture = $"{ac.currentCoolingSetpoint} 鈩�";
+                }
+                else if (ac.currentSystemMode == 4)
+                {
+                    model = Language.StringByID(R.MyInternationalizationString.Mode_Heat);
+                    tempareture = $"{ac.currentHeatingSetpoint} 鈩�";
+                }
+                else if (ac.currentSystemMode == 7)
+                {
+                    model = Language.StringByID(R.MyInternationalizationString.Mode_FanOnly);
+                }
+                else if (ac.currentSystemMode == 8)
+                {
+                    model = Language.StringByID(R.MyInternationalizationString.Mode_Dry);
+                    tempareture = $"{ac.currentCoolingSetpoint} 鈩�";
+                }
+
+                if (ac.currentFanMode == 1)
+                {
+                    wind = Language.StringByID(R.MyInternationalizationString.Fan_Low);
+                }
+                else if (ac.currentFanMode == 2)
+                {
+                    wind = Language.StringByID(R.MyInternationalizationString.Fan_Middle);
+                }
+                else
+                {
+                    wind = Language.StringByID(R.MyInternationalizationString.Fan_Height);
+                }
+
+                if (string.IsNullOrEmpty(tempareture))
+                {
+                    return $"{model},{wind}";
+                }
+                return $"{model},{wind},{tempareture}";
+            }
+            else if (device.Type == DeviceType.IASZone)
+            {
+                var ias = CommonDevice as IASZone;
+                //鍖哄垎浼犳劅鍣ㄥ叿浣撶被鍨�
+                var info = Common.LocalDevice.Current.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice> { device },false);
+                if (info.ConcreteType == DeviceConcreteType.Sensor_Infrared)
+                {
+                    //绾㈠
+                    if (ias.iASInfo?.Alarm1 == 1)
+                    {
+                        return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_HavePerson);
+                    }
+                    return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_NoPerson);
+                }
+                else if (info.ConcreteType == DeviceConcreteType.Sensor_Water)
+                {
+                    //姘存蹈
+                    if (ias.iASInfo?.Alarm1 == 1)
+                    {
+                        return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_HaveWater);
+                    }
+                    return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Normal);
+                }
+                else if (info.ConcreteType == DeviceConcreteType.Sensor_DoorWindow)
+                {
+                    //闂ㄧ獥
+                    if (ias.iASInfo?.Alarm1 == 1)
+                    {
+                        return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Open);
+                    }
+                    return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Close);
+                }
+                else if (info.ConcreteType == DeviceConcreteType.Sensor_CarbonMonoxide)
+                {
+                    //鐕冩皵
+                    if (ias.iASInfo?.Alarm1 == 1)
+                    {
+                        return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Alarm);
+                    }
+                    return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Safe);
+                }
+                else if (info.ConcreteType == DeviceConcreteType.Sensor_Fire)
+                {
+                    //鐑熼浘
+                    if (ias.iASInfo?.Alarm1 == 1)
+                    {
+                        return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Alarm);
+                    }
+                    return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Safe);
+                }
+                else if (info.ConcreteType == DeviceConcreteType.Sensor_Pir)
+                {
+                    //pir
+                    if (ias.iASInfo?.Alarm1 == 1)
+                    {
+                        return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Alarm);
+                    }
+                    return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Safe);
+                }
+                else if (info.ConcreteType == DeviceConcreteType.Sensor_Keyfob)
+                {
+                    //閽ュ寵鎵�
+                    if (ias.iASInfo?.Alarm1 == 1)
+                    {
+                        return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Alarm);
+                    }
+                    return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Normal);
+                }
+                else if (info.ConcreteType == DeviceConcreteType.Sensor_Motion)
+                {
+                    //杩愬姩浼犳劅鍣�
+                    if (ias.iASInfo?.Alarm1 == 1)
+                    {
+                        return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Alarm);
+                    }
+                    return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Normal);
+                }
+                else if (info.ConcreteType == DeviceConcreteType.Sensor_EmergencyButton)
+                {
+                    //绱ф�ユ寜閽�
+                    if (ias.iASInfo?.Alarm1 == 1)
+                    {
+                        return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Alarm);
+                    }
+                    return Language.StringByID(R.MyInternationalizationString.IASZone_Statu_Normal);
+                }
+                return null;
+            }
+            else if (device.Type == DeviceType.TemperatureSensor)
+            {
+                var tempera = CommonDevice as TemperatureSensor;
+                if(tempera.SensorDiv==1)
+                {
+                    if (tempera.Temperatrue == 0)
+                    {
+                        return "--鈩�";
+                    }
+                    return $"{tempera.Temperatrue}鈩�";
+                }
+                else if(tempera.SensorDiv==2)
+                {
+                    if (tempera.Humidity == 0)
+                    {
+                        return "--%";
+                    }
+                    return $"{tempera.Humidity}%";
+                }
+                return null;
+            }
+            else
+            {
+                return null;
+            }
+        }
     }
 }

--
Gitblit v1.8.0