黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
@@ -10,8 +10,8 @@
    {
        #region 需要保存的变量
        /// <summary>
        /// 是否是自定义图片
        /// <summary>
        /// 是否是自定义图片
        /// </summary>
        public bool IsCustomizeImage = false;
        /// <summary>
@@ -27,9 +27,9 @@
        {
            get
            {
                if (string.IsNullOrEmpty(IconPath))
                {
                    return string.Empty;
                if (string.IsNullOrEmpty(IconPath))
                {
                    return string.Empty;
                }
                var pathArr = IconPath.Split('.');
                if (pathArr == null || string.IsNullOrEmpty(pathArr[0]))
@@ -72,14 +72,14 @@
        /// <para>262:Light sensor,光照传感器</para>
        /// <para>1026:sensor,传感器,具体类型的传感器DeviceType来区分</para>
        /// </summary>
        public int DeviceID;
        /// <summary>
        /// <para>2020.09.21追加:为了对应第三方设备,以及之后的多设备ID问题,追加的变量</para>
        /// <para>这是个特殊的,并且不保存在文件当中的ID, DeviceType由此值映射出来</para>
        /// <para>当设备是河东设备时,它与DeviceID相等</para>
        /// <para>当是真正的第三方设备时,它有可能与DeviceID不相等</para>
        /// <para>比如:2和256都是继电器,那么【DeviceID为2 或者 DeviceID为256】 而 【ExDeviceID固定为2】,【DeviceType为OnOffOutput】</para>
        /// <para>通俗来说:DeviceID是实际正确的ID,而【ExDeviceID是一种所属概念的ID】</para>
        public int DeviceID;
        /// <summary>
        /// <para>2020.09.21追加:为了对应第三方设备,以及之后的多设备ID问题,追加的变量</para>
        /// <para>这是个特殊的,并且不保存在文件当中的ID, DeviceType由此值映射出来</para>
        /// <para>当设备是河东设备时,它与DeviceID相等</para>
        /// <para>当是真正的第三方设备时,它有可能与DeviceID不相等</para>
        /// <para>比如:2和256都是继电器,那么【DeviceID为2 或者 DeviceID为256】 而 【ExDeviceID固定为2】,【DeviceType为OnOffOutput】</para>
        /// <para>通俗来说:DeviceID是实际正确的ID,而【ExDeviceID是一种所属概念的ID】</para>
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public int ExDeviceID;
@@ -118,11 +118,11 @@
        /// 0:设备不在线
        /// <para>1:设备在线</para>
        /// </summary>
        public int IsOnline;
        /// <summary>
        /// 1:路由设备
        /// <para>2:终端设备,电池设备</para>
        /// </summary>
        public int IsOnline;
        /// <summary>
        /// 1:路由设备
        /// <para>2:终端设备,电池设备</para>
        /// </summary>
        public int ZigbeeType;
        /// <summary>
        /// 固件版本
@@ -167,7 +167,7 @@
        /// <summary>
        /// 输出簇列表
        /// </summary>
        public List<OutClusterObj> OutClusterList = new List<OutClusterObj>();
        public List<OutClusterObj> OutClusterList = new List<OutClusterObj>();
        /// <summary>
        /// 用于记录设备最新上报的属性状态信息
        /// </summary>
@@ -179,8 +179,8 @@
        /// 是否已经读取了设备状态(此属性是给主页使用的)
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public bool HadReadDeviceStatu = false;
        public bool HadReadDeviceStatu = false;
        /// <summary>
        /// 是否是低电量(这个变量目前是给传感器用的)
        /// </summary>
@@ -248,19 +248,19 @@
        #endregion
        #region 设备保存及生成
        /// <summary>
        /// 由设备字符串比特恢复设备对象
        /// </summary>
        /// <param name="intDeviceType">设备DeviceType的整型值</param>
        /// <param name="strDeviceByte">设备Json文件转为比特后再转为的字符串</param>
        /// <summary>
        /// 由设备字符串比特恢复设备对象
        /// </summary>
        /// <param name="intDeviceType">设备DeviceType的整型值</param>
        /// <param name="strDeviceByte">设备Json文件转为比特后再转为的字符串</param>
        /// <returns></returns>
        public static CommonDevice CommonDeviceByByteString(int intDeviceType, string strDeviceByte)
        {
            //这是河东的特殊端点,不需要处理
            if (intDeviceType == 49408)
            {
                return null;
        {
            //这是河东的特殊端点,不需要处理
            if (intDeviceType == 49408)
            {
                return null;
            }
            CommonDevice device = null;
@@ -271,7 +271,7 @@
            }
            else if (intDeviceType == (int)DeviceType.OnOffOutput || intDeviceType == 256)
            {
                device = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte);
                device = Newtonsoft.Json.JsonConvert.DeserializeObject<ToggleLight>(strDeviceByte);
                device.ExDeviceID = (int)DeviceType.OnOffOutput;
            }
            else if (intDeviceType == (int)DeviceType.ColorDimmerSwitch)
@@ -321,7 +321,7 @@
            else if (intDeviceType == (int)DeviceType.DoorLock)
            {
                device = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLock>(strDeviceByte);
            }
            }
            else if (intDeviceType == (int)DeviceType.TemperatureSensor)
            {
                device = Newtonsoft.Json.JsonConvert.DeserializeObject<TemperatureSensor>(strDeviceByte);
@@ -341,7 +341,7 @@
            else if (intDeviceType == (int)DeviceType.ColorTemperatureLight)
            {
                device = Newtonsoft.Json.JsonConvert.DeserializeObject<ColorTemperatureLight>(strDeviceByte);
            }
            }
            else if (intDeviceType == (int)DeviceType.Buzzer)
            {
                device = Newtonsoft.Json.JsonConvert.DeserializeObject<Buzzer>(strDeviceByte);
@@ -355,20 +355,20 @@
                device = Newtonsoft.Json.JsonConvert.DeserializeObject<DimmerSwitch>(strDeviceByte);
            }
            else
            {
            {
                device = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice>(strDeviceByte);
            }
            //这是河东的特殊端点,不需要处理
            if (device.DeviceEpoint == 242 && intDeviceType == 97)
            {
                return null;
            if (device.DeviceEpoint == 242 && intDeviceType == 97)
            {
                return null;
            }
            if (device.ExDeviceID == 0)
            {
                //赋初始值
                device.ExDeviceID = device.DeviceID;
            if (device.ExDeviceID == 0)
            {
                //赋初始值
                device.ExDeviceID = device.DeviceID;
            }
            //能少存一个变量就少存一个
@@ -399,15 +399,15 @@
                //展示模板时,不允许保存文件(防止属性上报用的)
                return;
            }
            if (IconPath == string.Empty)
            {
                //保存设备图标(这里会保存一次,下面就不用保存了)
                this.SaveDeviceIcon();
                return;
            if (IconPath == string.Empty)
            {
                //保存设备图标(这里会保存一次,下面就不用保存了)
                this.SaveDeviceIcon();
                return;
            }
            Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
        }
        }
        /// <summary>
        /// 保存设备图标
        /// </summary>
@@ -415,25 +415,25 @@
        {
            if (IconPath == string.Empty)
            {
                //干接点
                if (this.Type == DeviceType.OnOffSwitch)
                {
                    IconPath = "Device/DryContact.png";
                }
                //干接点
                if (this.Type == DeviceType.OnOffSwitch)
                {
                    IconPath = "Device/DryContact.png";
                }
                else if (this.Type == DeviceType.ColorDimmableLight)
                {
                    //彩灯
                    IconPath = "Device/ColorLight.png";
                }
                }
                else if (this.Type == DeviceType.DimmableLight)
                {
                    //调光器
                    IconPath = "Device/Light.png";
                }
                else if (this.Type == DeviceType.ColorTemperatureLight)
                {
                    //色温灯
                    IconPath = "Device/ColorLightTemperature.png";
                }
                else if (this.Type == DeviceType.ColorTemperatureLight)
                {
                    //色温灯
                    IconPath = "Device/ColorLightTemperature.png";
                }
                else if (this.Type == DeviceType.OnOffOutput)
                {
@@ -460,31 +460,31 @@
                    //湿度传感器
                    IconPath = "Device/SensorHumidity.png";
                }
                else if (this.Type == DeviceType.TemperatureSensor)
                {
                    if (((TemperatureSensor)this).SensorDiv == 1)
                    {
                        //温度传感器
                        IconPath = "Device/SensorTemperature.png";
                    }
                    else if (((TemperatureSensor)this).SensorDiv == 2)
                    {
                        //湿度传感器
                        IconPath = "Device/SensorHumidity.png";
                    }
                else if (this.Type == DeviceType.TemperatureSensor)
                {
                    if (((TemperatureSensor)this).SensorDiv == 1)
                    {
                        //温度传感器
                        IconPath = "Device/SensorTemperature.png";
                    }
                    else if (((TemperatureSensor)this).SensorDiv == 2)
                    {
                        //湿度传感器
                        IconPath = "Device/SensorHumidity.png";
                    }
                }
                else if (this.Type != DeviceType.UnKown)
                {
                    //其他的图标有点特殊
                    string unSelectPic = string.Empty;
                    string selectPic = string.Empty;
                    Shared.Common.LocalDevice.Current.GetDeviceObjectIcon(new List<CommonDevice> { this }, ref unSelectPic, ref selectPic);
                    IconPath = unSelectPic;
                }
                else if (this.Type != DeviceType.UnKown)
                {
                    //其他的图标有点特殊
                    string unSelectPic = string.Empty;
                    string selectPic = string.Empty;
                    Shared.Phone.HdlDeviceCommonLogic.Current.GetDeviceObjectIcon(new List<CommonDevice> { this }, ref unSelectPic, ref selectPic);
                    IconPath = unSelectPic;
                }
                Shared.Common.Global.WriteFileByBytesByHomeId(FilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
            }
        }
        }
        #endregion
        #region 输入输出镞定义
@@ -715,20 +715,20 @@
            /// 驱动代码。为0时,表示zigbee协调器设备。其他值表示为虚拟驱动设备
            /// </summary>
            public int DriveCode;
            /// <summary>
            /// 厂商名称
            /// <summary>
            /// 厂商名称
            /// </summary>
            public string ManufacturerName = string.Empty;
            /// <summary>
            /// 模块ID
            /// <summary>
            /// 模块ID
            /// </summary>
            public string ModelIdentifier = string.Empty;
            /// <summary>
            /// 好像是序列号
            /// <summary>
            /// 好像是序列号
            /// </summary>
            public string ProductCode = string.Empty;
            /// <summary>
            /// 设备功能类型(空气开关和继电器专用)
            /// <summary>
            /// 设备功能类型(空气开关和继电器专用)
            /// </summary>
            public int FunctionType = -1;
            /// <summary>