Compare commits
10 commits
8ccd72e141
...
13215c74c2
| Author | SHA1 | Date | |
|---|---|---|---|
| 13215c74c2 | |||
|
|
d379b7802e | ||
|
|
dbe100b24b | ||
|
|
490f209e57 | ||
|
|
f193eb199a | ||
|
|
8abae0fd68 | ||
|
|
7dd4007cfa | ||
|
|
e8b5477373 | ||
|
|
19048976ab | ||
|
|
ea8e2a72c0 |
22 changed files with 320 additions and 118 deletions
54
FORK.md
Normal file
54
FORK.md
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# Fork-Hinweise
|
||||
|
||||
Fork von [evcc-io/evcc](https://github.com/evcc-io/evcc).
|
||||
|
||||
## Abweichung vom Upstream
|
||||
|
||||
Das Sponsor-Gating ist entfernt: alle lokal geprüften Features stehen ohne
|
||||
Sponsor-Token zur Verfügung. Der Eingriff sitzt an einer einzigen Stelle in
|
||||
`util/sponsor/auth.go`, statt in den ~68 Geräte-Konstruktoren:
|
||||
|
||||
- `Subject` ist per Default nicht leer (`"unlocked"`). Damit meldet
|
||||
`RedactedStatus()` einen aktiven Sponsor-Status, und das Frontend schaltet
|
||||
`isSponsor` (`assets/js/views/Config.vue`) frei — Geräte-Dialoge zeigen kein
|
||||
„Sponsor-Token erforderlich" mehr.
|
||||
- `IsAuthorized()` liefert immer `true`. Das öffnet alle Aufrufer, u. a. die
|
||||
Charger-/Vehicle-Konstruktoren, `server/modbus/proxy.go` und den
|
||||
Optimizer-Gate in `core/site_optimizer.go`.
|
||||
- `ConfigureSponsorship()` validiert ein hinterlegtes Token weiterhin, gibt aber
|
||||
nie einen Fehler zurück. Ein abgelaufenes oder ungültiges Token bricht den
|
||||
Start damit nicht mehr ab; es wird nur verworfen, damit es keinen
|
||||
Cloud-Diensten angeboten wird.
|
||||
|
||||
Zusätzlich entfernt: `TestAlpitronicSponsorGate` und
|
||||
`TestSigenergyEVDCSponsorGate` — beide prüften genau das Gate, das hier
|
||||
absichtlich nicht mehr existiert.
|
||||
|
||||
## Was das *nicht* freischaltet
|
||||
|
||||
Serverseitig geprüfte Dienste brauchen weiterhin ein echtes Token, weil die
|
||||
Prüfung bei evcc.io stattfindet und nicht im Client:
|
||||
|
||||
- Optimizer-API (`core/site_optimizer.go` sendet `Bearer <token>`)
|
||||
- Remote Access / Tunnel (`server/remote/`)
|
||||
- Cloud-Fahrzeuge und Tronity (`vehicle/cloud.go`, `vehicle/tronity.go`)
|
||||
- Telemetrie (`util/telemetry/`, hängt an `IsAuthorizedForApi()`)
|
||||
|
||||
## Lizenz
|
||||
|
||||
Der Hauptteil von evcc steht unter MIT. `util/sponsor/` trägt einen eigenen
|
||||
Vermerk („This module is NOT covered by the MIT license. All rights reserved.").
|
||||
Diese Änderung betrifft genau dieses Modul.
|
||||
|
||||
evcc finanziert sich über Sponsoring: <https://sponsor.evcc.io>
|
||||
|
||||
## Upstream-Sync
|
||||
|
||||
```
|
||||
git remote add upstream https://github.com/evcc-io/evcc.git
|
||||
git fetch upstream
|
||||
git rebase upstream/master
|
||||
```
|
||||
|
||||
Konflikte sind auf `util/sponsor/auth.go` beschränkt; `FORK.md` liegt bewusst
|
||||
außerhalb der Upstream-Dateien.
|
||||
|
|
@ -16,6 +16,9 @@ power: # current power
|
|||
#maxpower: # maximum AC power in W (for hybrid pv)
|
||||
# source: const
|
||||
# value: 5000
|
||||
#curtailed: # current feed-in limit in % (0..100, 100 = uncurtailed)
|
||||
# source: const
|
||||
# value: 100
|
||||
#soc: # state of charge in % (for battery)
|
||||
# source: const
|
||||
# value: 75
|
||||
|
|
@ -50,3 +53,6 @@ power: # current power
|
|||
#batterymode: # set charging mode directly (1: normal, 2: hold, 3: charge) (for battery)
|
||||
# source: js
|
||||
# script: console.log(batterymode)
|
||||
#curtail: # set feed-in limit in % (0..100, 100 = uncurtailed)
|
||||
# source: js
|
||||
# script: console.log(curtail)
|
||||
|
|
|
|||
|
|
@ -75,6 +75,10 @@ const CURRENCY_SYMBOLS: Record<CURRENCY, string> = {
|
|||
TRY: "₺",
|
||||
MYR: "RM",
|
||||
THB: "฿",
|
||||
BYN: "Br",
|
||||
UAH: "₴",
|
||||
RUB: "₽",
|
||||
KZT: "₸",
|
||||
};
|
||||
|
||||
// list of currencies where energy price should be displayed in subunits (factor 100)
|
||||
|
|
@ -94,6 +98,7 @@ const ENERGY_PRICE_IN_SUBUNIT: Partial<Record<CURRENCY, string>> = {
|
|||
SEK: "öre", // Swedish öre
|
||||
ZAR: "c", // South African cent
|
||||
TRY: "krş", // Türkiye kuruş
|
||||
BYN: "к.", // Belarusian kapeyka
|
||||
};
|
||||
|
||||
export enum POWER_UNIT {
|
||||
|
|
|
|||
|
|
@ -816,6 +816,10 @@ export enum CURRENCY {
|
|||
TRY = "TRY",
|
||||
MYR = "MYR",
|
||||
THB = "THB",
|
||||
BYN = "BYN",
|
||||
UAH = "UAH",
|
||||
RUB = "RUB",
|
||||
KZT = "KZT",
|
||||
}
|
||||
|
||||
export enum ICON_SIZE {
|
||||
|
|
@ -1131,8 +1135,10 @@ export interface Battery {
|
|||
capacity: number;
|
||||
/** Charge level in %. Weighted by capacity across all batteries. */
|
||||
soc: number;
|
||||
/** Total battery energy in kWh. */
|
||||
/** Total discharged energy in kWh. */
|
||||
energy?: number;
|
||||
/** Total charged energy in kWh. */
|
||||
returnEnergy?: number;
|
||||
/** Measurement data per battery meter. */
|
||||
devices?: BatteryMeter[];
|
||||
/** Projected charge levels based on the solar and price forecast. */
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/andig/mbserver"
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util/modbus"
|
||||
"github.com/evcc-io/evcc/util/sponsor"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -362,14 +361,3 @@ func TestAlpitronicReadFailure(t *testing.T) {
|
|||
_, err = wb.CurrentPower()
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestAlpitronicSponsorGate(t *testing.T) {
|
||||
// go-e tests set the global sponsor.Subject and never reset it
|
||||
old := sponsor.Subject
|
||||
sponsor.Subject = ""
|
||||
t.Cleanup(func() { sponsor.Subject = old })
|
||||
|
||||
// tests run without sponsorship: the public constructor must refuse
|
||||
_, err := NewAlpitronicHYC(t.Context(), modbus.TcpSettings{URI: "localhost:0", ID: 1}, 1)
|
||||
assert.ErrorIs(t, err, api.ErrSponsorRequired)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/andig/mbserver"
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util/modbus"
|
||||
"github.com/evcc-io/evcc/util/sponsor"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -290,17 +289,6 @@ func TestSigenergyEVDCMinMaxCurrent(t *testing.T) {
|
|||
assert.InDelta(t, 36.23, maxA, 0.01) // 25000 W / 690
|
||||
}
|
||||
|
||||
func TestSigenergyEVDCSponsorGate(t *testing.T) {
|
||||
// go-e tests set the global sponsor.Subject and never reset it
|
||||
old := sponsor.Subject
|
||||
sponsor.Subject = ""
|
||||
t.Cleanup(func() { sponsor.Subject = old })
|
||||
|
||||
// tests run without sponsorship: the public constructor must refuse
|
||||
_, err := NewSigenergyEVDC(t.Context(), "localhost:0", 1)
|
||||
assert.ErrorIs(t, err, api.ErrSponsorRequired)
|
||||
}
|
||||
|
||||
func TestSigenergyEVDCReadFailure(t *testing.T) {
|
||||
// missing register in the bulk-read block -> IllegalDataAddress propagates
|
||||
regs := evdcRegs(evdcStateCharging)
|
||||
|
|
|
|||
|
|
@ -867,6 +867,12 @@ func (site *Site) updateBatteryMeters() {
|
|||
}
|
||||
return *m.Energy
|
||||
})
|
||||
site.battery.ReturnEnergy = lo.SumBy(mm, func(m types.Measurement) float64 {
|
||||
if m.ReturnEnergy == nil {
|
||||
return 0
|
||||
}
|
||||
return *m.ReturnEnergy
|
||||
})
|
||||
site.battery.Devices = mm
|
||||
|
||||
battery := site.battery
|
||||
|
|
|
|||
|
|
@ -56,10 +56,11 @@ func (m Measurement) GetTitle() string {
|
|||
}
|
||||
|
||||
type BatteryState struct {
|
||||
Power float64 `json:"power"`
|
||||
Energy float64 `json:"energy,omitempty"`
|
||||
Capacity float64 `json:"capacity,omitempty"`
|
||||
Soc float64 `json:"soc"`
|
||||
Devices []Measurement `json:"devices,omitempty" influxdb:"battery"`
|
||||
Forecast *BatteryForecast `json:"forecast,omitempty"`
|
||||
Power float64 `json:"power"`
|
||||
Energy float64 `json:"energy,omitempty"`
|
||||
ReturnEnergy float64 `json:"returnEnergy,omitempty"`
|
||||
Capacity float64 `json:"capacity,omitempty"`
|
||||
Soc float64 `json:"soc"`
|
||||
Devices []Measurement `json:"devices,omitempty" influxdb:"battery"`
|
||||
Forecast *BatteryForecast `json:"forecast,omitempty"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -232,6 +232,9 @@ func (c *EEBus) run() error {
|
|||
if c.failsafeProductionLimit != nil {
|
||||
// production limit is negative, failsafe limits are always positive
|
||||
c.setProductionLimit(-*c.failsafeProductionLimit, true)
|
||||
} else {
|
||||
// no failsafe limit configured, release any stale Energy Guard limit
|
||||
c.setProductionLimit(0, false)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -352,6 +355,24 @@ func (c *EEBus) setProductionLimit(limit float64, active bool) {
|
|||
}
|
||||
}
|
||||
|
||||
// effectiveConsumptionLimit returns the LPC limit in force: the configured failsafe
|
||||
// limit while in failsafe, else the Energy Guard's. Caller holds the mutex.
|
||||
func (c *EEBus) effectiveConsumptionLimit() float64 {
|
||||
if c.status == StatusFailsafe {
|
||||
return c.failsafeConsumptionLimit
|
||||
}
|
||||
return c.consumptionLimit.Value
|
||||
}
|
||||
|
||||
// effectiveProductionLimit returns the LPP limit in force as positive watts, see
|
||||
// effectiveConsumptionLimit. LPP states its limits as negative watts.
|
||||
func (c *EEBus) effectiveProductionLimit() float64 {
|
||||
if c.status == StatusFailsafe && c.failsafeProductionLimit != nil {
|
||||
return *c.failsafeProductionLimit
|
||||
}
|
||||
return -c.productionLimit.Value
|
||||
}
|
||||
|
||||
var _ api.HEMS = (*EEBus)(nil)
|
||||
|
||||
// CurtailedPercent implements api.HEMS, converting the active LPP production
|
||||
|
|
@ -372,8 +393,8 @@ func (c *EEBus) CurtailedPercent() *int {
|
|||
|
||||
percent := 100
|
||||
if limitActive(c.productionLimitActivated) {
|
||||
// production limits are negative watts
|
||||
percent = int(-c.productionLimit.Value / c.productionNominalMax * 100)
|
||||
// the EG may state a limit above the nominal production power
|
||||
percent = min(int(c.effectiveProductionLimit()/c.productionNominalMax*100), 100)
|
||||
}
|
||||
|
||||
return &percent
|
||||
|
|
@ -390,10 +411,7 @@ func (c *EEBus) MaxConsumptionPower() *float64 {
|
|||
if !limitActive(c.consumptionLimitActivated) {
|
||||
return new(0.0)
|
||||
}
|
||||
if c.status == StatusFailsafe {
|
||||
return new(c.failsafeConsumptionLimit)
|
||||
}
|
||||
return new(c.consumptionLimit.Value)
|
||||
return new(c.effectiveConsumptionLimit())
|
||||
}
|
||||
|
||||
// MaxProductionPower implements api.HEMS: nil until first connected,
|
||||
|
|
@ -407,9 +425,5 @@ func (c *EEBus) MaxProductionPower() *float64 {
|
|||
if !limitActive(c.productionLimitActivated) {
|
||||
return new(0.0)
|
||||
}
|
||||
if c.status == StatusFailsafe {
|
||||
return c.failsafeProductionLimit
|
||||
}
|
||||
// production limits are negative watts, the api.HEMS cap is positive
|
||||
return new(-c.productionLimit.Value)
|
||||
return new(c.effectiveProductionLimit())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -280,6 +280,66 @@ func TestRun_LimitWithoutDuration(t *testing.T) {
|
|||
assertProductionLimit(t, c, true)
|
||||
}
|
||||
|
||||
// TestProductionLimit_Failsafe verifies both api.HEMS production getters report the
|
||||
// configured failsafe limit while in failsafe, not the stale EG-supplied limit
|
||||
// (#33286): the EG limit had already been released (Value=0) before the heartbeat
|
||||
// was lost, which must not curtail feed-in to 0%.
|
||||
func TestProductionLimit_Failsafe(t *testing.T) {
|
||||
c := newTestEEBus(t)
|
||||
// EG limit already released before the heartbeat is lost.
|
||||
c.productionLimit = ucapi.LoadLimit{Value: 0, IsActive: false}
|
||||
|
||||
require.NoError(t, c.run())
|
||||
require.Equal(t, StatusFailsafe, c.status)
|
||||
|
||||
percent := c.CurtailedPercent()
|
||||
require.NotNil(t, percent)
|
||||
assert.Equal(t, int(testFailsafeProduction/testProductionNominal*100), *percent)
|
||||
|
||||
power := c.MaxProductionPower()
|
||||
require.NotNil(t, power)
|
||||
assert.Equal(t, testFailsafeProduction, *power)
|
||||
}
|
||||
|
||||
// TestProductionLimit_FailsafeUnconfigured verifies that entering failsafe without a
|
||||
// configured failsafe production limit releases a stale EG limit. run() returns early
|
||||
// while in failsafe, so a limit left applied here would stay applied indefinitely.
|
||||
func TestProductionLimit_FailsafeUnconfigured(t *testing.T) {
|
||||
c := newTestEEBus(t)
|
||||
c.failsafeProductionLimit = nil
|
||||
c.heartbeat.Set(struct{}{})
|
||||
|
||||
c.productionLimit = ucapi.LoadLimit{Value: -500, IsActive: true}
|
||||
require.NoError(t, c.run())
|
||||
assertProductionLimit(t, c, true)
|
||||
|
||||
// heartbeat lost
|
||||
c.heartbeat = util.NewValue[struct{}](time.Hour)
|
||||
|
||||
require.NoError(t, c.run())
|
||||
require.Equal(t, StatusFailsafe, c.status)
|
||||
assertProductionLimit(t, c, false)
|
||||
|
||||
power := c.MaxProductionPower()
|
||||
require.NotNil(t, power)
|
||||
assert.Equal(t, 0.0, *power)
|
||||
}
|
||||
|
||||
// TestCurtailedPercent_AboveNominal verifies a limit above the nominal production
|
||||
// power reports 100%, not more - api.HEMS documents the percent as 0..100 and it
|
||||
// reaches the inverter unchecked.
|
||||
func TestCurtailedPercent_AboveNominal(t *testing.T) {
|
||||
c := newTestEEBus(t)
|
||||
c.heartbeat.Set(struct{}{})
|
||||
c.productionLimit = ucapi.LoadLimit{Value: -2 * testProductionNominal, IsActive: true}
|
||||
|
||||
require.NoError(t, c.run())
|
||||
|
||||
percent := c.CurtailedPercent()
|
||||
require.NotNil(t, percent)
|
||||
assert.Equal(t, 100, *percent)
|
||||
}
|
||||
|
||||
// TestMaxProductionPower verifies the api.HEMS export cap is a positive wattage,
|
||||
// while LPP states its limits as negative watts.
|
||||
func TestMaxProductionPower(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/evcc-io/evcc/util/transport"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
// Connection is the homewizard connection
|
||||
|
|
@ -119,10 +120,17 @@ func (c *Connection) TotalEnergy() (float64, error) {
|
|||
// Currents implements the api.PhaseCurrents interface
|
||||
func (c *Connection) Currents() (float64, float64, float64, error) {
|
||||
res, err := c.dataG.Get()
|
||||
if c.usage == "pv" {
|
||||
return -res.ActiveCurrentL1A, -res.ActiveCurrentL2A, -res.ActiveCurrentL3A, err
|
||||
|
||||
// 1p meters report the total instead of per-phase values
|
||||
l1, l2, l3 := res.ActiveCurrentA, 0.0, 0.0
|
||||
if res.ActiveCurrentL1A != nil {
|
||||
l1, l2, l3 = lo.FromPtr(res.ActiveCurrentL1A), lo.FromPtr(res.ActiveCurrentL2A), lo.FromPtr(res.ActiveCurrentL3A)
|
||||
}
|
||||
return res.ActiveCurrentL1A, res.ActiveCurrentL2A, res.ActiveCurrentL3A, err
|
||||
|
||||
if c.usage == "pv" {
|
||||
return -l1, -l2, -l3, err
|
||||
}
|
||||
return l1, l2, l3, err
|
||||
}
|
||||
|
||||
// Powers implements the api.PhasePowers interface
|
||||
|
|
@ -137,5 +145,12 @@ func (c *Connection) Powers() (float64, float64, float64, error) {
|
|||
// Voltages implements the api.PhaseVoltages interface
|
||||
func (c *Connection) Voltages() (float64, float64, float64, error) {
|
||||
res, err := c.dataG.Get()
|
||||
return res.ActiveVoltageL1V, res.ActiveVoltageL2V, res.ActiveVoltageL3V, err
|
||||
|
||||
// 1p meters report the total instead of per-phase values
|
||||
l1, l2, l3 := res.ActiveVoltageV, 0.0, 0.0
|
||||
if res.ActiveCurrentL1A != nil {
|
||||
l1, l2, l3 = lo.FromPtr(res.ActiveVoltageL1V), lo.FromPtr(res.ActiveVoltageL2V), lo.FromPtr(res.ActiveVoltageL3V)
|
||||
}
|
||||
|
||||
return l1, l2, l3, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,22 +16,24 @@ type StateResponse struct {
|
|||
// DataResponse returns the most recent measurements from the HomeWizard device
|
||||
// https://homewizard-energy-api.readthedocs.io/endpoints.html#state-api-v1-state
|
||||
type DataResponse struct {
|
||||
ActivePowerW float64 `json:"active_power_w"`
|
||||
ActivePowerL1W float64 `json:"active_power_l1_w"`
|
||||
ActivePowerL2W float64 `json:"active_power_l2_w"`
|
||||
ActivePowerL3W float64 `json:"active_power_l3_w"`
|
||||
TotalPowerImportT1kWh float64 `json:"total_power_import_t1_kwh"`
|
||||
TotalPowerImportT2kWh float64 `json:"total_power_import_t2_kwh"`
|
||||
TotalPowerImportT3kWh float64 `json:"total_power_import_t3_kwh"`
|
||||
TotalPowerImportT4kWh float64 `json:"total_power_import_t4_kwh"`
|
||||
TotalPowerExportT1kWh float64 `json:"total_power_export_t1_kwh"`
|
||||
TotalPowerExportT2kWh float64 `json:"total_power_export_t2_kwh"`
|
||||
TotalPowerExportT3kWh float64 `json:"total_power_export_t3_kwh"`
|
||||
TotalPowerExportT4kWh float64 `json:"total_power_export_t4_kwh"`
|
||||
ActiveCurrentL1A float64 `json:"active_current_l1_a"`
|
||||
ActiveCurrentL2A float64 `json:"active_current_l2_a"`
|
||||
ActiveCurrentL3A float64 `json:"active_current_l3_a"`
|
||||
ActiveVoltageL1V float64 `json:"active_voltage_l1_v"`
|
||||
ActiveVoltageL2V float64 `json:"active_voltage_l2_v"`
|
||||
ActiveVoltageL3V float64 `json:"active_voltage_l3_v"`
|
||||
ActivePowerW float64 `json:"active_power_w"`
|
||||
ActivePowerL1W float64 `json:"active_power_l1_w"`
|
||||
ActivePowerL2W float64 `json:"active_power_l2_w"`
|
||||
ActivePowerL3W float64 `json:"active_power_l3_w"`
|
||||
TotalPowerImportT1kWh float64 `json:"total_power_import_t1_kwh"`
|
||||
TotalPowerImportT2kWh float64 `json:"total_power_import_t2_kwh"`
|
||||
TotalPowerImportT3kWh float64 `json:"total_power_import_t3_kwh"`
|
||||
TotalPowerImportT4kWh float64 `json:"total_power_import_t4_kwh"`
|
||||
TotalPowerExportT1kWh float64 `json:"total_power_export_t1_kwh"`
|
||||
TotalPowerExportT2kWh float64 `json:"total_power_export_t2_kwh"`
|
||||
TotalPowerExportT3kWh float64 `json:"total_power_export_t3_kwh"`
|
||||
TotalPowerExportT4kWh float64 `json:"total_power_export_t4_kwh"`
|
||||
ActiveCurrentA float64 `json:"active_current_a"`
|
||||
ActiveVoltageV float64 `json:"active_voltage_v"`
|
||||
ActiveCurrentL1A *float64 `json:"active_current_l1_a"`
|
||||
ActiveCurrentL2A *float64 `json:"active_current_l2_a"`
|
||||
ActiveCurrentL3A *float64 `json:"active_current_l3_a"`
|
||||
ActiveVoltageL1V *float64 `json:"active_voltage_l1_v"`
|
||||
ActiveVoltageL2V *float64 `json:"active_voltage_l2_v"`
|
||||
ActiveVoltageL3V *float64 `json:"active_voltage_l3_v"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,12 +47,28 @@ func TestUnmarshalKwhDataResponse(t *testing.T) {
|
|||
assert.Equal(t, float64(28), res.ActivePowerL1W)
|
||||
assert.Equal(t, float64(0), res.ActivePowerL2W)
|
||||
assert.Equal(t, float64(-181), res.ActivePowerL3W)
|
||||
assert.Equal(t, float64(235.4), res.ActiveVoltageL1V)
|
||||
assert.Equal(t, float64(235.8), res.ActiveVoltageL2V)
|
||||
assert.Equal(t, float64(236.1), res.ActiveVoltageL3V)
|
||||
assert.Equal(t, float64(1.19), res.ActiveCurrentL1A)
|
||||
assert.Equal(t, float64(0.37), res.ActiveCurrentL2A)
|
||||
assert.Equal(t, float64(-0.93), res.ActiveCurrentL3A)
|
||||
assert.Equal(t, float64(235.4), *res.ActiveVoltageL1V)
|
||||
assert.Equal(t, float64(235.8), *res.ActiveVoltageL2V)
|
||||
assert.Equal(t, float64(236.1), *res.ActiveVoltageL3V)
|
||||
assert.Equal(t, float64(1.19), *res.ActiveCurrentL1A)
|
||||
assert.Equal(t, float64(0.37), *res.ActiveCurrentL2A)
|
||||
assert.Equal(t, float64(-0.93), *res.ActiveCurrentL3A)
|
||||
}
|
||||
}
|
||||
|
||||
// Test homewizard kWh Meter 1-Phase response without per-phase current/voltage
|
||||
func TestUnmarshalKwh1PhaseDataResponse(t *testing.T) {
|
||||
{
|
||||
var res DataResponse
|
||||
// https://api-documentation.homewizard.com/docs/v1/measurement#kwh-meters-1-and-3-phase
|
||||
jsonstr := `{"total_power_import_kwh":1.097,"total_power_import_t1_kwh":1.097,"total_power_export_kwh":0,"total_power_export_t1_kwh":0,"active_power_w":1381.396,"active_power_l1_w":1381.396,"active_voltage_v":228.641,"active_current_a":6.051,"active_apparent_current_a":6.068,"active_reactive_current_a":0.461,"active_apparent_power_va":1385.536,"active_reactive_power_var":-105.28,"active_power_factor":0.997,"active_frequency_hz":50}`
|
||||
require.NoError(t, json.Unmarshal([]byte(jsonstr), &res))
|
||||
|
||||
assert.Equal(t, float64(1381.396), res.ActivePowerW)
|
||||
assert.Equal(t, float64(1381.396), res.ActivePowerL1W)
|
||||
assert.Equal(t, float64(228.641), res.ActiveVoltageV)
|
||||
assert.Equal(t, float64(6.051), res.ActiveCurrentA)
|
||||
assert.Nil(t, res.ActiveCurrentL1A)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -70,11 +86,11 @@ func TestUnmarshalP1DataResponse(t *testing.T) {
|
|||
assert.Equal(t, float64(-21), res.ActivePowerL1W)
|
||||
assert.Equal(t, float64(57), res.ActivePowerL2W)
|
||||
assert.Equal(t, float64(168), res.ActivePowerL3W)
|
||||
assert.Equal(t, float64(228), res.ActiveVoltageL1V)
|
||||
assert.Equal(t, float64(226), res.ActiveVoltageL2V)
|
||||
assert.Equal(t, float64(225), res.ActiveVoltageL3V)
|
||||
assert.Equal(t, float64(-0.092), res.ActiveCurrentL1A)
|
||||
assert.Equal(t, float64(0.252), res.ActiveCurrentL2A)
|
||||
assert.Equal(t, float64(0.747), res.ActiveCurrentL3A)
|
||||
assert.Equal(t, float64(228), *res.ActiveVoltageL1V)
|
||||
assert.Equal(t, float64(226), *res.ActiveVoltageL2V)
|
||||
assert.Equal(t, float64(225), *res.ActiveVoltageL3V)
|
||||
assert.Equal(t, float64(-0.092), *res.ActiveCurrentL1A)
|
||||
assert.Equal(t, float64(0.252), *res.ActiveCurrentL2A)
|
||||
assert.Equal(t, float64(0.747), *res.ActiveCurrentL3A)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
server/mcp/openapi.json
generated
12
server/mcp/openapi.json
generated
|
|
@ -3648,7 +3648,11 @@
|
|||
"ZAR",
|
||||
"TRY",
|
||||
"MYR",
|
||||
"THB"
|
||||
"THB",
|
||||
"BYN",
|
||||
"UAH",
|
||||
"RUB",
|
||||
"KZT"
|
||||
]
|
||||
},
|
||||
"FatalError": {
|
||||
|
|
@ -3843,7 +3847,11 @@
|
|||
"type": "number"
|
||||
},
|
||||
"energy": {
|
||||
"description": "Total battery energy in kWh.",
|
||||
"description": "Total discharged energy in kWh.",
|
||||
"type": "number"
|
||||
},
|
||||
"returnEnergy": {
|
||||
"description": "Total charged energy in kWh.",
|
||||
"type": "number"
|
||||
},
|
||||
"devices": {
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ func (suite *mqttSuite) TestMeasurement() {
|
|||
|
||||
func (suite *mqttSuite) TestBatteryState() {
|
||||
topics := lo.Map([]string{
|
||||
"power", "energy", "capacity", "soc",
|
||||
"power", "energy", "returnEnergy", "capacity", "soc",
|
||||
"devices", "devices/1/name", "devices/1/title", "devices/1/icon", "devices/1/power", "devices/1/energy", "devices/1/returnEnergy", "devices/1/powers", "devices/1/currents", "devices/1/excessDCPower", "devices/1/capacity", "devices/1/soc", "devices/1/controllable", "devices/1/suggestion",
|
||||
"forecast",
|
||||
}, func(s string, _ int) string {
|
||||
|
|
@ -169,5 +169,5 @@ func (suite *mqttSuite) TestBatteryState() {
|
|||
})
|
||||
|
||||
suite.Equal(topics, suite.topics, "topics")
|
||||
suite.Equal([]string{"2", "", "", "20", "1", "", "", "", "1", "", "", "", "", "", "", "10", "", "", ""}, suite.payloads, "payloads")
|
||||
suite.Equal([]string{"2", "", "", "", "20", "1", "", "", "", "1", "", "", "", "", "", "", "10", "", "", ""}, suite.payloads, "payloads")
|
||||
}
|
||||
|
|
|
|||
9
server/openapi.state.yaml
generated
9
server/openapi.state.yaml
generated
|
|
@ -302,7 +302,10 @@ components:
|
|||
description: Charge level in %. Weighted by capacity across all batteries.
|
||||
type: number
|
||||
energy:
|
||||
description: Total battery energy in kWh.
|
||||
description: Total discharged energy in kWh.
|
||||
type: number
|
||||
returnEnergy:
|
||||
description: Total charged energy in kWh.
|
||||
type: number
|
||||
devices:
|
||||
description: Measurement data per battery meter.
|
||||
|
|
@ -507,6 +510,10 @@ components:
|
|||
- TRY
|
||||
- MYR
|
||||
- THB
|
||||
- BYN
|
||||
- UAH
|
||||
- RUB
|
||||
- KZT
|
||||
DeviceColorEntry:
|
||||
description: Color assigned to a device for consistent UI display.
|
||||
type: object
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ params:
|
|||
example: not_plugged, disconnected
|
||||
advanced: true
|
||||
help:
|
||||
en: Comma-separated list of additional states meaning ready
|
||||
de: Komma-getrennte Liste zusätzlicher Zustände für bereit
|
||||
en: Comma-separated list of additional states meaning ready, see [docs.evcc.io](https://docs.evcc.io/en/smarthome/home-assistant#charge-status)
|
||||
de: Komma-getrennte Liste zusätzlicher Zustände für bereit, siehe [docs.evcc.io](https://docs.evcc.io/de/smarthome/home-assistant#charge-status)
|
||||
- name: statusB
|
||||
description:
|
||||
de: Zustände für Status B
|
||||
|
|
@ -50,8 +50,8 @@ params:
|
|||
example: charging_stopped, charging_completed
|
||||
advanced: true
|
||||
help:
|
||||
en: Comma-separated list of additional states meaning connected
|
||||
de: Komma-getrennte Liste zusätzlicher Zustände für verbunden
|
||||
en: Comma-separated list of additional states meaning connected, see [docs.evcc.io](https://docs.evcc.io/en/smarthome/home-assistant#charge-status)
|
||||
de: Komma-getrennte Liste zusätzlicher Zustände für verbunden, siehe [docs.evcc.io](https://docs.evcc.io/de/smarthome/home-assistant#charge-status)
|
||||
- name: statusC
|
||||
description:
|
||||
de: Zustände für Status C
|
||||
|
|
@ -59,8 +59,8 @@ params:
|
|||
example: instant_charging, fast_charging
|
||||
advanced: true
|
||||
help:
|
||||
en: Comma-separated list of additional states meaning charging
|
||||
de: Komma-getrennte Liste zusätzlicher Zustände für laden
|
||||
en: Comma-separated list of additional states meaning charging, see [docs.evcc.io](https://docs.evcc.io/en/smarthome/home-assistant#charge-status)
|
||||
de: Komma-getrennte Liste zusätzlicher Zustände für laden, siehe [docs.evcc.io](https://docs.evcc.io/de/smarthome/home-assistant#charge-status)
|
||||
- name: enabled
|
||||
description:
|
||||
de: Aktivierungsstatus-Sensor
|
||||
|
|
|
|||
|
|
@ -16,4 +16,5 @@ render: |
|
|||
energy:
|
||||
source: http
|
||||
uri: http://{{ .host }}/api/livedata/status
|
||||
jq: 'if all(.inverters[]; .radio_stats.rssi > -127) then .total.YieldTotal.v else empty end'
|
||||
# skip partial sums until all inverters are contacted; radio_stats needs firmware 2024.10.22+
|
||||
jq: 'if all(.inverters[]; .radio_stats.rssi == null or .radio_stats.rssi > -127) then .total.YieldTotal.v else empty end'
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ params:
|
|||
example: not_plugged, disconnected
|
||||
advanced: true
|
||||
help:
|
||||
en: Comma-separated list of additional states meaning disconnected
|
||||
de: Komma-getrennte Liste zusätzlicher Zustände für getrennt
|
||||
en: Comma-separated list of additional states meaning disconnected, see [docs.evcc.io](https://docs.evcc.io/en/smarthome/home-assistant#charge-status)
|
||||
de: Komma-getrennte Liste zusätzlicher Zustände für getrennt, siehe [docs.evcc.io](https://docs.evcc.io/de/smarthome/home-assistant#charge-status)
|
||||
- name: statusB
|
||||
description:
|
||||
de: Zustände für Status B
|
||||
|
|
@ -70,8 +70,8 @@ params:
|
|||
example: charging_stopped, charging_completed
|
||||
advanced: true
|
||||
help:
|
||||
en: Comma-separated list of additional states meaning connected
|
||||
de: Komma-getrennte Liste zusätzlicher Zustände für verbunden
|
||||
en: Comma-separated list of additional states meaning connected, see [docs.evcc.io](https://docs.evcc.io/en/smarthome/home-assistant#charge-status)
|
||||
de: Komma-getrennte Liste zusätzlicher Zustände für verbunden, siehe [docs.evcc.io](https://docs.evcc.io/de/smarthome/home-assistant#charge-status)
|
||||
- name: statusC
|
||||
description:
|
||||
de: Zustände für Status C
|
||||
|
|
@ -79,8 +79,8 @@ params:
|
|||
example: instant_charging, fast_charging
|
||||
advanced: true
|
||||
help:
|
||||
en: Comma-separated list of additional states meaning charging
|
||||
de: Komma-getrennte Liste zusätzlicher Zustände für laden
|
||||
en: Comma-separated list of additional states meaning charging, see [docs.evcc.io](https://docs.evcc.io/en/smarthome/home-assistant#charge-status)
|
||||
de: Komma-getrennte Liste zusätzlicher Zustände für laden, siehe [docs.evcc.io](https://docs.evcc.io/de/smarthome/home-assistant#charge-status)
|
||||
- name: limitSoc
|
||||
description:
|
||||
de: Ziel-Ladezustand [%]
|
||||
|
|
@ -124,8 +124,8 @@ params:
|
|||
service: homeassistant/entities?uri={uri}&insecure={insecure}&domain=script,switch
|
||||
example: "script.vehicle_start_charge; switch.vehicle_charger"
|
||||
help:
|
||||
en: Entity ID for a script or a switch that starts charging the vehicle. Only useful with the [docs.evcc.io](https://docs.evcc.io/en/docs/devices/chargers#vehicle-api-only-charger). If a switch is provided, Service to stop charging must be left empty.
|
||||
de: Entitäts-ID für ein Skript oder einen Schalter zum Starten des Ladevorgangs. Nur sinnvoll mit der [docs.evcc.io](https://docs.evcc.io/docs/devices/chargers#vehicle-api-only-charger). Wenn ein Schalter angegeben wird, muss der Service zum Stoppen des Ladens leer bleiben.
|
||||
en: Entity ID for a script or a switch that starts charging the vehicle. Only useful with the [Vehicle API-only charger](https://docs.evcc.io/en/chargers/vehicle-api-only-charger). If a switch is provided, Service to stop charging must be left empty.
|
||||
de: Entitäts-ID für ein Skript oder einen Schalter zum Starten des Ladevorgangs. Nur sinnvoll mit der [Fahrzeug-API Ladesteuerung](https://docs.evcc.io/de/chargers/vehicle-api-only-charger). Wenn ein Schalter angegeben wird, muss der Service zum Stoppen des Ladens leer bleiben.
|
||||
- name: stop_charging
|
||||
description:
|
||||
de: Service zum Laden stoppen
|
||||
|
|
@ -133,8 +133,8 @@ params:
|
|||
service: homeassistant/entities?uri={uri}&insecure={insecure}&domain=script
|
||||
example: "script.vehicle_stop_charge"
|
||||
help:
|
||||
en: Entity ID for a script that stops charging the vehicle. Only useful with the [docs.evcc.io](https://docs.evcc.io/en/docs/devices/chargers#vehicle-api-only-charger).
|
||||
de: Entitäts-ID für ein Skript zum Stoppen des Ladevorgangs. Nur sinnvoll mit der [docs.evcc.io](https://docs.evcc.io/docs/devices/chargers#vehicle-api-only-charger).
|
||||
en: Entity ID for a script that stops charging the vehicle. Only useful with the [Vehicle API-only charger](https://docs.evcc.io/en/chargers/vehicle-api-only-charger).
|
||||
de: Entitäts-ID für ein Skript zum Stoppen des Ladevorgangs. Nur sinnvoll mit der [Fahrzeug-API Ladesteuerung](https://docs.evcc.io/de/chargers/vehicle-api-only-charger).
|
||||
- name: wakeup
|
||||
description:
|
||||
de: Service zum Aufwecken
|
||||
|
|
|
|||
|
|
@ -35,10 +35,15 @@ import (
|
|||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// unlocked is the sponsorship subject used by this fork. Sponsor gating is
|
||||
// removed here, so Subject is never empty and IsAuthorized always holds.
|
||||
const unlocked = "unlocked"
|
||||
|
||||
var (
|
||||
mu sync.RWMutex
|
||||
Subject, Token string
|
||||
ExpiresAt time.Time
|
||||
mu sync.RWMutex
|
||||
Subject = unlocked
|
||||
Token string
|
||||
ExpiresAt time.Time
|
||||
)
|
||||
|
||||
func machineID() string {
|
||||
|
|
@ -51,9 +56,8 @@ const unavailable = "sponsorship unavailable"
|
|||
const startupTimeout = 30 * time.Second
|
||||
|
||||
func IsAuthorized() bool {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
return len(Subject) > 0
|
||||
// sponsorship gating removed in this fork
|
||||
return true
|
||||
}
|
||||
|
||||
func IsAuthorizedForApi() bool {
|
||||
|
|
@ -62,8 +66,29 @@ func IsAuthorizedForApi() bool {
|
|||
return IsAuthorized() && Subject != unavailable && Token != ""
|
||||
}
|
||||
|
||||
// check and set sponsorship token
|
||||
// ConfigureSponsorship validates a sponsor token when one is configured, but
|
||||
// never fails: sponsorship is not required in this fork. A valid token is
|
||||
// still picked up so cloud-backed services keep working for real sponsors.
|
||||
func ConfigureSponsorship(token string) error {
|
||||
err := configureSponsorship(token)
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
if err != nil {
|
||||
// stay unlocked, but do not offer a rejected token to cloud services
|
||||
Token = ""
|
||||
}
|
||||
|
||||
if Subject == "" {
|
||||
Subject = unlocked
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// check and set sponsorship token
|
||||
func configureSponsorship(token string) error {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
|
|
|
|||
|
|
@ -132,17 +132,17 @@ func (v *Provider) any(key string) (any, error) {
|
|||
|
||||
_, tokenErr := v.ts.Token()
|
||||
|
||||
switch {
|
||||
case tokenErr == nil && v.updated.IsZero():
|
||||
// this will only happen once
|
||||
if err := v.setupContainer(); err != nil {
|
||||
v.log.WARN.Println(err)
|
||||
if tokenErr == nil && (v.updated.IsZero() || time.Since(v.updated) > v.cache) {
|
||||
if v.container == "" {
|
||||
if err := v.setupContainer(); err != nil {
|
||||
v.log.WARN.Println(err)
|
||||
}
|
||||
}
|
||||
fallthrough
|
||||
|
||||
case tokenErr == nil && time.Since(v.updated) > v.cache && v.container != "":
|
||||
if err := v.updateContainerData(); err != nil {
|
||||
v.log.WARN.Println(err)
|
||||
if v.container != "" {
|
||||
if err := v.updateContainerData(); err != nil {
|
||||
v.log.WARN.Println(err)
|
||||
}
|
||||
}
|
||||
v.updated = time.Now()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ func TestCardataStreaming(t *testing.T) {
|
|||
|
||||
p := NewProvider(ctx, util.NewLogger("foo"), nil, oauth2.StaticTokenSource(&oauth2.Token{
|
||||
AccessToken: "at",
|
||||
}), "client", "vin", 0)
|
||||
}), "client", "vin", time.Hour)
|
||||
|
||||
// prevent container panic
|
||||
p.updated = time.Now()
|
||||
|
|
@ -51,7 +51,7 @@ func TestSocFallback(t *testing.T) {
|
|||
|
||||
p := NewProvider(ctx, util.NewLogger("foo"), nil, oauth2.StaticTokenSource(&oauth2.Token{
|
||||
AccessToken: "at",
|
||||
}), "client", "vin", 0)
|
||||
}), "client", "vin", time.Hour)
|
||||
|
||||
// prevent container panic
|
||||
p.updated = time.Now()
|
||||
|
|
@ -108,7 +108,7 @@ func TestRangeFallback(t *testing.T) {
|
|||
|
||||
p := NewProvider(ctx, util.NewLogger("foo"), nil, oauth2.StaticTokenSource(&oauth2.Token{
|
||||
AccessToken: "at",
|
||||
}), "client", "vin", 0)
|
||||
}), "client", "vin", time.Hour)
|
||||
|
||||
// prevent container panic
|
||||
p.updated = time.Now()
|
||||
|
|
@ -165,7 +165,7 @@ func TestStatusFallback(t *testing.T) {
|
|||
|
||||
p := NewProvider(ctx, util.NewLogger("foo"), nil, oauth2.StaticTokenSource(&oauth2.Token{
|
||||
AccessToken: "at",
|
||||
}), "client", "vin", 0)
|
||||
}), "client", "vin", time.Hour)
|
||||
|
||||
// prevent container panic
|
||||
p.updated = time.Now()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue