黄学彪
2019-12-20 23fb45dd846ed8b62304c408c6bbe64265d4ac8b
ZigbeeApp/Shared/Common/Device.cs
@@ -725,11 +725,12 @@
        }
        /// <summary>
        /// 根据MAC地址,获取全部回路的设备对象(已经排序)
        /// 根据MAC地址,获取全部回路的设备对象
        /// </summary>
        /// <param name="DeviceAddr">Mac地址</param>
        /// <param name="sort">是否排序</param>
        /// <returns></returns>
        public List<CommonDevice> GetDevicesByMac(string DeviceAddr)
        public List<CommonDevice> GetDevicesByMac(string DeviceAddr, bool sort = true)
        {
            var list = new List<CommonDevice>();
            if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false)
@@ -744,6 +745,11 @@
                    list.Add(device);
                }
            }
            if (sort == false)
            {
                return list;
            }
            //排序
            list.Sort((obj1, obj2) =>
            {
@@ -1216,7 +1222,7 @@
                return info;
            }
            //获取第三方设备的【设备类型】
            return this.GetNotHdlMyDeviceEnumInfo(listdevice);
            return this.GetNotHdlMyDeviceEnumInfo(listdevice, false);
        }
        /// <summary>
@@ -1246,7 +1252,7 @@
            else
            {
                //获取第三方设备的【设备类型】
                var myDeviceType = this.GetNotHdlMyDeviceEnumInfo(listDevice);
                var myDeviceType = this.GetNotHdlMyDeviceEnumInfo(listDevice, false);
                strName = Language.StringByID(myDeviceType.ConcreteTextId);
            }
            if (ApendFalge == true && listDevice[0].DriveCode > 0)
@@ -1314,9 +1320,29 @@
        /// <summary>
        /// 获取第三方设备的【设备类型】
        /// </summary>
        /// <param name="listdevice"></param>
        /// <param name="device">设备回路</param>
        /// <param name="margeSensor">
        /// <para>是否将所有类型的传感器都归为【传感器】,</para>
        /// <para>false的时候:【ConcreteType】和【ConcreteTextId】可能会有不同的值</para>
        /// <para>true的时候:【ConcreteType】统一为Sensor,【ConcreteTextId】统一为传感器</para>
        /// </param>
        /// <returns></returns>
        public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List<CommonDevice> listdevice)
        public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(CommonDevice device, bool margeSensor = true)
        {
            return this.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice>() { device }, margeSensor);
        }
        /// <summary>
        /// 获取第三方设备的【设备类型】(不建议使用)
        /// </summary>
        /// <param name="listdevice">Mac都一样的设备列表</param>
        /// <param name="margeSensor">
        /// <para>是否将所有类型的传感器都归为【传感器】,</para>
        /// <para>false的时候:【ConcreteType】和【ConcreteTextId】可能会有不同的值</para>
        /// <para>true的时候:【ConcreteType】统一为Sensor,【ConcreteTextId】统一为传感器</para>
        /// </param>
        /// <returns></returns>
        public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List<CommonDevice> listdevice, bool margeSensor = true)
        {
            var dicType = new Dictionary<DeviceType, CommonDevice>();
            foreach (CommonDevice device in listdevice)
@@ -1331,9 +1357,18 @@
            //1包含面板的话,当面板处理
            if (dicType.ContainsKey(DeviceType.OnOffSwitch) == true)
            {
                info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId200;
                info.BeloneType = DeviceBeloneType.A按键面板;
                info.ConcreteType = DeviceConcreteType.ButtonPanel;
                if (listdevice.Count > 1)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId200;
                    info.BeloneType = DeviceBeloneType.A按键面板;
                    info.ConcreteType = DeviceConcreteType.ButtonPanel;
                }
                else
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId16;
                    info.BeloneType = DeviceBeloneType.A干接点;
                    info.ConcreteType = DeviceConcreteType.DryContact;
                }
            }
            //3包含窗帘的话,当窗帘处理
            else if (dicType.ContainsKey(DeviceType.WindowCoveringDevice) == true)
@@ -1345,16 +1380,56 @@
            //4空气开关
            else if (dicType.ContainsKey(DeviceType.AirSwitch) == true)
            {
                //默认值
                info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4100;
                info.BeloneType = DeviceBeloneType.A空气开关;
                info.BeloneType = DeviceBeloneType.A智能空开;
                info.ConcreteType = DeviceConcreteType.AirSwitch;
                if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A开关)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13;
                    info.BeloneType = DeviceBeloneType.A开关;
                    info.ConcreteType = DeviceConcreteType.Switch;
                }
                else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A插座)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14;
                    info.BeloneType = DeviceBeloneType.A插座;
                    info.ConcreteType = DeviceConcreteType.Socket1;
                }
                else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A灯光)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15;
                    info.BeloneType = DeviceBeloneType.A灯光;
                    info.ConcreteType = DeviceConcreteType.Light;
                }
            }
            //5继电器
            else if (dicType.ContainsKey(DeviceType.OnOffOutput) == true)
            {
                //默认值
                info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2300;
                info.BeloneType = DeviceBeloneType.A继电器;
                info.ConcreteType = DeviceConcreteType.Relay;
                if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A开关)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13;
                    info.BeloneType = DeviceBeloneType.A开关;
                    info.ConcreteType = DeviceConcreteType.Switch;
                }
                else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A插座)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14;
                    info.BeloneType = DeviceBeloneType.A插座;
                    info.ConcreteType = DeviceConcreteType.Socket1;
                }
                else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A灯光)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15;
                    info.BeloneType = DeviceBeloneType.A灯光;
                    info.ConcreteType = DeviceConcreteType.Light;
                }
            }
            //6调光器
            else if (dicType.ContainsKey(DeviceType.DimmableLight) == true)
@@ -1401,16 +1476,23 @@
            //12包含传感器的话,当传感器处理
            else if (dicType.ContainsKey(DeviceType.IASZone) == true)
            {
                //设置传感器具体的类型
                info.BeloneType = DeviceBeloneType.A传感器;
                this.SetSensorDeviceSpecificType(ref info, listdevice);
                info.ConcreteType = DeviceConcreteType.Sensor;
                info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200;
                if (margeSensor == false)
                {
                    //设置传感器具体的类型
                    this.SetSensorDeviceSpecificType(ref info, listdevice);
                }
            }
            //13包含温度传感器的话
            else if (dicType.ContainsKey(DeviceType.TemperatureSensor) == true)
            {
                bool temperatrue = false;
                bool humidity = false;
                foreach (var device in listdevice)
                //获取全部的回路
                var listTemp = this.GetDevicesByMac(listdevice[0].DeviceAddr, false);
                foreach (var device in listTemp)
                {
                    if (device is TemperatureSensor)
                    {
@@ -1470,10 +1552,6 @@
        /// <param name="listdevice">设备对象</param>
        private void SetSensorDeviceSpecificType(ref DeviceEnumInfo info, List<CommonDevice> listdevice)
        {
            //默认名字:传感器
            info.ConcreteType = DeviceConcreteType.Sensor;
            info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200;
            //如果这个设备拥有多个回路的话,我也不知道怎么命名,只能给个默认名字
            if (listdevice.Count > 1)
            {
@@ -2314,7 +2392,7 @@
        //=========★★空气开关类(4100-????)★★=========
        /// <summary>
        /// 智能空气开关
        /// 智能空开
        /// </summary>
        AirSwitch = -4100,
        /// <summary>
@@ -2335,6 +2413,24 @@
        /// zigbee转buspro协议转换器
        /// </summary>
        Converter_ZbBuspro = 4201,
        //=========★★其他类(????-????)★★=========
        /// <summary>
        /// 干接点
        /// </summary>
        DryContact = -10000,
        /// <summary>
        /// 灯光(注意,它输入其他类,不是设备类型)
        /// </summary>
        Light = -10001,
        /// <summary>
        /// 插座
        /// </summary>
        Socket1 = -10002,
        /// <summary>
        /// 开关
        /// </summary>
        Switch = -10003,
    }
    /// <summary>
@@ -2380,9 +2476,9 @@
        /// </summary>
        A中继器 = 3900,
        /// <summary>
        /// 空气开关(4100-4199)
        /// 智能空开(4100-4199)
        /// </summary>
        A空气开关 = 4100,
        A智能空开 = 4100,
        /// <summary>
        /// 转换器(4200-4699)
        /// </summary>
@@ -2402,7 +2498,23 @@
        /// <summary>
        /// 湿度传感器
        /// </summary>
        A湿度传感器 = 12
        A湿度传感器 = 12,
        /// <summary>
        /// 开关
        /// </summary>
        A开关 = 13,
        /// <summary>
        /// 插座
        /// </summary>
        A插座 = 14,
        /// <summary>
        /// 灯光
        /// </summary>
        A灯光 = 15,
        /// <summary>
        /// 干接点
        /// </summary>
        A干接点 = 16
    }
    #endregion