templates

package
v0.0.0-...-55f9a13 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParamUsage  = "usage"
	ParamModbus = "modbus"

	HemsTypeSMA = "sma"

	ModbusChoiceRS485    = "rs485"
	ModbusChoiceTCPIP    = "tcpip"
	ModbusChoiceUDP      = "udp"
	ModbusKeyRS485Serial = "rs485serial"
	ModbusKeyRS485TCPIP  = "rs485tcpip"
	ModbusKeyTCPIP       = "tcpip"
	ModbusKeyUDP         = "udp"

	ModbusParamId       = "id"
	ModbusParamDevice   = "device"
	ModbusParamBaudrate = "baudrate"
	ModbusParamComset   = "comset"
	ModbusParamURI      = "uri"
	ModbusParamHost     = "host"
	ModbusParamPort     = "port"
	ModbusParamRTU      = "rtu"
)
View Source
const (
	RenderModeDocs int = iota
	RenderModeUnitTest
	RenderModeInstance
)
View Source
const (
	CapabilityISO151182      = "iso151182"       // ISO 15118-2 support
	CapabilityMilliAmps      = "mA"              // Granular current control support
	CapabilityRFID           = "rfid"            // RFID support
	Capability1p3p           = "1p3p"            // 1P/3P phase switching support
	CapabilityBatteryControl = "battery-control" // Battery control support
)
View Source
const (
	RequirementEEBUS       = "eebus"       // EEBUS Setup is required
	RequirementMQTT        = "mqtt"        // MQTT Setup is required
	RequirementSponsorship = "sponsorship" // Sponsorship is required
	RequirementSkipTest    = "skiptest"    // Template should be rendered but not tested
)

Variables

View Source
var (
	ValidModbusChoices = []string{ModbusChoiceRS485, ModbusChoiceTCPIP, ModbusChoiceUDP}

	// ModbusParams contains all field names used by modbus templates
	ModbusParams = []string{
		ModbusParamId, ModbusParamDevice, ModbusParamBaudrate, ModbusParamComset,
		ModbusParamURI, ModbusParamHost, ModbusParamPort, ModbusParamRTU,
	}

	ModbusConnectionTypes = []string{
		ModbusKeyTCPIP, ModbusKeyUDP, ModbusKeyRS485Serial, ModbusKeyRS485TCPIP,
	}
)
View Source
var (
	ConfigDefaults configDefaults
)

Functions

func ClassStrings

func ClassStrings() []string

ClassStrings returns a slice of all String values of the enum

func EncoderLanguage

func EncoderLanguage(lang string)

EncoderLanguage sets the template language for encoding json

func FuncMap

func FuncMap(tmpl *template.Template) *template.Template

FuncMap returns a sprig template.FuncMap with additional include function

func ParamTypeStrings

func ParamTypeStrings() []string

ParamTypeStrings returns a slice of all String values of the enum

func Register

func Register(class Class, filepath string) error

Register adds a template file to the registry

func TestClass

func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values map[string]any))

func UsageStrings

func UsageStrings() []string

UsageStrings returns a slice of all String values of the enum

func WithDeprecated

func WithDeprecated() filterFunc

WithDeprecated returns a filterFunc that includes all templates

Types

type Class

type Class int
const (
	Charger Class
	Meter
	Vehicle
	Tariff
	Loadpoint
	Circuit
	Messenger
)

func ClassString

func ClassString(s string) (Class, error)

ClassString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ClassValues

func ClassValues() []Class

ClassValues returns all values of the enum

func (Class) IsAClass

func (i Class) IsAClass() bool

IsAClass returns "true" if the value is listed in the enum definition. "false" otherwise

func (Class) String

func (i Class) String() string

type CountryCode

type CountryCode string

func (CountryCode) IsValid

func (c CountryCode) IsValid() bool

type Instance

type Instance struct {
	Type  string
	Other map[string]any `yaml:",inline"`
}

Instance is an actual instantiated template

func RenderInstance

func RenderInstance(class Class, other map[string]any) (*Instance, error)

RenderInstance renders an actual configuration instance

type Param

type Param struct {
	Name        string       // Param name which is used for assigning defaults properties and referencing in render
	Description TextLanguage // language specific titles (presented in UI instead of Name)
	Help        TextLanguage // cli configuration help
	Preset      string       `json:"-"`          // Reference a predefined set of params
	Required    bool         `json:",omitempty"` // cli if the user has to provide a non empty value
	Mask        bool         `json:",omitempty"` // cli if the value should be masked, e.g. for passwords
	Private     bool         `json:",omitempty"` // value should be redacted in bug reports, e.g. email, locations, ...
	Advanced    bool         `json:",omitempty"` // cli if the user does not need to be asked. Requires a "Default" to be defined.
	Deprecated  bool         `json:",omitempty"` // if the parameter is deprecated and thus should not be presented in the cli or docs
	Default     string       `json:",omitempty"` // default value if no user value is provided in the configuration
	Example     string       `json:",omitempty"` // cli example value
	Value       string       `json:"-"`          // user provided value via cli configuration
	Values      []string     `json:",omitempty"` // user provided list of values e.g. for Type "list"
	Unit        string       `json:",omitempty"` // unit of the value, e.g. "kW", "kWh", "A", "V"
	Usages      []string     `json:",omitempty"` // restrict param to these usage types, e.g. "battery" for home battery capacity
	Type        ParamType    // string representation of the value type, "string" is default
	Choice      []string     `json:",omitempty"` // defines a set of choices, e.g. "grid", "pv", "battery", "charge" for "usage"
	Service     string       `json:",omitempty"` // defines a service to provide choices
	Pattern     *Pattern     `json:",omitempty"` // regex pattern and examples for input validation

	// TODO move somewhere else should not be part of the param definition
	Baudrate int    `json:",omitempty"` // device specific default for modbus RS485 baudrate
	Comset   string `json:",omitempty"` // device specific default for modbus RS485 comset
	Port     int    `json:",omitempty"` // device specific default for modbus TCPIP port
	ID       int    `json:",omitempty"` // device specific default for modbus ID
}

Param is a proxy template parameter Params can be defined: 1. in the template: uses entries in 4. for default properties and values, can be overwritten here 2. in defaults.yaml presets: can ne referenced in 1 and some values set here can be overwritten in 1. See OverwriteProperties method 3. in defaults.yaml modbus section: are referenced in 1 by a `name:modbus` param entry. Some values here can be overwritten in 1. 4. in defaults.yaml param section: defaults for some params Generelle Reihenfolge der Werte (außer Description, Default, Type): 1. defaults.yaml param section 2. defaults.yaml presets 3. defaults.yaml modbus section 4. template

func (*Param) DefaultValue

func (p *Param) DefaultValue(renderMode int) any

DefaultValue returns a default or example value depending on the renderMode

func (*Param) IsAdvanced

func (p *Param) IsAdvanced() bool

func (*Param) IsDeprecated

func (p *Param) IsDeprecated() bool

func (*Param) IsMasked

func (p *Param) IsMasked() bool

func (*Param) IsPrivate

func (p *Param) IsPrivate() bool

func (*Param) IsRequired

func (p *Param) IsRequired() bool

func (*Param) IsZero

func (p *Param) IsZero(s string) bool

func (Param) MarshalJSON

func (p Param) MarshalJSON() ([]byte, error)

func (*Param) OverwriteProperties

func (p *Param) OverwriteProperties(withParam Param)

OverwriteProperties merges properties from parameter definition

type ParamType

type ParamType int
const (
	TypeString ParamType = iota // default type string
	TypeBool
	TypeChoice
	TypeChargeModes
	TypeDuration
	TypeFloat
	TypeInt
	TypeList
	TypeZones
	TypePricePerKWh
)

func ParamTypeString

func ParamTypeString(s string) (ParamType, error)

ParamTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ParamTypeValues

func ParamTypeValues() []ParamType

ParamTypeValues returns all values of the enum

func (ParamType) IsAParamType

func (i ParamType) IsAParamType() bool

IsAParamType returns "true" if the value is listed in the enum definition. "false" otherwise

func (ParamType) MarshalText

func (i ParamType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for ParamType

func (ParamType) String

func (i ParamType) String() string

func (*ParamType) UnmarshalText

func (i *ParamType) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for ParamType

type Pattern

type Pattern struct {
	Regex    string   `json:",omitempty"`
	Examples []string `json:",omitempty"`
}

Pattern contains regex pattern and examples for input validation

func (*Pattern) Validate

func (p *Pattern) Validate(value string) error

Validate checks if a value matches the pattern and returns a descriptive error if not

type Product

type Product struct {
	Brand       string       // product brand
	Description TextLanguage `json:",omitempty"` // product name
}

Product contains naming information about a product a template supports

func (Product) Identifier

func (p Product) Identifier() string

Identifier returns a unique language-independent identifier for the product

func (Product) Title

func (p Product) Title(lang string) string

Title returns the product title in the given language

type Requirements

type Requirements struct {
	EVCC        []string     // EVCC requirements, e.g. sponsorship
	Description TextLanguage // Description of requirements, e.g. how the device needs to be prepared
}

Requirements

func (Requirements) MarshalJSON

func (r Requirements) MarshalJSON() ([]byte, error)

type Template

type Template struct {
	Template     string
	Deprecated   bool           `json:"-"`
	Auth         map[string]any `json:",omitempty"` // OAuth parameters (if required)
	Group        string         `json:",omitempty"` // the group this template belongs to, references groupList entries
	Covers       []string       `json:",omitempty"` // list of covered outdated template names
	Products     []Product      `json:",omitempty"` // list of products this template is compatible with
	Capabilities []string       `json:",omitempty"`
	Countries    []CountryCode  `json:",omitempty"` // list of countries supported by this template
	Requirements Requirements   `json:",omitempty"`
	Params       []Param        `json:",omitempty"`
	Render       string         `json:"-"` // rendering template
}

Template describes is a proxy device for use with cli and automated testing

func ByClass

func ByClass(class Class, opt ...filterFunc) []Template

ByClass returns templates for class excluding deprecated templates

func ByName

func ByName(class Class, name string) (Template, error)

ByClass returns templates for class and name including deprecated templates

func (*Template) Defaults

func (t *Template) Defaults(renderMode int) map[string]any

Defaults returns a map of default values for the template

func (*Template) GroupTitle

func (t *Template) GroupTitle(lang string) string

return the language specific group title

func (*Template) ModbusChoices

func (t *Template) ModbusChoices() []string

return all modbus choices defined in the template

func (*Template) ModbusParams

func (t *Template) ModbusParams(modbusType string, values map[string]any)

ModbusParams adds the modbus parameters' default values

func (*Template) ModbusValues

func (t *Template) ModbusValues(renderMode int, values map[string]any)

ModbusValues adds the values required for modbus.tpl to the value map

func (*Template) ParamByName

func (t *Template) ParamByName(name string) (int, Param)

return the param with the given name

func (*Template) RenderDocumentation

func (t *Template) RenderDocumentation(product Product, lang string) ([]byte, error)

RenderDocumentation renders the documentation template

func (*Template) RenderProxyWithValues

func (t *Template) RenderProxyWithValues(values map[string]any, lang string) ([]byte, error)

RenderProxyWithValues renders the proxy template

func (*Template) RenderResult

func (t *Template) RenderResult(renderMode int, other map[string]any) ([]byte, map[string]any, error)

RenderResult renders the result template to instantiate the proxy

func (*Template) ResolveGroup

func (t *Template) ResolveGroup() error

check if the provided group exists

func (*Template) ResolvePresets

func (t *Template) ResolvePresets() error

add the referenced base Params and overwrite existing ones

func (*Template) SetParamDefault

func (t *Template) SetParamDefault(name string, value string)

SetParamDefault updates the default value of a param

func (*Template) SortRequiredParamsFirst

func (t *Template) SortRequiredParamsFirst() error

func (*Template) UpdateModbusParamsWithDefaults

func (t *Template) UpdateModbusParamsWithDefaults() error

UpdateModbusParamsWithDefaults populates modbus param fields with global defaults when device-specific values are not set (zero/empty).

func (*Template) UpdateParamsWithDefaults

func (t *Template) UpdateParamsWithDefaults() error

UpdateParamWithDefaults adds default values to specific param name entries

func (*Template) Usages

func (t *Template) Usages() []string

Usages returns the list of supported usages

func (*Template) Validate

func (t *Template) Validate() error

validate the template (only rudimentary for now)

type TextLanguage

type TextLanguage struct {
	Generic string `json:",omitempty"` // language independent
	DE      string `json:",omitempty"` // german text
	EN      string `json:",omitempty"` // english text
}

TextLanguage contains language-specific texts

func (TextLanguage) MarshalJSON

func (t TextLanguage) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (*TextLanguage) ShortString

func (t *TextLanguage) ShortString(lang string) string

ShortString reduces help texts to one line and adds ...

func (*TextLanguage) String

func (t *TextLanguage) String(lang string) string

func (*TextLanguage) Update

func (t *TextLanguage) Update(new TextLanguage, always bool)

Update the language specific texts

always true to always update if the new value is not empty

always false to update only if the old value is empty and the new value is not empty

type Usage

type Usage int
const (
	UsageGrid Usage = iota
	UsagePV
	UsageBattery
	UsageCharge
	UsageAux
)

func UsageString

func UsageString(s string) (Usage, error)

UsageString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func UsageValues

func UsageValues() []Usage

UsageValues returns all values of the enum

func (Usage) IsAUsage

func (i Usage) IsAUsage() bool

IsAUsage returns "true" if the value is listed in the enum definition. "false" otherwise

func (Usage) MarshalText

func (i Usage) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for Usage

func (Usage) String

func (i Usage) String() string

func (*Usage) UnmarshalText

func (i *Usage) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for Usage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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