Ejemplo n.º 1
0
        /// <summary>
        /// Pulls all the bulbs and their current state from the bridge
        /// </summary>
        public void ProcBulbs(string jsondata)
        {
            try
            {
                JObject json = JObject.Parse(jsondata);
                HueBridge.HueBulbs.Clear();
                foreach (var bulb in json)
                {
                    string id  = bulb.Key;
                    uint   hue = 0;
                    uint   sat = 0;
                    uint   ct  = 0;
                    string colormode;
                    bool   on           = (bool)json[id]["state"]["on"];
                    uint   bri          = (uint)json[id]["state"]["bri"];
                    string type         = (string)json[id]["type"];
                    string name         = (string)json[id]["name"];
                    string model        = (string)json[id]["modelid"];
                    string manufacturer = (string)json[id]["manufacturername"];
                    string uid          = (string)json[id]["uniqueid"];
                    string swver        = (string)json[id]["swversion"];
                    bool   reachable    = (bool)json[id]["state"]["reachable"];
                    if (json[id]["state"].SelectToken("colormode") != null)
                    {
                        colormode = (string)json[id]["state"]["colormode"];
                        if (json[id]["state"].SelectToken("hue") != null)
                        {
                            hue = (uint)json[id]["state"]["hue"];
                        }
                        if (json[id]["state"].SelectToken("sat") != null)
                        {
                            sat = (uint)json[id]["state"]["sat"];
                        }
                        if (json[id]["state"].SelectToken("ct") != null)
                        {
                            ct = (uint)json[id]["state"]["ct"];
                        }
                        HueBridge.HueBulbs.Add(new HueBulb(id, on, bri, hue, sat, ct, type, name, model, manufacturer, uid, swver, colormode, reachable));
                    }
                    else
                    {
                        HueBridge.HueBulbs.Add(new HueBulb(id, on, bri, type, name, model, manufacturer, uid, swver, reachable));
                    }
                }

                /*
                 * foreach (var bulb in HueBridge.HueBulbs)
                 * {
                 *      CrestronConsole.PrintLine("Bulb Name: {0}, Bulb ID: {1}", bulb.Name, bulb.Id);
                 * }*/
                BulbNum = (ushort)HueBridge.HueBulbs.Count;
                CrestronConsole.PrintLine("{0} Bulbs discovered", BulbNum);
                HueBridge.GetBridgeInfo("groups");
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Error getting bulbs: {0}", e);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Pulls all the groups/rooms from the bridge
        /// </summary>
        public void ProcRooms(string jsondata)
        {
            try
            {
                JObject json = JObject.Parse(jsondata);
                HueBridge.HueGroups.Clear();
                foreach (var group in json)
                {
                    string   load;
                    uint     bri;
                    JArray   loadList;
                    string[] loads;
                    string   roomclass;
                    string   type;
                    string   id = group.Key;
                    if ((string)json[id]["type"] == "Room")
                    {
                        string name = (string)json[id]["name"];
                        roomclass = (string)json[id]["class"];
                        type      = (string)json[id]["type"];
                        bri       = 0;
                        if (json[id]["lights"].HasValues)
                        {
                            load     = (string)json[id]["lights"][0];
                            loadList = (JArray)json[id]["lights"];
                            loads    = loadList.ToObject <string[]>();
                            if (json[id]["action"].SelectToken("bri") != null)
                            {
                                bri = (uint)json[id]["action"]["bri"];
                            }
                        }
                        else
                        {
                            load  = "0";
                            loads = null;
                            CrestronConsole.PrintLine("No lights in {0}", name);
                        }

                        bool on = (bool)json[group.Key]["action"]["on"];
                        HueBridge.HueGroups.Add(new HueGroup(id, name, type, on, bri, load, loads, roomclass));
                    }
                }
                GroupNum = (ushort)HueBridge.HueGroups.Count;
                CrestronConsole.PrintLine("{0} Rooms discovered", GroupNum);
                if (Authorized == 1)
                {
                    HueBridge.GetBridgeInfo("scenes");
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Error getting rooms: {0}", e);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Pulls all the bulbs and their current state from the bridge
 /// </summary>
 ushort getBulbs()
 {
     try
     {
         if (HueBridge.Authorized == true)
         {
             string  json  = HueBridge.GetBridgeInfo("lights");
             JObject JData = JObject.Parse(json);
             HueBridge.HueBulbs.Clear();
             foreach (var bulb in JData)
             {
                 string id           = bulb.Key;
                 bool   on           = (bool)JData[id]["state"]["on"];
                 uint   bri          = (uint)JData[id]["state"]["bri"];
                 string alert        = (string)JData[id]["state"]["alert"];
                 bool   reachable    = (bool)JData[id]["state"]["reachable"];
                 string type         = (string)JData[id]["type"];
                 string name         = (string)JData[id]["name"];
                 string model        = (string)JData[id]["modelid"];
                 string manufacturer = (string)JData[id]["manufacturername"];
                 string uid          = (string)JData[id]["uniqueid"];
                 string swver        = (string)JData[id]["swversion"];
                 if (type.Contains("color") || type.Contains("Color"))
                 {
                     uint hue = (uint)JData[id]["state"]["hue"];
                     uint sat = (uint)JData[id]["state"]["sat"];
                     HueBridge.HueBulbs.Add(new HueBulb(id, on, bri, hue, sat, alert, reachable, type, name, model, manufacturer, uid, swver));
                 }
                 else
                 {
                     HueBridge.HueBulbs.Add(new HueBulb(id, on, bri, alert, reachable, type, name, model, manufacturer, uid, swver));
                 }
             }
             BulbNum = (ushort)HueBridge.HueBulbs.Count;
             CrestronConsole.PrintLine("{0} Bulbs discovered", BulbNum);
             return(1);
         }
         else
         {
             CrestronConsole.PrintLine("Bridge not authorized");
             return(0);
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Error getting bulbs {0}", e);
         return(0);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Pulls all the scenes from the bridge and assigns them to their appropriate room based on the assigned bulbs
 /// </summary>
 ushort getScenes()
 {
     try
     {
         if (HueBridge.Authorized == true)
         {
             string  json  = HueBridge.GetBridgeInfo("scenes");
             JObject JData = JObject.Parse(json);
             HueBridge.HueScenes.Clear();
             foreach (var scene in JData)
             {
                 string id   = scene.Key;
                 string name = (string)JData[id]["name"];
                 string load = (string)JData[id]["lights"][0];
                 for (int x = 0; x < (HueBridge.HueGroups.Count); x++)
                 {
                     if (HueBridge.HueGroups[x].loads.Contains(load))
                     {
                         for (int y = 1; y < 20; y++)
                         {
                             if (HueBridge.HueGroups[x].SceneName[y] == null)
                             {
                                 HueBridge.HueGroups[x].SceneName[y] = name;
                                 HueBridge.HueGroups[x].SceneID[y]   = id;
                                 break;
                             }
                         }
                     }
                 }
             }
             CrestronConsole.PrintLine("{0} Scenes discovered", JData.Count);
             return(1);
         }
         else
         {
             CrestronConsole.PrintLine("Bridge not authorized");
             return(0);
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Error getting scenes: {0}", e);
         return(0);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Gets bridge data starting with lights
 /// </summary>
 public void getData()
 {
     try
     {
         if (HueBridge.Authorized)
         {
             HueBridge.GetBridgeInfo("lights");
         }
         else
         {
             CrestronConsole.PrintLine("Bridge not authorized");
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Error getting bulbs {0}", e);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Pulls all the groups/rooms from the bridge
        /// </summary>
        ushort getRooms()
        {
            try
            {
                if (HueBridge.Authorized == true)
                {
                    string  json  = HueBridge.GetBridgeInfo("groups");
                    JObject JData = JObject.Parse(json);
                    HueBridge.HueGroups.Clear();
                    foreach (var group in JData)
                    {
                        string   id       = group.Key;
                        string   name     = (string)JData[group.Key]["name"];
                        string   load     = (string)JData[group.Key]["lights"][0];
                        JArray   LoadList = (JArray)JData[group.Key]["lights"];
                        string[] loads    = LoadList.ToObject <string[]>();
                        string   type     = (string)JData[group.Key]["type"];
                        bool     on       = (bool)JData[group.Key]["action"]["on"];
                        uint     bri      = (uint)JData[group.Key]["action"]["bri"];
                        string   alert    = (string)JData[group.Key]["action"]["alert"];
                        HueBridge.HueGroups.Add(new HueGroup(name, type, on, bri, alert, load, loads));
                    }
                    for (int i = 0; i < JData.Count; i++)
                    {
                        Array.Clear(HueBridge.HueGroups[i].SceneName, 0, 20);
                        Array.Clear(HueBridge.HueGroups[i].SceneID, 0, 20);
                    }

                    GroupNum = (ushort)HueBridge.HueGroups.Count;
                    CrestronConsole.PrintLine("{0} Rooms discovered", GroupNum);
                    return(1);
                }
                else
                {
                    CrestronConsole.PrintLine("Bridge not authorized");
                    return(0);
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Error getting rooms: {0}", e);
                return(0);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Pulls all the groups/rooms from the bridge
        /// </summary>
        public void ProcRooms(String jsondata)
        {
            try
            {
                JObject jData = JObject.Parse(jsondata);
                HueBridge.HueGroups.Clear();
                foreach (var group in jData)
                {
                    string   load;
                    JArray   LoadList;
                    string[] loads;
                    string   id   = group.Key;
                    string   name = (string)jData[group.Key]["name"];
                    if (jData[group.Key]["lights"].HasValues)
                    {
                        load     = (string)jData[group.Key]["lights"][0];
                        LoadList = (JArray)jData[group.Key]["lights"];
                        loads    = LoadList.ToObject <string[]>();
                    }
                    else
                    {
                        load  = "0";
                        loads = null;
                    }

                    string type  = (string)jData[group.Key]["type"];
                    bool   on    = (bool)jData[group.Key]["action"]["on"];
                    uint   bri   = (uint)jData[group.Key]["action"]["bri"];
                    string alert = (string)jData[group.Key]["action"]["alert"];
                    HueBridge.HueGroups.Add(new HueGroup(id, name, type, on, bri, alert, load, loads));
                }
                GroupNum = (ushort)HueBridge.HueGroups.Count;
                CrestronConsole.PrintLine("{0} Rooms discovered", GroupNum);
                HueBridge.GetBridgeInfo("scenes");
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Error getting rooms: {0}", e);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Pulls all the bulbs and their current state from the bridge
 /// </summary>
 public void ProcBulbs(String jsondata)
 {
     try
     {
         JObject jData = JObject.Parse(jsondata);
         HueBridge.HueBulbs.Clear();
         foreach (var bulb in jData)
         {
             string id           = bulb.Key;
             bool   on           = (bool)jData[id]["state"]["on"];
             uint   bri          = (uint)jData[id]["state"]["bri"];
             string alert        = (string)jData[id]["state"]["alert"];
             bool   reachable    = (bool)jData[id]["state"]["reachable"];
             string type         = (string)jData[id]["type"];
             string name         = (string)jData[id]["name"];
             string model        = (string)jData[id]["modelid"];
             string manufacturer = (string)jData[id]["manufacturername"];
             string uid          = (string)jData[id]["uniqueid"];
             string swver        = (string)jData[id]["swversion"];
             if (type.Contains("color") || type.Contains("Color"))
             {
                 uint hue = (uint)jData[id]["state"]["hue"];
                 uint sat = (uint)jData[id]["state"]["sat"];
                 HueBridge.HueBulbs.Add(new HueBulb(id, on, bri, hue, sat, alert, reachable, type, name, model, manufacturer, uid, swver));
             }
             else
             {
                 HueBridge.HueBulbs.Add(new HueBulb(id, on, bri, alert, reachable, type, name, model, manufacturer, uid, swver));
             }
         }
         BulbNum = (ushort)HueBridge.HueBulbs.Count;
         CrestronConsole.PrintLine("{0} Bulbs discovered", BulbNum);
         HueBridge.GetBridgeInfo("groups");
     }
     catch (Exception e)
     {
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Pulls all the bulbs and their current state from the bridge
        /// </summary>
        public void ProcBulbs(string jsondata)
        {
            try
            {
                JObject json = JObject.Parse(jsondata);
                HueBridge.HueBulbs.Clear();
                uint   hue;
                uint   sat;
                uint   ct;
                uint   bri;
                string colormode;
                string type;
                string name;
                string manufacturer;
                string uid;
                string swver;
                bool   reachable;
                string model;
                bool   on;
                int    index = 0;
                foreach (var bulb in json)
                {
                    string id = bulb.Key;
                    hue          = 0;
                    sat          = 0;
                    ct           = 0;
                    bri          = 0;
                    colormode    = "";
                    type         = "";
                    name         = "";
                    manufacturer = "";
                    uid          = "";
                    swver        = "";
                    reachable    = false;
                    model        = "";
                    on           = false;
                    if (json[id]["state"].SelectToken("on") != null)
                    {
                        on = (bool)json[id]["state"]["on"];
                    }
                    if (json[id]["state"].SelectToken("reachable") != null)
                    {
                        reachable = (bool)json[id]["state"]["reachable"];
                    }
                    if (json[id].SelectToken("type") != null)
                    {
                        type = (string)json[id]["type"];
                    }
                    if (json[id].SelectToken("name") != null)
                    {
                        name = (string)json[id]["name"];
                    }
                    if (json[id].SelectToken("modelid") != null)
                    {
                        model = (string)json[id]["modelid"];
                    }
                    if (json[id].SelectToken("manufacturername") != null)
                    {
                        manufacturer = (string)json[id]["manufacturername"];
                    }
                    if (json[id].SelectToken("uniqueid") != null)
                    {
                        uid = (string)json[id]["uniqueid"];
                    }
                    if (json[id].SelectToken("swversion") != null)
                    {
                        swver = (string)json[id]["swversion"];
                    }
                    HueBridge.HueBulbs.Add(new HueBulb()
                    {
                        Id = id, On = on, Type = type, Name = name, Model = model, Manufacturer = manufacturer, Uid = uid, SwVer = swver, Reachable = reachable
                    });
                    index = HueBridge.HueBulbs.Count - 1;
                    if (json[id]["state"].SelectToken("bri") != null)
                    {
                        bri = (uint)json[id]["state"]["bri"];
                        HueBridge.HueBulbs[index].Bri = bri;
                    }
                    if (json[id]["state"].SelectToken("colormode") != null)
                    {
                        colormode = (string)json[id]["state"]["colormode"];
                        HueBridge.HueBulbs[index].ColorMode = colormode;
                        if (json[id]["state"].SelectToken("hue") != null)
                        {
                            hue = (uint)json[id]["state"]["hue"];
                            HueBridge.HueBulbs[index].Hue = hue;
                        }
                        if (json[id]["state"].SelectToken("sat") != null)
                        {
                            sat = (uint)json[id]["state"]["sat"];
                            HueBridge.HueBulbs[index].Sat = sat;
                        }

                        if (json[id]["state"].SelectToken("ct") != null)
                        {
                            ct = (uint)json[id]["state"]["ct"];
                            HueBridge.HueBulbs[index].Ct = ct;
                        }
                    }
                }

                /*
                 * foreach (var bulb in HueBridge.HueBulbs)
                 * {
                 *      CrestronConsole.PrintLine("Bulb Name: {0}, Bulb ID: {1}", bulb.Name, bulb.Id);
                 * }*/
                BulbNum = (ushort)HueBridge.HueBulbs.Count;
                CrestronConsole.PrintLine("{0} Bulbs discovered", BulbNum);
                if (Authorized == 1)
                {
                    HueBridge.GetBridgeInfo("groups");
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Error getting bulbs: {0}", e);
            }
        }