evcc-io/util/templates/usage_enumer.go

106 lines
2.7 KiB
Go

// Code generated by "enumer -type Usage -trimprefix Usage -transform=lower -text"; DO NOT EDIT.
package templates
import (
"fmt"
"strings"
)
const _UsageName = "gridcurtailpvbatterychargeaux"
var _UsageIndex = [...]uint8{0, 4, 11, 13, 20, 26, 29}
const _UsageLowerName = "gridcurtailpvbatterychargeaux"
func (i Usage) String() string {
if i < 0 || i >= Usage(len(_UsageIndex)-1) {
return fmt.Sprintf("Usage(%d)", i)
}
return _UsageName[_UsageIndex[i]:_UsageIndex[i+1]]
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _UsageNoOp() {
var x [1]struct{}
_ = x[UsageGrid-(0)]
_ = x[UsageCurtail-(1)]
_ = x[UsagePV-(2)]
_ = x[UsageBattery-(3)]
_ = x[UsageCharge-(4)]
_ = x[UsageAux-(5)]
}
var _UsageValues = []Usage{UsageGrid, UsageCurtail, UsagePV, UsageBattery, UsageCharge, UsageAux}
var _UsageNameToValueMap = map[string]Usage{
_UsageName[0:4]: UsageGrid,
_UsageLowerName[0:4]: UsageGrid,
_UsageName[4:11]: UsageCurtail,
_UsageLowerName[4:11]: UsageCurtail,
_UsageName[11:13]: UsagePV,
_UsageLowerName[11:13]: UsagePV,
_UsageName[13:20]: UsageBattery,
_UsageLowerName[13:20]: UsageBattery,
_UsageName[20:26]: UsageCharge,
_UsageLowerName[20:26]: UsageCharge,
_UsageName[26:29]: UsageAux,
_UsageLowerName[26:29]: UsageAux,
}
var _UsageNames = []string{
_UsageName[0:4],
_UsageName[4:11],
_UsageName[11:13],
_UsageName[13:20],
_UsageName[20:26],
_UsageName[26:29],
}
// UsageString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func UsageString(s string) (Usage, error) {
if val, ok := _UsageNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _UsageNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Usage values", s)
}
// UsageValues returns all values of the enum
func UsageValues() []Usage {
return _UsageValues
}
// UsageStrings returns a slice of all String values of the enum
func UsageStrings() []string {
strs := make([]string, len(_UsageNames))
copy(strs, _UsageNames)
return strs
}
// IsAUsage returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Usage) IsAUsage() bool {
for _, v := range _UsageValues {
if i == v {
return true
}
}
return false
}
// MarshalText implements the encoding.TextMarshaler interface for Usage
func (i Usage) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for Usage
func (i *Usage) UnmarshalText(text []byte) error {
var err error
*i, err = UsageString(string(text))
return err
}