Use mk2if instead of datasource as data source.
This removes support for the python based mk2daemon.
This commit is contained in:
@@ -31,57 +31,39 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
package webgui
|
||||
|
||||
import (
|
||||
"github.com/hpdvanwyk/invertergui/datasource"
|
||||
"fmt"
|
||||
"github.com/hpdvanwyk/invertergui/mk2if"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type mockSource struct {
|
||||
}
|
||||
|
||||
func NewMockSource() datasource.DataSource {
|
||||
return &mockSource{}
|
||||
}
|
||||
|
||||
func (s *mockSource) GetData(status *datasource.MultiplusStatus) error {
|
||||
status.OutCurrent = 2.0
|
||||
status.InCurrent = 2.3
|
||||
status.OutVoltage = 230.0
|
||||
status.InVoltage = 230.1
|
||||
status.BatVoltage = 25
|
||||
status.BatCurrent = -10
|
||||
status.InFreq = 50
|
||||
status.OutFreq = 50
|
||||
status.Leds = []int{0, 0, 0, 0, 1, 0, 0, 1}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestWebGui(t *testing.T) {
|
||||
t.Skip("Not yet implimented")
|
||||
//TODO figure out how to test template output.
|
||||
}
|
||||
|
||||
type templateTest struct {
|
||||
input *statusProcessed
|
||||
input *mk2if.Mk2Info
|
||||
output *templateInput
|
||||
}
|
||||
|
||||
var fakenow = time.Date(2017, 1, 2, 3, 4, 5, 6, time.UTC)
|
||||
var templateInputTests = []templateTest{
|
||||
{
|
||||
input: &statusProcessed{
|
||||
status: datasource.MultiplusStatus{
|
||||
OutCurrent: 2.0,
|
||||
InCurrent: 2.3,
|
||||
OutVoltage: 230.0,
|
||||
InVoltage: 230.1,
|
||||
BatVoltage: 25,
|
||||
BatCurrent: -10,
|
||||
InFreq: 50,
|
||||
OutFreq: 50,
|
||||
Leds: []int{0, 0, 0, 0, 1, 0, 0, 1}},
|
||||
err: nil,
|
||||
input: &mk2if.Mk2Info{
|
||||
OutCurrent: 2.0,
|
||||
InCurrent: 2.3,
|
||||
OutVoltage: 230.0,
|
||||
InVoltage: 230.1,
|
||||
BatVoltage: 25,
|
||||
BatCurrent: -10,
|
||||
InFrequency: 50,
|
||||
OutFrequency: 50,
|
||||
ChargeState: 1,
|
||||
LedListOn: []int{mk2if.LED_MAIN, mk2if.LED_FLOAT},
|
||||
Errors: nil,
|
||||
Timestamp: fakenow,
|
||||
},
|
||||
output: &templateInput{
|
||||
Error: nil,
|
||||
@@ -97,16 +79,18 @@ var templateInputTests = []templateTest{
|
||||
BatCurrent: "-10.000",
|
||||
BatPower: "-250.000",
|
||||
InFreq: "50.000",
|
||||
BatCharge: "0.000",
|
||||
OutFreq: "50.000",
|
||||
BatCharge: "100.000",
|
||||
Leds: []string{"Mains", "Float"}},
|
||||
},
|
||||
}
|
||||
|
||||
func TestTemplateInput(t *testing.T) {
|
||||
for i := range templateInputTests {
|
||||
templateInput := buildTemplateInput(templateInputTests[i].input, fakenow)
|
||||
templateInput := buildTemplateInput(templateInputTests[i].input)
|
||||
if !reflect.DeepEqual(templateInput, templateInputTests[i].output) {
|
||||
t.Errorf("buildTemplateInput not producing expected results")
|
||||
fmt.Printf("%v\n%v\n", templateInput, templateInputTests[i].output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user