sp_lamp_on() public method

public sp_lamp_on ( string username, byte password, Nullable lamp_id ) : int
username string
password byte
lamp_id Nullable
return int
Beispiel #1
0
        /// <summary>
        /// PSP 15.1
        /// Lampen dimmen
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Passwort</param>
        /// <param name="lampId">Lampen Id</param>
        /// <param name="brightness">Helligkeit</param>
        /// <param name="lampOnOff">Lampe ein/ Lampe aus</param>
        /// <returns>success -> ob erfolgreich oder nicht</returns>
        public static bool dimLamp(string username, string password, int lampId, byte brightness, bool lampOnOff)
        {
            bool success = false;
            //Übergebenes Passwort hashen und in Var pwhash speichern für Übergabe an DB
            Byte[] pwhash = HelperClass.GetHash(password);

            using (itin18_aktEntities cont = new itin18_aktEntities())
            {
                string dbLampName = "";
                int hueId = -1;
                List<fn_show_lamps_Result> db = cont.fn_show_lamps(username, pwhash).ToList();
                List<fn_show_lamp_status_Result> ls = new List<fn_show_lamp_status_Result>();

                try
                {
                    foreach (var item in db)
                    {
                        if (lampId == item.id)
                        {
                            dbLampName = item.name;
                            ls = cont.fn_show_lamp_status(username, pwhash, item.id).ToList();
                            if (ls[0].bright != brightness && ls[0].status == lampOnOff)
                            {
                                cont.sp_lamp_dimm(username, pwhash, item.id, brightness);
                            }
                            else if(ls[0].bright != brightness && ls[0].status != lampOnOff)
                            {
                                cont.sp_lamp_dimm(username, pwhash, item.id, brightness);

                                if (lampOnOff == false)
                                {
                                    cont.sp_lamp_off(username, pwhash, lampId);
                                }
                            }
                            else if(ls[0].bright == brightness && ls[0].status != lampOnOff)
                            {
                                if (lampOnOff == false)
                                {
                                    cont.sp_lamp_off(username, pwhash, lampId);
                                }
                                else
                                {
                                    cont.sp_lamp_on(username, pwhash, lampId);
                                }
                            }   
                        }
                   
                    }

                    hueId = HueAccess.GetLampId(dbLampName);
                    HelperClass.SetLampBrightness(hueId, brightness);
                    HelperClass.SetLampState(hueId, lampOnOff);
                    success = true;
                }
                catch (Exception e)
                {
                    success = false;
                }                              
            }
            return success;  
        }
Beispiel #2
0
        /// <summary>
        /// PSP 2.1
        /// Editieren eines Lampennamens anhand des alten Lampennamens
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Passwort</param>
        /// <param name="lampNameOld">alter Lampenname</param>
        /// <param name="lampNameNew">neuer Lampenname</param>
        /// <returns>success -> ob erfolgreich oder nicht</returns>
        internal static bool editLampName(string username, string password, string lampNameOld, string lampNameNew)
        {
            //Übergebenes Passwort hashen und in Var pwhash speichern für Übergabe an DB
            Byte[] pwhash = HelperClass.GetHash(password);
            bool success = false;
            using (itin18_aktEntities cont = new itin18_aktEntities())
            {
                
                List<fn_show_lamp_status_Result> dbLampStatus = null;
                List<fn_show_lamp_control_Result> dbLampsStatus = cont.fn_show_lamp_control(username, pwhash).ToList();
                List<fn_show_lamp_control_Result> dbLampsStatusResult = new List<fn_show_lamp_control_Result>();
                List<fn_show_lampgroups_Result> dbLampGroups = cont.fn_show_lampgroups(username, pwhash).ToList();
                List<fn_show_lampgroup_status_Result> dbLampGroupStatus = null;
                List<fn_show_lamps_Result> dbLampsNew = null;
                //temporäre Variablen
                int? dbLampIdNew = 0;
                int? dblampId = 0;
                string dblampAdr = "";
                string dbLampGroupName = "";

                try
                {
                    foreach (var item in dbLampsStatus)
                    {
                        // Suche des alten Namens zwecks Änderung
                        if (item.lampname == lampNameOld)
                        {
                            dblampId = item.lamp_id;

                            dblampAdr = item.address;

                            dbLampStatus = cont.fn_show_lamp_status(username, pwhash, item.lamp_id).ToList();

                            dbLampsStatusResult.Add(item);

                            dbLampGroupName = item.groupname;
                        }
                    }

                    //Edit gibt es nicht in der DB, Lampe wird gelöscht und wieder neu angelegt
                    cont.sp_delete_lamp(dblampId, username, pwhash);
                    cont.sp_add_lamp(username, pwhash, dblampAdr, lampNameNew);

                    dbLampsNew = cont.fn_show_lamps(username, pwhash).ToList();
                    foreach (var item in dbLampsNew)
                    {
                        if (item.name == lampNameNew)
                        {
                            dbLampIdNew = item.id;
                        }
                    }

                    foreach (var outerItem in dbLampGroups)
                    {
                        dbLampGroupStatus = cont.fn_show_lampgroup_status(username, pwhash, outerItem.id).ToList();
                        foreach (var innerItem in dbLampGroupStatus)
                        {
                            if (innerItem.id == dblampId)
                            {
                                cont.sp_delete_lamp_from_roomgroup(username, pwhash, outerItem.id, dblampId);
                                cont.sp_add_lamp_to_lampgroup(username, pwhash, outerItem.id, dbLampIdNew);
                            }
                        }
                    }

                    cont.sp_lamp_dimm(username, pwhash, dbLampIdNew, dbLampStatus[0].bright);
                    if (dbLampStatus[0].status == true)
                    {
                        cont.sp_lamp_on(username, pwhash, dbLampIdNew);
                    }
                    else
                    {
                        cont.sp_lamp_off(username, pwhash, dbLampIdNew);
                    }
                 //Namen der Lampe in der HUE-Bridge ändern
                 HelperClass.SetLampName(HueAccess.GetLampId(lampNameOld), lampNameNew);
                    success = true;
                }
                catch (Exception e)
                {
                    success = false;
                }
               
            }
            return success;
        }
Beispiel #3
0
        /// <summary>
        /// Lampengruppen ein-/ausschalten
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Passwort</param>
        /// <param name="groupId">Lampengruppen Id</param>
        /// <param name="onOff">Lampe ein/ Lampe aus</param>
        /// <returns>success -> ob erfolgreich oder nicht</returns>
        public static bool switchGroup(string username, string password, int groupId, bool onOff)
        {
            bool success = false;
            //Übergebenes Passwort hashen und in Var pwhash speichern für Übergabe an DB
            Byte[] pwhash = HelperClass.GetHash(password);

            using (itin18_aktEntities cont = new itin18_aktEntities())
            {
                List<fn_show_lamp_control_Result> dbL = cont.fn_show_lamp_control(username, pwhash).ToList();
                List<fn_show_lampgroups_Result> dbGr = cont.fn_show_lampgroups(username, pwhash).ToList();
                string dbGroupName = "";
                int HueLampId = 0;


                foreach (var item in dbGr)
                {
                    if (item.id==groupId)
                    {
                        dbGroupName = item.roomgroupname;
                    }
                }

                foreach (var item in dbL)
                {
                    if (item.groupname==dbGroupName)
                    {
                        HueLampId = HueAccess.GetLampId(item.lampname);
                        if (onOff==true)
                        {
                            cont.sp_lamp_on(username, pwhash, item.lamp_id);
                            HelperClass.SetLampState(HueLampId, true);
                        }
                        else
                        {
                            cont.sp_lamp_off(username, pwhash, item.lamp_id);
                            HelperClass.SetLampState(HueLampId, false);
                        }
                    }
                }
                
            }
            return success;

            }
Beispiel #4
0
        /// <summary>
        /// PSP 13.1 switchLamp
        /// Lampe Ein/Aus
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="lampOnOff"></param>
        /// <param name="lampId"></param>
        /// <returns>success -> ob erfolgreich oder nicht</returns>
        public static bool switchLamp(string username, string password, bool lampOnOff, int lampId)
        {
            bool success = false;
            //Übergebenes Passwort hashen und in Var pwhash speichern für Übergabe an DB
            Byte[] pwhash = HelperClass.GetHash(password);
            
            using (itin18_aktEntities cont = new itin18_aktEntities())
            {
                List<fn_show_lamps_Result> dbLamps = cont.fn_show_lamps(username, pwhash).ToList();
                int HueLampId = 0;
                string dbLampName = "";

                try
                {
                    foreach (var item in dbLamps)
                    {
                        if (lampId == item.id)
                        {
                            dbLampName = item.name;
                            break;
                        }
                    }
                    HueLampId = HueAccess.GetLampId(dbLampName);



                    if (lampOnOff == true)
                    {
                        cont.sp_lamp_on(username, pwhash, lampId);
                        // Vereinfachter aufruf über die HelperClass
                        HelperClass.SetLampState(HueLampId, true);
                    }
                    else
                    {
                        cont.sp_lamp_off(username, pwhash, lampId);
                        // Vereinfachter aufruf über die HelperClass
                        HelperClass.SetLampState(HueLampId, false);
                    }
                    success = true;
                    
                }
                catch (Exception e)
                {
                    success = false;
                }
            }
            return success;
        }