cli: allow setting vehicle current (if supported) (#12429)
This commit is contained in:
parent
2f30247115
commit
fbf4a6dcc5
2 changed files with 31 additions and 13 deletions
|
|
@ -17,11 +17,9 @@ var chargerCmd = &cobra.Command{
|
|||
Run: runCharger,
|
||||
}
|
||||
|
||||
const noCurrent = -1
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(chargerCmd)
|
||||
chargerCmd.Flags().IntP(flagCurrent, "i", noCurrent, flagCurrentDescription)
|
||||
chargerCmd.Flags().IntP(flagCurrent, "i", 0, flagCurrentDescription)
|
||||
//lint:ignore SA1019 as Title is safe on ascii
|
||||
chargerCmd.Flags().BoolP(flagEnable, "e", false, strings.Title(flagEnable))
|
||||
//lint:ignore SA1019 as Title is safe on ascii
|
||||
|
|
@ -46,15 +44,6 @@ func runCharger(cmd *cobra.Command, args []string) {
|
|||
log.FATAL.Fatal(err)
|
||||
}
|
||||
|
||||
current := int64(noCurrent)
|
||||
if flag := cmd.Flags().Lookup(flagCurrent); flag.Changed {
|
||||
var err error
|
||||
current, err = strconv.ParseInt(flag.Value.String(), 10, 64)
|
||||
if err != nil {
|
||||
log.ERROR.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
||||
var phases int
|
||||
if flag := cmd.Flags().Lookup(flagPhases); flag.Changed {
|
||||
var err error
|
||||
|
|
@ -68,9 +57,14 @@ func runCharger(cmd *cobra.Command, args []string) {
|
|||
|
||||
var flagUsed bool
|
||||
for _, v := range config.Instances(chargers) {
|
||||
if current != noCurrent {
|
||||
if flag := cmd.Flags().Lookup(flagCurrent); flag.Changed {
|
||||
flagUsed = true
|
||||
|
||||
current, err := strconv.ParseInt(flag.Value.String(), 10, 64)
|
||||
if err != nil {
|
||||
log.ERROR.Fatalln(err)
|
||||
}
|
||||
|
||||
if err := v.MaxCurrent(current); err != nil {
|
||||
log.ERROR.Println("set current:", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util/config"
|
||||
"github.com/spf13/cobra"
|
||||
|
|
@ -16,6 +18,7 @@ var vehicleCmd = &cobra.Command{
|
|||
|
||||
func init() {
|
||||
rootCmd.AddCommand(vehicleCmd)
|
||||
vehicleCmd.Flags().Int64P(flagCurrent, "i", 0, flagCurrentDescription)
|
||||
vehicleCmd.Flags().BoolP(flagStart, "a", false, flagStartDescription)
|
||||
vehicleCmd.Flags().BoolP(flagStop, "o", false, flagStopDescription)
|
||||
vehicleCmd.Flags().BoolP(flagWakeup, "w", false, flagWakeupDescription)
|
||||
|
|
@ -49,6 +52,27 @@ func runVehicle(cmd *cobra.Command, args []string) {
|
|||
|
||||
var flagUsed bool
|
||||
for _, v := range config.Instances(vehicles) {
|
||||
if flag := cmd.Flags().Lookup(flagCurrent); flag.Changed {
|
||||
flagUsed = true
|
||||
|
||||
f, err := strconv.ParseFloat(flag.Value.String(), 64)
|
||||
if err != nil {
|
||||
log.ERROR.Println("max current:", err)
|
||||
} else {
|
||||
if vv, ok := v.(api.ChargerEx); ok {
|
||||
if err := vv.MaxCurrentMillis(f); err != nil {
|
||||
log.ERROR.Println("max current:", err)
|
||||
}
|
||||
} else if vv, ok := v.(api.CurrentController); ok {
|
||||
if err := vv.MaxCurrent(int64(f)); err != nil {
|
||||
log.ERROR.Println("max current:", err)
|
||||
}
|
||||
} else {
|
||||
log.ERROR.Println("max current: not implemented")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Lookup(flagWakeup).Changed {
|
||||
flagUsed = true
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue