Documentation
¶
Index ¶
- Constants
- Variables
- func ClassStrings() []string
- func EncoderLanguage(lang string)
- func FuncMap(tmpl *template.Template) *template.Template
- func ParamTypeStrings() []string
- func Register(class Class, filepath string) error
- func TestClass(t *testing.T, class Class, ...)
- func UsageStrings() []string
- func WithDeprecated() filterFunc
- type Class
- type CountryCode
- type Instance
- type Param
- func (p *Param) DefaultValue(renderMode int) any
- func (p *Param) IsAdvanced() bool
- func (p *Param) IsDeprecated() bool
- func (p *Param) IsMasked() bool
- func (p *Param) IsPrivate() bool
- func (p *Param) IsRequired() bool
- func (p *Param) IsZero(s string) bool
- func (p Param) MarshalJSON() ([]byte, error)
- func (p *Param) OverwriteProperties(withParam Param)
- type ParamType
- type Pattern
- type Product
- type Requirements
- type Template
- func (t *Template) Defaults(renderMode int) map[string]any
- func (t *Template) GroupTitle(lang string) string
- func (t *Template) ModbusChoices() []string
- func (t *Template) ModbusParams(modbusType string, values map[string]any)
- func (t *Template) ModbusValues(renderMode int, values map[string]any)
- func (t *Template) ParamByName(name string) (int, Param)
- func (t *Template) RenderDocumentation(product Product, lang string) ([]byte, error)
- func (t *Template) RenderProxyWithValues(values map[string]any, lang string) ([]byte, error)
- func (t *Template) RenderResult(renderMode int, other map[string]any) ([]byte, map[string]any, error)
- func (t *Template) ResolveGroup() error
- func (t *Template) ResolvePresets() error
- func (t *Template) SetParamDefault(name string, value string)
- func (t *Template) SortRequiredParamsFirst() error
- func (t *Template) UpdateModbusParamsWithDefaults() error
- func (t *Template) UpdateParamsWithDefaults() error
- func (t *Template) Usages() []string
- func (t *Template) Validate() error
- type TextLanguage
- type Usage
Constants ¶
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" )
const ( RenderModeDocs int = iota RenderModeUnitTest RenderModeInstance )
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 )
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 ¶
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, } )
var (
ConfigDefaults configDefaults
)
var ValidCapabilities = []string{CapabilityISO151182, CapabilityMilliAmps, CapabilityRFID, Capability1p3p, CapabilityBatteryControl}
var ValidRequirements = []string{RequirementEEBUS, RequirementMQTT, RequirementSponsorship, RequirementSkipTest}
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 ParamTypeStrings ¶
func ParamTypeStrings() []string
ParamTypeStrings returns a slice of all String values of the enum
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 ¶
ClassString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
type CountryCode ¶
type CountryCode string
func (CountryCode) IsValid ¶
func (c CountryCode) IsValid() bool
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 ¶
DefaultValue returns a default or example value depending on the renderMode
func (*Param) IsAdvanced ¶
func (*Param) IsDeprecated ¶
func (*Param) IsRequired ¶
func (Param) MarshalJSON ¶
func (*Param) OverwriteProperties ¶
OverwriteProperties merges properties from parameter definition
type ParamType ¶
type ParamType int
func ParamTypeString ¶
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 ¶
IsAParamType returns "true" if the value is listed in the enum definition. "false" otherwise
func (ParamType) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface for ParamType
func (*ParamType) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface for ParamType
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 ¶
Identifier returns a unique language-independent identifier for the product
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 (*Template) GroupTitle ¶
return the language specific group title
func (*Template) ModbusChoices ¶
return all modbus choices defined in the template
func (*Template) ModbusParams ¶
ModbusParams adds the modbus parameters' default values
func (*Template) ModbusValues ¶
ModbusValues adds the values required for modbus.tpl to the value map
func (*Template) ParamByName ¶
return the param with the given name
func (*Template) RenderDocumentation ¶
RenderDocumentation renders the documentation template
func (*Template) RenderProxyWithValues ¶
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 ¶
check if the provided group exists
func (*Template) ResolvePresets ¶
add the referenced base Params and overwrite existing ones
func (*Template) SetParamDefault ¶
SetParamDefault updates the default value of a param
func (*Template) SortRequiredParamsFirst ¶
func (*Template) UpdateModbusParamsWithDefaults ¶
UpdateModbusParamsWithDefaults populates modbus param fields with global defaults when device-specific values are not set (zero/empty).
func (*Template) UpdateParamsWithDefaults ¶
UpdateParamWithDefaults adds default values to specific param name entries
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
func UsageString ¶
UsageString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func (Usage) IsAUsage ¶
IsAUsage returns "true" if the value is listed in the enum definition. "false" otherwise
func (Usage) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface for Usage
func (*Usage) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface for Usage