Beispiel #1
0
// AskLocationConfirm search the list of cities matching the provided name
// and shows a dialog with the list of locations for the user to choose.
// When validated, the config file is updated and ...(TODO: need reload, to check).
// If no data is found, the user is sent back to the AskLocationText dialog with
// the text he provided.
//
func (app *Applet) AskLocationConfirm(locstr string) {
	if locstr == "" {
		app.SetLocationCode("", "*AUTODETECT*")
		return
	}
	locations, e := weather.FindLocation(locstr)
	if app.Log().Err(e, "FindLocation") {
		app.ShowDialog("Find location: "+e.Error(), 10)
		return
	}

	if len(locations) == 0 { // Try again.
		app.AskLocationText(locstr)
		return
	}

	var ids []string
	for _, loc := range locations {
		ids = append(ids, loc.Name)
	}

	e = app.PopupDialog(cdtype.DialogData{
		Message: app.Translate("Select your location:"),
		Widget: cdtype.DialogWidgetList{
			Values: ids,
		},
		Buttons: "ok;cancel",
		Callback: cdtype.DialogCallbackValidInt(func(id int) {
			app.SetLocationCode(locations[id].ID, locations[id].Name)
		}),
	})
	app.Log().Err(e, "popup AskLocation")
}
Beispiel #2
0
func TestDockbus(t *testing.T) {
	wea := weather.New()
	locations, e := weather.FindLocation("paris")
	assert.NoError(t, e, "weather.FindLocation")
	assert.NotEmpty(t, locations, "locations")

	wea.SetConfig(&weather.Config{
		LocationCode:       locations[0].ID,
		NbDays:             10,
		DisplayCurrentIcon: true,
		Time24H:            true,
		UseCelcius:         true,
	})
	for e := range wea.Get() {
		assert.NoError(t, e, "weather.Get")
	}
	cur := wea.Current()
	assert.NotNil(t, cur, "Current")

	fc := wea.Forecast()
	assert.True(t, len(fc.Days) > 10, "Forecast")

	assert.Equal(t, "Paris-Montsouris, 75, FR", cur.Observatory, "Observatory")
	assert.Equal(t, "Paris, 75, France", cur.LocName, "LocName")
	assert.Equal(t, "°C", cur.UnitTemp, "UnitTemp")
	assert.Equal(t, "km/h", cur.UnitSpeed, "UnitSpeed")
	assert.NotEmpty(t, cur.WeatherIcon, "WeatherIcon")
	assert.NotEmpty(t, cur.MoonIcon, "MoonIcon")
}
Beispiel #3
0
// DetectLocation tries to detect your location from IP and get the matching code.
//
func (app *Applet) DetectLocation() {
	loc, e := iplocation.Get()
	if app.Log().Err(e, "autodetect location") {
		return
	}
	locations, e := weather.FindLocation(loc.City + ", " + loc.Country)
	if app.Log().Err(e, "FindLocation") || len(locations) == 0 {
		return
	}
	app.conf.LocationCode = locations[0].ID // do not save, just set live value.
	app.Log().Debug("autodetect location", locations[0].Name)
}