forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_enumer.go
107 lines (90 loc) · 2.89 KB
/
feature_enumer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Code generated by "enumer -type Feature -text"; DO NOT EDIT.
package api
import (
"fmt"
"strings"
)
const _FeatureName = "OfflineCoarseCurrentIntegratedDeviceHeatingRetryableWelcomeCharge"
var _FeatureIndex = [...]uint8{0, 7, 20, 36, 43, 52, 65}
const _FeatureLowerName = "offlinecoarsecurrentintegrateddeviceheatingretryablewelcomecharge"
func (i Feature) String() string {
i -= 1
if i < 0 || i >= Feature(len(_FeatureIndex)-1) {
return fmt.Sprintf("Feature(%d)", i+1)
}
return _FeatureName[_FeatureIndex[i]:_FeatureIndex[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 _FeatureNoOp() {
var x [1]struct{}
_ = x[Offline-(1)]
_ = x[CoarseCurrent-(2)]
_ = x[IntegratedDevice-(3)]
_ = x[Heating-(4)]
_ = x[Retryable-(5)]
_ = x[WelcomeCharge-(6)]
}
var _FeatureValues = []Feature{Offline, CoarseCurrent, IntegratedDevice, Heating, Retryable, WelcomeCharge}
var _FeatureNameToValueMap = map[string]Feature{
_FeatureName[0:7]: Offline,
_FeatureLowerName[0:7]: Offline,
_FeatureName[7:20]: CoarseCurrent,
_FeatureLowerName[7:20]: CoarseCurrent,
_FeatureName[20:36]: IntegratedDevice,
_FeatureLowerName[20:36]: IntegratedDevice,
_FeatureName[36:43]: Heating,
_FeatureLowerName[36:43]: Heating,
_FeatureName[43:52]: Retryable,
_FeatureLowerName[43:52]: Retryable,
_FeatureName[52:65]: WelcomeCharge,
_FeatureLowerName[52:65]: WelcomeCharge,
}
var _FeatureNames = []string{
_FeatureName[0:7],
_FeatureName[7:20],
_FeatureName[20:36],
_FeatureName[36:43],
_FeatureName[43:52],
_FeatureName[52:65],
}
// FeatureString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func FeatureString(s string) (Feature, error) {
if val, ok := _FeatureNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _FeatureNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Feature values", s)
}
// FeatureValues returns all values of the enum
func FeatureValues() []Feature {
return _FeatureValues
}
// FeatureStrings returns a slice of all String values of the enum
func FeatureStrings() []string {
strs := make([]string, len(_FeatureNames))
copy(strs, _FeatureNames)
return strs
}
// IsAFeature returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Feature) IsAFeature() bool {
for _, v := range _FeatureValues {
if i == v {
return true
}
}
return false
}
// MarshalText implements the encoding.TextMarshaler interface for Feature
func (i Feature) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for Feature
func (i *Feature) UnmarshalText(text []byte) error {
var err error
*i, err = FeatureString(string(text))
return err
}