コード例 #1
0
        public async Task GetBruntDevices()
        {
            await Login();

            var devices = await bruntClient.GetDevices();

            Assert.NotNull(devices);
            Assert.True(devices.Length == 2);
        }
コード例 #2
0
        public void OnTimer(object sender, ElapsedEventArgs args, bool isSunset)
        {
            eventLog.WriteEntry("Twilight!", EventLogEntryType.Information, eventId++);
            timer.Stop();
            timer.Elapsed -= (send, e) => this.OnTimer(send, e, isSunset);

            // Set BruntPosition
            var bruntClient = new BruntClient();
            var login       = bruntClient.Login(new BruntLoginCredz()
            {
                ID = config.ID, PASS = config.PASS
            }).Result;

            if (login == null)
            {
                eventLog.WriteEntry("Login failed!", EventLogEntryType.Error, eventId++);
                return;
            }
            var devices = bruntClient.GetDevices().Result;

            if (devices == null)
            {
                eventLog.WriteEntry("Error getting devices!", EventLogEntryType.Error, eventId++);
                return;
            }
            foreach (var d in devices.Where(d => config.Devices.Select(cd => cd.Name.ToLower().Trim()).Contains(d.NAME.ToLower().Trim())))
            {
                var deviceConfig = config.Devices.SingleOrDefault(dc => dc.Name.ToLower().Trim() == d.NAME.ToLower().Trim());
                var changed      = bruntClient.SetDevicePosition(
                    new BruntDevicePositionChange()
                {
                    DeviceName      = d.thingUri,
                    requestPosition = isSunset ? deviceConfig.SunsetPosition : deviceConfig.SunrisePosition
                }).Result;

                if (changed == null)
                {
                    eventLog.WriteEntry("Error updating device position!", EventLogEntryType.Error, eventId++);
                    return;
                }
                else
                {
                    eventLog.WriteEntry($"Changed {d.NAME} position to {(isSunset ? "sunset" : "sunrise")}", EventLogEntryType.Information, eventId++);
                }
            }

            var twilightClient = GetSSClient();
            var twilightInfo   = twilightClient.GetSunriseSunsetForDate().Result;
            var interval       = twilightClient.GetIntervalTillNextTwilight(twilightInfo, today);

            eventLog.WriteEntry($"{(isSunset ? "Sunset" : "Sunrise")} Twilight in {interval.Item1} milliseconds.", EventLogEntryType.Information, eventId++);

            timer.Interval = interval.Item1;
            timer.Elapsed += (send, e) => this.OnTimer(send, e, interval.Item2);
            timer.Start();
        }