sp_lamp_dimm() public méthode

public sp_lamp_dimm ( string username, byte password, Nullable lamp_id, Nullable bright ) : int
username string
password byte
lamp_id Nullable
bright Nullable
Résultat int
Exemple #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;  
        }
Exemple #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;
        }