黄学彪
2020-05-13 2be70a32d2a8c517bd9868fb60913fcc843e66fe
ZigbeeApp/Shared/Common/Device.cs
@@ -400,6 +400,27 @@
            }
        }
        /// <summary>
        /// 添加虚拟设备到缓存
        /// </summary>
        /// <param name="device">设备对象</param>
        public void AddVirtualDeviceToMemory(CommonDevice device)
        {
            string mainKeys = this.GetDeviceMainKeys(device);
            this.dicAllDevice[mainKeys] = device;
            //设备回路收集
            if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == false)
            {
                this.dicDeviceEpoint[device.DeviceAddr] = new HashSet<int>();
            }
            if (this.dicDeviceEpoint[device.DeviceAddr].Contains(device.DeviceEpoint) == false)
            {
                this.dicDeviceEpoint[device.DeviceAddr].Add(device.DeviceEpoint);
            }
            device.ReSave();
        }
        #endregion
        #region ■ 修改设备___________________________
@@ -416,6 +437,14 @@
            this.SetEpointName(device, newName);
            this.BackupDeviceAfterReName(device);
            //如果住宅为虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                //修改设备名字的话,主页需要重新刷新
                Phone.UserView.UserPage.Instance.RefreshForm = true;
                return true;
            }
            //不再检测名字是否一样
            //成员只能修改自己本地的名字
@@ -438,6 +467,8 @@
                //备份数据
                await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A端点名称, newName);
            }
            //修改设备名字的话,主页需要重新刷新
            Phone.UserView.UserPage.Instance.RefreshForm = true;
            return true;
        }
@@ -462,6 +493,11 @@
                //更改名字后,刷新设备缓存
                this.BackupDeviceAfterReName(device2);
            }
            //如果住宅为虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return true;
            }
            CommonDevice device = listDevice[0];
@@ -596,6 +632,9 @@
        /// <param name="deleteRoom">是否从房间删除</param>
        public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true)
        {
            //删除缓存设备的话,主页需要重新刷新
            Phone.UserView.UserPage.Instance.RefreshForm = true;
            if (deleteRoom == true)
            {
                //从房间中删除
@@ -679,7 +718,11 @@
        /// <param name="device"></param>
        public void SetFixedPositionCommand(CommonDevice device)
        {
            device.IdentifyControl(device.DeviceAddr, device.DeviceEpoint, 5);
            //如果当前住宅不是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == false)
            {
                device.IdentifyControl(device.DeviceAddr, device.DeviceEpoint, 5);
            }
        }
        /// <summary>
@@ -1003,15 +1046,8 @@
                //继电器,掉光器都叫回路
                return Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + epointNo;
            }
            //获取设备类型
            var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
            if (device.Type == DeviceType.Thermostat)
            {
                //新风面板中的Thermostat叫温度传感器
                if (deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir)
                {
                    return Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
                }
                //空调都叫室内机
                return Language.StringByID(R.MyInternationalizationString.uIndoorUnit) + epointNo;
            }
@@ -1025,7 +1061,10 @@
                //新风面板湿度传感器
                return Language.StringByID(R.MyInternationalizationString.HumiditySensor);
            }
            else if (device.Type == DeviceType.OnOffSwitch)
            //获取设备类型
            var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
            if (device.Type == DeviceType.OnOffSwitch)
            {
                //面板的干接点叫按键
                if (deviceInfoType.BeloneType == DeviceBeloneType.A按键面板)
@@ -1036,6 +1075,19 @@
                else
                {
                    return Language.StringByID(R.MyInternationalizationString.uDeviceBelongId16) + epointNo;
                }
            }
            else if (device.Type == DeviceType.TemperatureSensor)
            {
                if (deviceInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir)
                {
                    //新风面板中的Thermostat为温度传感器
                    return Language.StringByID(R.MyInternationalizationString.TemperatureSensor);
                }
                else if (deviceInfoType.BeloneType == DeviceBeloneType.A按键面板)
                {
                    //面板的温度探头叫  面板名字+温度
                    return Language.StringByID(deviceInfoType.DefultNameId) + Language.StringByID(R.MyInternationalizationString.uTemperature);
                }
            }
            //其他情况,使用它的默认名称
@@ -1279,7 +1331,7 @@
        }
        /// <summary>
        /// 设置【设备类型】的图标到指定的控件
        /// 设置【设备类型】的图标到指定的控件(此方法不能用在设备功能类型菜单的图标)
        /// </summary>
        /// <param name="btnIcon">控件对象</param>
        /// <param name="listdevice">设备对象</param>
@@ -1301,7 +1353,7 @@
        }
        /// <summary>
        /// 获取【设备类型】的图标
        /// 获取【设备类型】的图标(此方法不能用在设备功能类型菜单的图标)
        /// </summary>
        /// <param name="listdevice">设备对象</param>
        /// <param name="unSelectPath">图片地址</param>
@@ -1317,13 +1369,42 @@
        }
        /// <summary>
        /// 获取【设备类型】的图标
        /// 获取【设备功能类型】的菜单图标
        /// </summary>
        /// <param name="specificType">自定义设备类型</param>
        /// <param name="unSelectPath">图片地址</param>
        /// <param name="selectPath">图片地址</param>
        /// <returns></returns>
        public void GetDeviceObjectIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath)
        public void GetDeviceFunctionTypeMenuIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath)
        {
            //新风小模块
            if (specificType == DeviceConcreteType.Relay_FangyueFreshAirModul)
            {
                unSelectPath = "Device/FreshAirEpoint.png";
                selectPath = "Device/FreshAirEpointSelected.png";
                return;
            }
            //PM2.5空气质量传感器
            else if (specificType == DeviceConcreteType.Sensor_PMTwoPointFive)
            {
                unSelectPath = "Device/AirQualitySensorEpoint.png";
                selectPath = "Device/AirQualitySensorEpointSelected.png";
                return;
            }
            //上面需要特殊处理
            //获取【设备类型】的图标
            this.GetDeviceObjectIcon(specificType, ref unSelectPath, ref selectPath);
        }
        /// <summary>
        /// 获取【设备类型】的图标 2020.05.13:次函数不再公开
        /// </summary>
        /// <param name="specificType">自定义设备类型</param>
        /// <param name="unSelectPath">图片地址</param>
        /// <param name="selectPath">图片地址</param>
        /// <returns></returns>
        private void GetDeviceObjectIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath)
        {
            //将具体类型转字符串
            string strSpecific = Enum.GetName(typeof(DeviceConcreteType), specificType);
@@ -1360,6 +1441,7 @@
            unSelectPath = imageFilePath;
            selectPath = imageSelectFilePath;
        }
        #endregion
@@ -1758,6 +1840,22 @@
                }
                info.ObjectTypeNameId = 60000;//传感器
            }
            //14新风设备
            else if (dicType.ContainsKey(DeviceType.FreshAir) == true)
            {
                info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId2310;
                info.BeloneType = DeviceBeloneType.A新风;
                info.ConcreteType = DeviceConcreteType.Relay_FangyueFreshAirModul;
                info.ObjectTypeNameId = 60011;//新风
            }
            //15 PM2.5传感器设备
            else if (dicType.ContainsKey(DeviceType.PMSensor) == true)
            {
                info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1307;
                info.BeloneType = DeviceBeloneType.APM2点5空气质量传感器;
                info.ConcreteType = DeviceConcreteType.Sensor_PMTwoPointFive;
                info.ObjectTypeNameId = 60000;//传感器
            }
            int value = (int)info.BeloneType;
            if (dicDeviceAllNameID.ContainsKey("uDeviceBelongId" + value) == true)
@@ -1934,9 +2032,19 @@
        /// <param name="listMac">设备Mac地址</param>
        public void DeleteRealDeviceFromRoom(List<string> listMac)
        {
            bool save = false;
            foreach (var deviceMacAddr in listMac)
            {
                this.dicDeviceRoomId.Remove(deviceMacAddr);
                if (this.dicDeviceRoomId.ContainsKey(deviceMacAddr) == true)
                {
                    this.dicDeviceRoomId.Remove(deviceMacAddr);
                    save = true;
                }
            }
            if (save == false)
            {
                //没有改变,不需要保存
                return;
            }
            //保存记录
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
@@ -2007,6 +2115,7 @@
            list.Add(DeviceBeloneType.A插座);
            list.Add(DeviceBeloneType.A调光器);
            list.Add(DeviceBeloneType.A窗帘);
            list.Add(DeviceBeloneType.A新风);
            list.Add(DeviceBeloneType.A空调);
            list.Add(DeviceBeloneType.A继电器);
            list.Add(DeviceBeloneType.A干接点);
@@ -2022,7 +2131,62 @@
        #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 dicDevice = new Dictionary<string, CommonDevice>();
            foreach (var device in listDevice)
            {
                if (dicDevice.ContainsKey(device.DeviceAddr) == false)
                {
                    dicDevice[device.DeviceAddr] = device;
                    continue;
                }
                //设备是否处于在线状态
                bool online = this.CheckDeviceIsOnline(device);
                if (online == true)
                {
                    //如果设备回路在线,则优先使用在线的回路,后来的直接覆盖
                    dicDevice[device.DeviceAddr] = device;
                }
            }
            var listReturn = new List<CommonDevice>();
            foreach (var device in dicDevice.Values)
            {
                listReturn.Add(device);
            }
            return listReturn;
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 从缓存变量检测设备是否在线
        /// </summary>
        /// <param name="i_device"></param>
        /// <returns></returns>
        public bool CheckDeviceIsOnline(CommonDevice i_device)
        {
            //0:离线 1:在线 2:正在刷新状态
            return i_device.IsOnline == 1 || i_device.IsOnline == 2;
        }
        /// <summary>
        /// 判断该设备是否可以显示在主页
@@ -2040,6 +2204,15 @@
            {
                //2020.03.23追加式样:未指定类型的继电器,不显示
                if (i_device.DfunctionType == DeviceFunctionType.A未定义)
                {
                    return false;
                }
            }
            //如果是新风面板的新风设备,则不显示
            else if (i_device.Type == DeviceType.FreshAir)
            {
                var myInfoType = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { i_device });
                if (myInfoType.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir)
                {
                    return false;
                }
@@ -2370,6 +2543,7 @@
                mainDevice.DeviceEpointName = device.DeviceInfo.DeviceName;
            }
            mainDevice.CurrentGateWayId = device.CurrentGateWayId;
            mainDevice.ZigbeeType = device.DeviceInfo.ZigbeeType;
            mainDevice.IsOnline = device.DeviceInfo.IsOnline;
            mainDevice.DriveCode = device.DeviceInfo.DriveCode;
            mainDevice.IasDeviceType = device.DeviceInfo.DeviceType;
@@ -2393,8 +2567,6 @@
            mainDevice.InClusterList.AddRange(device.DeviceInfo.InClusterList);
            mainDevice.OutClusterList.Clear();
            mainDevice.OutClusterList.AddRange(device.DeviceInfo.OutClusterList);
            mainDevice.AttributeStatus.Clear();
            mainDevice.AttributeStatus.AddRange(device.DeviceInfo.AttributeStatus);
            //如果是温度传感器
            if (mainDevice.Type == DeviceType.TemperatureSensor)
@@ -2483,6 +2655,7 @@
            else if (deviceType == DeviceType.FreshAir) { device = new FreshAir(); }
            else if (deviceType == DeviceType.DoorLock) { device = new DoorLock(); }
            else if (deviceType == DeviceType.TemperatureSensor) { device = new TemperatureSensor(); }
            else if (deviceType == DeviceType.PMSensor) { device = new PMSensor(); }
            else if (deviceType == DeviceType.FreshAirHumiditySensor) { device = new HumiditySensor(); }
            else if (deviceType == DeviceType.OtaDevice || deviceType == DeviceType.OtaPanelDevice) { device = new OTADevice(); }
            else { return null; }
@@ -2501,11 +2674,9 @@
        public void SetNewDeviceMainKeys(CommonDevice device, Newtonsoft.Json.Linq.JObject jobject)
        {
            //设置设备主键类
            device.Time = jobject.Value<int>("Time");
            device.DeviceID = jobject.Value<int>("Device_ID");
            device.DeviceAddr = jobject.Value<string>("DeviceAddr");
            device.DeviceEpoint = jobject.Value<int>("Epoint");
            device.DataID = jobject.Value<int>("Data_ID");
        }
        #endregion
@@ -2574,23 +2745,27 @@
            //=========★★安防类传感器类(1300-2299)★★=========
            //这里是麦乐克的
            this.dicDeviceModelIdEnum["MULTI-GASE--EA07"] = "1300-1300-60000";//燃气传感器
            this.dicDeviceModelIdEnum["MULTI-MECI--EA01"] = "1301-1300-60000";//门窗磁传感器
            this.dicDeviceModelIdEnum["MULTI-FIRE--EA05"] = "1302-1300-60000";//烟雾传感器
            this.dicDeviceModelIdEnum["MULTI-MOTI--EA04"] = "1303-1300-60000";//红外传感器
            this.dicDeviceModelIdEnum["MULTI-WATE--EA02"] = "1304-1300-60000";//水浸传感器
            this.dicDeviceModelIdEnum["MULTI-BURO--EA06"] = "1305-1300-60000";//紧急按键
            this.dicDeviceModelIdEnum["MULTI-GASE--EA07"] = "1300-1200-60000";//燃气传感器
            this.dicDeviceModelIdEnum["MULTI-MECI--EA01"] = "1301-1200-60000";//门窗磁传感器
            this.dicDeviceModelIdEnum["MULTI-FIRE--EA05"] = "1302-1200-60000";//烟雾传感器
            this.dicDeviceModelIdEnum["MULTI-MOTI--EA04"] = "1303-1200-60000";//红外传感器
            this.dicDeviceModelIdEnum["MULTI-WATE--EA02"] = "1304-1200-60000";//水浸传感器
            this.dicDeviceModelIdEnum["MULTI-BURO--EA06"] = "1305-1200-60000";//紧急按键
            //这里是河东的
            this.dicDeviceModelIdEnum["MSG01/M-ZB.10"] = "1300-1300-60000";//燃气传感器
            this.dicDeviceModelIdEnum["MSDC01/M-ZB.10"] = "1301-1300-60000";//门窗磁传感器
            this.dicDeviceModelIdEnum["MSS01/M-ZB.10"] = "1302-1300-60000";//烟雾传感器
            this.dicDeviceModelIdEnum["MSPIR01/M-ZB.10"] = "1303-1300-60000";//红外传感器
            this.dicDeviceModelIdEnum["MSW01/M-ZB.10"] = "1304-1300-60000";//水浸传感器
            this.dicDeviceModelIdEnum["MBU01/M-ZB.10"] = "1305-1300-60000";//紧急按键
            this.dicDeviceModelIdEnum["MSG01/M-ZB.10"] = "1300-1200-60000";//燃气传感器
            this.dicDeviceModelIdEnum["MSDC01/M-ZB.10"] = "1301-1200-60000";//门窗磁传感器
            this.dicDeviceModelIdEnum["MSS01/M-ZB.10"] = "1302-1200-60000";//烟雾传感器
            this.dicDeviceModelIdEnum["MSPIR01/M-ZB.10"] = "1303-1200-60000";//红外传感器
            this.dicDeviceModelIdEnum["MSW01/M-ZB.10"] = "1304-1200-60000";//水浸传感器
            this.dicDeviceModelIdEnum["MBU01/M-ZB.10"] = "1305-1200-60000";//紧急按键
            this.dicDeviceModelIdEnum["MGCD01/ZB.10"] = "1306-1200-60000";//吸顶燃气传感器
            //PM2.5空气质量传感器 【该设备属于第三方设备,没有镜像ID】
            this.dicDeviceModelIdEnum["SZ_PM100"] = "1307-1200-60000";//PM2.5空气质量传感器
            //=========★★继电器类(2300-2499)★★=========
            this.dicDeviceModelIdEnum["MPR0310-ZB.10"] = "2300-2300-60001";//3路继电器小模块
            this.dicDeviceModelIdEnum["MFA01-ZB1.0"] = "2310-2300-60001";//方悦新风小模块
            this.dicDeviceModelIdEnum["MFA01-ZB.10"] = "2310-2300-60011";//方悦新风小模块
            //=========★★调光器类(2500-2799)★★=========
            this.dicDeviceModelIdEnum["MPD0101-ZB.10"] = "2500-2500-60007";//1路调光器小模块
@@ -2633,9 +2808,8 @@
            this.dicPictrueShard["ButtonPanel_SimpleFour"] = "ButtonPanel_Four";//简约4按键面板 沿用 4按键的图标
            this.dicPictrueShard["ButtonPanel_SimpleThree"] = "ButtonPanel_Three";//简约3按键面板 沿用 3按键的图标
            this.dicPictrueShard["ButtonPanel_SimpleTwo"] = "ButtonPanel_Two";//简约2按键面板 沿用 2按键的图标
            this.dicPictrueShard["IntelligentLocks_Sone"] = "IntelligentLocks_H06C";//S-one的门锁图片沿用H06C的图标
            this.dicPictrueShard["Relay_FangyueFreshAirModul"] = "Relay_ThreeLoad";//方悦新风小模块图片沿用3路继电器的图标
            this.dicPictrueShard["IntelligentLocks_Sone"] = "IntelligentLocks_H06C";//S-one的门锁图片 沿用 H06C的图标
            this.dicPictrueShard["Relay_FangyueFreshAirModul"] = "Relay_ThreeLoad";//方悦新风小模块图片 沿用 3路继电器的图标
        }
        #endregion
@@ -2775,6 +2949,15 @@
        /// 紧急按钮
        /// </summary>
        Sensor_EmergencyButton = 1305,
        /// <summary>
        /// 吸顶燃气传感器
        /// </summary>
        Sensor_CeilingGas = 1306,
        /// <summary>
        /// PM2.5空气质量传感器
        /// </summary>
        Sensor_PMTwoPointFive = 1307,
        /// <summary>
        /// 运动传感器
        /// </summary>
@@ -2926,9 +3109,17 @@
        /// </summary>
        A传感器 = 1200,
        /// <summary>
        /// PM2.5空气质量传感器
        /// </summary>
        APM2点5空气质量传感器 = 1307,
        /// <summary>
        /// 继电器(2300-2499)
        /// </summary>
        A继电器 = 2300,
        /// <summary>
        /// 新风
        /// </summary>
        A新风 = 2310,
        /// <summary>
        /// 调光器(2500-2799)
        /// </summary>
@@ -2984,7 +3175,7 @@
        /// <summary>
        /// 干接点
        /// </summary>
        A干接点 = 16
        A干接点 = 16,
    }
    #endregion