Beispiel #1
0
 /// <summary>
 /// Return the object latest values from the selected bridge.
 /// </summary>
 /// <param name="bridge">Bridge to get the object from.</param>
 /// <param name="obj">Object to get values.</param>
 /// <returns>The latest values of the object.</returns>
 public static HueObject GetBridgeObject(Bridge bridge, HueObject obj)
 {
     if (obj == null)
     {
         return(null);
     }
     log.Debug($@"Fetching object : {obj.Id} of type {obj.GetType()}");
     if (obj is Light)
     {
         return(GetBridgeLight(bridge, obj.Id));
     }
     if (obj is Group)
     {
         return(GetBridgeGroup(bridge, obj.Id));
     }
     if (obj is Scene)
     {
         return(GetBridgeScene(bridge, obj.Id));
     }
     if (obj is Schedule)
     {
         return(GetBridgeSchedule(bridge, obj.Id));
     }
     if (obj is Sensor)
     {
         return(GetBridgeSensor(bridge, obj.Id));
     }
     if (obj is Rule)
     {
         return(GetBridgeRule(bridge, obj.Id));
     }
     return(null);
 }
Beispiel #2
0
 public static void SetName(this HueObject obj, string newName)
 {
     if (newName == null)
     {
         return;
     }
     if (!obj.HasProperty("name"))
     {
         return;
     }
     obj.GetType().GetProperty("name").SetValue(obj, newName);
 }
        private void btnRename_Click(object sender, RoutedEventArgs e)
        {
            MethodInfo    mi      = typeof(Bridge).GetMethod("RenameObject");
            MethodInfo    generic = mi.MakeGenericMethod(_obj.GetType());
            CommandResult comres  = (CommandResult)generic.Invoke(_bridge, new object[] { _obj.Id, tbNewName.Text });

            if (comres.Success)
            {
                DialogResult = true;
                Close();
            }
            else
            {
                MessageBoxError.ShowLastErrorMessages(_bridge);
            }
        }
Beispiel #4
0
 public static string GetName(this HueObject obj)
 {
     return(obj.HasProperty("name") ? obj.GetType().GetProperty("name").GetValue(obj).ToString() : "Unknown");
 }