105 lines
4.4 KiB
Go
105 lines
4.4 KiB
Go
package briefing
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/module"
|
|
)
|
|
|
|
type CurrentConditionsModule struct {
|
|
ConditionText string `json:"condition_text,omitempty"`
|
|
ConditionTextLower string `json:"condition_text_lower,omitempty"`
|
|
IsDay *bool `json:"is_day,omitempty"`
|
|
TemperatureC *int `json:"temperature_c,omitempty"`
|
|
TemperatureF *int `json:"temperature_f,omitempty"`
|
|
ApparentTemperatureC *int `json:"apparent_temperature_c,omitempty"`
|
|
ApparentTemperatureF *int `json:"apparent_temperature_f,omitempty"`
|
|
DewpointC *int `json:"dewpoint_c,omitempty"`
|
|
DewpointF *int `json:"dewpoint_f,omitempty"`
|
|
RelativeHumidityPercent *int `json:"relative_humidity_percent,omitempty"`
|
|
WindSpeedKmh *int `json:"wind_speed_kmh,omitempty"`
|
|
WindSpeedMph *int `json:"wind_speed_mph,omitempty"`
|
|
WindDirection string `json:"wind_direction,omitempty"`
|
|
WindDirectionText string `json:"wind_direction_text,omitempty"`
|
|
}
|
|
|
|
type CurrentConditionsPromptExport struct {
|
|
ConditionText string `json:"condition_text,omitempty"`
|
|
IsDay *bool `json:"is_day,omitempty"`
|
|
TemperatureC *int `json:"temperature_c,omitempty"`
|
|
TemperatureF *int `json:"temperature_f,omitempty"`
|
|
ApparentTemperatureC *int `json:"apparent_temperature_c,omitempty"`
|
|
ApparentTemperatureF *int `json:"apparent_temperature_f,omitempty"`
|
|
DewpointC *int `json:"dewpoint_c,omitempty"`
|
|
DewpointF *int `json:"dewpoint_f,omitempty"`
|
|
RelativeHumidityPercent *int `json:"relative_humidity_percent,omitempty"`
|
|
WindSpeedKmh *int `json:"wind_speed_kmh,omitempty"`
|
|
WindSpeedMph *int `json:"wind_speed_mph,omitempty"`
|
|
WindDirection string `json:"wind_direction,omitempty"`
|
|
}
|
|
|
|
func buildCurrentConditionsModule(ctx ModuleContext, _ any) (*module.Output, error) {
|
|
current := ctx.Collected.Current
|
|
if current == nil {
|
|
return nil, nil
|
|
}
|
|
value := CurrentConditionsModule{
|
|
ConditionText: current.ConditionText,
|
|
ConditionTextLower: strings.ToLower(current.ConditionText),
|
|
IsDay: copyBool(current.IsDay),
|
|
TemperatureC: roundedInt(current.TemperatureC),
|
|
TemperatureF: roundedInt(current.TemperatureF),
|
|
ApparentTemperatureC: roundedInt(current.ApparentTemperatureC),
|
|
ApparentTemperatureF: roundedInt(current.ApparentTemperatureF),
|
|
DewpointC: roundedInt(current.DewpointC),
|
|
DewpointF: roundedInt(current.DewpointF),
|
|
RelativeHumidityPercent: roundedInt(current.RelativeHumidityPercent),
|
|
WindSpeedKmh: roundedInt(current.WindSpeedKmh),
|
|
WindSpeedMph: roundedInt(current.WindSpeedMph),
|
|
WindDirection: windDirectionLabel(current.WindDirectionDegrees),
|
|
WindDirectionText: windDirectionTextLabel(current.WindDirectionDegrees),
|
|
}
|
|
if value.isEmpty() {
|
|
return nil, nil
|
|
}
|
|
return &module.Output{ID: module.CurrentConditions, StanzaName: "current_conditions", Value: value}, nil
|
|
}
|
|
|
|
func exportCurrentConditionsPromptValue(value any) (any, error) {
|
|
rich, ok := value.(CurrentConditionsModule)
|
|
if !ok {
|
|
return nil, unexpectedPromptExportValue(value, CurrentConditionsModule{})
|
|
}
|
|
return CurrentConditionsPromptExport{
|
|
ConditionText: rich.ConditionText,
|
|
IsDay: copyBool(rich.IsDay),
|
|
TemperatureC: copyInt(rich.TemperatureC),
|
|
TemperatureF: copyInt(rich.TemperatureF),
|
|
ApparentTemperatureC: copyInt(rich.ApparentTemperatureC),
|
|
ApparentTemperatureF: copyInt(rich.ApparentTemperatureF),
|
|
DewpointC: copyInt(rich.DewpointC),
|
|
DewpointF: copyInt(rich.DewpointF),
|
|
RelativeHumidityPercent: copyInt(rich.RelativeHumidityPercent),
|
|
WindSpeedKmh: copyInt(rich.WindSpeedKmh),
|
|
WindSpeedMph: copyInt(rich.WindSpeedMph),
|
|
WindDirection: rich.WindDirection,
|
|
}, nil
|
|
}
|
|
|
|
func (v CurrentConditionsModule) isEmpty() bool {
|
|
return v.ConditionText == "" &&
|
|
v.ConditionTextLower == "" &&
|
|
v.IsDay == nil &&
|
|
v.TemperatureC == nil &&
|
|
v.TemperatureF == nil &&
|
|
v.ApparentTemperatureC == nil &&
|
|
v.ApparentTemperatureF == nil &&
|
|
v.DewpointC == nil &&
|
|
v.DewpointF == nil &&
|
|
v.RelativeHumidityPercent == nil &&
|
|
v.WindSpeedKmh == nil &&
|
|
v.WindSpeedMph == nil &&
|
|
v.WindDirection == "" &&
|
|
v.WindDirectionText == ""
|
|
}
|