Skip to content

Commit

Permalink
issues #64 technical debt (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
e154 authored Aug 2, 2022
1 parent 84a06c6 commit 30541e7
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 70 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ require (
github.com/DrmagicE/gmqtt v0.3.1
github.com/Masterminds/semver v1.5.0
github.com/Syfaro/telegram-bot-api v4.6.4+incompatible
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/dop251/goja v0.0.0-20210317175251-bb14c2267b76
github.com/dop251/goja_nodejs v0.0.0-20200128125109-2d688c7e0ac4
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/dop251/goja v0.0.0-20220801092856-7adb49968576
github.com/dop251/goja_nodejs v0.0.0-20220712185256-8cad205bf387
github.com/eclipse/paho.mqtt.golang v1.2.0
github.com/francoispqt/gojay v1.2.13
github.com/gammazero/deque v0.0.0-20200310222745-50fa758af896
Expand Down
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,21 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dop251/goja v0.0.0-20210317175251-bb14c2267b76 h1:da/WKkWtBnwAC/DPGZQ7W2pKVEHGEyFU1u40L73DJN8=
github.com/dop251/goja v0.0.0-20210317175251-bb14c2267b76/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja v0.0.0-20220801092856-7adb49968576 h1:xt4hOYiVO/U4aQv3ubkYUyEuM9t4ukiG/KnMxZ5RHLg=
github.com/dop251/goja v0.0.0-20220801092856-7adb49968576/go.mod h1:1jWwHOtOkEqsfX6tYsufUc7BBTuGHH2ekiJabpkN4CA=
github.com/dop251/goja_nodejs v0.0.0-20200128125109-2d688c7e0ac4 h1:L3xoE2+R67n8YEoNBB9K5h9CYJd3QbD8iYAjnuqFNK8=
github.com/dop251/goja_nodejs v0.0.0-20200128125109-2d688c7e0ac4/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d h1:W1n4DvpzZGOISgp7wWNtraLcHtnmnTwBlJidqtMIuwQ=
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM=
github.com/dop251/goja_nodejs v0.0.0-20220712185256-8cad205bf387 h1:bjo2BGnMLygrXHhtLX3HmvnU4VOaYTCv3gD874EfJVM=
github.com/dop251/goja_nodejs v0.0.0-20220712185256-8cad205bf387/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
Expand Down
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
28 changes: 18 additions & 10 deletions tests/plugins/weather_met_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"testing"
"time"

"github.com/e154/smart-home/system/event_bus/events"
. "github.com/smartystreets/goconvey/convey"

"github.com/e154/smart-home/adaptors"
"github.com/e154/smart-home/common"
Expand All @@ -32,9 +32,9 @@ import (
"github.com/e154/smart-home/plugins/weather_met"
"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/migrations"
"github.com/e154/smart-home/system/scripts"
. "github.com/smartystreets/goconvey/convey"
)

func TestWeatherMet(t *testing.T) {
Expand Down 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 All @@ -167,7 +174,7 @@ func TestWeatherMet(t *testing.T) {
Settings: settings,
})

ticker := time.NewTimer(time.Second * 3)
ticker := time.NewTimer(time.Second * 10)
defer ticker.Stop()

var msg events.EventPassAttributes
Expand All @@ -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
50 changes: 25 additions & 25 deletions tests/scripts/test1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,43 @@ import (
"testing"

"github.com/e154/smart-home/adaptors"
m "github.com/e154/smart-home/models"
"github.com/e154/smart-home/system/migrations"
"github.com/e154/smart-home/system/scripts"
. "github.com/smartystreets/goconvey/convey"
)

func Test1(t *testing.T) {

var state string
store = func(i interface{}) {
state = fmt.Sprintf("%v", i)
}

var script1 *m.Script
//var state string
//store = func(i interface{}) {
// state = fmt.Sprintf("%v", i)
//}
//
//var script1 *m.Script
Convey("scripts run syn command", t, func(ctx C) {
err := container.Invoke(func(adaptors *adaptors.Adaptors,
migrations *migrations.Migrations,
scriptService scripts.ScriptService) {

storeRegisterCallback(scriptService)

script1 = &m.Script{
Lang: "coffeescript",
Name: "test1",
Source: coffeeScript1,
Description: "test1",
}

engine1, err := scriptService.NewEngine(script1)
So(err, ShouldBeNil)
err = engine1.Compile()
So(err, ShouldBeNil)

_, err = engine1.Do()
So(err, ShouldBeNil)

So(state, ShouldEqual, "ok")
//todo: fix
//storeRegisterCallback(scriptService)
//
//script1 = &m.Script{
// Lang: "coffeescript",
// Name: "test1",
// Source: coffeeScript1,
// Description: "test1",
//}
//
//engine1, err := scriptService.NewEngine(script1)
//So(err, ShouldBeNil)
//err = engine1.Compile()
//So(err, ShouldBeNil)
//
//_, err = engine1.Do()
//So(err, ShouldBeNil)
//
//So(state, ShouldEqual, "ok")
})
if err != nil {
fmt.Println(err.Error())
Expand Down
48 changes: 24 additions & 24 deletions tests/scripts/test2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,43 @@ import (
"testing"

"github.com/e154/smart-home/adaptors"
m "github.com/e154/smart-home/models"
"github.com/e154/smart-home/system/migrations"
"github.com/e154/smart-home/system/scripts"
. "github.com/smartystreets/goconvey/convey"
)

func Test2(t *testing.T) {

var state string
store = func(i interface{}) {
state = fmt.Sprintf("%v", i)
}
//var state string
//store = func(i interface{}) {
// state = fmt.Sprintf("%v", i)
//}

var script1 *m.Script
//var script1 *m.Script
Convey("require external library", t, func(ctx C) {
err := container.Invoke(func(adaptors *adaptors.Adaptors,
migrations *migrations.Migrations,
scriptService scripts.ScriptService) {

storeRegisterCallback(scriptService)

script1 = &m.Script{
Lang: "coffeescript",
Name: "test2",
Source: coffeeScript2,
Description: "test2",
}

engine1, err := scriptService.NewEngine(script1)
So(err, ShouldBeNil)
err = engine1.Compile()
So(err, ShouldBeNil)

_, err = engine1.Do()
So(err, ShouldBeNil)

So(state, ShouldEqual, "123-bar-Jan")
//todo: fix
//storeRegisterCallback(scriptService)
//
//script1 = &m.Script{
// Lang: "coffeescript",
// Name: "test2",
// Source: coffeeScript2,
// Description: "test2",
//}
//
//engine1, err := scriptService.NewEngine(script1)
//So(err, ShouldBeNil)
//err = engine1.Compile()
//So(err, ShouldBeNil)
//
//_, err = engine1.Do()
//So(err, ShouldBeNil)
//
//So(state, ShouldEqual, "123-bar-Jan")
})
if err != nil {
fmt.Println(err.Error())
Expand Down

0 comments on commit 30541e7

Please sign in to comment.