Пример #1
0
        /// <summary>
        /// Refreshes all light objects and state information.
        /// </summary>
        public void Refresh()
        {
            Lights.Clear();

            JObject lights = JsonClient.RequestSecure(HttpMethod.Get, "/lights") as JObject;

            for (int i = 1; i <= Configuration.MAX_LIGHTS; i++)
            {
                if (lights[i.ToString()] != null)
                {
                    Light l = ((JObject)lights[i.ToString()]).ToObject <Light>();
                    l.ID = i;
                    l.RefreshState();
                    Lights.Add(l);
                }
                else
                {
                    // Lights are sequential, break if we don't have a light with the specified index.
                    break;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Registers a new user with the bridge device.
        /// </summary>
        /// <exception cref="HueConfigurationException">Thrown when this class has not been initialized (the <see cref="DeviceIP" /> is <c>null</c>).</exception>
        private static bool RegisterNewUser()
        {
            RequireInitialization();

            dynamic data = new ExpandoObject();

            data.devicetype = AppID;

            JArray response = JsonClient.Request(HttpMethod.Post, "/api", data);

            try
            {
                if (response[0]["success"]["username"] != null)
                {
                    Username = response[0]["success"]["username"].ToString();
                    return(true);
                }
                return(false);
            }
            catch
            {
                return(false);
            }
        }
Пример #3
0
 /// <summary>
 /// Sets the state of all lights, using Group 0.
 /// </summary>
 /// <param name="newState">The new state to apply to every light.</param>
 public static void SetStateAll(JObject newState)
 {
     JsonClient.RequestSecure(HttpMethod.Put, "/groups/0/action", newState);
 }