mac
2024-07-25 3f6685c77beeb12baf840733fb890860f4c26e7c
HDL_ON/Entity/Function/Function.cs
@@ -100,7 +100,7 @@
        /// <returns></returns>
        public FunctionAttributes GetAttribute(string key)
        {
            var attr = attributes.Find((a) => a.key == key);
            var attr = GetFunctionAttributes().Find((a) => a.key == key);
            return attr;
        }
@@ -108,8 +108,9 @@
        /// 获取属性当前状态
        /// </summary>
        /// <param name="key"></param>
        /// <param name="defaultValue">默认值</param>
        /// <returns></returns>
        public string GetAttrState(string key , string defaultValue = "0")
        public string GetAttrState(string key, string defaultValue = "0")
        {
            //一级查询keyValue值
            var attrState = attributes.Find((s) => s.key == key.ToString());
@@ -120,7 +121,7 @@
            if (string.IsNullOrEmpty(attrState.state))
            {
                //二级查询keyValue值
                return GetOriginalState(key);
                return GetOriginalState(key, defaultValue);
            }
            return attrState.state;
        }
@@ -130,13 +131,14 @@
        /// 默认值:0
        /// </summary>
        /// <param name="key">语雀定义的属性值</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns></returns>
        public string GetOriginalState(string key)
        public string GetOriginalState(string key, string defaultValue)
        {
            var originalState = status.Find((s) => s.key == key.ToString());
            if (originalState == null || string.IsNullOrEmpty(originalState.value))
            {
                return "0";
                return defaultValue;
            }
            return originalState.value;
        }
@@ -171,6 +173,16 @@
                string iconPath = spk.Replace(".", "");
                switch (spk)
                {
                    case SPK.SensorDryContact2:
                    case SPK.OtherCommon:
                        iconPath = "sensordryContact";
                        break;
                    //case SPK.SensorLight:
                    //    iconPath = "lightswitch";
                    //    break;
                    case SPK.AirSwitchP3:
                        iconPath = "electricalbreaker";
                        break;
                    case SPK.PanelSocket:
                        iconPath = "electricalsocket";
                        break;
@@ -277,6 +289,10 @@
        /// </summary>
        public string extDevId = string.Empty;
        /// <summary>
        /// 物理设备(模块)型号
        /// </summary>
        public string omodel = string.Empty;
        /// <summary>
        /// 设备spk
        /// </summary>
        public string spk = "";
@@ -369,6 +385,39 @@
        /// </summary>
        public List<FunctionAttributes> attributes = new List<FunctionAttributes>();
        public List<FunctionAttributes> GetFunctionAttributes()
        {
            if (spk == SPK.GroupControl)
            {
                var list = new List<FunctionAttributes>();
                var gc = FunctionList.List.groupControls.Find((obj) => obj.sid == sid);
                if (gc != null)
                {
                    foreach (var temp in gc.sids)
                    {
                        var light = FunctionList.List.GetLightList().Find((obj) => obj.sid == temp.sid);
                        if (light != null)
                        {
                            foreach (var attr in light.attributes)
                            {
                                if (list.Find((obj) => obj.key == attr.key) == null)
                                {
                                    list.Add(attr);
                                }
                            }
                        }
                    }
                }
                return list;
            }
            else
            {
                return attributes;
            }
        }
        /// <summary>
        /// 房间ID列表
        /// 该功能添加到到房间列表
@@ -405,20 +454,52 @@
        /// </summary>
        public bool collect = false;
        private bool _online = false;
        /// <summary>
        /// 是否在线
        /// </summary>
        public bool online
        {
        private bool _online;
        public bool online {
            get
            {
                if (spk == SPK.AirSwitchP3|| spk == SPK.ElectricalTvHisense)
                {
                    return _online;
                }
                return true;
            }
            set
            {
                _online = value;
            }
        }
        ///// <summary>
        ///// 是否在线
        ///// </summary>
        //public bool online
        //{
        //    get
        //    {
        //        if(spk == SPK.AirSwitchP3)
        //        {
        //            return _online;
        //        }
        //        return true;
        //    }
        //    set
        //    {
        //        _online = value;
        //    }
        //}
        public bool isOnline()
        {
            if (spk == SPK.AirSwitchP3)
            {
                return online;
            }
            return true;
        }
        public void setOnine(bool isOnline)
        {
            online = isOnline;
        }
        /// <summary>
@@ -523,6 +604,14 @@
                SetAttrState(sta.key, sta.value);
            }
        }
        /// <summary>
        /// 功能列表排序
        /// </summary>
        public int FunctionOrderNumber = 9999;
        /// <summary>
        /// 房间列表排序
        /// </summary>
        public int RoomOrderNumber = 9999;
        /// <summary>
@@ -553,13 +642,27 @@
            new System.Threading.Thread(() =>
            {
                if (collect)
                {
                    result = ApiUtlis.Ins.HttpRequest.CollectDevice(deviceId).Code;
                if (spk == SPK.GroupControl) {
                    var groupControl = FunctionList.List.groupControls.Find((obj) => obj.sid == sid);
                    if (collect)
                    {
                        result = ApiUtlis.Ins.HttpRequest.CollectGroupControl(groupControl.userDeviceGroupControlId).Code;
                    }
                    else
                    {
                        result = ApiUtlis.Ins.HttpRequest.CancelCollectGroupControl(groupControl.userDeviceGroupControlId).Code;
                    }
                }
                else
                {
                    result = ApiUtlis.Ins.HttpRequest.CancelCollectDevice(deviceId).Code;
                    if (collect)
                    {
                        result = ApiUtlis.Ins.HttpRequest.CollectDevice(deviceId).Code;
                    }
                    else
                    {
                        result = ApiUtlis.Ins.HttpRequest.CancelCollectDevice(deviceId).Code;
                    }
                }
                //提示错误
                if (result != StateCode.SUCCESS)
@@ -668,9 +771,9 @@
        /// <summary>
        /// 保存房间绑定信息
        /// </summary>
        public void UpdataRoomIds()
        public async void UpdataRoomIds()
        {
            new System.Threading.Thread(() =>
            new System.Threading.Thread( () =>
            {
                var pack = ApiUtlis.Ins.HttpRequest.UpdataDevcieBindRoomInfo(this);
                //直接保存本地,
@@ -740,10 +843,82 @@
        public SceneFunction ConvertSceneFunction()
        {
            var sFunc = new SceneFunction();
            foreach (var attr in attributes)
            var list = new List<FunctionAttributes>();
            if (spk == SPK.GroupControl)
            {
                lock (list)
                {
                    var gc = FunctionList.List.groupControls.Find((obj) => obj.sid == sid);
                    if (gc != null)
                    {
                        foreach (var temp in gc.sids)
                        {
                            var tempDevice = FunctionList.List.GetLightList().Find((obj) => obj.sid == temp.sid);
                            if (tempDevice != null)
                            {
                                foreach (var attr in tempDevice.attributes)
                                {
                                    if (list.Find((obj) => obj.key == attr.key) == null)
                                    {
                                        list.Add(attr);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (spk == SPK.MusicStandard || spk == SPK.AvMusic)
            {
                list.Add(new FunctionAttributes
                {
                    key = FunctionAttributeKey.OnOff,
                    curValue = string.Empty,
                });
                list.Add(new FunctionAttributes
                {
                    key = FunctionAttributeKey.Volume,
                    curValue = string.Empty,
                });
                list.Add(new FunctionAttributes
                {
                    key = FunctionAttributeKey.SongName,
                    curValue = string.Empty,
                });
            }
            else if (spk == SPK.ElectricalTvHisense)
            {
                list.Add(new FunctionAttributes
                {
                    key = FunctionAttributeKey.OnOff,
                    curValue = string.Empty,
                });
                list.Add(new FunctionAttributes
                {
                    key = FunctionAttributeKey.SetVolume,
                    curValue = string.Empty,
                });
                list.Add(new FunctionAttributes
                {
                    key = FunctionAttributeKey.Signal,
                    curValue = string.Empty,
                });
            }
            else
            {
                list.AddRange(attributes);
            }
            foreach (var attr in list)
            {
                if(attr.key == FunctionAttributeKey.ColorfulBegin || attr.key == FunctionAttributeKey.ColorfulEnd || attr.key == FunctionAttributeKey.ColorfulTime)
                {
                    continue;
                }
                //窗帘同时发送开关跟百分比会有问题,
                if(spk == SPK.CurtainRoller || spk == SPK.CurtainTrietex)
                if(spk == SPK.CurtainRoller || spk == SPK.CurtainTrietex || spk == SPK.CurtainDream)
                {
                    if (attr.key == FunctionAttributeKey.OnOff)
                    {
@@ -752,10 +927,69 @@
                            continue;
                        }
                    }
                }else if (spk == SPK.GroupControl)
                {
                    sFunc.type = "5";
                }
                switch (attr.key)
                {
                    case FunctionAttributeKey.SetTemp:
                        var tt = GetAttribute(FunctionAttributeKey.TempType);
                        if (tt == null)
                        {
                            attr.unit = "°C";
                        }
                        else
                        {
                            if (tt.unit == string.Empty)
                            {
                                attr.unit = "°C";
                            }
                            else
                            {
                                if (tt.unit == "C")
                                {
                                    attr.unit = "°C";
                                }
                                else if (tt.unit == "F")
                                {
                                    attr.unit = "°F";
                                }
                                else
                                {
                                    attr.unit = tt.unit;
                                }
                            }
                        }
                        break;
                    case FunctionAttributeKey.RoomTemp:
                        attr.unit = "°C";
                        var tempType = attributes.Find((obj) => obj.key == FunctionAttributeKey.TempType);
                        if (tempType != null)
                        {
                            attr.unit = tempType.curValue.ToString();
                        }
                        break;
                    case FunctionAttributeKey.Percent:
                    case FunctionAttributeKey.Brightness:
                        attr.unit = "%";
                        break;
                    case FunctionAttributeKey.CCT:
                        attr.unit = "K";
                        break;
                    case FunctionAttributeKey.Angle:
                        attr.unit = "°";
                        break;
                }
                switch (attr.key)
                {
                    case FunctionAttributeKey.SongName:
                    case FunctionAttributeKey.Volume:
                    case FunctionAttributeKey.SetVolume:
                    case FunctionAttributeKey.Signal:
                    case FunctionAttributeKey.OnOff:
                    case FunctionAttributeKey.Brightness:
                    case FunctionAttributeKey.Mode:
@@ -765,11 +999,15 @@
                    case FunctionAttributeKey.CCT:
                    case FunctionAttributeKey.RGB:
                    case FunctionAttributeKey.Angle:
                    case FunctionAttributeKey.Colorful:
                    case FunctionAttributeKey.ColorfulBegin:
                    case FunctionAttributeKey.ColorfulEnd:
                    case FunctionAttributeKey.ColorfulTime:
                    case "security":
                        //case FunctionAttributeKey.FadeTime:
                        if (attr.curValue.ToString() == "{}")
                        {
                            if (attr.key == FunctionAttributeKey.OnOff)
                            if (attr.key == FunctionAttributeKey.OnOff || attr.key == FunctionAttributeKey.Colorful)
                            {
                                attr.curValue = "off";
                            }
@@ -808,13 +1046,16 @@
                            {
                                vv = 26;
                            }
                            sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = Convert.ToInt32(vv).ToString(), max = attr.max, min = attr.min });
                            sFunc.status.Add(new SceneFunctionStatus() {
                                UintString = attr.unit,
                                key = attr.key, value = Convert.ToInt32(vv).ToString(), max = attr.max, min = attr.min }) ;
                        }
                        else
                        {
                            sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = attr.curValue.ToString(), max = attr.max, min = attr.min });
                            sFunc.status.Add(new SceneFunctionStatus() {
                                UintString = attr.unit,
                                key = attr.key, value = attr.curValue.ToString(), max = attr.max, min = attr.min });
                        }
                        break;
                }
            }
@@ -826,6 +1067,11 @@
        /// 更新时间
        /// </summary>
        public DateTime refreshTime = DateTime.MinValue;
        /// <summary>
        /// 最后更新状态的时间
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public DateTime updateTime = DateTime.MinValue;
        /// <summary>
        /// 获取本地控制数据
@@ -960,6 +1206,10 @@
        /// 云端负责生成
        /// </summary>
        public string deviceId = "0";
        /// <summary>
        /// 在线状态
        /// </summary>
        public bool online = true;
        public List<AttributesStatus> status = new List<AttributesStatus>();
    }
    /// <summary>
@@ -1019,6 +1269,10 @@
        /// 当前值
        /// </summary>
        public object curValue = new object();
        /// <summary>
        /// 属性单位
        /// </summary>
        public string unit=string.Empty;
    }
    /// <summary>
@@ -1026,6 +1280,79 @@
    /// </summary>
    public static class FunctionAttributeKey
    {
        #region 三相空开属性
        /// <summary>
        /// A相功率
        /// </summary>
        public const string PowerA = "power_a";
        /// <summary>
        /// B相功率
        /// </summary>
        public const string PowerB = "power_b";
        /// <summary>
        /// C相功率
        /// </summary>
        public const string PowerC = "power_c";
        /// <summary>
        /// A相电压
        /// </summary>
        public const string VoltageA = "voltage_a";
        /// <summary>
        /// B相电压
        /// </summary>
        public const string VoltageB = "voltage_b";
        /// <summary>
        /// C相电压
        /// </summary>
        public const string VoltageC = "voltage_c";
        /// <summary>
        /// A相电流
        /// </summary>
        public const string CurrentA = "current_a";
        /// <summary>
        /// B相电流
        /// </summary>
        public const string CurrentB = "current_b";
        /// <summary>
        /// C相电流
        /// </summary>
        public const string CurrentC = "current_c";
        /// <summary>
        /// A相温度
        /// </summary>
        public const string TempA = "temp_a";
        /// <summary>
        /// B相温度
        /// </summary>
        public const string TempB = "temp_b";
        /// <summary>
        /// C相温度
        /// </summary>
        public const string TempC = "temp_c";
        /// <summary>
        /// 过流值
        /// </summary>
        public const string MaxCurrent = "max_current";
        /// <summary>
        /// 过温值
        /// </summary>
        public const string MaxTemp = "max_temp";
        /// <summary>
        /// A相电量
        /// </summary>
        public const string ElectricityA = "electricity_a";
        /// <summary>
        /// B相电量
        /// </summary>
        public const string ElectricityB = "electricity_b";
        /// <summary>
        /// C相电量
        /// </summary>
        public const string ElectricityC = "electricity_c";
        #endregion
        public const string _null = "";
        /// <summary>
        /// 安防布防状态
@@ -1039,6 +1366,22 @@
        /// 亮度
        /// </summary>
        public const string Brightness = "brightness";
        /// <summary>
        /// 炫彩开关
        /// </summary>
        public const string Colorful = "colorful";
        /// <summary>
        /// 炫彩开启颜色
        /// </summary>
        public const string ColorfulBegin = "colorful_begin";
        /// <summary>
        /// 炫彩结束颜色
        /// </summary>
        public const string ColorfulEnd = "colorful_end";
        /// <summary>
        /// 炫彩运行时间
        /// </summary>
        public const string ColorfulTime = "colorful_time";
        /// <summary>
        /// 颜色
        /// </summary>
@@ -1151,7 +1494,12 @@
        public const string Temperature = "temperature";
        public const string Hcho = "hcho";
        public const string Humidity = "humidity";
        /// <summary>
        /// 照度
        /// </summary>
        public const string Illuminance = "illuminance";
        public const string Pm25 = "pm25";
        public const string Pm10 = "pm10";
        public const string Tvoc = "tvoc";
        /// <summary>
        /// 状态,传感器
@@ -1289,6 +1637,32 @@
        /// </summary>
        public const string TotalElectricity = "total_electricity";
        /// <summary>
        /// 海信tv音量
        /// </summary>
        public const string SetVolume = "set_volume";
        /// <summary>
        /// 海信tv信号源(0:LiveTV;2:PS;3:HDMI_1;4:HDMI_2;5:HDMI_3;6:HDMI_4;11:AV;)
        /// </summary>
        public const string Signal = "signal";
        /// <summary>
        /// 音乐音量
        /// </summary>
        public const string Volume = "volume";
        /// <summary>
        /// 歌曲名
        /// </summary>
        public const string SongName = "song_name";
        /// <summary>
        /// 列表名
        /// </summary>
        public const string PlaylistName = "playlist_name";
        /// <summary>
        /// 播放路径
        /// </summary>
        public const string Url = "url";
    }
    /// <summary>
@@ -1348,9 +1722,17 @@
    public static class SPK
    {
        /// <summary>
        /// 群控(自定义)
        /// </summary>
        public const string GroupControl = "groupControl";
        /// <summary>
        /// 通用开关
        /// </summary>
        public const string OtherCommon = "other.common";
        /// <summary>
        /// 序列
        /// </summary>
        public const string CommonSeries = "other.series";
        /// <summary>
        /// 大华摄像头
        /// </summary>
@@ -1374,10 +1756,7 @@
        /// 门锁
        /// </summary>
        public const string DoorLock = "security.door";
        /// <summary>
        /// 萤石视屏门锁
        /// </summary>
        public const string VideoDoorLock = "security.door.ezviz";
        /// <summary>
        /// 门锁spk列表
        /// </summary>
@@ -1388,10 +1767,30 @@
            list.Add(DoorLock);
            return list;
        }
        /// <summary>
        /// 猫眼(旧spk)
        /// </summary>
        public const string Peephole = "peephole";
        /// <summary>
        /// 猫眼(新spk 暂时没用)
        /// </summary>
        //public const string PeepholeEz = "security.peephole.ez";
        /// <summary>
        /// 萤石视频门锁
        /// </summary>
        public const string VideoDoorLock="security.door.ezviz";
        /// <summary>
        /// 萤石摄像头
        /// </summary>
        public const string Ev_Ipcam = "security.ipcam.ez";
        /// <summary>
        /// 影音中控
        /// </summary>
        public const string AvZkAiks = "av.zk.aiks";
        /// <summary>
        /// 萤石视频门锁spk列表
        /// </summary>
@@ -1400,6 +1799,31 @@
        {
            var list = new List<string>();
            list.Add(VideoDoorLock);
            return list;
        }
        /// <summary>
        /// 影音中控spk列表
        /// </summary>
        /// <returns></returns>
        public static List<string> GetVideoControlsSPKList()
        {
            var list = new List<string>
            {
                AvZkAiks
            };
            return list;
        }
        /// <summary>
        /// 萤石摄像头spk列表
        /// </summary>
        /// <returns></returns>
        public static List<string> GetEvIpcamSPKList()
        {
            var list = new List<string>();
            list.Add(Ev_Ipcam);
            return list;
        }
@@ -1494,7 +1918,7 @@
        public const string HvacAC = "hvac.ac";
        /// <summary>
        /// 毛细管空调
        /// </summary>
        /// </summaryc
        public const string HvacCac = "hvac.cac";
        /// <summary>
@@ -1594,6 +2018,8 @@
        {
            var spkList = new List<string>();
            spkList.Add(ElectricEnergy);
            spkList.Add(AirSwitch);
            spkList.Add(AirSwitchP3);
            return spkList;
        }
        #endregion
@@ -1632,6 +2058,10 @@
        /// (红外移动传感器)
        /// </summary>
        public const string SensorPir = "sensor.pir";
        /// <summary>
        /// 人体存在传感器
        /// </summary>
        public const string SensorPirHold = "sensor.pir_hold";
        /// <summary>
        /// (门窗传感器)
        /// </summary>
@@ -1687,6 +2117,7 @@
            var spkList = new List<string>();
            //spkList.Add(SensorLight);
            spkList.Add(SensorPir);
            spkList.Add(SensorPirHold);
            spkList.Add(SensorHelp);
            spkList.Add(SensorDoorWindow);
            spkList.Add(SensorSmoke);
@@ -1780,6 +2211,7 @@
            spkList.Add(SensorEnvironment2);
            spkList.Add(SensorEnvironment3);
            spkList.Add(SensorHcho);
            spkList.Add(SensorLight);
            return spkList;
        }
        /// <summary>
@@ -1796,6 +2228,7 @@
            spkList.Add(SensorTVOC);
            spkList.Add(SensorHumidity);
            spkList.Add(SensorHcho);
            spkList.Add(SensorLight);
            return spkList;
        }
@@ -1809,6 +2242,7 @@
            spkList.Add(SensorEnvironment); spkList.Add(SensorEnvironmentHailin);
            spkList.Add(SensorEnvironment2);
            spkList.Add(SensorEnvironment3);
            return spkList;
        }
@@ -1816,6 +2250,10 @@
        #endregion
        #region 家电
        /// <summary>
        /// 海信电视
        /// </summary>
        public const string ElectricalTvHisense = "electrical.tv.hisense";
        /// <summary>
        /// 家电、插座
        /// </summary>
@@ -1868,7 +2306,7 @@
        /// <summary>
        /// 红外热水器
        /// </summary>
        public const string HeaterIr = " ir.water_heater";
        public const string HeaterIr = "ir.water_heater";
        /// <summary>
        /// 红外风扇
        /// </summary>
@@ -1877,6 +2315,10 @@
        /// 智能空开
        /// </summary>
        public const string AirSwitch = "electrical.breaker";
        /// <summary>
        /// 三相智能空开
        /// </summary>
        public const string AirSwitchP3 = "electrical.breakerP3";
        #region 涂鸦
        /// <summary>
@@ -1930,6 +2372,7 @@
            spkList.Add(ElectricTuyaWaterValve);
            spkList.Add(ElectricTuyaWaterValve2);
            spkList.Add(AirSwitch);
            spkList.Add(ElectricalTvHisense);
            return spkList;
        }