Skip to content

Commit

Permalink
issues #64 technical debt
Browse files Browse the repository at this point in the history
  • Loading branch information
e154 committed Aug 2, 2022
1 parent 4acc340 commit dd5f6d4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
5 changes: 2 additions & 3 deletions plugins/weather/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
10 changes: 5 additions & 5 deletions plugins/weather_met/weather_met.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
22 changes: 15 additions & 7 deletions tests/plugins/weather_met_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
})

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
})
})

Expand All @@ -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",
Expand All @@ -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)
})
})

Expand Down

0 comments on commit dd5f6d4

Please sign in to comment.