コード例 #1
0
        public async Task <bool> Init()
        {
            try {
                var account = await api.Authenticate();

                if (account == null)
                {
                    return(false);
                }
                updater = new SmartThingsUpdateListener(api);
                updater.UpdateReceived += (obj) => {
                    Console.WriteLine("Status update");
                };
                await updater.StartListening();

                #region testing
                var devices = await api.GetDevices();

                devices.ToList().ForEach(x => Console.WriteLine($"Name: {x.Name} Label: {x.Label}"));
                var officeLights = devices.FirstOrDefault((x) => (x.Label?.Contains("Office") ?? false) && (x.Label?.Contains("Light") ?? false));
                await api.TurnOnDevice(officeLights);

                await Task.Delay(10000);

                await api.TurnOffDevice(officeLights);

                #endregion
                return(true);
            } catch (Exception ex) {
                Console.WriteLine(ex);
            }
            return(false);
        }
コード例 #2
0
        public async Task <bool> Init()
        {
            try {
                var account = await api.Authenticate();

                if (account == null)
                {
                    return(false);
                }
                updater = new SmartThingsUpdateListener(api);
                updater.UpdateReceived += (obj) => {
                    Console.WriteLine("Status update");
                    if (obj.ShouldIgnoreUpdate())
                    {
                        return;
                    }
                };
                await updater.StartListening();

                #region testing
                var devices = await api.GetDevices();

                var actions = devices.SelectMany(x => x.CurrentStates).Select(x => x.Name).Distinct().ToList();
                var json    = actions.ToJson();
                devices.ToList().ForEach(x => Console.WriteLine($"Name: {x.Name} Label: {x.Label} : {string.Join(",",x.CurrentStates.Select(y=> y.Name))}"));
                //await Task.Delay(5000);
                var officeLights = devices.FirstOrDefault((x) => (x.Label?.Contains("Office") ?? false) && (x.Label?.Contains("Light") ?? false));
                await api.TurnOnDevice(officeLights);

                await Task.Delay(10000);

                await api.TurnOffDevice(officeLights);

                #endregion
                return(true);
            } catch (Exception ex) {
                Console.WriteLine(ex);
            }
            return(false);
        }
コード例 #3
0
        public async Task <bool> Login()
        {
            var account = await api.Authenticate();

            if (account == null)
            {
                return(false);
            }
            Devices = await api.GetDevices();

            updater = new SmartThingsUpdateListener(api);
            updater.UpdateReceived += (obj) =>
            {
                Console.WriteLine("Status update");
                if (obj.ShouldIgnoreUpdate())
                {
                    return;
                }
            };
            await updater.StartListening();

            return(true);
        }