Пример #1
0
        private async Task UpdateHistory(DeviceViewModel deviceVm)
        {
            try
            {
                Log.Debug(deviceVm.Address.AbsoluteUri, "Running history update");

                // Figure out how much history needs to be loaded
                // Get last entry from history of device X
                var lastUpdate = Devices.First(d => d.Address == deviceVm.Address).History.LastOrDefault().Time;
                // Calculate required history pages (max20)
                var timePassed    = DateTime.Now - lastUpdate;
                var requiredPages = (int)Math.Ceiling(timePassed.TotalMinutes / _IMPULSE);
                Log.Debug(deviceVm.Address.AbsoluteUri, "Last value was from", lastUpdate, "therefore pages required:", requiredPages);
                if (requiredPages <= 0)
                {
                    requiredPages = 1;
                }
                else if (requiredPages > 20)
                {
                    requiredPages = 20;
                }
                // Connect
                var service = new YouLessService(deviceVm.Address);
                // get each page and add to devices history
                for (int i = requiredPages; i != 0; i--)
                {
                    // Update History
                    var history = await service.GetHistory(i);

                    deviceVm.UpdateHistory(history);
                }

                // Save
                Save();

                Log.Debug(deviceVm.Address.AbsoluteUri, "done");
            }
            catch (Exception ex)
            {
                Log.Debug(deviceVm.Address.AbsoluteUri, "FAILED");
                Log.Error(deviceVm.Address.AbsoluteUri, ex);
            }
        }
Пример #2
0
        // STATUS ########################################################################

        internal async Task UpdateStatus(DeviceViewModel deviceVm)
        {
            try
            {
                Log.Debug(deviceVm.Address.AbsoluteUri, "Running status update");

                // Connect
                var service = new YouLessService(deviceVm.Address);
                // Update Status
                var status = await service.GetStatus();

                deviceVm.UpdateStatus(status);
                deviceVm.Status = true;

                Log.Debug(deviceVm.Address.AbsoluteUri, "done");
            }
            catch (Exception ex)
            {
                deviceVm.Status = false;
                Log.Debug(deviceVm.Address.AbsoluteUri, "FAILED");
                Log.Error(deviceVm.Address.AbsoluteUri, ex);
            }
        }