Add support for getting a single device config (#1979)

This commit is contained in:
Andreas Linde 2021-12-05 23:44:30 +01:00 • committed by GitHub
parent 455f5b768c
commit 27b1fdf708
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 24 deletions

View file

@ -1,3 +1,16 @@
Intro = "Die nächsten Schritte führen durch die Einrichtung einer Konfigurationsdatei für evcc.\nBeachte dass dieser Prozess nicht alle möglichen Szenarien berücksichtigen kann.\nDurch Drücken von CTRL-C kann der Prozess abgebrochen werden.\n\nACHTUNG: Diese Funktionalität hat experimentellen Status!\n D.h. es kann möglich sein, dass die hiermit erstellte Konfigurationsdatei\n in einem Update nicht mehr funktionieren könnte und neu erzeugt werden müsste.\n Wir freuen uns auf euer Feedback auf https://github.com/evcc-io/evcc/discussions/\n\nAuf geht`s:"
Flow_Type = "Was möchtest du machen?"
Flow_Type_NewConfiguration = "Eine neue evcc Konfigurationsdatei erstellen"
Flow_Type_SingleDevice = "Ein einzelnes Gerät Konfigurieren"
Flow_NewConfiguration_Setup = "- Hausinstallation einrichten"
Flow_NewConfiguration_Select = "Wähle eines der folgenden PV Komplettsysteme aus, oder '{{ .ItemNotPresent }}' falls keines dieser Geräte vorhanden ist"
Flow_SingleDevice_Setup = "- Ein Gerät konfigurieren"
Flow_SingleDevice_Select = "Wähle eines der folgenden Gerätekategorien aus"
Flow_SingleDevice_Config = "Die Konfiguration lautet:"
ItemNotPresent = "Mein Gerät ist nicht in der Liste"
AddDeviceInCategory = "Möchtest du {{ .Article }} {{ .Category }} hinzufügen?"
@ -93,11 +106,6 @@ ValueError_Number = "Der Wert muss eine ganzzahlige Zahl sein."
Device_Configure = "Konfiguration"
Device_Added = "wurde erfolgreich hinzugefügt."
Intro = "Die nächsten Schritte führen durch die Einrichtung einer Konfigurationsdatei für evcc.\nBeachte dass dieser Prozess nicht alle möglichen Szenarien berücksichtigen kann.\nDurch Drücken von CTRL-C kann der Prozess abgebrochen werden.\n\nACHTUNG: Diese Funktionalität hat experimentellen Status!\n D.h. es kann möglich sein, dass die hiermit erstellte Konfigurationsdatei\n in einem Update nicht mehr funktionieren könnte und neu erzeugt werden müsste.\n Wir freuen uns auf euer Feedback auf https://github.com/evcc-io/evcc/discussions/\n\nAuf geht`s:"
Meters_Setup = "- Hausinstallation einrichten"
Meters_Guide_Select = "Wähle eines der folgenden PV Komplettsysteme aus, oder '{{ .ItemNotPresent }}' falls keines dieser Geräte vorhanden ist"
Loadpoint_Setup = "- Ladepunkt(e) einrichten"
Loadpoint_Title = "Titel des Ladepunktes"
Loadpoint_AddAnother = "Möchtest du einen weiteren Ladepunkt hinzufügen?"

View file

@ -1,3 +1,16 @@
Intro = "The next steps will guide you through the creation of a configuration file for evcc.\nPlease note that this process cannot cover all possible scenarios.\nYou can cancel the process by pressing CTRL-C anytime.\n\nNOTE: This functionality is in an experimental state!\n This means that the created configuration file may not work\n in a future update of evcc and would need to be recreated.\n We are looking forward to your feedback at https://github.com/evcc-io/evcc/discussions/\n\nLet's go:"
Flow_Type = "What do you want to do?"
Flow_Type_NewConfiguration = "Create a new evcc configuration file"
Flow_Type_SingleDevice = "Configure a single device"
Flow_NewConfiguration_Setup = "- Setup meters (house installation)"
Flow_NewConfiguration_Select = "Choose one of the following PV systems, or '{{ .ItemNotPresent }}' if you have none of them"
Flow_SingleDevice_Setup = "- Setup a device"
Flow_SingleDevice_Select = "Choose one of the following device categories"
Flow_SingleDevice_Config = "The configuration:"
ItemNotPresent = "My device is not in this list"
AddDeviceInCategory = "Do you want to add {{ .Article }} {{ .Category }}?"
@ -93,11 +106,6 @@ ValueError_Number = "The value has to be an integer."
Device_Configure = "Configuration"
Device_Added = "was successfully added."
Intro = "The next steps will guide you through the creation of a configuration file for evcc.\nPlease note that this process cannot cover all possible scenarios.\nYou can cancel the process by pressing CTRL-C anytime.\n\nNOTE: This functionality is in an experimental state!\n This means that the created configuration file may not work\n in a future update of evcc and would need to be recreated.\n We are looking forward to your feedback at https://github.com/evcc-io/evcc/discussions/\n\nLet's go:"
Meters_Setup = "- Setup meters (house installation)"
Meters_Guide_Select = "Choose one of the following PV systems, or '{{ .ItemNotPresent }}' if you have none of them"
Loadpoint_Setup = "- Setup loadpoint(s)"
Loadpoint_Title = "Loadpoint title"
Loadpoint_AddAnother = "Do you want to add another loadpoint?"

View file

@ -1,11 +1,13 @@
package configure
import (
"bufio"
_ "embed"
"errors"
"fmt"
"os"
"strconv"
"strings"
"github.com/BurntSushi/toml"
"github.com/cloudfoundry/jibber_jabber"
@ -66,16 +68,74 @@ func (c *CmdConfigure) Run(log *util.Logger, flagLang string, advancedMode, expa
fmt.Println()
fmt.Println(c.localizedString("Intro", nil))
flowChoices := []string{
c.localizedString("Flow_Type_NewConfiguration", nil),
c.localizedString("Flow_Type_SingleDevice", nil),
}
fmt.Println()
fmt.Println(c.localizedString("Meters_Setup", nil))
flowIndex, _ := c.askChoice(c.localizedString("Loadpoint_WallboxMaxPower", nil), flowChoices)
switch flowIndex {
case 0:
c.flowNewConfigFile()
case 1:
c.flowSingleDevice()
}
}
// configureSingleDevice implements the flow for getting a single device configuration
func (c *CmdConfigure) flowSingleDevice() {
fmt.Println()
fmt.Println(c.localizedString("Meters_Guide_Select", localizeMap{"ItemNotPresent": c.localizedString("ItemNotPresent", nil)}))
fmt.Println(c.localizedString("Flow_SingleDevice_Setup", nil))
fmt.Println()
fmt.Println(c.localizedString("Flow_SingleDevice_Select", nil))
// only consider the device categories that are marked for this flow
categoryChoices := []string{
DeviceCategories[DeviceCategoryGridMeter].title,
DeviceCategories[DeviceCategoryPVMeter].title,
DeviceCategories[DeviceCategoryBatteryMeter].title,
DeviceCategories[DeviceCategoryChargeMeter].title,
DeviceCategories[DeviceCategoryCharger].title,
DeviceCategories[DeviceCategoryVehicle].title,
}
fmt.Println()
_, cagetoryTitle := c.askChoice(c.localizedString("Flow_SingleDevice_Select", nil), categoryChoices)
var selectedCategory DeviceCategory
for item, data := range DeviceCategories {
if data.title == cagetoryTitle {
selectedCategory = item
break
}
}
devices := c.configureDevices(selectedCategory, false, false)
for _, item := range devices {
fmt.Println()
fmt.Println(c.localizedString("Flow_SingleDevice_Config", localizeMap{}))
fmt.Println()
scanner := bufio.NewScanner(strings.NewReader(item.Yaml))
for scanner.Scan() {
fmt.Println(" " + scanner.Text())
}
}
fmt.Println()
}
// configureNewConfigFile implements the flow for creating a new configuration file
func (c *CmdConfigure) flowNewConfigFile() {
fmt.Println()
fmt.Println(c.localizedString("Flow_NewConfiguration_Setup", nil))
fmt.Println()
fmt.Println(c.localizedString("Flow_NewConfiguration_Select", localizeMap{"ItemNotPresent": c.localizedString("ItemNotPresent", nil)}))
c.configureDeviceGuidedSetup()
c.configureDevices(DeviceCategoryGridMeter, false)
c.configureDevices(DeviceCategoryPVMeter, true)
c.configureDevices(DeviceCategoryBatteryMeter, true)
c.configureDevices(DeviceCategoryVehicle, true)
_ = c.configureDevices(DeviceCategoryGridMeter, true, false)
_ = c.configureDevices(DeviceCategoryPVMeter, true, true)
_ = c.configureDevices(DeviceCategoryBatteryMeter, true, true)
_ = c.configureDevices(DeviceCategoryVehicle, true, true)
c.configureLoadpoints()
c.configureSite()
@ -113,7 +173,7 @@ func (c *CmdConfigure) Run(log *util.Logger, flagLang string, advancedMode, expa
}
// configureDevices asks device specfic questions
func (c *CmdConfigure) configureDevices(deviceCategory DeviceCategory, askMultiple bool) []device {
func (c *CmdConfigure) configureDevices(deviceCategory DeviceCategory, askAdding, askMultiple bool) []device {
var devices []device
if deviceCategory == DeviceCategoryGridMeter && c.configuration.MetersOfCategory(deviceCategory) > 0 {
@ -125,14 +185,16 @@ func (c *CmdConfigure) configureDevices(deviceCategory DeviceCategory, askMultip
"Additional": DeviceCategories[deviceCategory].additional,
"Category": DeviceCategories[deviceCategory].title,
}
addDeviceText := c.localizedString("AddDeviceInCategory", localizeMap)
if c.configuration.MetersOfCategory(deviceCategory) > 0 {
addDeviceText = c.localizedString("AddAnotherDeviceInCategory", localizeMap)
}
if askAdding {
addDeviceText := c.localizedString("AddDeviceInCategory", localizeMap)
if c.configuration.MetersOfCategory(deviceCategory) > 0 {
addDeviceText = c.localizedString("AddAnotherDeviceInCategory", localizeMap)
}
fmt.Println()
if !c.askYesNo(addDeviceText) {
return nil
fmt.Println()
if !c.askYesNo(addDeviceText) {
return nil
}
}
for ok := true; ok; {