core

package
v0.0.0-...-e6e1b3f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Voltage global value
	Voltage float64
)

Functions

This section is empty.

Types

type Health

type Health struct {
	// contains filtered or unexported fields
}

Health is a health checker that needs regular updates to stay healthy

func NewHealth

func NewHealth(timeout time.Duration) (health *Health)

NewHealth creates new health checker

func (*Health) Healthy

func (health *Health) Healthy() bool

Healthy returns health status based on last update timestamp

func (*Health) Update

func (health *Health) Update()

Update updates the health timer on each loadpoint update

type LoadPoint

type LoadPoint struct {

	// exposed public configuration
	sync.Mutex                // guard status
	Mode       api.ChargeMode `mapstructure:"mode"` // Charge mode, guarded by mutex

	ForeignEV   bool          // Status to determine if a non configured car is connected
	NextPVCheck bool          // Determine next, delayed charger adjustment for pv mode
	Title       string        `mapstructure:"title"`      // UI title
	Phases      int64         `mapstructure:"phases"`     // Phases- required for converting power and current
	IntervalPV  time.Duration `mapstructure:"intervalPV"` // interval when not charging
	ChargerRef  string        `mapstructure:"charger"`    // Charger reference
	VehicleRef  string        `mapstructure:"vehicle"`    // Vehicle reference
	VehiclesRef []string      `mapstructure:"vehicles"`   // Vehicles reference
	Meters      struct {
		ChargeMeterRef string `mapstructure:"charge"` // Charge meter reference
	}
	SoC          SoCConfig
	OnDisconnect struct {
		Mode      api.ChargeMode `mapstructure:"mode"`      // Charge mode to apply when car disconnected
		TargetSoC int            `mapstructure:"targetSoC"` // Target SoC to apply when car disconnected
	}
	Enable, Disable ThresholdConfig

	MinCurrent    int64         // PV mode: start current	Min+PV mode: min current
	MaxCurrent    int64         // Max allowed current. Physically ensured by the charger
	GuardDuration time.Duration // charger enable/disable minimum holding time
	// contains filtered or unexported fields
}

LoadPoint is responsible for controlling charge depending on SoC needs and power availability.

func NewLoadPoint

func NewLoadPoint(log *util.Logger) *LoadPoint

NewLoadPoint creates a LoadPoint with sane defaults

func NewLoadPointFromConfig

func NewLoadPointFromConfig(log *util.Logger, cp configProvider, other map[string]interface{}) (*LoadPoint, error)

NewLoadPointFromConfig creates a new loadpoint

func (*LoadPoint) GetMaxCurrent

func (lp *LoadPoint) GetMaxCurrent() int64

GetMaxCurrent returns the minimal loadpoint current

func (*LoadPoint) GetMaxPower

func (lp *LoadPoint) GetMaxPower() int64

GetMaxPower returns the minimal loadpoint power taking active phases into account

func (*LoadPoint) GetMinCurrent

func (lp *LoadPoint) GetMinCurrent() int64

GetMinCurrent returns the minimal loadpoint current

func (*LoadPoint) GetMinPower

func (lp *LoadPoint) GetMinPower() int64

GetMinPower returns the minimal loadpoint power for a single phase

func (*LoadPoint) GetMinSoC

func (lp *LoadPoint) GetMinSoC() int

GetMinSoC returns loadpoint charge minimum soc

func (*LoadPoint) GetMode

func (lp *LoadPoint) GetMode() api.ChargeMode

GetMode returns loadpoint charge mode

func (*LoadPoint) GetTargetSoC

func (lp *LoadPoint) GetTargetSoC() int

GetTargetSoC returns loadpoint charge target soc

func (*LoadPoint) HasChargeMeter

func (lp *LoadPoint) HasChargeMeter() bool

HasChargeMeter determines if a physical charge meter is attached

func (*LoadPoint) Name

func (lp *LoadPoint) Name() string

Name returns the human-readable loadpoint title

func (*LoadPoint) Prepare

func (lp *LoadPoint) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Event, lpChan chan<- *LoadPoint, site *Site)

Prepare loadpoint configuration by adding missing helper elements

func (*LoadPoint) RemoteControl

func (lp *LoadPoint) RemoteControl(source string, demand RemoteDemand)

RemoteControl sets remote status demand

func (*LoadPoint) SetMinSoC

func (lp *LoadPoint) SetMinSoC(soc int) error

SetMinSoC sets loadpoint charge minimum soc

func (*LoadPoint) SetMode

func (lp *LoadPoint) SetMode(mode api.ChargeMode)

SetMode sets loadpoint charge mode

func (*LoadPoint) SetTargetCharge

func (lp *LoadPoint) SetTargetCharge(finishAt time.Time, targetSoC int)

SetTargetCharge sets loadpoint charge targetSoC

func (*LoadPoint) SetTargetSoC

func (lp *LoadPoint) SetTargetSoC(soc int) error

SetTargetSoC sets loadpoint charge target soc

func (*LoadPoint) Update

func (lp *LoadPoint) Update(sitePower float64)

Update is the main control function. It reevaluates meters and charger state

type LoadPointAPI

type LoadPointAPI interface {
	Name() string
	HasChargeMeter() bool

	// settings
	GetMode() api.ChargeMode
	SetMode(api.ChargeMode)
	GetTargetSoC() int
	SetTargetSoC(int) error
	GetMinSoC() int
	SetMinSoC(int) error
	SetTargetCharge(time.Time, int)
	RemoteControl(string, RemoteDemand)

	// energy
	GetMinCurrent() int64
	GetMaxCurrent() int64
	GetMinPower() int64
	GetMaxPower() int64
}

LoadPointAPI is the external loadpoint API

type MetersConfig

type MetersConfig struct {
	GridMeterRef        string `mapstructure:"grid"`        // Grid usage meter reference
	PVMeterRef          string `mapstructure:"pv"`          // PV generation meter reference
	BatteryMeterRef     string `mapstructure:"battery"`     // Battery charging meter reference
	ConsumptionMeterRef string `mapstructure:"consumption"` // Home consumption meter reference
}

MetersConfig contains the loadpoint's meter configuration

type PollConfig

type PollConfig struct {
	Mode     string        `mapstructure:"mode"`     // polling mode charging (default), connected, always
	Interval time.Duration `mapstructure:"interval"` // interval when not charging
}

PollConfig defines the vehicle polling mode and interval

type RemoteDemand

type RemoteDemand string

RemoteDemand defines external status demand

const (
	RemoteEnable      RemoteDemand = ""
	RemoteHardDisable RemoteDemand = "hard"
	RemoteSoftDisable RemoteDemand = "soft"
)

remote status demand definition

func RemoteDemandString

func RemoteDemandString(demand string) (RemoteDemand, error)

RemoteDemandString converts string to RemoteDemand

type Site

type Site struct {
	*Health

	sync.Mutex

	// configuration
	Title                   string       `mapstructure:"title"`                   // UI title
	Voltage                 float64      `mapstructure:"voltage"`                 // Operating voltage. 230V for Germany.
	ResidualPower           float64      `mapstructure:"residualPower"`           // PV meter only: household usage. Grid meter: household safety margin
	MaxCurrent              float64      `mapstructure:"maxcurrent"`              // MaxCurrent limit accross all loadpoints
	HasSunny5Menu           bool         `mapstructure:"hasSunny5Menu"`           // Enable the extended Sunny5 menu
	EnableContactorWellness bool         `mapstructure:"enableContactorWellness"` // MaxCurrent limit accross all loadpoints
	Meters                  MetersConfig // Meter references
	PrioritySoC             float64      `mapstructure:"prioritySoC"` // prefer battery up to this SoC
	// contains filtered or unexported fields
}

Site is the main configuration container. A site can host multiple loadpoints.

func NewSite

func NewSite() *Site

NewSite creates a Site with sane defaults

func NewSiteFromConfig

func NewSiteFromConfig(
	log *util.Logger,
	cp configProvider,
	other map[string]interface{},
	loadpoints []*LoadPoint,
) (*Site, error)

NewSiteFromConfig creates a new site

func (*Site) DumpConfig

func (site *Site) DumpConfig()

DumpConfig site configuration

func (*Site) GetHasSunny5Menu

func (site *Site) GetHasSunny5Menu() bool

HasSunny5Menu

func (*Site) GetMinSoC

func (site *Site) GetMinSoC() int

GetMinSoC gets loadpoint charge minimum soc

func (*Site) GetPrioritySoC

func (site *Site) GetPrioritySoC() float64

GetPrioritySoC returns the PrioritySoC

func (*Site) GetResidualPower

func (site *Site) GetResidualPower() float64

GetResidualPower

func (*Site) LoadPoints

func (site *Site) LoadPoints() []LoadPointAPI

LoadPoints returns the array of associated loadpoints

func (*Site) Prepare

func (site *Site) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Event)

Prepare attaches communication channels to site and loadpoints

func (*Site) Run

func (site *Site) Run(stopC chan struct{}, interval time.Duration)

Run is the main control loop. It reacts to trigger events by updating measurements and executing control logic.

func (*Site) SetMinSoC

func (site *Site) SetMinSoC(soc int) error

SetMinSoC sets loadpoint charge minimum soc

func (*Site) SetPrioritySoC

func (site *Site) SetPrioritySoC(soc float64) error

SetPrioritySoC sets the PrioritySoC

func (*Site) SetResidualPower

func (site *Site) SetResidualPower(power float64) error

SetResidualPower

type SiteAPI

type SiteAPI interface {
	Healthy() bool
	GetHasSunny5Menu() bool
	LoadPoints() []LoadPointAPI
	GetResidualPower() float64
	SetResidualPower(float64) error
	GetPrioritySoC() float64
	SetPrioritySoC(float64) error
	GetMinSoC() int
	SetMinSoC(int) error
}

SiteAPI is the external site API

type SoCConfig

type SoCConfig struct {
	Poll         PollConfig `mapstructure:"poll"`
	AlwaysUpdate bool       `mapstructure:"alwaysUpdate"`
	Levels       []int      `mapstructure:"levels"`
	Estimate     bool       `mapstructure:"estimate"`
	Min          int        `mapstructure:"min"`    // Default minimum SoC, guarded by mutex
	Target       int        `mapstructure:"target"` // Default target SoC, guarded by mutex
}

SoCConfig defines soc settings, estimation and update behaviour

type ThresholdConfig

type ThresholdConfig struct {
	Delay     time.Duration
	Threshold float64
}

ThresholdConfig defines enable/disable hysteresis parameters

type Updater

type Updater interface {
	Update(float64)
}

Updater abstracts the LoadPoint implementation for testing

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL