JLChen
2021-01-11 5a5a2b696866f947b6025d26c3302e8ffef46435
Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs
@@ -59,11 +59,13 @@
                                            if (btn.Tag.ToString () == DeviceType.LightEnergySocket.ToString () + "_Voltage" || btn.Tag.ToString () == DeviceType.LightEnergySwitch.ToString () + "_Voltage") {
                                                btn.Text = energy.ToString () + " W";
                                            }
                                        } else if (updataType == 11) {
                                            if (btn.Tag.ToString () == DeviceType.LightEnergySocket.ToString () + "_Electric" || btn.Tag.ToString () == DeviceType.LightEnergySwitch.ToString () + "_Electric") {
                                                btn.Text = ((double)(Convert.ToDouble (energy) / 10)).ToString () + " kw.h";
                                            }
                                        }
                                        //2020-07-01 客户提出隐藏kwh
                                        //else if (updataType == 11) {
                                        //    if (btn.Tag.ToString () == DeviceType.LightEnergySocket.ToString () + "_Electric" || btn.Tag.ToString () == DeviceType.LightEnergySwitch.ToString () + "_Electric") {
                                        //        btn.Text = ((double)(Convert.ToDouble (energy) / 10)).ToString () + " kw.h";
                                        //    }
                                        //}
                                    }
                                }
                            }
@@ -214,7 +216,7 @@
                        }
                    });
                } catch (Exception ex) {
                    Console.WriteLine (ex.Message);
                    Utlis.WriteLine (ex.Message);
                } finally {
                    //Application.RunOnMainThread (() => {
                    //    MainPage.Loading.Hide ();
@@ -230,7 +232,7 @@
        {
            foreach (var thread in UserMiddle.updateSensorhreadList) {
                thread.Abort ();
                Console.WriteLine ("abortThread");
                Utlis.WriteLine ("abortThread");
            }
            UserMiddle.updateSensorhreadList.Clear ();
            EnergtLightList.Clear ();
@@ -393,20 +395,28 @@
                    MainPage.Loading.Start ();
                    System.Threading.Tasks.Task.Run (() => {
                        if (UserConfig.Instance.HomeLists.Count == 0) {
                            var requestObj2 = new GetHomePagerObj ();
                            requestObj2.ReqDto.LoginAccessToken = MainPage.LoginUser.LoginTokenString;
                            //var requestObj2 = new HomeListObj ();
                            var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2);
                            var revertObj2 = MainPage.RequestHttps (API.GetHomePager, requestJson2);
                            if (revertObj2.StateCode.ToUpper() == "SUCCESS") {
                                var mResidenceRes = Newtonsoft.Json.JsonConvert.DeserializeObject<ResidenceRes> (revertObj2.ResponseData.ToString ());
                            //var requestObj2 = new GetHomePagerObj ();
                            //requestObj2.ReqDto.LoginAccessToken = MainPage.LoginUser.LoginTokenString;
                            ////var requestObj2 = new HomeListObj ();
                            //var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2);
                            //var revertObj2 = MainPage.RequestHttps (API.GetHomePager, requestJson2);
                            //if (revertObj2.StateCode.ToUpper() == StateCode.SUCCESS) {
                            //    var mResidenceRes = Newtonsoft.Json.JsonConvert.DeserializeObject<ResidenceRes> (revertObj2.ResponseData.ToString ());
                                if (mResidenceRes.PageData != null && mResidenceRes.PageData.Count > 0) {
                                    UserConfig.Instance.HomeLists = mResidenceRes.PageData;
                                    UserConfig.Instance.SaveUserConfig ();
                                }
                            //    if (mResidenceRes.PageData != null && mResidenceRes.PageData.Count > 0) {
                            //        UserConfig.Instance.HomeLists = mResidenceRes.PageData;
                            //        UserConfig.Instance.SaveUserConfig ();
                            //    }
                            //} else {
                            //    ShowGetHomePagerErrorInfo (revertObj2.StateCode);
                            //}
                            //获取住宅列表
                            var revertObjCode = HttpServerRequest.Current.GetHomePager ();
                            if (revertObjCode == StateCode.SUCCESS) {
                            } else {
                                ShowGetHomePagerErrorInfo (revertObj2.StateCode);
                                IMessageCommon.Current.ShowErrorInfoAlter (revertObjCode);
                            }
                        }
                        Application.RunOnMainThread (() => {
@@ -455,7 +465,7 @@
                                rowView.AddChidren (btnPoint);
                                var btnName = new Button () {
                                    Width = Application.GetRealWidth (550),
                                    Width = Application.GetRealWidth (300),
                                    Text = homeTemp.Name,
                                    TextAlignment = TextAlignment.CenterLeft,
                                    X = Application.GetRealWidth (90),
@@ -478,7 +488,7 @@
                                                System.IO.FileInfo fileInfo = new System.IO.FileInfo (IO.FileUtils.RootPath + fileName);
                                                if (fileInfo.Exists) {
                                                    fileInfo.MoveTo (oldRegionRootPath + fileName);
                                                    Console.WriteLine ("move file : " + fileName);
                                                    Utlis.WriteLine ("move file : " + fileName);
                                                }
                                                index++;
                                                Application.RunOnMainThread (() => {
@@ -501,14 +511,14 @@
                                                new Alert ("", Language.StringByID (R.MyInternationalizationString.SwitchRegionSuccessfully),
                                                          Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                                this.InitRoomView (roomFilePath);
                                                EquipmentPublicClass.CheckLinkRemote (2);
                                                EquipmentPublicClass.CheckLinkRemote (UserConfig.Instance.internetStatus);
                                            });
                                        } catch (Exception ex) {
                                            Application.RunOnMainThread (() => {
                                                new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet),
                                                           Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                            });
                                            Console.WriteLine (ex.Message);
                                            Utlis.WriteLine (ex.Message);
                                        } finally {
                                            Application.RunOnMainThread (() => {
                                                MainPage.Loading.Hide ();
@@ -661,24 +671,21 @@
                    CommonPage.RefreshAir = () => {
                        var airQualityR = CommonPage.AirQuality;
                        if (airQualityR != null &&
                            airQualityR.data != null &&
                            airQualityR.data.city != null &&
                            airQualityR.data.condition != null) {
                            AirQCity = btnCity.Text = airQualityR.data.city.name;
                            AirQTemp = btnTemp.Text = airQualityR.data.condition.temp + "°";
                            if (airQualityR.data.aqi != null) {
                                AirQAirPM25 = btnPM25.Text = "PM2.5  " + airQualityR.data.aqi.pm25;
                        if (airQualityR != null) {
                            AirQCity = btnCity.Text = airQualityR.city;
                            AirQTemp = btnTemp.Text = airQualityR.airQTemp + "°";
                            if (airQualityR.airQAirPM25 != null) {
                                AirQAirPM25 = btnPM25.Text = "PM2.5  " + airQualityR.airQAirPM25;
                            } else {
                                if (string.IsNullOrEmpty (airQualityR.data.condition.condition))
                                    btnPM25.Text = airQualityR.data.condition.condition;
                                if (string.IsNullOrEmpty (airQualityR.airQAirWeather))
                                    btnPM25.Text = airQualityR.airQAirWeather;
                            }
                            AirQHumidity = btnHumidity.Text = airQualityR.data.condition.humidity;
                            AirQHumidity = btnHumidity.Text = airQualityR.airQHumidity;
                            AirQHumidityIcon = btnHumidityIcon.UnSelectedImagePath = "AirQuality/HumidityIcon.png";
                            AirQAirPM25Icon = btnPM25Icon.UnSelectedImagePath = "AirQuality/PM25Icon.png";
                            AirLineNullBackgroundColor = btnAirLineNull.BackgroundColor = SkinStyle.Current.White20Transparent;
                            btnAirLineNull.BackgroundColor = SkinStyle.Current.White20Transparent;
                            #region
                            switch (airQualityR.data.condition.condition) {
                            switch (airQualityR.airQAirWeather) {
                            case "晴":
                            case "Sunny":
                            case "晴天":
@@ -848,6 +855,7 @@
                            #endregion
                        }
                    };
                    CommonPage.RefreshAir ();
                } else {
@@ -916,13 +924,16 @@
                        SelectedTextColor = SkinStyle.Current.TextColor1,
                    };
                    acRowView.AddChidren (tempDeviceName);
                    //2020-08-28 增加长按修改设备备注
                    ButtonNameAddMouseLongEventHandler (tempDeviceName, devcieCommon);
                    tempDeviceName.MouseUpEventHandler += openACControlPageEvent;
                    Button btnMode = new Button () {
                        X = Application.GetRealWidth (20),
                        Y = Application.GetRealHeight (40),
                        Width = Application.GetRealWidth (100),
                        Height = Application.GetRealHeight (100),
                        Width = Application.GetMinRealAverage (100),
                        Height = Application.GetMinRealAverage (100),
                        Tag = "Mode"
                    };
                    acRowView.AddChidren (btnMode);
@@ -932,8 +943,8 @@
                    Button btnWind = new Button () {
                        X = btnMode.Right + Application.GetRealWidth (0),
                        Y = Application.GetRealHeight (40),
                        Width = Application.GetRealWidth (100),
                        Height = Application.GetRealHeight (100),
                        Width = Application.GetMinRealAverage (100),
                        Height = Application.GetMinRealAverage (100),
                        Tag = "Wind"
                    };
                    acRowView.AddChidren (btnWind);
@@ -965,13 +976,17 @@
                    };
                    acRowView.AddChidren (tempSiwtch);
                    tempSiwtch.MouseUpEventHandler += (sender3, e3) => {
                        tempSiwtch.IsSelected = !tempSiwtch.IsSelected;
                        ac.Power = tempSiwtch.IsSelected ? (byte)1 : (byte)0;
                        if (ac.Type == DeviceType.ACPanel) {
                            Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 3, ac.Power, ac.LoopID });
                        } else if (ac.Type == DeviceType.ACDevice || ac.Type == DeviceType.HVAC || ac.Type == DeviceType.ACInfrared) {
                            Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] { ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature, ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature, ac.ChuShiTemperature, ac.RealModeAndFanSpeed, ac.Power, ac.SetMode, ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
                        }
                        //tempSiwtch.IsSelected = !tempSiwtch.IsSelected;
                        //ac.Power = tempSiwtch.IsSelected ? (byte)1 : (byte)0;
                        SendControlAc (ac, tempSiwtch.IsSelected ? (byte)0 : (byte)1);
                        //if (ac.Type == DeviceType.ACPanel) {
                        //    //2020-02-10 待修改
                        //    Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 3, ac.Power, ac.LoopID });
                        //} else if (ac.Type == DeviceType.ACDevice || ac.Type == DeviceType.HVAC || ac.Type == DeviceType.ACInfrared) {
                        //    //2020-02-10 待修改
                        //    Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] { ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature, ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature, ac.ChuShiTemperature, ac.RealModeAndFanSpeed, ac.Power, ac.SetMode, ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode });
                        //}
                    };
                    if (0 < ac.Power) {
@@ -1025,6 +1040,10 @@
                        IsMoreLines = true
                    };
                    fhRowView.AddChidren (tempDeviceName);
                    //2020-08-28 增加长按修改设备备注
                    ButtonNameAddMouseLongEventHandler (tempDeviceName, devcieCommon);
                    tempDeviceName.MouseUpEventHandler += (sender2, e2) => {
                        UserFHPage fhView = new UserFHPage (fh, room);
                        if (roomFilePath == Room.FavoriteRoom) {
@@ -1077,8 +1096,10 @@
                        fh.Status = tempSiwtch.IsSelected ? (byte)1 : (byte)0;
                        System.Threading.Tasks.Task.Run (() => {
                            if (fh.Type == DeviceType.FoolHeatPanel) {
                                //2020-02-10 待修改
                                Control.ControlBytesSend (Command.InstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 20, fh.Status, fh.LoopID });
                            } else if (fh.Type == DeviceType.FoolHeat) {
                                //2020-02-10 待修改
                                fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.Switch);
                            }
                        });
@@ -1141,6 +1162,13 @@
                        };
                        DeviceRowView.AddChidren (btnName);
                        //2020-08-28 增加长按修改设备备注
                        ButtonNameAddMouseLongEventHandler (btnName, devcieCommon);
                        //btnName.MouseLongEventHandler += (sender, e)=>{
                        //    RemarkDeviceName (devcieCommon, SimpleControl.CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (devcieCommon)), btnName);
                        //};
                        Button tempSwitch = new Button () {
                            Width = Application.GetMinRealAverage (90),
                            Height = Application.GetMinRealAverage (53),
@@ -1175,14 +1203,17 @@
                            };
                            tempSwitch.IsSelected = fanModule.Switch == 0 ? false : true;
                            tempSwitch.MouseUpEventHandler += (sender3, e3) => {
                                tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                if (tempSwitch.IsSelected) {
                                    fanModule.Switch = fanModule.WindSpeed;
                                } else {
                                    fanModule.Switch = 0;
                                }
                                Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, fanModule.Switch });
                                IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
                                //tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                //if (tempSwitch.IsSelected) {
                                //    fanModule.Switch = fanModule.WindSpeed;
                                //} else {
                                //    fanModule.Switch = 0;
                                //}
                                //Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, fanModule.Switch });
                                int mSetSwitch = tempSwitch.IsSelected ? 0 : fanModule.WindSpeed;
                                SendControl.SendControlSetSingleLight (fanModule, new byte [] { fanModule.LoopID, (byte)mSetSwitch });
                                //IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
                            };
                            #endregion
                        } else if (devcieCommon.Type == DeviceType.LightDimming || devcieCommon.Type == DeviceType.LightDALI) {
@@ -1265,18 +1296,23 @@
                            };
                            tempSwitch.MouseUpEventHandler += (sender3, e3) => {
                                tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                if (tempSwitch.IsSelected) {
                                    Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.LoopID, dimming.LastOpenBrightness, 0, 0 });
                                    tempLightSeekBar.Progress = dimming.CurrentBrightness = dimming.LastOpenBrightness;
                                    tempLightSeekBar.ThumbColor = SkinStyle.Current.SelectedColor;
                                //tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                if (!tempSwitch.IsSelected) {
                                    SendControl.SendControlSetSingleLight (dimming, new byte [] { dimming.LoopID, dimming.LastOpenBrightness, 0, 0 });
                                    //Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.LoopID, dimming.LastOpenBrightness, 0, 0 });
                                    //tempLightSeekBar.Progress = dimming.CurrentBrightness = dimming.LastOpenBrightness;
                                    //tempLightSeekBar.ThumbColor = SkinStyle.Current.SelectedColor;
                                    //dimming.CurrentBrightness = dimming.LastOpenBrightness;
                                } else {
                                    Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.LoopID, 0, 0, 0 });
                                    tempLightSeekBar.Progress = 0;
                                    tempLightSeekBar.ThumbColor = SkinStyle.Current.ThumbColor;
                                    dimming.CurrentBrightness = 0;
                                    SendControl.SendControlSetSingleLight (dimming, new byte [] { dimming.LoopID, 0, 0, 0 });
                                    //Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.LoopID, 0, 0, 0 });
                                    //tempLightSeekBar.Progress = 0;
                                    //tempLightSeekBar.ThumbColor = SkinStyle.Current.ThumbColor;
                                    //dimming.CurrentBrightness = 0;
                                }
                                btnValues.Text = dimming.CurrentBrightness + "%";
                                //btnValues.Text = dimming.CurrentBrightness + "%";
                            };
                            if (dimming.CurrentBrightness > 0) {
                                tempSwitch.IsSelected = true;
@@ -1352,7 +1388,7 @@
                                };
                                proessView.AddChidren (btnMaxBrightness);
                                horizontalSeekBar.ProgressChanged += (sender2, e4) => {
                                    Console.WriteLine (DateTime.Now.ToString ());
                                    Utlis.WriteLine (DateTime.Now.ToString ());
                                    btnMaxBrightness.Text = horizontalSeekBar.Progress + "%";
                                    System.Threading.Tasks.Task.Run (() => {
                                        if ((System.DateTime.Now - (DateTime)(horizontalSeekBar.Tag)).TotalMilliseconds < 100) {
@@ -1376,11 +1412,15 @@
                            tempSwitch.IsSelected = dimming.CurrentBrightness > 0 ? true : false;
                            tempSwitch.MouseUpEventHandler += (sender3, e3) => {
                                tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                if (tempSwitch.IsSelected) {
                                    Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 100, 0, 0 });
                                //tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                if (!tempSwitch.IsSelected) {
                                    SendControl.SendControlSetSingleLight (dimming, new byte [] { dimming.PhysicsLoopID, 100, 0, 0 });
                                    //Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 100, 0, 0 });
                                } else {
                                    Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 0, 0, 0 });
                                    SendControl.SendControlSetSingleLight (dimming, new byte [] { dimming.PhysicsLoopID, 0, 0, 0 });
                                    //Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 0, 0, 0 });
                                }
                            };
                            #endregion
@@ -1399,13 +1439,16 @@
                            btnIcon.SelectedImagePath = "Item/Light.png";
                            tempSwitch.IsSelected = dimming.CurrentBrightness > 0 ? true : false;
                            tempSwitch.MouseUpEventHandler += (sender3, e3) => {
                                tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                if (tempSwitch.IsSelected) {
                                    dimming.CurrentBrightness = 100;
                                    Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 100, 0, 0 });
                                //tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                if (!tempSwitch.IsSelected) {
                                    //dimming.CurrentBrightness = 100;
                                    SendControl.SendControlSetSingleLight (dimming, new byte [] { dimming.PhysicsLoopID, 100, 0, 0 });
                                    //Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 100, 0, 0 });
                                } else {
                                    dimming.CurrentBrightness = 0;
                                    Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 0, 0, 0 });
                                    //dimming.CurrentBrightness = 0;
                                    SendControl.SendControlSetSingleLight (dimming, new byte [] { dimming.PhysicsLoopID, 0, 0, 0 });
                                    //Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 0, 0, 0 });
                                }
                            };
                            #endregion
@@ -1483,6 +1526,7 @@
                                                lightLigicBytes [6] = e2 [0];
                                                lightLigicBytes [7] = e2 [1];
                                                lightLigicBytes [8] = e2 [2];
                                                //2020-02-10 待修改
                                                Control.ControlBytesSend (Command.SetLogicLoopColor, rgbLight.SubnetID, rgbLight.DeviceID, lightLigicBytes, SendCount.Zero);
                                                colorChangeTime = DateTime.Now;
                                                btnColor.BackgroundColor = (uint)(0xFF000000 + lightLigicBytes [6] * 256 * 256 + lightLigicBytes [7] * 256 + lightLigicBytes [8]);
@@ -1785,19 +1829,24 @@
                            tempSwitch.IsSelected = rgbLight.CurrentBrightness > 0 ? true : false;
                            tempSwitch.MouseUpEventHandler += (sender3, e3) => {
                                tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                if (tempSwitch.IsSelected) {
                                    rgbLight.CurrentBrightness = 100;
                                    Control.ControlBytesSend (Command.SetSingleLight, rgbLight.SubnetID, rgbLight.DeviceID, new byte [] { rgbLight.LoopID, 100, 0, 0 });
                                //tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                if (!tempSwitch.IsSelected) {
                                    //rgbLight.CurrentBrightness = 100;
                                    SendControl.SendControlSetSingleLight (rgbLight, new byte [] { rgbLight.LoopID, 100, 0, 0 });
                                    //Control.ControlBytesSend (Command.SetSingleLight, rgbLight.SubnetID, rgbLight.DeviceID, new byte [] { rgbLight.LoopID, 100, 0, 0 });
                                } else {
                                    rgbLight.CurrentBrightness = 0;
                                    Control.ControlBytesSend (Command.SetSingleLight, rgbLight.SubnetID, rgbLight.DeviceID, new byte [] { rgbLight.LoopID, 0, 0, 0 });
                                    //rgbLight.CurrentBrightness = 0;
                                    SendControl.SendControlSetSingleLight (rgbLight, new byte [] { rgbLight.LoopID, 0, 0, 0 });
                                    //Control.ControlBytesSend (Command.SetSingleLight, rgbLight.SubnetID, rgbLight.DeviceID, new byte [] { rgbLight.LoopID, 0, 0, 0 });
                                }
                            };
                            #endregion
                        } else if (devcieCommon.Type == DeviceType.LightSwitch ||
                            devcieCommon.Type == DeviceType.LightEnergySocket ||
                            devcieCommon.Type == DeviceType.LightEnergySwitch || devcieCommon.Type == DeviceType.LightSwitchSocket) {
                        } else if (devcieCommon.Type == DeviceType.LightSwitch
                            || devcieCommon.Type == DeviceType.LightEnergySocket
                            || devcieCommon.Type == DeviceType.LightEnergySwitch
                            || devcieCommon.Type == DeviceType.LightSwitchSocket) {
                            #region 继电器
                            LightSwitch switchLight = devcieCommon as LightSwitch;
                            tempSwitch.IsSelected = switchLight.CurrentBrightness == 100 ? true : false;
@@ -1824,33 +1873,40 @@
                                };
                                DeviceRowView.AddChidren (btnEnergy);
                                EnergtLightList.Add (devcieCommon);
                                Button btnElectric = new Button () {
                                    Width = Application.GetRealWidth (200),
                                    Height = Application.GetRealHeight (35),
                                    X = Application.GetRealWidth (320),
                                    Y = tempSwitch.Bottom,
                                    TextColor = SkinStyle.Current.TextColor1,
                                    TextAlignment = TextAlignment.CenterRight,
                                    SelectedTextColor = SkinStyle.Current.TextColor1,
                                    Tag = devcieCommon.Type.ToString () + "_Electric",
                                    Text = "0 kw.h"
                                };
                                DeviceRowView.AddChidren (btnElectric);
                                //2020-07-01 客户提出隐藏kwh
                                //Button btnElectric = new Button () {
                                //    Width = Application.GetRealWidth (200),
                                //    Height = Application.GetRealHeight (35),
                                //    X = Application.GetRealWidth (320),
                                //    Y = tempSwitch.Bottom,
                                //    TextColor = SkinStyle.Current.TextColor1,
                                //    TextAlignment = TextAlignment.CenterRight,
                                //    SelectedTextColor = SkinStyle.Current.TextColor1,
                                //    Tag = devcieCommon.Type.ToString () + "_Electric",
                                //    Text = "0 kw.h"
                                //};
                                //DeviceRowView.AddChidren (btnElectric);
                            }
                            tempSwitch.MouseUpEventHandler += (sender3, e3) => {
                                tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                if (tempSwitch.IsSelected) {
                                    switchLight.CurrentBrightness = 100;
                                    Control.ControlBytesSend (Command.SetSingleLight, switchLight.SubnetID, switchLight.DeviceID, new byte [] { switchLight.LoopID, 100, 0, 0 });
                                //tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                if (!tempSwitch.IsSelected) {
                                    //switchLight.CurrentBrightness = 100;
                                    SendControl.SendControlSetSingleLight (switchLight, new byte [] { switchLight.LoopID, 100, 0, 0 });
                                    //Control.ControlBytesSend (Command.SetSingleLight, switchLight.SubnetID, switchLight.DeviceID, new byte [] { switchLight.LoopID, 100, 0, 0 });
                                } else {
                                    switchLight.CurrentBrightness = 0;
                                    Control.ControlBytesSend (Command.SetSingleLight, switchLight.SubnetID, switchLight.DeviceID, new byte [] { switchLight.LoopID, 0, 0, 0 });
                                    //switchLight.CurrentBrightness = 0;
                                    SendControl.SendControlSetSingleLight (switchLight, new byte [] { switchLight.LoopID, 0, 0, 0 });
                                    //Control.ControlBytesSend (Command.SetSingleLight, switchLight.SubnetID, switchLight.DeviceID, new byte [] { switchLight.LoopID, 0, 0, 0 });
                                }
                                new System.Threading.Thread (() => {
                                    Control.ControlBytesSend (Command.ReadAnalogValue, switchLight.SubnetID, switchLight.DeviceID, new byte [] { 10, switchLight.LoopID }, SendCount.Zero);
                                    Control.ControlBytesSend (Command.ReadAnalogValue, switchLight.SubnetID, switchLight.DeviceID, new byte [] { 11, switchLight.LoopID }, SendCount.Zero);
                                }) { IsBackground = true }.Start ();
                                if (devcieCommon.Type == DeviceType.LightEnergySocket || devcieCommon.Type == DeviceType.LightEnergySwitch) {
                                    new System.Threading.Thread (() => {
                                        Control.ControlBytesSend (Command.ReadAnalogValue, switchLight.SubnetID, switchLight.DeviceID, new byte [] { 10, switchLight.LoopID }, SendCount.Zero);
                                        //2020-07-01 客户提出隐藏kwh
                                        //Control.ControlBytesSend (Command.ReadAnalogValue, switchLight.SubnetID, switchLight.DeviceID, new byte [] { 11, switchLight.LoopID }, SendCount.Zero);
                                    }) { IsBackground = true }.Start ();
                                }
                            };
                            #endregion
                        } else if (devcieCommon.Type == DeviceType.CurtainModel) {
@@ -1958,7 +2014,7 @@
                            try {
                                InfraredMode infraredTV = devcieCommon as InfraredMode;// Newtonsoft.Json.JsonConvert.DeserializeObject<InfraredMode> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                                if (infraredTV != null)
                                    Console.WriteLine (infraredTV.InfraredType);
                                    Utlis.WriteLine (infraredTV.InfraredType);
                                if (infraredTV.InfraredType == InfraredType.TV) {
                                    btnIcon.UnSelectedImagePath = "Item/InfraredTV.png";
                                    btnIcon.SelectedImagePath = "Item/InfraredTV.png";
@@ -1973,12 +2029,13 @@
                                    tempSwitch.MouseUpEventHandler += (sender3, e3) => {
                                        infraredTV.isOpen = tempSwitch.IsSelected = !tempSwitch.IsSelected;
                                        int RandKey = new Random ().Next (0, 255);
                                        //2020-02-10 待修改
                                        Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Power, 0, 0, (byte)RandKey });
                                        IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ());
                                    };
                                }
                            } catch (Exception ex) {
                                Console.WriteLine (ex.ToString ());
                                Utlis.WriteLine (ex.ToString ());
                                continue;
                            }
                            #endregion
@@ -2016,14 +2073,14 @@
                            };
                            DeviceRowView.AddChidren (tempSwitch);
                            if (udDevice.ActionType == 0) {
                                tempSwitch.Text = udDevice.ON_Text;
                                //tempSwitch.TextID = R.MyInternationalizationString.ON;
                                //tempSwitch.Text = udDevice.ON_Text;
                                tempSwitch.TextID = R.MyInternationalizationString.ON;
                            } else if (udDevice.ActionType == 1) {
                                tempSwitch.Text = udDevice.OFF_Text;
                                //tempSwitch.TextID = R.MyInternationalizationString.OFF;
                                //tempSwitch.Text = udDevice.OFF_Text;
                                tempSwitch.TextID = R.MyInternationalizationString.OFF;
                            } else if (udDevice.ActionType == 2) {
                                tempSwitch.Text = udDevice.OFF_Text;
                                //tempSwitch.TextID = R.MyInternationalizationString.OFF;
                                //tempSwitch.Text = udDevice.OFF_Text;
                                tempSwitch.TextID = R.MyInternationalizationString.OFF;
                                Button tempON = new Button () {
                                    Width = Application.GetRealWidth (110),
@@ -2039,6 +2096,7 @@
                                DeviceRowView.AddChidren (tempON);
                                tempON.MouseUpEventHandler += (sender3, e3) => {
                                    if (udDevice.UniversalType == 0xE01C) {
                                        //2020-02-10 待修改
                                        Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 255 }, SendCount.Zero);
                                    }
                                    DeviceRowView.BorderColor = SkinStyle.Current.Transparent;
@@ -2048,24 +2106,26 @@
                                    DeviceRowView.BorderColor = SkinStyle.Current.SelectedColor;
                                    tempON.BorderColor = SkinStyle.Current.SelectedColor;
                                };
                                tempSwitch.MouseUpEventHandler += (sender3, e3) => {
                                    if (udDevice.UniversalType == 0xE01C) {
                                        if (udDevice.ActionType == 0) {
                                            Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 255 }, SendCount.Zero);
                                        } else if (udDevice.ActionType == 1) {
                                            Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 }, SendCount.Zero);
                                        } else if (udDevice.ActionType == 2) {
                                            Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 }, SendCount.Zero);
                                        }
                                    }
                                    DeviceRowView.BorderColor = SkinStyle.Current.Transparent;
                                    tempSwitch.BorderColor = SkinStyle.Current.BorderColor;
                                };
                                tempSwitch.MouseDownEventHandler += (sende3r, e3) => {
                                    DeviceRowView.BorderColor = SkinStyle.Current.SelectedColor;
                                    tempSwitch.BorderColor = SkinStyle.Current.SelectedColor;
                                };
                            }
                            tempSwitch.MouseUpEventHandler += (sender3, e3) => {
                                if (udDevice.UniversalType == 0xE01C) {
                                    if (udDevice.ActionType == 0) {
                                        //2020-02-10 待修改
                                        Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 255 }, SendCount.Zero);
                                    } else if (udDevice.ActionType == 1) {
                                        Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 }, SendCount.Zero);
                                    } else if (udDevice.ActionType == 2) {
                                        Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 }, SendCount.Zero);
                                    }
                                }
                                DeviceRowView.BorderColor = SkinStyle.Current.Transparent;
                                tempSwitch.BorderColor = SkinStyle.Current.BorderColor;
                            };
                            tempSwitch.MouseDownEventHandler += (sende3r, e3) => {
                                DeviceRowView.BorderColor = SkinStyle.Current.SelectedColor;
                                tempSwitch.BorderColor = SkinStyle.Current.SelectedColor;
                            };
                            #endregion
                        } else if (devcieCommon.Type.ToString ().Contains ("Sensor")) {
                            #region 传感器
@@ -2258,23 +2318,29 @@
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine ("exddd :" + ex.ToString ());
                Utlis.WriteLine ("exddd :" + ex.ToString ());
            } finally {
                //2020-02-14 增加读状态操作
                UserMiddle.ReadAllDeviceStatus (false, true);
                readEnergyThead = new Thread ((obj) => {
                    while (readEnergy) {
                        System.Threading.Thread.Sleep (500);
                    while (readEnergy && !Control.IsEnterBackground) {
                        try {
                            for(int i=0;i<EnergtLightList.Count;i++){
                                var c = EnergtLightList [i];
                                Control.ControlBytesSend (Command.ReadAnalogValue, c.SubnetID, c.DeviceID, new byte [] { 10, c.LoopID }, SendCount.Zero);
                                Control.ControlBytesSend (Command.ReadAnalogValue, c.SubnetID, c.DeviceID, new byte [] { 11, c.LoopID }, SendCount.Zero);
                                //2020-07-01 客户提出隐藏kwh
                                //Control.ControlBytesSend (Command.ReadAnalogValue, c.SubnetID, c.DeviceID, new byte [] { 11, c.LoopID }, SendCount.Zero);
#if DEBUG
                                Application.RunOnMainThread (() => {
                                    Console.WriteLine ($"读取 { c.Name } 电能");
                                    Utlis.WriteLine ($"读取 { c.Name } 电能");
                                });
#endif
                                System.Threading.Thread.Sleep (500);
                            }
                            System.Threading.Thread.Sleep (9500);
                            System.Threading.Thread.Sleep (10000);
                        } catch {
                            EnergtLightList = new List<Common> ();
                        }
@@ -2292,5 +2358,61 @@
                }
            }
        }
        /// <summary>
        /// 空调控制,带返回结果
        /// </summary>
        /// <param name="mAcData"></param>
        /// <param name="bPower"></param>
        void SendControlAc (AC mAcData, byte bPower)
        {
            MainPage.Loading.Start ("Sending...");
            System.Threading.Tasks.Task.Run (() => {
                byte [] returnBytes = null;
                if (mAcData.Type == DeviceType.ACPanel) {
                    returnBytes = Control.ControlBytesSendHasReturn (Command.InstructionPanelKey, mAcData.SubnetID, mAcData.DeviceID, new byte [] { 3, bPower, mAcData.LoopID });
                } else if (mAcData.Type == DeviceType.ACDevice || mAcData.Type == DeviceType.HVAC || mAcData.Type == DeviceType.ACInfrared) {
                    returnBytes = Control.ControlBytesSendHasReturn (Command.SetACMode, mAcData.SubnetID, mAcData.DeviceID, new [] { mAcData.LoopID, mAcData.TemperatureMode, mAcData.IndoorTemperature, mAcData.CoolTemperature, mAcData.HeatTemperature, mAcData.AutoTemperature, mAcData.ChuShiTemperature, mAcData.RealModeAndFanSpeed, bPower, mAcData.SetMode, mAcData.SetFanSpeed, mAcData.SetTemperature, mAcData.ShaoFanMode });
                }
                Application.RunOnMainThread (() => {
                    if (returnBytes == null) {
                        new Alert ("", mAcData.Name + ErrorCode.ControlFailure, "Close").Show ();
                    }
                    MainPage.Loading.Hide ();
                });
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="btnName"></param>
        /// <param name="devcieCommon"></param>
        void ButtonNameAddMouseLongEventHandler (Button btnName,Common devcieCommon)
        {
            //2020-08-28 增加长按修改设备备注
            btnName.MouseLongEventHandler += (sender, e) => {
                RemarkDeviceName (devcieCommon, SimpleControl.CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (devcieCommon)), btnName);
            };
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="commonDevice"></param>
        /// <param name="commonBytes"></param>
        /// <param name="btnEquipment"></param>
        void RemarkDeviceName (Common commonDevice, byte[] commonBytes, Button btnEquipment)
        {
            Action successAction = () => {
                GenericDialog.Current.RefreshRemark (commonDevice);
                //if (!roomDeviceFilePathList.Contains (filePath)) {
                //    roomDeviceFilePathList.Add (filePath);
                //}
            };
            GenericDialog.Current.ShowModifyRemarksDialog (commonDevice, commonBytes, btnEquipment, successAction);
        }
    }
}