Site: consumer meter config key singular (BC) (#31573)
This commit is contained in:
parent
744b649b94
commit
73841bad32
5 changed files with 41 additions and 40 deletions
|
|
@ -94,6 +94,7 @@ export interface State {
|
||||||
pv?: Meter[];
|
pv?: Meter[];
|
||||||
aux?: Meter[];
|
aux?: Meter[];
|
||||||
ext?: Meter[];
|
ext?: Meter[];
|
||||||
|
consumers?: Meter[];
|
||||||
tariffs?: ConfigStatus<unknown, unknown>;
|
tariffs?: ConfigStatus<unknown, unknown>;
|
||||||
tariffGrid?: number;
|
tariffGrid?: number;
|
||||||
tariffFeedIn?: number;
|
tariffFeedIn?: number;
|
||||||
|
|
@ -755,7 +756,7 @@ export interface SiteConfig {
|
||||||
title: string;
|
title: string;
|
||||||
aux: string[] | null;
|
aux: string[] | null;
|
||||||
ext: string[] | null;
|
ext: string[] | null;
|
||||||
consumers: string[] | null;
|
consumer: string[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ValueOf<T> = T[keyof T];
|
export type ValueOf<T> = T[keyof T];
|
||||||
|
|
|
||||||
|
|
@ -679,7 +679,7 @@ export default defineComponent({
|
||||||
title: "",
|
title: "",
|
||||||
aux: null as string[] | null,
|
aux: null as string[] | null,
|
||||||
ext: null as string[] | null,
|
ext: null as string[] | null,
|
||||||
consumers: null as string[] | null,
|
consumer: null as string[] | null,
|
||||||
} as SiteConfig,
|
} as SiteConfig,
|
||||||
deviceValueTimeout: null as Timeout,
|
deviceValueTimeout: null as Timeout,
|
||||||
deviceValues: {
|
deviceValues: {
|
||||||
|
|
@ -737,7 +737,7 @@ export default defineComponent({
|
||||||
return this.getMetersByNames(names);
|
return this.getMetersByNames(names);
|
||||||
},
|
},
|
||||||
consumerMeters() {
|
consumerMeters() {
|
||||||
return this.getMetersByNames(this.site?.consumers);
|
return this.getMetersByNames(this.site?.consumer);
|
||||||
},
|
},
|
||||||
gridTariff() {
|
gridTariff() {
|
||||||
const name = this.tariffRefs?.grid;
|
const name = this.tariffRefs?.grid;
|
||||||
|
|
@ -1111,20 +1111,20 @@ export default defineComponent({
|
||||||
this.saveSite(type);
|
this.saveSite(type);
|
||||||
break;
|
break;
|
||||||
case "consumer":
|
case "consumer":
|
||||||
if (!this.site.consumers) this.site.consumers = [];
|
if (!this.site.consumer) this.site.consumer = [];
|
||||||
this.site.consumers.push(name);
|
this.site.consumer.push(name);
|
||||||
this.saveSite("consumers");
|
this.saveSite("consumer");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converted: move ext meter to consumers (history is reconciled on restart)
|
// Converted: move ext meter to consumer (history is reconciled on restart)
|
||||||
if (result.action === "converted") {
|
if (result.action === "converted") {
|
||||||
const name = this.meters.find((m) => m.id === result.id)?.name;
|
const name = this.meters.find((m) => m.id === result.id)?.name;
|
||||||
if (name) {
|
if (name) {
|
||||||
const ext = (this.site.ext || []).filter((n) => n !== name);
|
const ext = (this.site.ext || []).filter((n) => n !== name);
|
||||||
const consumers = [...(this.site.consumers || []), name];
|
const consumer = [...(this.site.consumer || []), name];
|
||||||
await api.put("/config/site", { ext, consumers });
|
await api.put("/config/site", { ext, consumer });
|
||||||
await this.loadSite();
|
await this.loadSite();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
core/site.go
12
core/site.go
|
|
@ -105,12 +105,12 @@ type Site struct {
|
||||||
|
|
||||||
// MetersConfig contains the site's meter configuration
|
// MetersConfig contains the site's meter configuration
|
||||||
type MetersConfig struct {
|
type MetersConfig struct {
|
||||||
GridMeterRef string `mapstructure:"grid"` // Grid usage meter
|
GridMeterRef string `mapstructure:"grid"` // Grid usage meter
|
||||||
PVMetersRef []string `mapstructure:"pv"` // PV meter
|
PVMetersRef []string `mapstructure:"pv"` // PV meter
|
||||||
BatteryMetersRef []string `mapstructure:"battery"` // Battery charging meter
|
BatteryMetersRef []string `mapstructure:"battery"` // Battery charging meter
|
||||||
ExtMetersRef []string `mapstructure:"ext"` // Meters used only for monitoring
|
ExtMetersRef []string `mapstructure:"ext"` // Meters used only for monitoring
|
||||||
AuxMetersRef []string `mapstructure:"aux"` // Auxiliary meters
|
AuxMetersRef []string `mapstructure:"aux"` // Auxiliary meters
|
||||||
ConsumerMetersRef []string `mapstructure:"consumers"` // Consumer meters
|
ConsumerMetersRef []string `mapstructure:"consumer"` // Consumer meters
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSiteFromConfig creates a new site
|
// NewSiteFromConfig creates a new site
|
||||||
|
|
|
||||||
|
|
@ -11,21 +11,21 @@ import (
|
||||||
func siteHandler(site site.API) http.HandlerFunc {
|
func siteHandler(site site.API) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
res := struct {
|
res := struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Grid string `json:"grid"`
|
Grid string `json:"grid"`
|
||||||
PV []string `json:"pv"`
|
PV []string `json:"pv"`
|
||||||
Battery []string `json:"battery"`
|
Battery []string `json:"battery"`
|
||||||
Aux []string `json:"aux"`
|
Aux []string `json:"aux"`
|
||||||
Ext []string `json:"ext"`
|
Ext []string `json:"ext"`
|
||||||
Consumers []string `json:"consumers"`
|
Consumer []string `json:"consumer"`
|
||||||
}{
|
}{
|
||||||
Title: site.GetTitle(),
|
Title: site.GetTitle(),
|
||||||
Grid: site.GetGridMeterRef(),
|
Grid: site.GetGridMeterRef(),
|
||||||
PV: site.GetPVMeterRefs(),
|
PV: site.GetPVMeterRefs(),
|
||||||
Battery: site.GetBatteryMeterRefs(),
|
Battery: site.GetBatteryMeterRefs(),
|
||||||
Aux: site.GetAuxMeterRefs(),
|
Aux: site.GetAuxMeterRefs(),
|
||||||
Ext: site.GetExtMeterRefs(),
|
Ext: site.GetExtMeterRefs(),
|
||||||
Consumers: site.GetConsumerMeterRefs(),
|
Consumer: site.GetConsumerMeterRefs(),
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonWrite(w, res)
|
jsonWrite(w, res)
|
||||||
|
|
@ -46,13 +46,13 @@ func validateRefs(w http.ResponseWriter, refs []string) bool {
|
||||||
func updateSiteHandler(site site.API) http.HandlerFunc {
|
func updateSiteHandler(site site.API) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var payload struct {
|
var payload struct {
|
||||||
Title *string
|
Title *string
|
||||||
Grid *string
|
Grid *string
|
||||||
PV *[]string
|
PV *[]string
|
||||||
Battery *[]string
|
Battery *[]string
|
||||||
Aux *[]string
|
Aux *[]string
|
||||||
Ext *[]string
|
Ext *[]string
|
||||||
Consumers *[]string
|
Consumer *[]string
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := jsonDecoder(r.Body).Decode(&payload); err != nil {
|
if err := jsonDecoder(r.Body).Decode(&payload); err != nil {
|
||||||
|
|
@ -109,12 +109,12 @@ func updateSiteHandler(site site.API) http.HandlerFunc {
|
||||||
setConfigDirty()
|
setConfigDirty()
|
||||||
}
|
}
|
||||||
|
|
||||||
if payload.Consumers != nil {
|
if payload.Consumer != nil {
|
||||||
if !validateRefs(w, *payload.Consumers) {
|
if !validateRefs(w, *payload.Consumer) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
site.SetConsumerMeterRefs(*payload.Consumers)
|
site.SetConsumerMeterRefs(*payload.Consumer)
|
||||||
setConfigDirty()
|
setConfigDirty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ site:
|
||||||
title: Hello World
|
title: Hello World
|
||||||
meters:
|
meters:
|
||||||
grid: grid
|
grid: grid
|
||||||
consumers:
|
consumer:
|
||||||
- fridge
|
- fridge
|
||||||
aux:
|
aux:
|
||||||
- heater
|
- heater
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue