Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
MobilettoSoft authored Dec 25, 2024
2 parents a033106 + 7866f36 commit 7af7dc6
Show file tree
Hide file tree
Showing 18 changed files with 256 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .goreleaser-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ builds:
- goos: windows
goarch: arm64
overrides:
- goos: windows
goarch: amd64
flags:
- -trimpath
- -tags=release,timetzdata
- goos: darwin
goarch: arm64
ldflags:
Expand Down
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ builds:
- goos: windows
goarch: arm64
overrides:
- goos: windows
goarch: amd64
flags:
- -trimpath
- -tags=release,timetzdata
- goos: darwin
goarch: arm64
ldflags:
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ RUN go mod download
# install tools
COPY Makefile .
COPY tools.go .
COPY cmd/decorate/ cmd/decorate/
COPY api/ api/
RUN make install

# prepare
Expand Down
2 changes: 1 addition & 1 deletion assets/js/components/Config/PropertyField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default {
return this.type === "Bool";
},
array() {
return this.type === "StringList";
return this.type === "List";
},
select() {
return this.validValues.length > 0;
Expand Down
2 changes: 1 addition & 1 deletion assets/js/components/Config/VehicleModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
<PropertyField
id="vehicleParamIdentifiers"
v-model="values.identifiers"
type="StringList"
type="List"
property="identifiers"
size="w-100"
class="me-2"
Expand Down
188 changes: 188 additions & 0 deletions charger/trydan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
package charger

// https://v2charge.com/trydan/

import (
"errors"
"fmt"
"strings"
"time"

"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/provider"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/sponsor"
)

type RealTimeData struct {
ID string `json:"ID"`
ChargeState int `json:"ChargeState"`
ReadyState int `json:"ReadyState"`
ChargePower float64 `json:"ChargePower"`
ChargeEnergy float64 `json:"ChargeEnergy"`
SlaveError int `json:"SlaveError"`
ChargeTime int `json:"ChargeTime"`
HousePower float64 `json:"HousePower"`
FVPower float64 `json:"FVPower"`
BatteryPower float64 `json:"BatteryPower"`
Paused int `json:"Paused"`
Locked int `json:"Locked"`
Timer int `json:"Timer"`
Intensity int `json:"Intensity"`
Dynamic int `json:"Dynamic"`
MinIntensity int `json:"MinIntensity"`
MaxIntensity int `json:"MaxIntensity"`
PauseDynamic int `json:"PauseDynamic"`
FirmwareVersion string `json:"FirmwareVersion"`
DynamicPowerMode int `json:"DynamicPowerMode"`
ContractedPower int `json:"ContractedPower"`
}

// Trydan charger implementation
type Trydan struct {
*request.Helper
uri string
statusG provider.Cacheable[RealTimeData]
current int
enabled bool
}

func init() {
registry.Add("trydan", NewTrydanFromConfig)
}

// NewTrydanFromConfig creates a Trydan charger from generic config
func NewTrydanFromConfig(other map[string]interface{}) (api.Charger, error) {
cc := struct {
URI string
Cache time.Duration
}{
Cache: time.Second,
}

if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}

if cc.URI == "" {
return nil, errors.New("missing uri")
}

return NewTrydan(cc.URI, cc.Cache)
}

// NewTrydan creates Trydan charger
func NewTrydan(uri string, cache time.Duration) (api.Charger, error) {
if !sponsor.IsAuthorized() {
return nil, api.ErrSponsorRequired
}

c := &Trydan{
Helper: request.NewHelper(util.NewLogger("trydan")),
uri: util.DefaultScheme(strings.TrimSuffix(uri, "/"), "http"),
}

c.statusG = provider.ResettableCached(func() (RealTimeData, error) {
var res RealTimeData
uri := fmt.Sprintf("%s/RealTimeData", c.uri)
err := c.GetJSON(uri, &res)
return res, err
}, cache)

return c, nil
}

// Status implements the api.Charger interface
func (t Trydan) Status() (api.ChargeStatus, error) {
data, err := t.statusG.Get()
if err != nil {
return api.StatusNone, err
}
switch state := data.ChargeState; state {
case 0:
return api.StatusA, nil
case 1:
return api.StatusB, nil
case 2:
return api.StatusC, nil
default:
return api.StatusNone, fmt.Errorf("unknown status: %d", state)
}
}

// Enabled implements the api.Charger interface
func (c Trydan) Enabled() (bool, error) {
data, err := c.statusG.Get()
return data.Paused == 0 && data.Locked == 0, err
}

func (c *Trydan) setValue(param string, value int) error {
uri := fmt.Sprintf("%s/write/%s=%d", c.uri, param, value)
res, err := c.GetBody(uri)
if str := string(res); err == nil && str != "OK" {
err = fmt.Errorf("command failed: %s", res)
}
return err
}

// Enable implements the api.Charger interface
func (c Trydan) Enable(enable bool) error {
var pause int
if !enable {
pause = 1
}

if err := c.setValue("Paused", pause); err != nil {
return err
}
if err := c.setValue("Locked", pause); err != nil {
return err
}
c.enabled = enable

return nil
}

// MaxCurrent implements the api.Charger interface
func (c Trydan) MaxCurrent(current int64) error {
err := c.setValue("Intensity", int(current))
if err == nil {
c.current = int(current)
}
return err
}

var _ api.ChargeRater = (*Trydan)(nil)

// ChargedEnergy implements the api.ChargeRater interface
func (c Trydan) ChargedEnergy() (float64, error) {
data, err := c.statusG.Get()
return data.ChargeEnergy, err
}

var _ api.ChargeTimer = (*Trydan)(nil)

// ChargeDuration implements the api.ChargeTimer interface
func (c Trydan) ChargeDuration() (time.Duration, error) {
data, err := c.statusG.Get()
return time.Duration(data.ChargeTime) * time.Second, err
}

var _ api.Meter = (*Trydan)(nil)

// CurrentPower implements the api.Meter interface
func (c Trydan) CurrentPower() (float64, error) {
data, err := c.statusG.Get()
return data.ChargePower, err
}

var _ api.Diagnosis = (*Trydan)(nil)

// Diagnose implements the api.Diagnosis interface
func (c *Trydan) Diagnose() {
data, err := c.statusG.Get()
if err != nil {
fmt.Printf("%#v", data)
}
}
2 changes: 1 addition & 1 deletion cmd/configure/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func (c *CmdConfigure) processParams(templateItem *templates.Template, deviceCat
}

switch param.Type {
case templates.TypeStringList:
case templates.TypeList:
values := c.processListInputConfig(param)
var nonEmptyValues []string
for _, value := range values {
Expand Down
31 changes: 19 additions & 12 deletions provider/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,28 @@ import (
)

type Pipeline struct {
log *util.Logger
re *regexp.Regexp
jq *gojq.Query
dflt string
unpack string
decode string
log *util.Logger
re *regexp.Regexp
jq *gojq.Query
allowEmpty bool
dflt string
unpack string
decode string
}

type Settings struct {
Regex string
Default string
Jq string
Unpack string
Decode string
AllowEmpty bool
Regex string
Default string
Jq string
Unpack string
Decode string
}

func New(log *util.Logger, cc Settings) (*Pipeline, error) {
p := &Pipeline{
log: log,
log: log,
allowEmpty: cc.AllowEmpty,
}

var err error
Expand Down Expand Up @@ -170,6 +173,10 @@ func (p *Pipeline) decodeValue(value []byte) (float64, error) {
}

func (p *Pipeline) Process(in []byte) ([]byte, error) {
if p.allowEmpty && len(bytes.TrimSpace(in)) == 0 {
return nil, nil
}

b := p.transformXML(in)

if p.re != nil {
Expand Down
4 changes: 2 additions & 2 deletions templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ Example Use Case: With SMA Home Manager, there can be a SMA Energy Meter used fo

- `string`: for string values (default)
- `bool`: for `true` and `false` values. If `help` is provided, than that help text is presented as the question
- `number`: for int values
- `int`: for int values
- `float`: for float values
- `stringlist`: for a list of strings, e.g.used for defining a list of `identifiers` for `vehicles`
- `list`: for a list of strings, e.g.used for defining a list of `identifiers` for `vehicles`
- `chargemodes`: for a selection of charge modes (including `None` which results in the param not being set)

### `advanced`
Expand Down
12 changes: 12 additions & 0 deletions templates/definition/charger/trydan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
template: trydan
products:
- brand: V2C Trydan
requirements:
evcc: ["sponsorship"]
description:
en: V2C trydan
params:
- name: host
render: |
type: trydan
uri: http://{{ .host }}
8 changes: 4 additions & 4 deletions templates/definition/common-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
"number",
"float",
"int",
"stringlist",
"list",
"chargemodes",
"duration"
]
Expand Down Expand Up @@ -293,9 +293,9 @@
"enum": [
"string",
"bool",
"number",
"int",
"float",
"stringlist",
"list",
"chargemodes",
"duration"
]
Expand Down Expand Up @@ -371,4 +371,4 @@
"title": "ParamDependency"
}
}
}
}
1 change: 1 addition & 0 deletions templates/definition/tariff/nordpool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ render: |
config:
source: http
uri: https://dataportal-api.nordpoolgroup.com/api/DayAheadPrices?market=DayAhead&date={{ `{{ addDate (now.Local) 0 0 1 | date "2006-01-02" }}` }}&deliveryArea={{ .region }}&currency={{ .currency }}
allowempty: true
jq: |
.multiAreaEntries | [
.[] |
Expand Down
5 changes: 1 addition & 4 deletions util/templates/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ params:
help:
de: "Kann meist erst später eingetragen werden, siehe: https://docs.evcc.io/docs/features/vehicle"
en: "Mostly this can be added later, see: https://docs.evcc.io/en/docs/features/vehicle"
type: stringlist
type: list
- name: priority
description:
de: Priorität
Expand Down Expand Up @@ -345,13 +345,11 @@ presets:
advanced: true
- name: identifiers
advanced: true
type: stringlist
- name: priority
advanced: true
- name: cache
default: 15m
advanced: true
type: duration
vehicle-common:
params:
- name: title
Expand All @@ -369,7 +367,6 @@ presets:
advanced: true
- name: identifiers
advanced: true
type: stringlist
- name: priority
advanced: true
vehicle-features:
Expand Down
Loading

0 comments on commit 7af7dc6

Please sign in to comment.