Skip to content

Commit

Permalink
Switch sockets: allow removing vehicle selection for integrated devic…
Browse files Browse the repository at this point in the history
…es (evcc-io#6368)
  • Loading branch information
andig authored Feb 26, 2023
1 parent 1d1d79b commit 06a68d8
Show file tree
Hide file tree
Showing 72 changed files with 428 additions and 243 deletions.
4 changes: 2 additions & 2 deletions cmd/configure/eebus.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ func (c *CmdConfigure) eebusCertificate() (map[string]interface{}, error) {

cert, err := eebus.CreateCertificate()
if err != nil {
return eebusConfig, fmt.Errorf("%s", c.localizedString("Error_EEBUS_Certificate_Create", nil))
return eebusConfig, fmt.Errorf("%s", c.localizedString("Error_EEBUS_Certificate_Create"))
}

pubKey, privKey, err := eebus.GetX509KeyPair(cert)
if err != nil {
return eebusConfig, fmt.Errorf("%s", c.localizedString("Error_EEBUS_Certificate_Use", nil))
return eebusConfig, fmt.Errorf("%s", c.localizedString("Error_EEBUS_Certificate_Use"))
}

eebusConfig = map[string]interface{}{
Expand Down
8 changes: 4 additions & 4 deletions cmd/configure/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *CmdConfigure) configureDeviceGuidedSetup() {
}

fmt.Println()
fmt.Println(templateItem.Title() + " " + c.localizedString("Device_Added", nil))
fmt.Println(templateItem.Title() + " " + c.localizedString("Device_Added"))

c.configureLinkedTypes(templateItem)
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (c *CmdConfigure) configureLinkedTemplate(templateItem templates.Template,
c.processDeviceCapabilities(templateItem.Capabilities)

fmt.Println()
fmt.Println(templateItem.Title() + " " + c.localizedString("Device_Added", nil))
fmt.Println(templateItem.Title() + " " + c.localizedString("Device_Added"))
return true
}
break
Expand All @@ -180,7 +180,7 @@ func (c *CmdConfigure) configureLinkedTemplate(templateItem templates.Template,
// configureDeviceCategory lets the user select and configure a device from a specific category
func (c *CmdConfigure) configureDeviceCategory(deviceCategory DeviceCategory) (device, []string, error) {
fmt.Println()
fmt.Printf("- %s %s\n", c.localizedString("Device_Configure", nil), DeviceCategories[deviceCategory].title)
fmt.Printf("- %s %s\n", c.localizedString("Device_Configure"), DeviceCategories[deviceCategory].title)

device := device{
Name: DeviceCategories[deviceCategory].defaultName,
Expand Down Expand Up @@ -227,7 +227,7 @@ func (c *CmdConfigure) configureDeviceCategory(deviceCategory DeviceCategory) (d
}

fmt.Println()
fmt.Println(deviceDescription + deviceTitle + " " + c.localizedString("Device_Added", nil))
fmt.Println(deviceDescription + deviceTitle + " " + c.localizedString("Device_Added"))

return device, capabilities, nil
}
66 changes: 24 additions & 42 deletions cmd/configure/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func (c *CmdConfigure) processDeviceSelection(deviceCategory DeviceCategory) (templates.Template, error) {
templateItem := c.selectItem(deviceCategory)

if templateItem.Title() == c.localizedString("ItemNotPresent", nil) {
if templateItem.Title() == c.localizedString("ItemNotPresent") {
return templateItem, c.errItemNotPresent
}

Expand Down Expand Up @@ -123,10 +123,10 @@ func (c *CmdConfigure) processDeviceRequirements(templateItem templates.Template
if len(requirementDescription) > 0 {
fmt.Println()
fmt.Println("-------------------------------------------------")
fmt.Println(c.localizedString("Requirements_Title", nil))
fmt.Println(c.localizedString("Requirements_Title"))
fmt.Println(requirementDescription)
if len(templateItem.Requirements.URI) > 0 {
fmt.Println(" " + c.localizedString("Requirements_More", nil) + " " + templateItem.Requirements.URI)
fmt.Println(" " + c.localizedString("Requirements_More") + " " + templateItem.Requirements.URI)
}
fmt.Println("-------------------------------------------------")
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func (c *CmdConfigure) processDeviceRequirements(templateItem templates.Template
fmt.Println()
eebusConfig, err := c.eebusCertificate()
if err != nil {
return fmt.Errorf("%s: %s", c.localizedString("Requirements_EEBUS_Cert_Error", nil), err)
return fmt.Errorf("%s: %s", c.localizedString("Requirements_EEBUS_Cert_Error"), err)
}

if err := c.configureEEBus(eebusConfig); err != nil {
Expand All @@ -181,7 +181,7 @@ func (c *CmdConfigure) processDeviceRequirements(templateItem templates.Template
}

fmt.Println()
fmt.Println(c.localizedString("Requirements_EEBUS_Pairing", nil))
fmt.Println(c.localizedString("Requirements_EEBUS_Pairing"))
fmt.Scanln()
}

Expand All @@ -194,10 +194,10 @@ func (c *CmdConfigure) processParamRequirements(param templates.Param) error {
if len(requirementDescription) > 0 {
fmt.Println()
fmt.Println("-------------------------------------------------")
fmt.Println(c.localizedString("Requirements_Title", nil))
fmt.Println(c.localizedString("Requirements_Title"))
fmt.Println(requirementDescription)
if len(param.Requirements.URI) > 0 {
fmt.Println(" " + c.localizedString("Requirements_More", nil) + " " + param.Requirements.URI)
fmt.Println(" " + c.localizedString("Requirements_More") + " " + param.Requirements.URI)
}
fmt.Println("-------------------------------------------------")
}
Expand All @@ -217,23 +217,23 @@ func (c *CmdConfigure) askSponsortoken(required, feature bool) error {
if required {
fmt.Println()
if feature {
fmt.Println(c.localizedString("Requirements_Sponsorship_Feature_Title", nil))
fmt.Println(c.localizedString("Requirements_Sponsorship_Feature_Title"))
} else {
fmt.Println(c.localizedString("Requirements_Sponsorship_Title", nil))
fmt.Println(c.localizedString("Requirements_Sponsorship_Title"))
}
} else {
fmt.Println()
fmt.Println(c.localizedString("Requirements_Sponsorship_Optional_Title", nil))
fmt.Println(c.localizedString("Requirements_Sponsorship_Optional_Title"))
}
fmt.Println()
if !c.askYesNo(c.localizedString("Requirements_Sponsorship_Token", nil)) {
if !c.askYesNo(c.localizedString("Requirements_Sponsorship_Token")) {
fmt.Println()
fmt.Println("--------------------------------------------")
return c.errItemNotPresent
}

sponsortoken := c.askValue(question{
label: c.localizedString("Requirements_Sponsorship_Token_Input", nil),
label: c.localizedString("Requirements_Sponsorship_Token_Input"),
mask: true,
required: true,
})
Expand Down Expand Up @@ -267,29 +267,11 @@ func (c *CmdConfigure) configureMQTT(templateItem templates.Template) (map[strin
_, paramPort := templateItem.ConfigDefaults.ParamByName("port")
_, paramUser := templateItem.ConfigDefaults.ParamByName("user")
_, paramPassword := templateItem.ConfigDefaults.ParamByName("password")
host := c.askValue(question{
label: paramHost.Description.String(c.lang),
mask: false,
required: true,
})

port := c.askValue(question{
label: paramPort.Description.String(c.lang),
mask: false,
required: true,
})

user := c.askValue(question{
label: paramUser.Description.String(c.lang),
mask: false,
required: false,
})

password := c.askValue(question{
label: paramPassword.Description.String(c.lang),
mask: true,
required: false,
})

host := c.askParam(paramHost)
port := c.askParam(paramPort)
user := c.askParam(paramUser)
password := c.askParam(paramPassword)

fmt.Println()
fmt.Println("--------------------------------------------")
Expand All @@ -309,7 +291,7 @@ func (c *CmdConfigure) configureMQTT(templateItem templates.Template) (map[strin
}

fmt.Println()
question := c.localizedString("TestingMQTTFailed", nil)
question := c.localizedString("TestingMQTTFailed")
if !c.askYesNo(question) {
return nil, fmt.Errorf("failed configuring mqtt: %w", err)
}
Expand Down Expand Up @@ -392,7 +374,7 @@ func (c *CmdConfigure) paramChoiceValues(params []templates.Param, name string)
// Returns a map with param name and values
func (c *CmdConfigure) processConfig(templateItem *templates.Template, deviceCategory DeviceCategory) map[string]interface{} {
fmt.Println()
fmt.Println(c.localizedString("Config_Title", nil))
fmt.Println(c.localizedString("Config_Title"))
fmt.Println()

c.processModbusConfig(templateItem, deviceCategory)
Expand Down Expand Up @@ -431,7 +413,7 @@ func (c *CmdConfigure) processParams(templateItem *templates.Template, deviceCat
}

switch param.Type {
case templates.ParamTypeStringList:
case templates.TypeStringList:
values := c.processListInputConfig(param)
var nonEmptyValues []string
for _, value := range values {
Expand Down Expand Up @@ -466,7 +448,7 @@ func (c *CmdConfigure) processListInputConfig(param templates.Param) []string {
break
}

if !c.askYesNo(" " + c.localizedString("Config_AddAnotherValue", nil)) {
if !c.askYesNo(" " + c.localizedString("Config_AddAnotherValue")) {
break
}
}
Expand All @@ -484,7 +466,7 @@ func (c *CmdConfigure) processInputConfig(param templates.Param) string {

help := param.Help.ShortString(c.lang)
if slices.Contains(param.Requirements.EVCC, templates.RequirementSponsorship) {
help = fmt.Sprintf("%s\n\n%s", help, c.localizedString("Requirements_Sponsorship_Feature_Title", nil))
help = fmt.Sprintf("%s\n\n%s", help, c.localizedString("Requirements_Sponsorship_Feature_Title"))
}

value := c.askValue(question{
Expand All @@ -498,7 +480,7 @@ func (c *CmdConfigure) processInputConfig(param templates.Param) string {
required: param.IsRequired(),
})

if param.Type == templates.ParamTypeBool && value == "true" {
if param.Type == templates.TypeBool && value == "true" {
if err := c.processParamRequirements(param); err != nil {
return "false"
}
Expand Down Expand Up @@ -539,7 +521,7 @@ func (c *CmdConfigure) processModbusConfig(templateItem *templates.Template, dev
// ask for modbus interface type
var index int
if len(choices) > 1 {
index, _ = c.askChoice(c.localizedString("Config_ModbusInterface", nil), choices)
index, _ = c.askChoice(c.localizedString("Config_ModbusInterface"), choices)
}

values := make(map[string]interface{})
Expand Down
1 change: 1 addition & 0 deletions cmd/configure/localization/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Config_Yes = "Ja"
Config_No = "Nein"
Cancel = "Die Konfiguration wurde abgebrochen.\n\nFalls diese geführte Konfiguration für dich noch nicht funktioniert, versuche es doch mal mit der manuellen Konfiguration. Details findest du auf der folgenden Webseite: https://docs.evcc.io/docs/\n"
InputError = "Bei der Eingabe ist ein Fehler aufgetreten:"
Value_Choice = "Auswahl:"
Value_Help = "Hilfe:"
Value_Required = "erforderlich"
Value_Optional = "optional"
Expand Down
1 change: 1 addition & 0 deletions cmd/configure/localization/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Config_Yes = "Yes"
Config_No = "No"
Cancel = "The configuration was cancelled.\n\nIf this guided configuration process doesn't work for you yet, please try the manual configuration. You can find more details about that on our website: https://docs.evcc.io/docs/\n"
InputError = "An input error occurred:"
Value_Choice = "Chose:"
Value_Help = "Help:"
Value_Required = "required"
Value_Optional = "optional"
Expand Down
Loading

0 comments on commit 06a68d8

Please sign in to comment.