예제 #1
0
파일: weather_test.go 프로젝트: sqp/godock
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")
}
예제 #2
0
파일: clouds.go 프로젝트: 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
}