71 lines
2 KiB
Go
71 lines
2 KiB
Go
package eebus
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/enbility/eebus-go/api"
|
|
ucapi "github.com/enbility/eebus-go/usecases/api"
|
|
"github.com/enbility/eebus-go/usecases/eg/lpc"
|
|
"github.com/enbility/ship-go/cert"
|
|
"github.com/enbility/spine-go/model"
|
|
"github.com/evcc-io/evcc/hems/eebus"
|
|
hems "github.com/evcc-io/evcc/hems/eebus"
|
|
server "github.com/evcc-io/evcc/server/eebus"
|
|
"github.com/evcc-io/evcc/util"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
const remotePort = 9001
|
|
|
|
func TestEEBus(t *testing.T) {
|
|
util.LogLevel("error", map[string]string{"eebus": "trace"})
|
|
|
|
certificate, err := cert.CreateCertificate("Demo", "Demo", "DE", "Demo-Server-01")
|
|
require.NoError(t, err, "certificate")
|
|
|
|
public, private, err := server.GetX509KeyPair(certificate)
|
|
require.NoError(t, err, "decode certificate")
|
|
|
|
_, err = server.NewServer(server.Config{
|
|
Certificate: server.Certificate{
|
|
Public: public,
|
|
Private: private,
|
|
},
|
|
})
|
|
|
|
require.NoError(t, err, "server")
|
|
|
|
inst, err := server.Instance()
|
|
require.NoError(t, err, "instance")
|
|
|
|
require.NotEmpty(t, inst.Ski(), "server ski")
|
|
|
|
box, err := createControlbox(t.Context(), inst.Ski(), remotePort)
|
|
require.NoError(t, err, "controlbox")
|
|
|
|
eventC := make(chan api.EventType, 16)
|
|
box.remoteEventC = eventC
|
|
|
|
// no hems.Run(): the run loop applies limits via the nil site and is not needed here
|
|
_, err = hems.NewEEBus(t.Context(), box.ski, eebus.Limits{}, nil, nil, time.Second)
|
|
require.NoError(t, err, "hems")
|
|
|
|
// wait for DataUpdateLimit which signals that limit descriptions and data are available
|
|
require.Eventually(t, func() bool {
|
|
return len(box.remoteEntity(lpc.DataUpdateLimit)) > 0
|
|
}, 30*time.Second, 100*time.Millisecond, "waiting for lpc.DataUpdateLimit")
|
|
|
|
t.Log(box.remoteEntities)
|
|
srvEntity := box.remoteEntity(lpc.DataUpdateLimit)[0]
|
|
|
|
_, err = box.uclpc.WriteConsumptionLimit(srvEntity, ucapi.LoadLimit{
|
|
IsActive: true,
|
|
Value: 1,
|
|
}, func(result model.ResultDataType, _ model.MsgCounterType) {
|
|
t.Logf("lpc result: %v", result)
|
|
})
|
|
|
|
// TODO no error
|
|
require.NoError(t, err, "consumption limit")
|
|
}
|