templates

package
v0.0.0-...-4b6ff7e Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

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

	HemsTypeSMA = "sma"

	ModbusChoiceRS485    = "rs485"
	ModbusChoiceTCPIP    = "tcpip"
	ModbusKeyRS485Serial = "rs485serial"
	ModbusKeyRS485TCPIP  = "rs485tcpip"
	ModbusKeyTCPIP       = "tcpip"

	ModbusParamNameId       = "id"
	ModbusParamNameDevice   = "device"
	ModbusParamNameBaudrate = "baudrate"
	ModbusParamNameComset   = "comset"
	ModbusParamNameURI      = "uri"
	ModbusParamNameHost     = "host"
	ModbusParamNamePort     = "port"
	ModbusParamNameRTU      = "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
	CapabilitySMAHems        = "smahems"         // SMA HEMS 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
)

Variables

View Source
var (
	ConfigDefaults configDefaults
)
View Source
var ValidModbusChoices = []string{ModbusChoiceRS485, ModbusChoiceTCPIP}

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 TestClass

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

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
	Circuit
)

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 Instance

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

Instance is an actual instantiated template

func RenderInstance

func RenderInstance(class Class, other map[string]interface{}) (*Instance, error)

RenderInstance renders an actual configuration instance

type LinkedTemplate

type LinkedTemplate struct {
	Template        string
	Usage           string // usage: "grid", "pv", "battery"
	Multiple        bool   // if true, multiple instances of this template can be added
	ExcludeTemplate string // only consider this if no device of the named linked template was added
}

Linked Template

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
	Reference     *bool        `json:",omitempty"` // if this is references another param definition
	ReferenceName string       `json:",omitempty"` // name of the referenced param if it is not identical to the defined name
	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
	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 "stringlist"
	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
	ValidValues   []string     `json:",omitempty"` // list of valid values the user can provide
	Choice        []string     `json:",omitempty"` // defines a set of choices, e.g. "grid", "pv", "battery", "charge" for "usage"
	AllInOne      *bool        `json:"-"`          // defines if the defined usages can all be present in a single device
	Requirements  Requirements `json:"-"`          // requirements for this param to be usable, only supported via Type "bool"

	// 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) interface{}

DefaultValue returns a default or example value depending on the renderMode

func (*Param) IsAdvanced

func (p *Param) IsAdvanced() bool

func (*Param) IsAllInOne

func (p *Param) IsAllInOne() bool

func (*Param) IsDeprecated

func (p *Param) IsDeprecated() bool

func (*Param) IsMasked

func (p *Param) IsMasked() bool

func (*Param) IsReference

func (p *Param) IsReference() bool

func (*Param) IsRequired

func (p *Param) IsRequired() bool

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
	TypeNumber
	TypeStringList
)

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 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) Title

func (p Product) Title(lang string) string

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
	URI         string       // URI to a webpage with more details about the preparation requirements
}

Requirements

type Template

type Template struct {
	TemplateDefinition
	// contains filtered or unexported fields
}

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 FromBytes

func FromBytes(b []byte) (Template, error)

func (*Template) Defaults

func (t *Template) Defaults(renderMode int) map[string]interface{}

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) GuidedSetupEnabled

func (t *Template) GuidedSetupEnabled() bool

GuidedSetupEnabled returns true if there are linked templates or >1 usage

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]interface{})

ModbusParams adds the modbus parameters' default values

func (*Template) ModbusValues

func (t *Template) ModbusValues(renderMode int, values map[string]interface{})

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]interface{}, lang string) ([]byte, error)

RenderProxyWithValues renders the proxy template

func (*Template) RenderResult

func (t *Template) RenderResult(renderMode int, other map[string]interface{}) ([]byte, map[string]interface{}, 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) SetCombinedTitle

func (t *Template) SetCombinedTitle(lang string)

set the language title by combining all product titles

func (*Template) SetParamDefault

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

SetParamDefault updates the default value of a param

func (*Template) SetTitle

func (t *Template) SetTitle(title string)

set the title for this templates

func (*Template) Title

func (t *Template) Title() string

return the title for this template

func (*Template) Titles

func (t *Template) Titles(lang string) []string

return the language specific product titles

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 TemplateDefinition

type TemplateDefinition struct {
	Template     string
	Deprecated   bool             `json:"-"`
	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"`
	Requirements Requirements     `json:"-"`
	Linked       []LinkedTemplate `json:",omitempty"` // a list of templates that should be processed as part of the guided setup
	Params       []Param          `json:",omitempty"`
	Render       string           `json:"-"` // rendering template
}

TemplateDefinition contains properties of a device template

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() (out []byte, err 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