Пример #1
0
        private void RefreshSpinControl()
        {
            DevSpinCtrl.Reset();

            if (currentDomoticzServer == null)
            {
                int ServerStatus = 0;
                currentDomoticzServer = new DomoticzServer();
                ServerStatus = currentDomoticzServer.InitServer(_serveradress, _serverport, _username, _password);

                if (ServerStatus != 1)
                    return;
            }

            AllDevResponse = currentDomoticzServer.GetAllDevices();

            List<DomoticzServer.Device> res = null;
            DeviceFilter F = new DeviceFilter(CurrentFilterBy);
            res = AllDevResponse.result.Where(x => F.Filter(x)).ToList();

            OnSort();

            DevSpinCtrl.SetRange(0, res.Count - 1);
            int i = 0;
            foreach (DomoticzServer.Device d in res)
            {
                DevSpinCtrl.AddLabel(d.Name + " (" + d.idx + ")", i);
                if (DeviceIdx == d.idx)
                {
                    DevSpinCtrl.Value = i;
                }
                i++;
            }
            DevSpinCtrl.Focus = true;
        }
Пример #2
0
 private void TestConnectionbutton_Click(object sender, EventArgs e)
 {
     UpdateInternalVars();
     DomoticzServer ds = new DomoticzServer();
     if(ds.InitServer(_serveradress, _serverport, _username, _password) == 1)
     {
         MessageBox.Show("Connection OK!");
     }
     else
     {
         MessageBox.Show("Connection failed!");
     }
 }
Пример #3
0
        /// <summary>
        /// Refresh information and thumbs
        /// </summary>
        private void Refresh()
        {
            if (currentDomoticzServer == null)
            {
                int ServerStatus = 1;

                currentDomoticzServer = new DomoticzServer();
                ServerStatus = currentDomoticzServer.InitServer(_serveradress, _serverport, _username, _password);

                if (ServerStatus == 0)
                {
                    Log.Info("No connection to server " + _serveradress);
                    GUIDialogOK dlgOK = (GUIDialogOK)GUIWindowManager.GetWindow(
                       (int)GUIWindow.Window.WINDOW_DIALOG_OK);
                    dlgOK.SetHeading("No connection");
                    dlgOK.SetLine(1, "No connection to server " + _serveradress);
                    dlgOK.SetLine(2, String.Empty);
                    dlgOK.SetLine(3, String.Empty);
                    dlgOK.DoModal(GUIDeviceDetails_WINDOW_ID);
                    currentDomoticzServer = null;
                    return;
                }

                if (ServerStatus == -1)
                {
                    Log.Info("Failed to authenticate to server " + _serveradress);
                    GUIDialogOK dlgOK = (GUIDialogOK)GUIWindowManager.GetWindow(
                       (int)GUIWindow.Window.WINDOW_DIALOG_OK);
                    dlgOK.SetHeading("Failed to authenticate");
                    dlgOK.SetLine(1, "Server: " + _serveradress);
                    dlgOK.SetLine(2, "Username: '******'");
                    dlgOK.SetLine(3, "Password: '******'");
                    dlgOK.DoModal(GUIDeviceDetails_WINDOW_ID);
                    currentDomoticzServer = null;
                    return;
                }

            }

            ///
            if (AllDevResponse == null)
            {
                RefreshSpinControl();
            }

            //DevResponse = currentDomoticzServer.GetSingleDevice(DeviceIdx);
            DomoticzServer.Device dev = null;

            if (AllDevResponse != null)
            {
                foreach (DomoticzServer.Device d in AllDevResponse.result)
                {
                    if (DeviceIdx == d.idx)
                    {
                        dev = d;
                        break;
                    }
                }

                //DomoticzServer.Device dev = DevResponse.result[0];
                SelectedDevice.Label = Translation.Lastupdate + ": " + dev.LastUpdate;

                string desc = currentDomoticzServer.GetDeviceDescription(dev);
                GUIPropertyManager.SetProperty("#MPDomoticz.Desc", desc);

                desc = Translation.Type + ": " + dev.Type + " " + dev.SubType;
                GUIPropertyManager.SetProperty("#MPDomoticz.TypeInfo", desc);

                desc = currentDomoticzServer.GetIcon(dev);
                GUIPropertyManager.SetProperty("#MPDomoticz.CurrentDeviceIcon", desc);
            }

            DomoticzServer.SunSetRise sun = currentDomoticzServer.GetSunSet();

            if (sun != null)
            {
                string str = Translation.Servertime + ": " + sun.ServerTime + " " +
                    Translation.Sunrise + ": " + sun.Sunrise + " " +
                    Translation.Sunset + ": " + sun.Sunset;

                GUIPropertyManager.SetProperty("#MPDomoticz.ServerTime", str);
            }
            else
            {
                currentDomoticzServer = null;
            }

            string fileDir = MediaPortal.Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Thumbs) + "\\MPDomoticz";
            Log.Info("Check: " + fileDir);
            if (!Directory.Exists(fileDir))
            {
                Directory.CreateDirectory(fileDir);
            }

            RefreshThumbsDir();

            string fileName = MediaPortal.Configuration.Config.GetFolder(MediaPortal.Configuration.Config.Dir.Thumbs) + "\\MPDomoticz\\" + DeviceIdx + "-Week.png";
            if (!File.Exists(fileName))
            {
                Log.Info("Generate graph:" + DeviceIdx + " '" + dev.Type + "' '" + dev.SubType + "'");
                Graph.GenerateGraph(currentDomoticzServer, DeviceIdx, fileName, currentDomoticzServer.GetGraphType(dev));
            }
            GUIPropertyManager.SetProperty("#MPDomoticz.WeekThumb", fileName);
        }
Пример #4
0
        /// <summary>
        /// Refresh the data in the plugin
        /// </summary>
        protected void Refresh()
        {
            if (currentDomoticzServer == null)
            {
                int ServerStatus = 1;

                currentDomoticzServer = new DomoticzServer();             
                ServerStatus = currentDomoticzServer.InitServer(_serveradress,_serverport, _username, _password);

                if (ServerStatus == 0)
                {
                    Log.Info("No connection to server " + _serveradress);
                    GUIDialogOK dlgOK = (GUIDialogOK)GUIWindowManager.GetWindow(
                       (int)GUIWindow.Window.WINDOW_DIALOG_OK);
                    dlgOK.SetHeading("No connection");
                    dlgOK.SetLine(1, "No connection to server " + _serveradress);
                    dlgOK.SetLine(2, String.Empty);
                    dlgOK.SetLine(3, String.Empty);
                    dlgOK.DoModal(WINDOW_ID);
                    currentDomoticzServer = null;
                    return;
                }

                if (ServerStatus == -1)
                {
                    Log.Info("Failed to authenticate to server " + _serveradress);
                    GUIDialogOK dlgOK = (GUIDialogOK)GUIWindowManager.GetWindow(
                       (int)GUIWindow.Window.WINDOW_DIALOG_OK);
                    dlgOK.SetHeading("Failed to authenticate");
                    dlgOK.SetLine(1, "Server: " + _serveradress);
                    dlgOK.SetLine(2, "Username: '******'");
                    dlgOK.SetLine(3, "Password: '******'");
                    dlgOK.DoModal(WINDOW_ID);
                    currentDomoticzServer = null;
                    return;
                }
            }


            DevResponse = null;
            
            DomoticzServer.SunSetRise sun = currentDomoticzServer.GetSunSet();            
            if (sun != null)
            {
                string str = Translation.Servertime + ": " + sun.ServerTime + " " +
                    Translation.Sunrise + ": " + sun.Sunrise + " " +
                    Translation.Sunset + ": " + sun.Sunset;

                GUIPropertyManager.SetProperty("#MPDomoticz.ServerTime", str);
            }
            else
            {                
                currentDomoticzServer = null;
            }

            if (listDevices != null)
            {                                
                DevResponse = currentDomoticzServer.GetAllDevices();
                                               
                if (DevResponse != null)
                {          
                    OnFilter();                    
                    UpdateButtons();
                }
                else
                {                    
                    currentDomoticzServer = null;
                }
            }
            

        }