Shorten call to create decorators by using go:generate env settings (#1010)
This commit is contained in:
parent
5e733d8f0e
commit
ec0831cf36
12 changed files with 31 additions and 11 deletions
|
|
@ -198,6 +198,11 @@ func main() {
|
||||||
pflag.Usage = Usage
|
pflag.Usage = Usage
|
||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
|
|
||||||
|
// read target from go:generate
|
||||||
|
if gopkg, ok := os.LookupEnv("GOPACKAGE"); *pkg == "" && ok {
|
||||||
|
pkg = &gopkg
|
||||||
|
}
|
||||||
|
|
||||||
if *base == "" || *pkg == "" || len(*types) == 0 {
|
if *base == "" || *pkg == "" || len(*types) == 0 {
|
||||||
Usage()
|
Usage()
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
|
|
@ -218,7 +223,14 @@ func main() {
|
||||||
generated := strings.TrimSpace(buf.String()) + "\n"
|
generated := strings.TrimSpace(buf.String()) + "\n"
|
||||||
|
|
||||||
var out io.Writer = os.Stdout
|
var out io.Writer = os.Stdout
|
||||||
if *target != "" {
|
|
||||||
|
// read target from go:generate
|
||||||
|
if gofile, ok := os.LookupEnv("GOFILE"); *target == "" && ok {
|
||||||
|
gofile = strings.TrimSuffix(gofile, ".go") + "_decorators.go"
|
||||||
|
target = &gofile
|
||||||
|
}
|
||||||
|
|
||||||
|
if target != nil {
|
||||||
name := *target
|
name := *target
|
||||||
if !strings.HasSuffix(name, ".go") {
|
if !strings.HasSuffix(name, ".go") {
|
||||||
name += ".go"
|
name += ".go"
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,14 @@ func NewEasee(user, password, charger string, cache time.Duration) (*Easee, erro
|
||||||
c.site = site.ID
|
c.site = site.ID
|
||||||
c.circuit = site.Circuits[0].ID
|
c.circuit = site.Circuits[0].ID
|
||||||
|
|
||||||
|
uri := fmt.Sprintf("%s/streams/amqp", easee.API)
|
||||||
|
req, err := request.New(http.MethodGet, uri, nil, request.JSONEncoding)
|
||||||
|
if err == nil {
|
||||||
|
var res map[string]interface{}
|
||||||
|
_ = c.DoJSON(req, &res)
|
||||||
|
fmt.Println(res)
|
||||||
|
}
|
||||||
|
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ func init() {
|
||||||
registry.Add("evsewifi", NewEVSEWifiFromConfig)
|
registry.Add("evsewifi", NewEVSEWifiFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run ../../cmd/tools/decorate.go -p charger -f decorateEVSE -o evsewifi_decorators -b *EVSEWifi -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)"
|
//go:generate go run ../../cmd/tools/decorate.go -f decorateEVSE -b *EVSEWifi -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)"
|
||||||
|
|
||||||
// NewEVSEWifiFromConfig creates a EVSEWifi charger from generic config
|
// NewEVSEWifiFromConfig creates a EVSEWifi charger from generic config
|
||||||
func NewEVSEWifiFromConfig(other map[string]interface{}) (api.Charger, error) {
|
func NewEVSEWifiFromConfig(other map[string]interface{}) (api.Charger, error) {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ func init() {
|
||||||
registry.Add("phoenix-em-eth", NewPhoenixEMEthFromConfig)
|
registry.Add("phoenix-em-eth", NewPhoenixEMEthFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run ../../cmd/tools/decorate.go -p charger -f decoratePhoenixEMEth -o phoenix-em-eth_decorators -b *PhoenixEMEth -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)"
|
//go:generate go run ../../cmd/tools/decorate.go -f decoratePhoenixEMEth -b *PhoenixEMEth -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)"
|
||||||
|
|
||||||
// NewPhoenixEMEthFromConfig creates a Phoenix charger from generic config
|
// NewPhoenixEMEthFromConfig creates a Phoenix charger from generic config
|
||||||
func NewPhoenixEMEthFromConfig(other map[string]interface{}) (api.Charger, error) {
|
func NewPhoenixEMEthFromConfig(other map[string]interface{}) (api.Charger, error) {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ func init() {
|
||||||
registry.Add("phoenix-ev-eth", NewPhoenixEVEthFromConfig)
|
registry.Add("phoenix-ev-eth", NewPhoenixEVEthFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run ../../cmd/tools/decorate.go -p charger -f decoratePhoenixEVEth -o phoenix-ev-eth_decorators -b *PhoenixEVEth -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)"
|
//go:generate go run ../../cmd/tools/decorate.go -f decoratePhoenixEVEth -b *PhoenixEVEth -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)"
|
||||||
|
|
||||||
// NewPhoenixEVEthFromConfig creates a Phoenix charger from generic config
|
// NewPhoenixEVEthFromConfig creates a Phoenix charger from generic config
|
||||||
func NewPhoenixEVEthFromConfig(other map[string]interface{}) (api.Charger, error) {
|
func NewPhoenixEVEthFromConfig(other map[string]interface{}) (api.Charger, error) {
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ func init() {
|
||||||
registry.Add("wallbe", NewWallbeFromConfig)
|
registry.Add("wallbe", NewWallbeFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// go:generate go run ../cmd/tools/decorate.go -p charger -f decorateWallbe -o wallbe_decorators -b *Wallbe -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)" -t "api.ChargerEx,MaxCurrentMillis,func(current float64) error"
|
// go:generate go run ../cmd/tools/decorate.go -f decorateWallbe -b *Wallbe -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)" -t "api.ChargerEx,MaxCurrentMillis,func(current float64) error"
|
||||||
|
|
||||||
// NewWallbeFromConfig creates a Wallbe charger from generic config
|
// NewWallbeFromConfig creates a Wallbe charger from generic config
|
||||||
func NewWallbeFromConfig(other map[string]interface{}) (api.Charger, error) {
|
func NewWallbeFromConfig(other map[string]interface{}) (api.Charger, error) {
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ type Warp struct {
|
||||||
enabled bool // cache
|
enabled bool // cache
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run ../../cmd/tools/decorate.go -p charger -f decorateWarp -o warp_decorators -b *Warp -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)"
|
//go:generate go run ../../cmd/tools/decorate.go -f decorateWarp -b *Warp -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)"
|
||||||
|
|
||||||
// NewWarp creates a new configurable charger
|
// NewWarp creates a new configurable charger
|
||||||
func NewWarp(mqttconf mqtt.Config, topic string, timeout time.Duration) (*Warp, error) {
|
func NewWarp(mqttconf mqtt.Config, topic string, timeout time.Duration) (*Warp, error) {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ func init() {
|
||||||
registry.Add(internal.Custom, NewConfigurableFromConfig)
|
registry.Add(internal.Custom, NewConfigurableFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run ../../cmd/tools/decorate.go -p meter -f decorateMeter -b api.Meter -o meter_decorators -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)" -t "api.Battery,SoC,func() (float64, error)"
|
//go:generate go run ../../cmd/tools/decorate.go -f decorateMeter -b api.Meter -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)" -t "api.Battery,SoC,func() (float64, error)"
|
||||||
|
|
||||||
// NewConfigurableFromConfig creates api.Meter from config
|
// NewConfigurableFromConfig creates api.Meter from config
|
||||||
func NewConfigurableFromConfig(other map[string]interface{}) (api.Meter, error) {
|
func NewConfigurableFromConfig(other map[string]interface{}) (api.Meter, error) {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ func init() {
|
||||||
registry.Add("modbus", NewModbusFromConfig)
|
registry.Add("modbus", NewModbusFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run ../../cmd/tools/decorate.go -p meter -f decorateModbus -b api.Meter -o modbus_decorators -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.Battery,SoC,func() (float64, error)"
|
//go:generate go run ../../cmd/tools/decorate.go -f decorateModbus -b api.Meter -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.Battery,SoC,func() (float64, error)"
|
||||||
|
|
||||||
// NewModbusFromConfig creates api.Meter from config
|
// NewModbusFromConfig creates api.Meter from config
|
||||||
func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) {
|
func NewModbusFromConfig(other map[string]interface{}) (api.Meter, error) {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ func init() {
|
||||||
registry.Add("sma", NewSMAFromConfig)
|
registry.Add("sma", NewSMAFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run ../../cmd/tools/decorate.go -p meter -f decorateSMA -b api.Meter -o sma_decorators -t "api.MeterEnergy,TotalEnergy,func() (float64, error)"
|
//go:generate go run ../../cmd/tools/decorate.go -f decorateSMA -b api.Meter -t "api.MeterEnergy,TotalEnergy,func() (float64, error)"
|
||||||
|
|
||||||
// NewSMAFromConfig creates a SMA Meter from generic config
|
// NewSMAFromConfig creates a SMA Meter from generic config
|
||||||
func NewSMAFromConfig(other map[string]interface{}) (api.Meter, error) {
|
func NewSMAFromConfig(other map[string]interface{}) (api.Meter, error) {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ func init() {
|
||||||
registry.Add("tesla", NewTeslaFromConfig)
|
registry.Add("tesla", NewTeslaFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run ../../cmd/tools/decorate.go -p meter -f decorateTesla -b api.Meter -o tesla_decorators -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.Battery,SoC,func() (float64, error)"
|
//go:generate go run ../../cmd/tools/decorate.go -f decorateTesla -b api.Meter -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.Battery,SoC,func() (float64, error)"
|
||||||
|
|
||||||
// NewTeslaFromConfig creates a Tesla Powerwall Meter from generic config
|
// NewTeslaFromConfig creates a Tesla Powerwall Meter from generic config
|
||||||
func NewTeslaFromConfig(other map[string]interface{}) (api.Meter, error) {
|
func NewTeslaFromConfig(other map[string]interface{}) (api.Meter, error) {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ func (m *embed) Identify() (string, error) {
|
||||||
return m.Identifier_, nil
|
return m.Identifier_, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run ../../cmd/tools/decorate.go -p vehicle -f decorateVehicle -b api.Vehicle -o vehicle_decorators -t "api.ChargeState,Status,func() (api.ChargeStatus, error)" -t "api.VehicleRange,Range,func() (int64, error)"
|
//go:generate go run ../../cmd/tools/decorate.go -f decorateVehicle -b api.Vehicle -t "api.ChargeState,Status,func() (api.ChargeStatus, error)" -t "api.VehicleRange,Range,func() (int64, error)"
|
||||||
|
|
||||||
// Vehicle is an api.Vehicle implementation with configurable getters and setters.
|
// Vehicle is an api.Vehicle implementation with configurable getters and setters.
|
||||||
type Vehicle struct {
|
type Vehicle struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue