public (bool status, WeatherData response) GetWeatherInfo(string apiKey, int pinCode = 689653, string countryCode = "in", bool withTTS = true) { if (!Core.IsNetworkAvailable) { Logger.Log("Cannot continue as network isn't available.", LogLevels.Warn); return(false, WeatherResult); } if (Helpers.IsNullOrEmpty(apiKey)) { return(false, WeatherResult); } if (pinCode <= 0 || Helpers.IsNullOrEmpty(countryCode)) { return(false, WeatherResult); } (bool status, ApiResponseStructure.Rootobject response) = FetchWeatherInfo(apiKey, pinCode, countryCode); if (status) { WeatherResult.Latitude = response.coord.lat; WeatherResult.Logitude = response.coord.lon; WeatherResult.Temperature = response.main.temp; WeatherResult.WeatherMain = response.weather[0].main; WeatherResult.WeatherIcon = response.weather[0].icon; WeatherResult.WeatherDescription = response.weather[0].description; WeatherResult.Pressure = response.main.pressure; WeatherResult.Humidity = response.main.humidity; WeatherResult.SeaLevel = response.main.sea_level; WeatherResult.GroundLevel = response.main.grnd_level; WeatherResult.WindSpeed = response.wind.speed; WeatherResult.WindDegree = response.wind.deg; WeatherResult.Clouds = response.clouds.all; WeatherResult.TimeZone = response.timezone; WeatherResult.LocationName = response.name; if (withTTS) { Helpers.InBackgroundThread(async() => { await TTSService.SpeakText($"Sir, The weather at {pinCode} is...", true).ConfigureAwait(false); await TTSService.SpeakText($"Temperature is {WeatherResult.Temperature}").ConfigureAwait(false); await TTSService.SpeakText($"Humidity is {WeatherResult.Humidity}").ConfigureAwait(false); await TTSService.SpeakText($"Pressure is {WeatherResult.Pressure}").ConfigureAwait(false); await TTSService.SpeakText($"Sea Level is {WeatherResult.SeaLevel}").ConfigureAwait(false); await TTSService.SpeakText($"Wind Speed is {WeatherResult.WindSpeed}").ConfigureAwait(false); await TTSService.SpeakText($"And the location name is {WeatherResult.LocationName}").ConfigureAwait(false); await TTSService.SpeakText($"and thats all sir!").ConfigureAwait(false); }); } return(true, WeatherResult); } else { Logger.Log("failed to assign weather info values", LogLevels.Trace); return(false, WeatherResult); } }
private void OnScheduledTimeReached(object sender, ScheduledTaskEventArgs e) { if (Alarms.Count <= 0) { return; } foreach (Alarm alarm in Alarms) { if (alarm.AlarmGuid == e.Guid) { Logger.Log($"ALARM >>> {alarm.AlarmMessage}"); if (alarm.ShouldUseTTS) { Task.Run(async() => await TTSService.SpeakText($"Sir, {alarm.AlarmMessage}", true).ConfigureAwait(false)); } Helpers.InBackgroundThread(async() => await PlayAlarmSound(alarm.AlarmGuid).ConfigureAwait(false)); alarm.IsCompleted = true; if (!alarm.ShouldRepeat) { foreach (SchedulerConfig task in Core.Scheduler.Configs) { if (task.Guid == e.Guid) { if (task.SchedulerTimer != null) { task.SchedulerTimer.Dispose(); } } } } return; } } }