Example #1
0
 public bool Filter(DomoticzServer.Device dev)
 {
     switch (currentFilterBy)
     {
         case DeviceFilterBy.Favorites:
             if (dev.Favorite > 0)
             {
                 return true;
             }
             return false;
         case DeviceFilterBy.Switches:
             if (dev.Type == "Lighting 2" ||
                 dev.Type == "Security")
             {
                 return true;
             }
             return false;
         case DeviceFilterBy.Temperature:
             if (dev.Type == "Temp" ||
                 dev.Type == "Temp + Humidity" ||
                 dev.Type == "Temp + Baro")
             {
                 return true;
             }
             return false;
         default:
             return true;
     }
 }
Example #2
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 #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);
        }
Example #4
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!");
     }
 }
Example #5
0
        private bool AddListItem(DomoticzServer.Device dev)
        {
            string skinName = MediaPortal.Configuration.Config.SkinName;
            string skinPath = MediaPortal.Configuration.Config.GetSubFolder(MediaPortal.Configuration.Config.Dir.Skin, skinName);

            string poster = skinPath + "\\Media\\Domoticz\\" + dev.TypeImg + "48.png";
            string thumb = skinPath + "\\Media\\Domoticz\\" + dev.TypeImg + ".png";

            GUIListItem item = new GUIListItem(dev.Name);                        

            switch (dev.Type)
            {
                case "Temp":
                    item.Label2 = dev.Temp.ToString() + "°";
                    poster = currentDomoticzServer.GetTempIcon(dev.Temp);
                    break;

                case "Temp + Humidity":
                    item.Label2 = dev.Temp.ToString() + "°";
                    if (dev.Humidity != null)
                    {
                        item.Label2 += " / " + dev.Humidity.ToString() + "%";
                    }
                    poster = currentDomoticzServer.GetTempIcon(dev.Temp);
                    break;
                case "Wind":
                    item.Label2 = dev.DirectionStr + " / " + dev.Speed + "m/s";
                    poster = skinPath + "\\Media\\Domoticz\\Wind" + dev.DirectionStr + ".png";
                    break;

                case "Lighting 2":
                    item.Label2 = dev.Status;
                    if (dev.Status == "On")
                    {
                        poster = skinPath + "\\Media\\Domoticz\\Light48_On.png";
                    }
                    else
                    {
                        poster = skinPath + "\\Media\\Domoticz\\Light48_Off.png";
                    }
                    break;

                case "Rain":
                    item.Label2 = dev.Rain + " mm";
                    break;

                default:
                    item.Label2 = "";
                    break;

            }

            if (!File.Exists(poster))
            {
                poster = thumb;
            }            

            item.IconImage = thumb;
            item.IconImageBig = thumb;
            item.ThumbnailImage = poster;
            item.MusicTag = dev;
            GUIControl.AddListItemControl(GetID, listDevices.GetID, item);
            return true;
        }
Example #6
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;
                }
            }
            

        }