Files
invertergui/mk2driver/mockmk2.go
Nathan Coad e995a252e1
All checks were successful
continuous-integration/drone/push Build is passing
feat: Enhance MK2 driver with device state management and improved command handling
2026-02-19 13:13:19 +11:00

131 lines
2.2 KiB
Go

package mk2driver
import (
"time"
)
type mock struct {
c chan *Mk2Info
}
var _ ProtocolControl = (*mock)(nil)
func NewMk2Mock() Mk2 {
tmp := &mock{
c: make(chan *Mk2Info, 1),
}
go tmp.genMockValues()
return tmp
}
func genBaseLeds(state LEDstate) map[Led]LEDstate {
return map[Led]LEDstate{
LedMain: state,
LedAbsorption: state,
LedBulk: state,
LedFloat: state,
LedInverter: state,
LedOverload: state,
LedLowBattery: state,
LedTemperature: state,
}
}
func (m *mock) C() chan *Mk2Info {
return m.c
}
func (m *mock) Close() {
}
func (m *mock) WriteRAMVar(_ uint16, _ int16) error {
return nil
}
func (m *mock) WriteSetting(_ uint16, _ int16) error {
return nil
}
func (m *mock) SetPanelState(_ PanelSwitchState, _ *float64) error {
return nil
}
func (m *mock) SetStandby(_ bool) error {
return nil
}
func (m *mock) GetDeviceState() (DeviceState, error) {
return DeviceStateOn, nil
}
func (m *mock) SetDeviceState(_ DeviceState) error {
return nil
}
func (m *mock) ReadRAMVarByID(_ uint16) (int16, error) {
return 0, nil
}
func (m *mock) ReadSettingByID(_ uint16) (int16, error) {
return 0, nil
}
func (m *mock) SelectRAMVar(_ uint16) error {
return nil
}
func (m *mock) SelectSetting(_ uint16) error {
return nil
}
func (m *mock) ReadSelected() (int16, error) {
return 0, nil
}
func (m *mock) ReadRAMVarInfo(id uint16) (RAMVarInfo, error) {
return RAMVarInfo{
ID: id,
Supported: false,
}, nil
}
func (m *mock) WriteSettingByID(_ uint16, _ int16) error {
return nil
}
func (m *mock) WriteRAMVarByID(_ uint16, _ int16) error {
return nil
}
func (m *mock) genMockValues() {
mult := 1.0
ledState := LedOff
for {
input := &Mk2Info{
OutCurrent: 2.0 * mult,
InCurrent: 2.3 * mult,
OutVoltage: 230.0 * mult,
InVoltage: 230.1 * mult,
BatVoltage: 25 * mult,
BatCurrent: -10 * mult,
InFrequency: 50 * mult,
OutFrequency: 50 * mult,
ChargeState: 1 * mult,
Errors: nil,
Timestamp: time.Now(),
Valid: true,
LEDs: genBaseLeds(ledState),
}
ledState = (ledState + 1) % 3
mult = mult - 0.1
if mult < 0 {
mult = 1.0
}
m.c <- input
time.Sleep(1 * time.Second)
}
}