Beispiel #1
0
        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));
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        internal async Task <HueObjectBase> LoginWrapperAsync(HueActionDelegate hueAction)
        {
            HueActionDelegate method = async delegate
            {
                return(!IsLoggedIn ? (HueObjectBase) new Error(-1, "", "No User Logged In") : await hueAction());
            };

            return(await ConnectionWrapperAsync(method));
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        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));
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
        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));
        }
Beispiel #8
0
        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));
        }
        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));
        }
Beispiel #10
0
        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));
        }
Beispiel #11
0
        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));
        }
Beispiel #12
0
        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));
        }
Beispiel #13
0
        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));
        }
Beispiel #14
0
        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));
        }
Beispiel #15
0
        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));
        }
Beispiel #16
0
        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));
        }
Beispiel #17
0
        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));
        }
Beispiel #18
0
        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);
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        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
            }));
        }
Beispiel #21
0
 internal async Task <HueObjectBase> ConnectionWrapperAsync(HueActionDelegate hueAction)
 {
     return(!Connected ? (HueObjectBase) new Error(-1, "", "Not connected to a Hue Bridge") : await hueAction());
 }