core

package
v0.0.0-...-722e3e0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 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 ActionConfig

type ActionConfig struct {
	Mode      api.ChargeMode `mapstructure:"mode"`      // Charge mode to apply when car disconnected
	TargetSoC int            `mapstructure:"targetSoC"` // Target SoC to apply when car disconnected
}

ActionConfig defines an action to take on event

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

	Title       string   `mapstructure:"title"`    // UI title
	Phases      int64    `mapstructure:"phases"`   // Charger enabled phases
	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    ActionConfig            `mapstructure:"onDisconnect"`
	OnIdentify      map[string]ActionConfig `mapstructure:"onIdentify"`
	Enable, Disable ThresholdConfig

	MinCurrent    float64       // PV mode: start current	Min+PV mode: min current
	MaxCurrent    float64       // 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) GetChargePower

func (lp *LoadPoint) GetChargePower() float64

GetChargePower returns the current charge power

func (*LoadPoint) GetMaxCurrent

func (lp *LoadPoint) GetMaxCurrent() float64

GetMaxCurrent returns the max loadpoint current

func (*LoadPoint) GetMaxPower

func (lp *LoadPoint) GetMaxPower() float64

GetMaxPower returns the max loadpoint power taking active phases into account

func (*LoadPoint) GetMinCurrent

func (lp *LoadPoint) GetMinCurrent() float64

GetMinCurrent returns the min loadpoint current

func (*LoadPoint) GetMinPower

func (lp *LoadPoint) GetMinPower() float64

GetMinPower returns the min 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) GetPhases

func (lp *LoadPoint) GetPhases() int

GetPhases returns loadpoint enabled phases

func (*LoadPoint) GetStatus

func (lp *LoadPoint) GetStatus() api.ChargeStatus

GetStatus returns the charging status

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)

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) SetMaxCurrent

func (lp *LoadPoint) SetMaxCurrent(current float64)

SetMaxCurrent returns the max loadpoint current

func (*LoadPoint) SetMinCurrent

func (lp *LoadPoint) SetMinCurrent(current float64)

SetMinCurrent returns the min loadpoint current

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) SetPhases

func (lp *LoadPoint) SetPhases(phases int) error

SetPhases sets loadpoint enabled phases

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, cheap bool)

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

type LoadPointAPI

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

	// status
	GetStatus() api.ChargeStatus

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

	// energy
	GetChargePower() float64
	GetMinCurrent() float64
	SetMinCurrent(float64)
	GetMaxCurrent() float64
	SetMaxCurrent(float64)
	GetMinPower() float64
	GetMaxPower() float64
}

LoadPointAPI is the external loadpoint API

type LoadpointController

type LoadpointController interface {
	LoadpointControl(LoadPointAPI)
}

LoadpointController gives access to loadpoint

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
}

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
	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,
	tariff api.Tariff,
) (*Site, error)

NewSiteFromConfig creates a new site

func (*Site) DumpConfig

func (site *Site) DumpConfig()

DumpConfig site configuration

func (*Site) GetPrioritySoC

func (site *Site) GetPrioritySoC() float64

GetPrioritySoC returns the PrioritySoC

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) SetPrioritySoC

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

SetPrioritySoC sets the PrioritySoC

type SiteAPI

type SiteAPI interface {
	Healthy() bool
	LoadPoints() []LoadPointAPI
	SetPrioritySoC(float64) error
}

SiteAPI is the external site API

type SoCConfig

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

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, bool)
}

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