diff --git a/plugins/weather/plugin.go b/plugins/weather/plugin.go index 4fc6ee095..2297d5da0 100644 --- a/plugins/weather/plugin.go +++ b/plugins/weather/plugin.go @@ -22,15 +22,14 @@ import ( "fmt" "sync" - "github.com/e154/smart-home/common/logger" - "github.com/e154/smart-home/system/event_bus/events" - "github.com/pkg/errors" "github.com/e154/smart-home/common" + "github.com/e154/smart-home/common/logger" m "github.com/e154/smart-home/models" "github.com/e154/smart-home/system/entity_manager" "github.com/e154/smart-home/system/event_bus" + "github.com/e154/smart-home/system/event_bus/events" "github.com/e154/smart-home/system/plugins" ) diff --git a/plugins/weather_met/weather_met.go b/plugins/weather_met/weather_met.go index 1899aeb0e..15002934c 100644 --- a/plugins/weather_met/weather_met.go +++ b/plugins/weather_met/weather_met.go @@ -76,15 +76,15 @@ func (p *WeatherMet) UpdateWeatherList(entityId common.EntityId, settings m.Attr Lon: settings[weather.AttrLon].Float64(), } - var update bool + //var update bool if _, ok := p.zones.Load(entityId); !ok { - update = true + //update = true } p.zones.Store(entityId, zone) - if !update { - return - } + //if !update { + // return + //} _ = p.UpdateForecastForAll() } diff --git a/tests/plugins/weather_met_test.go b/tests/plugins/weather_met_test.go index 637919b62..8fe9423d4 100644 --- a/tests/plugins/weather_met_test.go +++ b/tests/plugins/weather_met_test.go @@ -104,6 +104,10 @@ func TestWeatherMet(t *testing.T) { err = eventBus.Subscribe(event_bus.TopicEntities, fn) So(err, ShouldBeNil) + defer func() { + _ = eventBus.Unsubscribe(event_bus.TopicEntities, fn) + }() + settings := weatherPlugin.NewSettings() settings[weatherPlugin.AttrLat].Value = 54.9022 settings[weatherPlugin.AttrLon].Value = 83.0335 @@ -133,8 +137,7 @@ func TestWeatherMet(t *testing.T) { So(msg.To, ShouldEqual, "weather.home") So(msg.Attributes[weatherPlugin.AttrWeatherAttribution].String(), ShouldEqual, "Weather forecast from met.no, delivered by the Norwegian Meteorological Institute.") - err = eventBus.Unsubscribe(event_bus.TopicEntities, fn) - So(err, ShouldBeNil) + time.Sleep(time.Millisecond * 500) }) }) @@ -145,7 +148,6 @@ func TestWeatherMet(t *testing.T) { // ------------------------------------------------ ch := make(chan events.EventPassAttributes, 3) fn := func(topic string, msg interface{}) { - switch v := msg.(type) { case events.EventPassAttributes: ch <- v @@ -156,6 +158,11 @@ func TestWeatherMet(t *testing.T) { err = eventBus.Subscribe(event_bus.TopicEntities, fn) So(err, ShouldBeNil) + defer func() { + close(ch) + _ = eventBus.Unsubscribe(event_bus.TopicEntities, fn) + }() + settings := weatherPlugin.NewSettings() settings[weatherPlugin.AttrLat].Value = 54.9022 settings[weatherPlugin.AttrLon].Value = 83.0335 @@ -186,8 +193,7 @@ func TestWeatherMet(t *testing.T) { So(msg.To, ShouldEqual, "weather.home") So(msg.Attributes[weatherPlugin.AttrWeatherAttribution].String(), ShouldEqual, "Weather forecast from met.no, delivered by the Norwegian Meteorological Institute.") - err = eventBus.Unsubscribe(event_bus.TopicEntities, fn) - So(err, ShouldBeNil) + time.Sleep(time.Millisecond * 500) }) }) @@ -211,6 +217,10 @@ func TestWeatherMet(t *testing.T) { err = eventBus.Subscribe(event_bus.TopicEntities, fn) So(err, ShouldBeNil) + defer func() { + _ = eventBus.Unsubscribe(event_bus.TopicEntities, fn) + }() + eventBus.Publish(event_bus.TopicEntities, events.EventRemoveActor{ PluginName: weatherPlugin.EntityWeather, EntityId: "weather.home", @@ -233,8 +243,6 @@ func TestWeatherMet(t *testing.T) { So(msg.EntityId, ShouldEqual, "weather_met.home") - err = eventBus.Unsubscribe(event_bus.TopicEntities, fn) - So(err, ShouldBeNil) }) })