/// <summary> /// Attempts to discover the bridge IP address by invoking a Philips discovery broker API. /// </summary> private static void DiscoverBridgeIP() { try { var brokerInfo = JsonClient.RequestBroker() as JArray; DeviceIP = IPAddress.Parse(((JObject)brokerInfo[0])["internalipaddress"].Value <string>()); } catch (Exception ex) { throw new HubIPAddressNotFoundException(ex); } }
/// <summary> /// Retrieves the complete bridge configuration object, including the user whitelist. /// </summary> /// <returns>A <see cref="SharpBot_CLI.Config.Configuration" /> object representing the current configuration state of the bridge.</returns> //public static Config.Configuration GetBridgeConfiguration() //{ // RequireAuthentication(); // return ((JObject)JsonClient.RequestSecure("/config")).ToObject<Config.Configuration>(); //} /// <summary> /// Deletes the specified user from the whitelist. /// </summary> /// <param name="username">The user to delete.</param> /// <returns><c>true</c> on success, <c>false</c> otherwise.</returns> public static bool DeleteUser(string username) { RequireAuthentication(); JArray response = (JArray)JsonClient.RequestSecure(HttpMethod.Delete, "/config/whitelist/" + username); try { return(!string.IsNullOrWhiteSpace(response[0]["success"].Value <string>())); } catch { return(false); } }
/// <summary> /// Refreshes this light's state information. /// </summary> public void RefreshState(JToken localState = null) { if (localState == null) { localState = JsonClient.RequestSecure("/lights/" + ID); JsonConvert.PopulateObject(localState.ToString(), this); } else { JsonConvert.PopulateObject(localState.ToString(), State); } JsonConvert.PopulateObject(localState.ToString(), this); if (StateChanged != null) { StateChanged(this, State); } }
/// <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; } } }
/// <summary> /// Instructs the bridge to discover new lights. A maximum of 15 new lights is added to the bridge configuration. If you are adding more than 15 lights, call this method once per 1 minute. /// </summary> public static void Discover() { JsonClient.RequestSecure(HttpMethod.Post, "/lights"); }
/// <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); }
/// <summary> /// Sets this light's state information using a JSON object. /// </summary> /// <param name="newState">The Json object containing the new state information.</param> /// <remarks>For information on valid properties, see this API reference: http://developers.meethue.com/1_lightsapi.html#16_set_light_state </remarks> public void SetState(JObject newState) { JsonClient.RequestSecure(HttpMethod.Put, "/lights/" + ID + "/state", newState); RefreshState(newState); }