Skip to content

Commit

Permalink
Merge branch 'master' into chore/split-modbus
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jan 15, 2024
2 parents 5eeff48 + 4fa0155 commit e549236
Show file tree
Hide file tree
Showing 33 changed files with 349 additions and 365 deletions.
2 changes: 1 addition & 1 deletion assets/js/components/ChargingPlan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default {
);
},
apiVehicle: function () {
return `vehicles/${this.vehicle.name}/`;
return `vehicles/${this.vehicle?.name}/`;
},
apiLoadpoint: function () {
return `loadpoints/${this.id}/`;
Expand Down
4 changes: 2 additions & 2 deletions assets/js/components/LabelAndValue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<slot name="value">
<AnimatedNumber v-if="valueFmt" :to="value" :format="valueFmt" />
<span v-else>{{ value }}</span>
<div v-if="extraValue" class="extraValue text-nowrap">
{{ extraValue }}
<div class="extraValue text-nowrap">
{{ extraValue || "&nbsp;" }}
</div>
</slot>
</h3>
Expand Down
22 changes: 9 additions & 13 deletions assets/js/components/Loadpoint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,9 @@ export default {
// charging: Boolean,
enabled: Boolean,
vehicleDetectionActive: Boolean,
vehiclePresent: Boolean,
vehicleRange: Number,
vehicleSoc: Number,
vehicleName: String,
vehicleTitle: String,
vehicleIcon: String,
vehicleTargetSoc: Number,
vehicleCapacity: Number,
Expand Down Expand Up @@ -214,6 +212,9 @@ export default {
vehicle: function () {
return this.vehicles?.find((v) => v.name === this.vehicleName);
},
vehicleTitle: function () {
return this.vehicle?.title;
},
loadpointTitle: function () {
return this.title || this.$t("main.loadpoint.fallbackName");
},
Expand Down Expand Up @@ -241,22 +242,17 @@ export default {
showChargingIndicator: function () {
return this.charging && this.chargePower > 0;
},
socBasedCharging: function () {
return (!this.vehicleFeatureOffline && this.vehiclePresent) || this.vehicleSoc > 0;
},
knownVehicle: function () {
vehicleKnown: function () {
return !!this.vehicleName;
},
vehicleHasSoc: function () {
return this.knownVehicle && !this.vehicleFeatureOffline;
return this.vehicleKnown && !this.vehicleFeatureOffline;
},
socBasedCharging: function () {
return this.vehicleHasSoc || this.vehicleSoc > 0;
},
socBasedPlanning: function () {
// TODO: deduplicate business logic. see also: socBasedPlanning() in loadpoint.go
return (
this.knownVehicle &&
this.vehicleCapacity > 0 &&
(this.vehicleHasSoc || this.vehicleSoc > 0)
);
return this.socBasedCharging && this.vehicleCapacity > 0;
},
},
watch: {
Expand Down
11 changes: 5 additions & 6 deletions assets/js/components/VehicleTitle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export default {
vehicleDetectionActive: Boolean,
vehicleIcon: String,
vehicleName: String,
vehiclePresent: Boolean,
vehicles: { type: Array, default: () => [] },
vehicleTitle: String,
},
Expand All @@ -72,22 +71,22 @@ export default {
return null;
},
name() {
if (this.vehiclePresent) {
return this.vehicleTitle || this.$t("main.vehicle.fallbackName");
if (this.vehicleTitle) {
return this.vehicleTitle;
}
if (this.connected) {
return this.$t("main.vehicle.unknown");
}
return this.$t("main.vehicle.none");
},
isUnknown() {
return !this.vehiclePresent;
vehicleKnown() {
return !!this.vehicleName;
},
otherVehicles() {
return this.vehicles.filter((v) => v.name !== this.vehicleName);
},
showOptions() {
return !this.isUnknown || this.vehicles.length;
return this.vehicleKnown || this.vehicles.length;
},
vehicleOptionsProps: function () {
return this.collectProps(VehicleOptions);
Expand Down
1 change: 0 additions & 1 deletion core/keys/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const (
VehicleDetectionActive = "vehicleDetectionActive" // vehicle detection active
VehicleIcon = "vehicleIcon" // vehicle icon for ui
VehicleOdometer = "vehicleOdometer" // vehicle odometer
VehiclePresent = "vehiclePresent" // vehicle detected
VehicleRange = "vehicleRange" // vehicle range
VehicleSoc = "vehicleSoc" // vehicle soc
VehicleTargetSoc = "vehicleTargetSoc" // vehicle soc limit
Expand Down
13 changes: 1 addition & 12 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,7 @@ func (lp *Loadpoint) publish(key string, val interface{}) {
return
}

p := util.Param{Key: key, Val: val}

// https://github.com/evcc-io/evcc/issues/11191 prevent deadlock
select {
case lp.uiChan <- p:
default:
go func() {
lp.uiChan <- p
}()
}
lp.uiChan <- util.Param{Key: key, Val: val}
}

// evChargeStartHandler sends external start event
Expand Down Expand Up @@ -600,8 +591,6 @@ func (lp *Loadpoint) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Even
}

// vehicle
lp.publish(keys.VehiclePresent, false)
lp.publish(keys.VehicleTitle, "")
lp.publish(keys.VehicleIcon, "")
lp.publish(keys.VehicleName, "")
lp.publish(keys.VehicleCapacity, 0.0)
Expand Down
4 changes: 0 additions & 4 deletions core/loadpoint_vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ func (lp *Loadpoint) setActiveVehicle(v api.Vehicle) {
}
lp.socEstimator = soc.NewEstimator(lp.log, lp.charger, v, estimate)

lp.publish(keys.VehiclePresent, true)
lp.publish(keys.VehicleTitle, v.Title())
lp.publish(keys.VehicleName, vehicle.Settings(lp.log, v).Name())
lp.publish(keys.VehicleIcon, v.Icon())
lp.publish(keys.VehicleCapacity, v.Capacity())
Expand All @@ -147,8 +145,6 @@ func (lp *Loadpoint) setActiveVehicle(v api.Vehicle) {
} else {
lp.socEstimator = nil
lp.publish(keys.VehicleSoc, 0)
lp.publish(keys.VehiclePresent, false)
lp.publish(keys.VehicleTitle, "")
lp.publish(keys.VehicleName, "")
lp.publish(keys.VehicleIcon, "")
lp.publish(keys.VehicleCapacity, 0.0)
Expand Down
32 changes: 20 additions & 12 deletions core/site.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package core

import (
"context"
"errors"
"fmt"
"math"
Expand All @@ -25,6 +26,7 @@ import (
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/config"
"github.com/evcc-io/evcc/util/telemetry"
"github.com/smallnest/chanx"
)

const standbyPower = 10 // consider less than 10W as charger in standby
Expand Down Expand Up @@ -362,16 +364,7 @@ func (site *Site) publish(key string, val interface{}) {
val = s.String()
}

p := util.Param{Key: key, Val: val}

// https://github.com/evcc-io/evcc/issues/11191 prevent deadlock
select {
case site.uiChan <- p:
default:
go func() {
site.uiChan <- p
}()
}
site.uiChan <- util.Param{Key: key, Val: val}
}

// publishDelta deduplicates messages before publishing
Expand Down Expand Up @@ -853,7 +846,22 @@ func (site *Site) prepare() {

// Prepare attaches communication channels to site and loadpoints
func (site *Site) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Event) {
site.uiChan = uiChan
// https://github.com/evcc-io/evcc/issues/11191 prevent deadlock
// https://github.com/evcc-io/evcc/pull/11675 maintain message order

// infinite queue with channel semantics
ch := chanx.NewUnboundedChan[util.Param](context.Background(), 2)

// use ch.In for writing
site.uiChan = ch.In

// use ch.Out for reading
go func() {
for p := range ch.Out {
uiChan <- p
}
}()

site.lpUpdateChan = make(chan *Loadpoint, 1) // 1 capacity to avoid deadlock

site.prepare()
Expand All @@ -868,7 +876,7 @@ func (site *Site) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Event)
select {
case param := <-lpUIChan:
param.Loadpoint = &id
uiChan <- param
site.uiChan <- param
case ev := <-lpPushChan:
ev.Loadpoint = &id
pushChan <- ev
Expand Down
2 changes: 1 addition & 1 deletion evcc.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ modbusproxy:
# for documentation see https://docs.evcc.io/docs/devices/meters
meters:
- name: grid
type: modbus
type: mbmd
model: sdm # SDM630
uri: rs485.fritz.box:23
rtu: true # rs485 device connected using ethernet adapter
Expand Down
47 changes: 23 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/andig/mbserver v0.0.0-20230310211055-1d29cbb5820e
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
github.com/avast/retry-go/v4 v4.5.1
github.com/aws/aws-sdk-go v1.49.7
github.com/aws/aws-sdk-go v1.49.21
github.com/basgys/goxml2json v1.1.0
github.com/basvdlei/gotsmart v0.0.3
github.com/benbjohnson/clock v1.3.5
Expand All @@ -33,10 +33,10 @@ require (
github.com/fatih/structs v1.1.0
github.com/glebarez/sqlite v1.10.0
github.com/go-http-utils/etag v0.0.0-20161124023236-513ea8f21eb1
github.com/go-playground/validator/v10 v10.16.0
github.com/go-playground/validator/v10 v10.17.0
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/godbus/dbus/v5 v5.1.0
github.com/gokrazy/updater v0.0.0-20230215172637-813ccc7f21e2
github.com/gokrazy/updater v0.0.0-20240113102150-4ac511a17e33
github.com/google/go-github/v32 v32.1.0
github.com/google/uuid v1.5.0
github.com/gorilla/handlers v1.5.2
Expand All @@ -45,7 +45,7 @@ require (
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
github.com/grid-x/modbus v0.0.0-20230713135356-d9fefd3ae5a5
github.com/hashicorp/go-version v1.6.0
github.com/hasura/go-graphql-client v0.10.1
github.com/hasura/go-graphql-client v0.10.2
github.com/influxdata/influxdb-client-go/v2 v2.13.0
github.com/insomniacslk/tapo v1.0.0
github.com/itchyny/gojq v0.12.14
Expand All @@ -71,13 +71,14 @@ require (
github.com/nicksnyder/go-i18n/v2 v2.3.0
github.com/olekukonko/tablewriter v0.0.5
github.com/philippseith/signalr v0.6.3
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/prometheus-community/pro-bing v0.3.0
github.com/prometheus/client_golang v1.17.0
github.com/prometheus/common v0.45.0
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/common v0.46.0
github.com/robertkrimen/otto v0.3.0
github.com/samber/lo v1.39.0
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/smallnest/chanx v1.2.0
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
github.com/spf13/jwalterweatherman v1.1.0
Expand All @@ -90,14 +91,14 @@ require (
github.com/writeas/go-strip-markdown/v2 v2.1.1
gitlab.com/bboehmke/sunny v0.16.0
go.uber.org/mock v0.4.0
golang.org/x/crypto/x509roots/fallback v0.0.0-20231218163308-9d2ee975ef9f
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848
golang.org/x/net v0.19.0
golang.org/x/oauth2 v0.15.0
golang.org/x/sync v0.5.0
golang.org/x/crypto/x509roots/fallback v0.0.0-20240108164429-dbb6ec16ecef
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3
golang.org/x/net v0.20.0
golang.org/x/oauth2 v0.16.0
golang.org/x/sync v0.6.0
golang.org/x/text v0.14.0
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.31.0
google.golang.org/protobuf v1.32.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/gorm v1.25.5
nhooyr.io/websocket v1.8.10
Expand All @@ -119,7 +120,7 @@ require (
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect
github.com/glebarez/go-sqlite v1.22.0 // indirect
github.com/go-http-utils/fresh v0.0.0-20161124030543-7231e26a4b27 // indirect
github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
Expand All @@ -129,7 +130,7 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.3.1 // indirect
github.com/gobwas/ws v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
Expand All @@ -151,15 +152,14 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mergermarket/go-pkcs7 v0.0.0-20170926155232-153b18ea13c9 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/miekg/dns v1.1.57 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oapi-codegen/runtime v1.1.0 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/pascaldekloe/name v1.0.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
Expand All @@ -185,18 +185,17 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
gitlab.com/c0b/go-ordered-json v0.0.0-20201030195603-febf46534d5a // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/tools v0.16.1 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect
modernc.org/libc v1.38.0 // indirect
modernc.org/libc v1.40.2 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/sqlite v1.28.0 // indirect
Expand Down
Loading

0 comments on commit e549236

Please sign in to comment.