Exemplo n.º 1
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")
}
Exemplo n.º 2
0
Arquivo: clouds.go Projeto: sqp/godock
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
	app := &Applet{AppBase: base, weather: weather.New()}
	app.SetConfig(&app.conf, app.actions()...)

	// Events.
	events.OnClick = app.DialogWeatherCurrent
	events.OnMiddleClick = app.DialogWeatherCurrent
	events.OnSubClick = app.DialogWeatherForecast
	events.OnBuildMenu = func(menu cdtype.Menuer) {
		var items []int
		if app.weather.Current() != nil || app.weather.Forecast() != nil {
			if app.weather.Current() != nil {
				items = append(items, ActionShowCurrent)
			}
			items = append(items, ActionOpenWebpage, ActionRecheckNow)
		}
		items = append(items, ActionSetLocation)
		app.Action().BuildMenu(menu, items)
	}

	// Weather polling.
	app.Poller().Add(app.Check)
	app.Poller().SetPreCheck(func() { app.SetEmblem(app.FileLocation("img", IconWork), EmblemWork) })
	app.Poller().SetPostCheck(func() { app.SetEmblem("none", EmblemWork) })
	return app
}