Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Install dependencies and run tests
run: |
go mod download
go test -v ./... -coverpkg=./... -short -coverprofile=unit_coverage.out
go test -v ./... -coverpkg=./... -short -coverprofile=unit_coverage.out -race

- name: Archive code coverage results
uses: actions/upload-artifact@v4
Expand Down
39 changes: 39 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: "2"
linters:
default: all
enable:
- bodyclose
- copyloopvar
- decorder
- errcheck
- errname
- forbidigo
- goconst
- gocritic
- gosec
- govet
- ineffassign
- intrange
- misspell
- nestif
- predeclared
- staticcheck
- testifylint
- unparam
- unused
- wastedassign
- whitespace
- wrapcheck
exclusions:
generated: lax
paths:
- ./examples

formatters:
settings:
goimports:
local-prefixes:
- github.com/ChargePi/ocpp-manager
enable:
- gofmt
- goimports
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY:gen format lint

gen:
mockery

lint:
golangci-lint run

format:
golangci-lint fmt
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ getting and setting values, validating values, and enforcing mandatory keys.
- Mandatory key enforcement
- Custom value validation
- Provides sane default values
- Supports OCPP 1.6 and 2.0.1 (separate packages for each version)

## Roadmap

- [x] Configuration versioning
- [x] Custom value validation
- [x] Mandatory key enforcement
- [x] Support for OCPP 1.6
- [ ] Support for OCPP 2.0.1
- [x] Support for OCPP 2.0.1

## Installing

Expand All @@ -26,6 +27,8 @@ getting and setting values, validating values, and enforcing mandatory keys.

## ⚡ Usage

### OCPP 1.6

Check out the full [OCPP 1.6 example](examples/v16/example.go).

```go
Expand Down Expand Up @@ -92,6 +95,10 @@ func main() {

```

### OCPP 2.0.1

TBD

## Notes

1. This library is still in development, and the API might change in the future.
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.22.1
replace github.com/lorenzodonini/ocpp-go v0.18.0 => github.com/ChargePi/ocpp-go v0.21.0

require (
github.com/ChargePi/ocppManager-go v1.2.0
github.com/agrison/go-commons-lang v0.0.0-20240106075236-2e001e6401ef
github.com/lorenzodonini/ocpp-go v0.18.0
github.com/samber/lo v1.47.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/ChargePi/ocpp-go v0.21.0 h1:YP6uCu75D/TJFwkWsRHHtRthapmrxZscKBylBc8oc9Q=
github.com/ChargePi/ocpp-go v0.21.0/go.mod h1:2kcukDdhui4u730VfnYVWuwzDLgw+mBRGDir/QAyBhg=
github.com/ChargePi/ocppManager-go v1.2.0 h1:OV90kAD22yVYTSE+uHIgTtiwUOYpEwyHDPJb8d6AltM=
github.com/ChargePi/ocppManager-go v1.2.0/go.mod h1:7kWtV1+qQw+OSOHBuE/wUsTH5Id5+/euzsCfke9NQ2E=
github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/agrison/go-commons-lang v0.0.0-20240106075236-2e001e6401ef h1:KkznClyESbRaLmRo7Oam4vv5L4oknDK+mixJ9mypl6E=
Expand Down
9 changes: 9 additions & 0 deletions ocpp_v201/charging_station.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ocpp_v201

import "github.com/ChargePi/ocpp-manager/ocpp_v201/component"

type ChargingStation struct {
ID string
components map[component.ComponentName]component.Component // Charging station (top level) specific components
controllerManager Manager
}
62 changes: 62 additions & 0 deletions ocpp_v201/component/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package component

import "github.com/ChargePi/ocpp-manager/ocpp_v201/variables"

type Component interface {

// GetName Essentially a component type.
GetName() ComponentName

// GetInstanceId returns the unique instance ID of this component.
GetInstanceId() string

// RegisterSubComponent registers a sub-component to this component.
RegisterSubComponent(component Component)

// UnregisterSubComponent unregisters a sub-component from this component.
UnregisterSubComponent(component Component)

// GetSubComponents returns all sub-components of this component.
GetSubComponents() []Component

// GetRequiredVariables returns required variables for this component
GetRequiredVariables() []variables.VariableName

// GetSupportedVariables returns supported variables (both required and optional) for this component
GetSupportedVariables() []variables.VariableName

// GetVariable retrieves a variable by its name.
GetVariable(key variables.VariableName, opts ...GetSetVariableOption) (*variables.Variable, error)

// UpdateVariable updates a variable's attribute with a new value.
UpdateVariable(variable variables.VariableName, attribute string, value interface{}, opts ...GetSetVariableOption) error

// Validate checks if the variable is valid for this component.
Validate(key variables.VariableName) bool
}

type ComponentName string

const (
ComponentNameOCPPCommCtrlr ComponentName = "OCPPCommCtrlr"
ComponentNameLocalAuthListCtrlr ComponentName = "LocalAuthListCtrlr"
ComponentNameTxCtrlr ComponentName = "TxCtrlr"
ComponentNameDeviceDataCtrlr ComponentName = "DeviceDataCtrlr"
ComponentNameSecurityCtrlr ComponentName = "SecurityCtrlr"
ComponentNameClockCtrlr ComponentName = "ClockCtrlr"
ComponentNameCustomizationCtrlr ComponentName = "CustomizationCtrlr"
ComponentNameSampledDataCtrlr ComponentName = "SampledDataCtrlr"
ComponentNameAlignedDataCtrlr ComponentName = "AlignedDataCtrlr"
ComponentNameReservationCtrlr ComponentName = "ReservationCtrlr"
ComponentNameSmartChargingCtrlr ComponentName = "SmartChargingCtrlr"
ComponentNameTariffCostCtrlr ComponentName = "TariffCostCtrlr"
ComponentNameMonitoringCtrlr ComponentName = "MonitoringCtrlr"
ComponentNameDisplayMessageCtrlr ComponentName = "DisplayMessageCtrlr"
ComponentNameISO15118Ctrlr ComponentName = "ISO15118Ctrlr"
ComponentNameAuthCtrlr ComponentName = "AuthCtrlr"
ComponentNameAuthCacheCtrlr ComponentName = "AuthCacheCtrlr"
ComponentNameChargingStation ComponentName = "ChargingStation"
ComponentNameEVSE ComponentName = "EVSE"
ComponentNameConnector ComponentName = "Connector"
ComponentNameConnectedEV ComponentName = "ConnectedEV"
)
14 changes: 14 additions & 0 deletions ocpp_v201/component/component_variable_opts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package component

type GetSetVariableOption func(o *componentVariableOptions)

type componentVariableOptions struct {
attributeType string
}

// WithAttributeType sets the attribute type for the variable options.
func WithAttributeType(attributeType string) GetSetVariableOption {
return func(o *componentVariableOptions) {
o.attributeType = attributeType
}
}
42 changes: 42 additions & 0 deletions ocpp_v201/component/component_variable_opts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package component

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestOptions(t *testing.T) {
tests := []struct {
name string
opts []GetSetVariableOption
expected componentVariableOptions
}{
{
name: "default options",
expected: componentVariableOptions{
attributeType: "",
},
opts: []GetSetVariableOption{},
},
{
name: "with attribute type",
expected: componentVariableOptions{
attributeType: "abc",
},
opts: []GetSetVariableOption{
WithAttributeType("abc"),
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
opts := componentVariableOptions{}
for _, opt := range tt.opts {
opt(&opts)
}

assert.Equal(t, tt.expected, opts)
})
}
}
8 changes: 8 additions & 0 deletions ocpp_v201/connector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ocpp_v201

import "github.com/ChargePi/ocpp-manager/ocpp_v201/component"

type Connector struct {
ID int
components map[component.ComponentName]component.Component
}
Loading
Loading