public async Task <HueObjectBase> GetGroupsFullAsync() { HueActionDelegate method = async delegate { string returnString = await Context.GetAsync(Context.GroupsAllURI()); var groups = HueObjectFactory.CreateHueObject(returnString, Context, HueObjectType.Group) as HueObjectCollectionBase <Group>; if (groups != null) { var groups2 = (from l in groups.Dictionary.Values select l).ToList(); foreach (Group group in groups2) { HueObjectBase groupDetail = await group.GetAttributesAsync(); var detail = groupDetail as Group; if (detail != null) { groups.Dictionary[group.ID] = detail; } } _groups = groups; } return(groups); }; return(await Context.LoginWrapperAsync(method)); }
public BridgeConfig(JObject jObject) { Name = (string)jObject["name"]; MAC = (string)jObject["mac"]; DHCP = (bool?)jObject["dhcp"]; IPAddress = (string)jObject["ipaddress"]; NetMask = (string)jObject["netmask"]; Gateway = (string)jObject["gateway"]; ProxyAddress = (string)jObject["proxyaddress"]; ProxyPort = (int?)jObject["proxyport"]; LastUpdated = (DateTime?)jObject["UTC"]; WhiteList = jObject["whitelist"] != null ? new HueObjectCollectionBase <Client>(JObject.FromObject(jObject["whitelist"])) : new HueObjectCollectionBase <Client>(); SoftwareVersion = (string)jObject["swversion"]; if (jObject["swupdate"] != null) { HueObjectBase softwareUpdate = HueObjectFactory.CreateHueObject(jObject["swupdate"].ToString(), HueObjectType.BridgeSoftwareUpdate); var update = softwareUpdate as BridgeSoftwareUpdate; if (update != null) { SoftwareUpdate = update; } } LinkButton = (bool?)jObject["linkbutton"]; PortalServices = (bool?)jObject["portalservices"]; }
public Light(JObject jObject, HueConnection context, string id) : this(context, id) { if (jObject["state"] != null) { var lightState = HueObjectFactory.CreateHueObject(jObject["state"].ToString(), HueObjectType.LightState) as State; if (lightState != null) { State = lightState; } } Type = (string)jObject["type"]; LightType = EnumHelper.GetEnumWithDescription <LightType>(Type); SupportsColorModeAttribute supportsColorModeAttribute = LightType.GetEnumAttribute <SupportsColorModeAttribute>(); if (supportsColorModeAttribute != null) { SupportedColorModes = supportsColorModeAttribute.Modes; } else { SupportedColorModes = new List <ColorMode>(); } Name = (string)jObject["name"]; ModelID = (string)jObject["modelid"]; SoftwareVersion = (string)jObject["swversion"]; }
public async Task <HueObjectBase> LoginAsync(string userID) { HueActionDelegate method = async delegate { string returnString = await Context.GetAsync(String.Format(Resources.ConfigURI, InternalIPAddress, userID)); HueObjectBase returnObject = HueObjectFactory.CreateHueObject(returnString, HueObjectType.BridgeConfig); var bridgeConfig = returnObject as BridgeConfig; if (bridgeConfig != null) { if (bridgeConfig.WhiteList.Count > 0) { Context.LoggedInID = userID; var success = new HueObjectCollectionBase <Success>(); success.Dictionary.Add("1", new Success("", String.Format("Logged in with id {0}", userID))); return(success); } var error = new HueObjectCollectionBase <Error>(); error.Dictionary.Add("1", new Error(-1, returnString, String.Format("unable to login with id {0}", userID))); return(error); } return(returnObject); }; return(await Context.ConnectionWrapperAsync(method)); }
public async Task <HueObjectBase> DeleteGroupAsync(string groupID) { HueActionDelegate method = async delegate { string returnString = await Context.DeleteAsync(Context.GroupURI(groupID)); return(HueObjectFactory.CreateHueObject(returnString, HueObjectType.Success)); }; return(await Context.LoginWrapperAsync(method)); }
public async Task <HueObjectBase> RemoveClientAsync(string idToDelete) { HueActionDelegate method = async delegate { string returnString = await Context.DeleteAsync(String.Format(Resources.UserDeleteURI, InternalIPAddress, Context.LoggedInID, idToDelete)); return(HueObjectFactory.CreateHueObject(returnString, HueObjectType.Success)); }; return(await Context.LoginWrapperAsync(method)); }
protected async Task <HueObjectBase> GetAttributesAsync <T>(string id) { HueActionDelegate method = async delegate { string returnString = await Context.GetAsync(URI); return(HueObjectFactory.CreateHueObject(JObject.Parse(returnString), id, Context, HueObjectFactory.GetType(typeof(T)))); }; return(await Context.LoginWrapperAsync(method)); }
public async Task <HueObjectBase> DeleteScheduleAsync(string scheduleID) { HueActionDelegate method = async delegate { string returnString = await Context.DeleteAsync(String.Format(Resources.ScheduleURI, InternalIPAddress, Context.LoggedInID, scheduleID)); return(HueObjectFactory.CreateHueObject(returnString, HueObjectType.Success)); }; return(await Context.LoginWrapperAsync(method)); }
public async Task <HueObjectBase> GetAttributesAsync() { HueActionDelegate method = async delegate { string returnString = await Context.GetAsync(Context.ScheduleURI(ID)); return(HueObjectFactory.CreateHueObject(JObject.Parse(returnString), ID, Context, HueObjectType.Schedule)); }; return(await Context.LoginWrapperAsync(method)); }
public async Task <HueObjectBase> GetSchedulesAsync() { HueActionDelegate method = async delegate { string returnString = await Context.GetAsync(String.Format(Resources.SchedulesAllURI, InternalIPAddress, Context.LoggedInID)); return(HueObjectFactory.CreateHueObject(returnString, Context, HueObjectType.Schedule)); }; return(await Context.LoginWrapperAsync(method)); }
public async Task <HueObjectBase> StartNewLightScanAsync() { HueActionDelegate method = async delegate { string returnString = await Context.PostAsync(string.Format(Resources.LightsAllURI, InternalIPAddress, Context.LoggedInID), ""); return(HueObjectFactory.CreateHueObject(returnString, HueObjectType.Success)); } ; return(await Context.LoginWrapperAsync(method)); }
public async Task <HueObjectBase> SetBridgeConfigurationAsync(BridgeConfig bridgeConfig) { HueActionDelegate method = async delegate { string newConfigString = bridgeConfig.ToJSON(); string returnString = await Context.PutAsync(String.Format(Resources.ConfigURI, InternalIPAddress, Context.LoggedInID), newConfigString); return(HueObjectFactory.CreateHueObject(returnString, HueObjectType.Success)); }; return(await Context.LoginWrapperAsync(method)); }
public async Task <HueObjectBase> SetAttributesAsync(Schedule schedule) { HueActionDelegate method = async delegate { string newScheduleString = schedule.ToJSON(); string returnString = await Context.PutAsync(Context.ScheduleURI(ID), newScheduleString); return(HueObjectFactory.CreateHueObject(returnString, HueObjectType.Success)); }; return(await Context.LoginWrapperAsync(method)); }
public async Task <HueObjectBase> GetLastAddedLightsAsync() { HueActionDelegate method = async delegate { string returnString = await Context.GetAsync(string.Format(Resources.LightsNewURI, InternalIPAddress, Context.LoggedInID)); return(HueObjectFactory.CreateHueObject(returnString, HueObjectType.LastAddedLights)); } ; return(await Context.LoginWrapperAsync(method)); }
public async Task <HueObjectBase> CreateScheduleAsync(Schedule schedule) { HueActionDelegate method = async delegate { string newScheduleString = schedule.ToJSON(); string returnString = await Context.PostAsync(String.Format(Resources.SchedulesAllURI, InternalIPAddress, Context.LoggedInID), newScheduleString); return(HueObjectFactory.CreateHueObject(returnString, HueObjectType.Success)); }; return(await Context.LoginWrapperAsync(method)); }
public async Task <HueObjectBase> CreateNewClientAsync(string clientType, string id) { HueActionDelegate method = async delegate { var newClient = new Client(clientType, id); string newClientString = newClient.ToJSON(); string returnString = await Context.PostAsync(String.Format(Resources.DefaultURI, InternalIPAddress), newClientString); return(HueObjectFactory.CreateHueObject(returnString, HueObjectType.Success)); }; return(await Context.ConnectionWrapperAsync(method)); }
public async Task <HueObjectBase> CreateGroupAsync(string groupName, IEnumerable <string> lights) { HueActionDelegate method = async delegate { var newGroup = new Group { Name = groupName, LightsIDs = lights.ToList() }; string newGroupString = newGroup.ToJSON(); string returnString = await Context.PostAsync(Context.GroupsAllURI(), newGroupString); return(HueObjectFactory.CreateHueObject(returnString, HueObjectType.Success)); }; return(await Context.LoginWrapperAsync(method)); }
public Schedule(JObject jObject, HueConnection connection, string id) : base(connection, id) { Name = (string)jObject["name"]; Description = (string)jObject["description"]; if (jObject["command"] != null) { var command = HueObjectFactory.CreateHueObject(jObject["command"].ToString(), HueObjectType.Command) as Command; if (command != null) { Command = command; } } Time = (DateTime?)jObject["time"]; }
protected async Task <HueObjectBase> SetAttributesAsync <T>(string id, T myObject) { HueActionDelegate method = async delegate { string newObjectString = JsonConvert.SerializeObject(myObject, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); string returnString = await Context.PutAsync(URI, newObjectString); return(HueObjectFactory.CreateHueObject(returnString, HueObjectType.Success)); } ; return(await Context.LoginWrapperAsync(method)); }
public async Task <HueObjectBase> GetLightsAsync() { HueActionDelegate method = async delegate { string returnString = await Context.GetAsync(string.Format(Resources.LightsAllURI, InternalIPAddress, Context.LoggedInID)); return(HueObjectFactory.CreateHueObject(returnString, Context, HueObjectType.Light)); }; var rv = await Context.LoginWrapperAsync(method); var lights = rv as HueObjectCollectionBase <Light>; if (lights != null) { _lights = lights; } return(rv); }
public async Task <HueObjectBase> GetGroupsAsync() { HueActionDelegate method = async delegate { string returnString = await Context.GetAsync(Context.GroupsAllURI()); return(HueObjectFactory.CreateHueObject(returnString, Context, HueObjectType.Group)); }; var rv = await Context.LoginWrapperAsync(method); var groups = rv as HueObjectCollectionBase <Group>; if (groups != null) { _groups = groups; } return(rv); }
public Group(JObject jObject, HueConnection context, string id) : base(context, id) { Name = (string)jObject["name"]; if (jObject["action"] != null) { var lightState = HueObjectFactory.CreateHueObject(jObject["action"].ToString(), HueObjectType.LightState) as State; if (lightState != null) { State = lightState; } } Lights = new HueObjectCollectionBase <Light>(); if (jObject["lights"] != null) { LightsIDs = jObject["lights"].ToObject <List <string> >(); } }
protected async Task <HueObjectBase> SetStateAsync(string id, State state) { string uri = StateURI; HueActionDelegate method = async delegate { string newStateString = JsonConvert.SerializeObject(state, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); string returnString = await Context.PutAsync(uri, newStateString); return(HueObjectFactory.CreateHueObject(returnString, HueObjectType.Success)); }; return(await Context.ThrottleWrapperAsync(new HueConnection.QueueItem { Time = DateTime.Now, Path = uri, Action = method })); }
public HueObjectCollectionBase(JObject jObject, HueConnection connection) { Dictionary = new Dictionary <string, T>(); foreach (KeyValuePair <string, object> kvp in JsonConvert.DeserializeObject <Dictionary <string, object> >(jObject.ToString())) { try { JObject myObject = JObject.FromObject(kvp.Value); HueObjectBase item = HueObjectFactory.CreateHueObject(myObject, kvp.Key, connection, HueObjectFactory.GetType(typeof(T))); if (item is T) { Dictionary.Add(kvp.Key, (T)item); } } catch (ArgumentException exception) { Debug.WriteLine("Error when converting {0} : {1} - {2}", kvp.Key, kvp.Value, exception.Message); } } }
public HueObjectCollectionBase(JArray jArray, HueConnection connection) { Dictionary = new Dictionary <string, T>(); foreach (object myObject in JsonConvert.DeserializeObject <List <object> >(jArray.ToString())) { try { JObject myJObject = JObject.FromObject(myObject); HueObjectBase item = HueObjectFactory.CreateHueObject(myJObject, connection, HueObjectFactory.GetType(typeof(T))); if (item is T) { Dictionary.Add(Dictionary.Count.ToString(CultureInfo.InvariantCulture), (T)item); } } catch (ArgumentException exception) { Debug.WriteLine("Error when converting {0} - {1}", myObject, exception.Message); } } }
private async Task <HueObjectBase> GetBridgesFromPortalAPIAsync(HueConnection connection) { string returnString = await connection.GetAsync(Resources.BridgeUPNPURI); return(HueObjectFactory.CreateHueObject(returnString, connection, HueObjectType.Bridge) as HueObjectCollectionBase <Bridge> ?? (HueObjectBase) new Error(-1, "", "No Hue Bridge Found")); }