Documentation
¶
Overview ¶
Package control is the channel between plugyard commands and the process that owns a running site: HTTP with JSON over a Unix domain socket in the data directory (see docs/adr/0004). The channel is internal and may change between versions.
Index ¶
- Constants
- Variables
- func SocketPath(dataDir, siteName string) string
- func WholeCharger(action string) bool
- type ChargerState
- type Client
- func (c *Client) Chargers(ctx context.Context) ([]ChargerState, error)
- func (c *Client) Close()
- func (c *Client) Exec(ctx context.Context, req ExecRequest) ([]ExecResult, error)
- func (c *Client) Inspect(ctx context.Context, chargePointID string) (Inspection, error)
- func (c *Client) Power(ctx context.Context, req PowerRequest) ([]ExecResult, error)
- func (c *Client) Shutdown(ctx context.Context) error
- type ExecRequest
- type ExecResult
- type Info
- type Inspection
- type PowerRequest
- type Server
Constants ¶
const ( OpStart = "start" OpStop = "stop" OpRestart = "restart" OpKill = "kill" OpRemove = "rm" )
Power operations that PowerRequest can carry.
const ( ActionPlug = "plug" ActionUnplug = "unplug" ActionTap = "tap" ActionFault = "fault" ActionClear = "clear" ActionOffline = "offline" ActionOnline = "online" ActionReboot = "reboot" ActionFail = "fail" )
Actions that ExecRequest can carry.
const ProtocolVersion = 7
ProtocolVersion changes whenever requests or answers change shape. A command only talks to a site that speaks the same version.
Variables ¶
var ErrAlreadyRunning = errors.New("the site is already running")
ErrAlreadyRunning is returned by Serve when a live process already serves a site of the same name.
Functions ¶
func SocketPath ¶
SocketPath returns the socket file of the site with the given name.
func WholeCharger ¶
WholeCharger reports whether an action is about a charger as a whole and not one of its connectors.
Types ¶
type ChargerState ¶
type ChargerState struct {
Site string `json:"site"`
// Name is the charger's name, unique on the machine.
Name string `json:"name"`
// Powered says whether the charger is powered on. It is not part of the
// JSON output: a charger that is off shows "stopped" as its connection.
Powered bool `json:"-"`
charger.Snapshot
}
ChargerState is a charger's state together with the site it runs in.
type Client ¶
type Client struct {
// Info describes the site behind the socket.
Info Info
// contains filtered or unexported fields
}
Client talks to one running site.
func Discover ¶
Discover returns a client for every site running under dataDir, sorted by site name. Sockets left behind by processes that died are removed.
func Probe ¶
Probe returns a client for the site with the given name if it is running under dataDir.
func (*Client) Chargers ¶
func (c *Client) Chargers(ctx context.Context) ([]ChargerState, error)
Chargers returns the state of every charger in the site.
func (*Client) Exec ¶
func (c *Client) Exec(ctx context.Context, req ExecRequest) ([]ExecResult, error)
Exec runs an action on chargers of the site and returns one result per charge point ID, in the order given.
func (*Client) Power ¶
func (c *Client) Power(ctx context.Context, req PowerRequest) ([]ExecResult, error)
Power powers chargers of the site on or off, or removes them, and returns one result per charge point ID, in the order given.
type ExecRequest ¶
type ExecRequest struct {
ChargePointIDs []string `json:"chargePointIds"`
Action string `json:"action"`
// Connector is the connector the action is about. For a fault it may be
// 0, meaning the charger as a whole.
Connector int `json:"connector"`
// Fault is the fault a fault action reports.
Fault charger.Fault `json:"fault"`
// For is how long an offline action lasts; zero means until online.
For time.Duration `json:"for,omitempty"`
// Fail is what a fail action makes fail: one of charger.Failures.
Fail string `json:"fail,omitempty"`
// Tag is the tag presented by a tap.
Tag string `json:"tag,omitempty"`
// EVPreset names an EV preset of the site to plug in.
EVPreset string `json:"evPreset,omitempty"`
// EV holds the EV parameters given with a plug. They take precedence
// over the preset.
EV ev.Overrides `json:"ev"`
}
ExecRequest asks a site to run one action on some of its chargers.
type ExecResult ¶
type ExecResult struct {
ChargePointID string `json:"chargePointId"`
// Connector is zero for an operation on the whole charger.
Connector int `json:"connector,omitempty"`
OK bool `json:"ok"`
// Message is the outcome when OK, and the reason when not.
Message string `json:"message"`
}
ExecResult says what an action did on one charger.
type Info ¶
type Info struct {
Protocol int `json:"protocol"`
Site string `json:"site"`
PID int `json:"pid"`
// Chargers is the number of chargers in the site, powered on or not.
Chargers int `json:"chargers"`
// Powered is the number of chargers that are powered on.
Powered int `json:"powered"`
// CSMS lists the distinct CSMS URLs the site connects to.
CSMS []string `json:"csms"`
// Speed is how many times faster than real time EVs charge.
Speed float64 `json:"speed"`
}
Info identifies the process behind a socket.
type Inspection ¶
type Inspection struct {
Model *model.Model `json:"model"`
CSMSURL string `json:"csmsUrl"`
// State is nil for a charger that has never run.
State *charger.State `json:"state"`
}
Inspection is everything a site knows about one of its chargers.
type PowerRequest ¶
type PowerRequest struct {
ChargePointIDs []string `json:"chargePointIds"`
Op string `json:"op"`
// Force lets OpRemove stop a running charger first.
Force bool `json:"force,omitempty"`
}
PowerRequest asks a site to power some of its chargers on or off, or to remove them.