private fn_show_lamps ( string username, byte password ) : IQueryable |
||
username | string | |
password | byte | |
return | IQueryable |
/// <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; }
/// <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; }
/// <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; }
/// <summary> /// PSP 3.2 /// Löschen einer Lampe anhand der Lampenadresse /// </summary> /// <param name="username">Username</param> /// <param name="password">Passwort</param> /// <param name="lampAdress">Lampen Adresse</param> /// <returns>success -> ob erfolgreich oder nicht</returns> public static bool deleteLamp(string username, string password, string lampAdress) { 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()) { //Nach Lampe in DB über Funktion suchen foreach (var item in cont.fn_show_lamps(username, pwhash)) { //Adresse wird geprüft if (item.address == lampAdress) { try { //Lampe aus DB entfernen cont.sp_delete_lamp(item.id, username, pwhash); //HUE-Bridge entfernt die Lampe (Da nicht benutzt) automatisch. Liste lamps aktualisieren //Sollte die Lampe, obwohl vorhanden gelöscht werden, wird dies von uns nicht unterstützt! HueAccess.getLampList(); success = true; } catch (Exception e) { success = false; } } } } return success; }
/// <summary> /// Die in der DB eingetragenen Lampennamen als Liste /// </summary> /// <param name="username">Username</param> /// <param name="password">Passwort</param> /// <returns>Liste des Datentyp's "fn_show_lamps_Result". D.h. einen Table aller Lampen</returns> public static List<fn_show_lamps_Result> GetAllLamps(string username, string password) { //Ü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> tmp = new List<fn_show_lamps_Result>(); try { return cont.fn_show_lamps(username, pwhash).ToList(); } catch (Exception e) { //Fehlermeldung in die leere Liste hinzufügen, die FM wird als name eingetragen tmp.Add(new fn_show_lamps_Result { address = "", name = "Keine Datenbankverbindung" }); tmp.Add(new fn_show_lamps_Result { address = "", name = "No database connection" }); return tmp; } } }
/// <summary> /// Die HueLampId wird durch die Abfrage der Db ausgegeben /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="dbLampId">LampenID der DB</param> /// <returns></returns> public static int GetHueLampId(string username, Byte[] password, int dbLampId) { int hueLampId = -1; //Ü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> db = cont.fn_show_lamps(username, password).ToList(); foreach (var item in db) { if (item.id == dbLampId) { hueLampId = HueAccess.GetLampId(item.name); break; } } } return hueLampId; }