Skip to content

Commit

Permalink
Add AC Thor (#11912)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Jan 28, 2024
1 parent 1ee09c5 commit f165014
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 27 deletions.
15 changes: 15 additions & 0 deletions templates/definition/meter/thor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
template: thor
products:
- brand: my-PV
description:
generic: AC•THOR
params:
- name: usage
choice: ["aux"]
- name: host
render: |
type: custom
power:
source: http
uri: http://{{ .host }}/data.jsn
jq: .power_act
50 changes: 27 additions & 23 deletions util/templates/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,22 @@ func sorted(keys []string) []string {
}

func generateBrandJSON() error {
chargers := make([]string, 0)
smartPlugs := make([]string, 0)
var chargers, smartPlugs []string
for _, tmpl := range templates.ByClass(templates.Charger) {
for _, product := range tmpl.Products {
if product.Brand != "" {
if tmpl.Group == "switchsockets" {
smartPlugs = append(smartPlugs, product.Brand)
} else {
chargers = append(chargers, product.Brand)
}
if product.Brand == "" {
continue
}

if tmpl.Group == "switchsockets" {
smartPlugs = append(smartPlugs, product.Brand)
} else {
chargers = append(chargers, product.Brand)
}
}
}

vehicles := make([]string, 0)
var vehicles []string
for _, tmpl := range templates.ByClass(templates.Vehicle) {
for _, product := range tmpl.Products {
if product.Brand != "" {
Expand All @@ -121,22 +122,25 @@ func generateBrandJSON() error {
}
}

meters := make([]string, 0)
pvBattery := make([]string, 0)
var meters, pvBattery []string
for _, tmpl := range templates.ByClass(templates.Meter) {
for i := range tmpl.Params {
if tmpl.Params[i].Name == "usage" {
for j := range tmpl.Params[i].Choice {
usage := tmpl.Params[i].Choice[j]
for _, product := range tmpl.Products {
if product.Brand != "" {
switch usage {
case "grid", "charge":
meters = append(meters, product.Brand)
case "pv", "battery":
pvBattery = append(pvBattery, product.Brand)
}
}
if tmpl.Params[i].Name != templates.ParamUsage {
continue
}

for j := range tmpl.Params[i].Choice {
usage, _ := templates.UsageString(tmpl.Params[i].Choice[j])
for _, product := range tmpl.Products {
if product.Brand == "" {
continue
}

switch usage {
case templates.UsageGrid, templates.UsageCharge, templates.UsageAux:
meters = append(meters, product.Brand)
case templates.UsagePV, templates.UsageBattery:
pvBattery = append(pvBattery, product.Brand)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions util/templates/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
UsagePV
UsageBattery
UsageCharge
UsageAux
)

const (
Expand Down
12 changes: 8 additions & 4 deletions util/templates/usage_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f165014

Please sign in to comment.