Пример #1
0
        public void FromWeatherDataInfoConnectedTest()
        {
            var info = new WeatherDataInfo()
            {
                Connected   = true,
                Temperature = 15,
                Humidity    = 99.8f
            };

            var sut = new ImageMetaData();

            sut.FromWeatherDataInfo(info);

            Assert.AreEqual(15, sut.WeatherData.Temperature);
            Assert.AreEqual((double)99.8f, sut.WeatherData.Humidity);
        }
Пример #2
0
 public async Task Disconnect()
 {
     if (WeatherData != null)
     {
         Logger.Info("Disconnected Weather Device");
     }
     if (updateTimer != null)
     {
         await updateTimer.Stop();
     }
     WeatherData?.Disconnect();
     WeatherData     = null;
     WeatherDataInfo = DeviceInfo.CreateDefaultInstance <WeatherDataInfo>();
     BroadcastWeatherDataInfo();
     RaisePropertyChanged(nameof(WeatherData));
 }
Пример #3
0
 public void FromWeatherDataInfo(WeatherDataInfo info)
 {
     if (info.Connected)
     {
         WeatherData.CloudCover     = info.CloudCover;
         WeatherData.DewPoint       = info.DewPoint;
         WeatherData.Humidity       = info.Humidity;
         WeatherData.Pressure       = info.Pressure;
         WeatherData.SkyBrightness  = info.SkyBrightness;
         WeatherData.SkyQuality     = info.SkyQuality;
         WeatherData.SkyTemperature = info.SkyTemperature;
         WeatherData.StarFWHM       = info.StarFWHM;
         WeatherData.Temperature    = info.Temperature;
         WeatherData.WindDirection  = info.WindDirection;
         WeatherData.WindGust       = info.WindGust;
         WeatherData.WindSpeed      = info.WindSpeed;
     }
 }
Пример #4
0
        private async Task <bool> ChooseWeatherData()
        {
            await ss.WaitAsync();

            try {
                await Disconnect();

                if (updateTimer != null)
                {
                    await updateTimer.Stop();
                }

                if (WeatherDataChooserVM.SelectedDevice.Id == "No_Device")
                {
                    profileService.ActiveProfile.WeatherDataSettings.Id = WeatherDataChooserVM.SelectedDevice.Id;
                    return(false);
                }

                applicationStatusMediator.StatusUpdate(
                    new ApplicationStatus()
                {
                    Source = Title,
                    Status = Locale.Loc.Instance["LblConnecting"]
                }
                    );

                var weatherdev = (IWeatherData)WeatherDataChooserVM.SelectedDevice;
                _cancelChooseWeatherDataSource?.Dispose();
                _cancelChooseWeatherDataSource = new CancellationTokenSource();
                if (weatherdev != null)
                {
                    try {
                        var connected = await weatherdev?.Connect(_cancelChooseWeatherDataSource.Token);

                        _cancelChooseWeatherDataSource.Token.ThrowIfCancellationRequested();
                        if (connected)
                        {
                            WeatherData = weatherdev;

                            WeatherDataInfo = new WeatherDataInfo {
                                Connected      = true,
                                Name           = WeatherData.Name,
                                AveragePeriod  = WeatherData.AveragePeriod,
                                CloudCover     = WeatherData.CloudCover,
                                DewPoint       = WeatherData.DewPoint,
                                Humidity       = WeatherData.Humidity,
                                Pressure       = WeatherData.Pressure,
                                RainRate       = WeatherData.RainRate,
                                SkyBrightness  = WeatherData.SkyBrightness,
                                SkyQuality     = WeatherData.SkyQuality,
                                SkyTemperature = WeatherData.SkyTemperature,
                                StarFWHM       = WeatherData.StarFWHM,
                                Temperature    = WeatherData.Temperature,
                                WindDirection  = WeatherData.WindDirection,
                                WindGust       = WeatherData.WindGust,
                                WindSpeed      = WeatherData.WindSpeed
                            };

                            Notification.ShowSuccess(Locale.Loc.Instance["LblWeatherConnected"]);

                            updateTimer.Start();

                            profileService.ActiveProfile.WeatherDataSettings.Id = WeatherData.Id;

                            Logger.Info($"Successfully connected Weather Device. Id: {weatherdev.Id} Name: {weatherdev.Name} Driver Version: {weatherdev.DriverVersion}");

                            return(true);
                        }
                        else
                        {
                            WeatherDataInfo.Connected = false;
                            WeatherData = null;
                            return(false);
                        }
                    } catch (OperationCanceledException) {
                        if (WeatherDataInfo.Connected)
                        {
                            await Disconnect();
                        }
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            } finally {
                ss.Release();
                applicationStatusMediator.StatusUpdate(
                    new ApplicationStatus()
                {
                    Source = Title,
                    Status = string.Empty
                }
                    );
            }
        }
Пример #5
0
 public void UpdateDeviceInfo(WeatherDataInfo deviceInfo)
 {
     this.weatherDataInfo = deviceInfo;
 }