Example #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;
        }
Example #2
0
 // <summary>
 ///Handle automatic refresh of content from the Domoticz server 
 /// </summary>
 public override void Process()
 {
     TimeSpan ts = DateTime.Now - RefreshTime;
     if ((ts.TotalSeconds >= RefreshInterval))
     {
         // Reset time
         RefreshTime = DateTime.Now;
         AllDevResponse = null;
         Refresh();
     }
     base.Process();
 }
Example #3
0
        private void EnumerateDeviceLeft()
        {
            int prevIdx = -1;
            int nextIdx = -1;
            bool getNext = false;

            DevResponse = currentDomoticzServer.GetAllDevices();

            OnSort();
            foreach (DomoticzServer.Device dev in DevResponse.result)
            {
                if (getNext == true)
                {
                    nextIdx = dev.idx;
                    break;
                }
                else
                {
                    if (DeviceIdx == dev.idx)
                    {
                        getNext = true;
                    }
                    else
                    {
                        prevIdx = dev.idx;
                    }
                }
            }
            Log.Info("Left: " + prevIdx + " " + DeviceIdx + " " + nextIdx);
        }
Example #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;
                }
            }
            

        }