xm
2020-07-14 d87400af518ebc9274f4447f06476959c3aa5102
ZigbeeApp/Shared/Common/Device.cs
@@ -260,7 +260,7 @@
                //添加缓存
                this.AddDeviceToMemory(ref device);
                //移除存在的设备内存
                //移除存在的设备内存
                string maikey = this.GetDeviceMainKeys(device);
                if (dicExist.ContainsKey(maikey) == true)
                {
@@ -434,7 +434,7 @@
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                //修改设备名字的话,主页需要重新刷新
                Phone.UserView.UserPage.Instance.RefreshForm = true;
                Phone.UserView.UserPage.Instance.RefreshAllForm = true;
                return true;
            }
@@ -458,7 +458,7 @@
                }
            }
            //修改设备名字的话,主页需要重新刷新
            Phone.UserView.UserPage.Instance.RefreshForm = true;
            Phone.UserView.UserPage.Instance.RefreshAllForm = true;
            return true;
        }
@@ -551,7 +551,7 @@
            //获取编辑设备Mac名字的命令字符
            var sendData = this.GetReDeviceMacNameCommandText(device.DeviceAddr, device.DeviceEpoint, macName);
            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "MacRename", sendData, "MacRename_Respon");
            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "MacRename", sendData, "MacRename_Respon", 8);
            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
            {
                return null;
@@ -578,7 +578,7 @@
            }
            //获取编辑设备端点名字的命令字符
            var sendData = this.GetReDeviceEpointNameCommandText(device.DeviceAddr, device.DeviceEpoint, deviceName);
            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "DeviceRename", sendData, "DeviceRenameRespon");
            var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "DeviceRename", sendData, "DeviceRenameRespon", 8);
            if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
            {
                return null;
@@ -719,7 +719,7 @@
        public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true)
        {
            //删除缓存设备的话,主页需要重新刷新
            Phone.UserView.UserPage.Instance.RefreshForm = true;
            Phone.UserView.UserPage.Instance.RefreshAllForm = true;
            if (deleteRoom == true)
            {
@@ -860,6 +860,11 @@
                    //传感器除了Pir都没有定位功能
                    return true;
                }
                else if (myTypeInfo.ConcreteType == DeviceConcreteType.Sensor_SphericalMotion)
                {
                    //球型移动传感器虽然是电池设备,但是它有定位功能
                    return true;
                }
                return false;
            }
@@ -887,6 +892,22 @@
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 检测设备是否拥有一键同步功能
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public bool DeviceIsCanSynchronization(CommonDevice device)
        {
            //获取设备类型的
            var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
            if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction)
            {
                return true;
            }
            return false;
        }
@@ -1156,7 +1177,7 @@
        public List<string> GetAllDeviceFile()
        {
            List<string> listDeviceFile = new List<string>();
            List<string> listAllFile = Global.FileListByHomeId();
            List<string> listAllFile = HdlFileLogic.Current.GetRootPathListFile();
            foreach (string file in listAllFile)
            {
@@ -2207,6 +2228,12 @@
                info.ConcreteType = DeviceConcreteType.Sensor_DoorWindow;
                info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1301;
            }
            else if (iasZone.IasDeviceType == 541)
            {
                //球型移动传感器
                info.ConcreteType = DeviceConcreteType.Sensor_SphericalMotion;
                info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1205;
            }
        }
        #endregion
@@ -2219,12 +2246,21 @@
        private void InitRealDeviceRoomId()
        {
            this.dicDeviceRoomId = new Dictionary<string, string>();
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
            var strData = UserCenterLogic.LoadFileContent(fullName);
            string fullName = DirNameResourse.DeviceRoomIdFile;
            var strData = HdlFileLogic.Current.ReadFileTextContent(fullName);
            if (strData != null)
            {
                this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
            }
        }
        /// <summary>
        /// 获取全部物理设备所属房间的记录
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, string> GetAllRealDeviceRoomData()
        {
            return this.dicDeviceRoomId;
        }
        /// <summary>
@@ -2278,8 +2314,7 @@
            if (save == true)
            {
                //保存记录
                string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
                UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
                HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId);
                //添加自动备份
                HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
@@ -2299,7 +2334,7 @@
                return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
            }
            var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
            return HdlRoomLogic.Current.GetFloorRoomName(room);
            return HdlRoomLogic.Current.GetRoomName(room);
        }
        /// <summary>
@@ -2347,8 +2382,7 @@
                return;
            }
            //保存记录
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
            UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
            HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId);
            //添加自动备份
            HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
@@ -2450,39 +2484,6 @@
        #endregion
        #region ■ 获取设备在线状态列表_______________
        /// <summary>
        /// 获取设备在线状态列表(注意,一个设备只返回一个回路)
        /// </summary>
        /// <param name="gwId">网关id</param>
        /// <returns></returns>
        public List<CommonDevice> GetDeviceOnlineList(string gwId)
        {
            var zbway = HdlGatewayLogic.Current.GetLocalGateway(gwId);
            int statu = 0;
            var listDevice = this.GetDeviceListFromGateway(zbway, ref statu, false, ShowErrorMode.NO);
            if (statu == -1)
            {
                //当出现异常时,使用后备操作,直接获取本地的设备列表
                listDevice = this.GetDeviceByGatewayID(gwId);
            }
            var listCheck = new HashSet<string>();
            var listReturn = new List<CommonDevice>();
            foreach (var device in listDevice)
            {
                if (listCheck.Contains(device.DeviceAddr) == false)
                {
                    listCheck.Add(device.DeviceAddr);
                    listReturn.Add(device);
                }
            }
            return listReturn;
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
@@ -2495,7 +2496,7 @@
            var listDevice = this.GetDevicesByMac(i_device.DeviceAddr, false);
            foreach (var device in listDevice)
            {
                //0:离线 1:在线 2:正在刷新状态
                //0:离线 1:在线 2:正在刷新状态
                bool statu = i_device.IsOnline == 1 || i_device.IsOnline == 2;
                if (statu == true)
                {
@@ -2554,6 +2555,20 @@
                {
                    return false;
                }
            }
            //如果是新风面板或环境面板,则都不显示任何回路
            var myInfoTypeTemp = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
            if (myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir || myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleEnvironment)
            {
                return false;
            }
            else if (myInfoTypeTemp.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction)
            {
                if (i_device.Type != DeviceType.OnOffOutput)
                {
                    return false;
                }
            }
            return true;
        }
@@ -2913,6 +2928,8 @@
            mainDevice.ModelIdentifier = device.DeviceInfo.ModelIdentifier;
            //序列号
            mainDevice.SerialNumber = device.DeviceInfo.ProductCode;
            //设备功能类型
            mainDevice.DfunctionType = (DeviceFunctionType)device.DeviceInfo.FunctionType;
            mainDevice.InClusterList.Clear();
            mainDevice.InClusterList.AddRange(device.DeviceInfo.InClusterList);
@@ -2939,6 +2956,11 @@
            else if (mainDevice.Type == DeviceType.DimmableLight)
            {
                mainDevice.DfunctionType = DeviceFunctionType.A灯光;
                if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
                {
                    //调光器固定灯光
                    this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A灯光);
                }
                if (mainDevice.IsCustomizeImage == false)
                {
                    mainDevice.IconPath = "Device/Light.png";
@@ -2948,6 +2970,11 @@
            else if (mainDevice.Type == DeviceType.ColorTemperatureLight)
            {
                mainDevice.DfunctionType = DeviceFunctionType.A灯光;
                if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
                {
                    //色温灯固定灯光
                    this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A灯光);
                }
                if (mainDevice.IsCustomizeImage == false)
                {
                    mainDevice.IconPath = "Device/ColorLightTemperature.png";
@@ -2957,18 +2984,17 @@
            else if (mainDevice.Type == DeviceType.OnOffOutput)
            {
                //2020.05.13变更:继电器都默认为灯光
                //var myType = this.GetHdlMyDeviceEnumInfo(mainDevice);
                //if (myType != null && myType.ConcreteType == DeviceConcreteType.Relay_ThreeLoad)
                if (mainDevice.DfunctionType == DeviceFunctionType.A未定义)
                {
                    if (mainDevice.DfunctionType == DeviceFunctionType.A未定义)
                    mainDevice.DfunctionType = DeviceFunctionType.A灯光;
                    if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
                    {
                        mainDevice.DfunctionType = DeviceFunctionType.A灯光;
                    }
                    if (mainDevice.IsCustomizeImage == false)
                    {
                        mainDevice.IconPath = "Device/Light.png";
                        //继电器默认为灯光
                        this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A灯光);
                    }
                }
                //根据功能类型,重新设置设备回路图标
                this.ResetIconPathByDeviceFunctionType(mainDevice);
            }
            //如果是空气开关的话
            else if (mainDevice.Type == DeviceType.AirSwitch)
@@ -2977,20 +3003,52 @@
                if (mainDevice.DfunctionType == DeviceFunctionType.A未定义)
                {
                    mainDevice.DfunctionType = DeviceFunctionType.A开关;
                    if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A开关)
                    {
                        //空气开关默认为开关
                        this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A开关);
                    }
                }
                if (mainDevice.IsCustomizeImage == false)
                {
                    mainDevice.IconPath = "Device/Switch.png";
                }
                //根据功能类型,重新设置设备回路图标
                this.ResetIconPathByDeviceFunctionType(mainDevice);
            }
            //如果是彩灯的话
            else if (mainDevice.Type == DeviceType.ColorDimmableLight)
            {
                mainDevice.DfunctionType = DeviceFunctionType.A灯光;
                if (device.DeviceInfo.FunctionType != (int)DeviceFunctionType.A灯光)
                {
                    //彩灯默认为开关
                    this.SendDeviceFunctionTypeToGateway(mainDevice, DeviceFunctionType.A灯光);
                }
                if (mainDevice.IsCustomizeImage == false)
                {
                    mainDevice.IconPath = "Device/ColorLight.png";
                }
            }
        }
        /// <summary>
        /// 根据功能类型,重新设置设备回路图标
        /// </summary>
        /// <param name="device"></param>
        private void ResetIconPathByDeviceFunctionType(CommonDevice device)
        {
            if (device.IsCustomizeImage == true)
            {
                return;
            }
            if (device.DfunctionType == DeviceFunctionType.A开关)
            {
                device.IconPath = "Device/Switch.png";
            }
            else if (device.DfunctionType == DeviceFunctionType.A插座)
            {
                device.IconPath = "Device/Socket1.png";
            }
            else
            {
                device.IconPath = "Device/Light.png";
            }
        }
@@ -3111,6 +3169,7 @@
            //=========★★PIR传感器类(1200-1299)★★=========
            this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200-60000";//pir传感器220
            this.dicDeviceModelIdEnum["MSPIRB-ZB.10"] = "1205-1200-60000";//球型移动传感器
            //=========★★安防类传感器类(1300-2299)★★=========
            //这里是麦乐克的
@@ -3130,7 +3189,7 @@
            this.dicDeviceModelIdEnum["MGCD01/M-ZB.10"] = "1306-1200-60000";//吸顶燃气传感器
            //PM2.5空气质量传感器 【该设备属于第三方设备,没有镜像ID】
            this.dicDeviceModelIdEnum["MSPM25/M-ZB.10"] = "1307-1200-60000";//PM2.5空气质量传感器
            this.dicDeviceModelIdEnum["MSPM25/M-ZB.10"] = "1307-1200-60000";//PM2.5空气质量传感器
            //=========★★继电器类(2300-2499)★★=========
            this.dicDeviceModelIdEnum["MPR0310-ZB.10"] = "2300-2300-60001";//3路继电器小模块
@@ -3300,6 +3359,10 @@
        /// pir传感器220 镜像id:1200
        /// </summary>
        Sensor_Pir = 1200,
        /// <summary>
        /// 球形移动传感器 镜像id:1205
        /// </summary>
        Sensor_SphericalMotion = 1205,
        //=========★★安防类传感器类(1300-2299)★★=========
        /// <summary>