Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather output #283

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import coil.compose.AsyncImage
import org.dicio.skill.context.SkillContext
import org.dicio.skill.skill.SkillOutput
import org.stypox.dicio.R
import org.stypox.dicio.io.graphical.Headline
import org.stypox.dicio.io.graphical.HeadlineSpeechSkillOutput
import org.stypox.dicio.util.getString
import org.stypox.dicio.util.lowercaseCapitalized
Expand All @@ -33,10 +32,11 @@ sealed interface WeatherOutput : SkillOutput {
val temp: Double,
val tempMin: Double,
val tempMax: Double,
val tempString: String,
val windSpeed: Double,
) : WeatherOutput {
override fun getSpeechOutput(ctx: SkillContext): String = ctx.getString(
R.string.skill_weather_in_city_there_is_description, city, description
R.string.skill_weather_in_city_there_is_description, city, description, tempString
)

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.stypox.dicio.util.ConnectionUtils
import org.stypox.dicio.util.StringUtils
import java.io.FileNotFoundException
import java.util.Locale
import kotlin.math.roundToInt

class WeatherSkill(correspondingSkillInfo: SkillInfo, data: StandardRecognizerData<Weather>) :
StandardRecognizerSkill<Weather>(correspondingSkillInfo, data) {
Expand Down Expand Up @@ -47,14 +48,18 @@ class WeatherSkill(correspondingSkillInfo: SkillInfo, data: StandardRecognizerDa
val mainObject = weatherData.getJSONObject("main")
val windObject = weatherData.getJSONObject("wind")

val temp = mainObject.getDouble("temp")
return WeatherOutput.Success(
city = weatherData.getString("name"),
description = weatherObject.getString("description")
.apply { this[0].uppercaseChar() + this.substring(1) },
iconUrl = ICON_BASE_URL + weatherObject.getString("icon") + ICON_FORMAT,
temp = mainObject.getDouble("temp"),
temp = temp,
tempMin = mainObject.getDouble("temp_min"),
tempMax = mainObject.getDouble("temp_max"),
tempString = ctx.parserFormatter
?.niceNumber(temp.roundToInt().toDouble())?.speech(true)?.get()
?: (temp.roundToInt().toString()),
windSpeed = windObject.getDouble("speed"),
)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<string name="skill_open_opening">Apro %1$s…</string>
<string name="skill_search_here_is_what_i_found">Ecco cosa ho trovato</string>
<string name="skill_weather_could_not_find_city">Non ho trovato la città %1$s</string>
<string name="skill_weather_in_city_there_is_description">Al momento a %1$s c\'è %2$s</string>
<string name="skill_weather_in_city_there_is_description">Ci sono %2$s e %3$s gradi a %1$s al momento</string>
<string name="skill_weather_description_temperature">%1$s · %2$.1f°C</string>
<string name="skill_weather_min_max_wind">Temperatura minima: %1$.1f °C
\nTemperatura massima: %2$.1f °C
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<string name="skill_search_no_results">The search returned no results, try telling me again what you want to search for</string>
<string name="skill_search_what_question">What do you want to search for?</string>
<string name="skill_weather_could_not_find_city">Could not find city %1$s</string>
<string name="skill_weather_in_city_there_is_description">Currently in %1$s there is %2$s</string>
<string name="skill_weather_in_city_there_is_description">There is %2$s and %3$s degrees in %1$s right now</string>
<string name="skill_weather_description_temperature">%1$s · %2$.1f°C</string>
<string name="skill_weather_min_max_wind">Minimum temperature: %1$.1f°C\nMaximum temperature: %2$.1f°C\nWind speed: %3$.1fm/s</string>
<string name="skill_lyrics_song_not_found">Unable to find song %1$s</string>
Expand Down