site

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package site holds a running site: a named group of chargers owned by one process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPacer

func NewPacer(perSecond float64) func(ctx context.Context) error

NewPacer returns a function that spaces out connection attempts to at most perSecond a second across every charger that shares it. It returns nil when perSecond is zero, meaning no limit.

Types

type Config

type Config struct {
	Name string
	// Speed multiplies the rate of EV charging. Zero means 1.
	Speed float64
	// ConnectRate is the most new connections to open per second. Zero
	// means no limit.
	ConnectRate float64
	// Presets holds the EV presets by name.
	Presets map[string]ev.Overrides
	// Log, if set, receives the log of every charger.
	Log func(charger.Entry)
	// Diagnostics, if set, returns the log of one charger between two
	// moments, for GetDiagnostics.
	Diagnostics func(chargePointID string, from, to time.Time) ([]byte, error)
	// AllowUploads lists the hosts diagnostics may be uploaded to besides
	// the machine the CSMS is on.
	AllowUploads []string
	// UploadsInsecureSkipVerify turns off the check of the certificate of
	// an https or ftps server diagnostics are uploaded to.
	UploadsInsecureSkipVerify bool
	// Store, if set, keeps the chargers' state.
	Store  Store
	Timing charger.Timing
}

Config describes a site.

type Member

type Member struct {
	// ID is the charge point ID.
	ID string
	// Name is the charger's name, unique on the machine.
	Name  string
	Model *model.Model
	CSMS  charger.CSMS
	// EV names the EV preset used when a plug does not name one.
	EV string
}

Member is a charger of a site, whether powered on or not.

type MemberState

type MemberState struct {
	Name string
	// Powered says whether the charger is powered on.
	Powered bool
	charger.Snapshot
}

MemberState is a member and where it stands.

type Site

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

Site is a running site.

func New

func New(cfg Config, members []Member) (*Site, error)

New checks the members and returns a site that is not running yet.

func (*Site) CSMS

func (s *Site) CSMS() []string

CSMS returns the distinct CSMS URLs of the site, sorted.

func (*Site) Charger

func (s *Site) Charger(id string) *charger.Charger

Charger returns the charger with the given charge point ID if it is powered on, and nil otherwise.

func (*Site) EVParams

func (s *Site) EVParams(chargePointID, preset string, given ev.Overrides) (ev.Params, error)

EVParams works out the EV to plug into a charger. From weakest to strongest: the built-in EV, the charger's default preset, the preset named with the plug, and the parameters given with the plug.

func (*Site) Has

func (s *Site) Has(id string) bool

Has reports whether the site has a charger with the given charge point ID.

func (*Site) Inspect

func (s *Site) Inspect(id string) (Member, *charger.State, bool)

Inspect returns a charger of the site with its state: as it is now when the charger is powered on, and as it was saved otherwise. The state is nil for a charger that has never run.

func (*Site) Kill

func (s *Site) Kill(id string) (string, error)

Kill cuts a charger's power.

func (*Site) Len

func (s *Site) Len() int

Len returns the number of chargers in the site, powered on or not.

func (*Site) Name

func (s *Site) Name() string

Name returns the site's name.

func (*Site) Powered

func (s *Site) Powered() int

Powered returns the number of chargers that are powered on.

func (*Site) Remove

func (s *Site) Remove(id string, force bool) (string, error)

Remove takes a charger out of the site and wipes its saved state. A charger that is powered on is refused unless force is set, which stops it first.

func (*Site) Restart

func (s *Site) Restart(id string) (string, error)

Restart stops a charger and starts it again.

func (*Site) Run

func (s *Site) Run(ctx context.Context, powerOn func(chargePointID string) bool) error

Run powers on the chargers for which powerOn reports true (all of them when it is nil) and keeps the site running until ctx is cancelled, which shuts every charger down in an orderly way, or until the last powered charger has been stopped.

func (*Site) Speed

func (s *Site) Speed() float64

Speed returns how many times faster than real time the site's EVs charge.

func (*Site) Start

func (s *Site) Start(id string) (string, error)

Start powers a charger on.

func (*Site) States

func (s *Site) States() []MemberState

States returns where every charger of the site stands, sorted by charge point ID.

func (*Site) Stop

func (s *Site) Stop(id string) (string, error)

Stop shuts a charger down in an orderly way and waits until it is off.

type Store

type Store interface {
	// LoadState returns a charger's saved state, or nil if it has none.
	LoadState(chargePointID string) (*charger.State, error)
	SaveState(chargePointID string, state charger.State) error
	// Remove deletes a charger and its state.
	Remove(chargePointID string) error
}

Store is where a site keeps the state of its chargers.

Jump to

Keyboard shortcuts

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