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[];
|
||||
aux?: Meter[];
|
||||
ext?: Meter[];
|
||||
consumers?: Meter[];
|
||||
tariffs?: ConfigStatus<unknown, unknown>;
|
||||
tariffGrid?: number;
|
||||
tariffFeedIn?: number;
|
||||
|
|
@ -755,7 +756,7 @@ export interface SiteConfig {
|
|||
title: string;
|
||||
aux: string[] | null;
|
||||
ext: string[] | null;
|
||||
consumers: string[] | null;
|
||||
consumer: string[] | null;
|
||||
}
|
||||
|
||||
export type ValueOf<T> = T[keyof T];
|
||||
|
|
|
|||
|
|
@ -679,7 +679,7 @@ export default defineComponent({
|
|||
title: "",
|
||||
aux: null as string[] | null,
|
||||
ext: null as string[] | null,
|
||||
consumers: null as string[] | null,
|
||||
consumer: null as string[] | null,
|
||||
} as SiteConfig,
|
||||
deviceValueTimeout: null as Timeout,
|
||||
deviceValues: {
|
||||
|
|
@ -737,7 +737,7 @@ export default defineComponent({
|
|||
return this.getMetersByNames(names);
|
||||
},
|
||||
consumerMeters() {
|
||||
return this.getMetersByNames(this.site?.consumers);
|
||||
return this.getMetersByNames(this.site?.consumer);
|
||||
},
|
||||
gridTariff() {
|
||||
const name = this.tariffRefs?.grid;
|
||||
|
|
@ -1111,20 +1111,20 @@ export default defineComponent({
|
|||
this.saveSite(type);
|
||||
break;
|
||||
case "consumer":
|
||||
if (!this.site.consumers) this.site.consumers = [];
|
||||
this.site.consumers.push(name);
|
||||
this.saveSite("consumers");
|
||||
if (!this.site.consumer) this.site.consumer = [];
|
||||
this.site.consumer.push(name);
|
||||
this.saveSite("consumer");
|
||||
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") {
|
||||
const name = this.meters.find((m) => m.id === result.id)?.name;
|
||||
if (name) {
|
||||
const ext = (this.site.ext || []).filter((n) => n !== name);
|
||||
const consumers = [...(this.site.consumers || []), name];
|
||||
await api.put("/config/site", { ext, consumers });
|
||||
const consumer = [...(this.site.consumer || []), name];
|
||||
await api.put("/config/site", { ext, consumer });
|
||||
await this.loadSite();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ type MetersConfig struct {
|
|||
BatteryMetersRef []string `mapstructure:"battery"` // Battery charging meter
|
||||
ExtMetersRef []string `mapstructure:"ext"` // Meters used only for monitoring
|
||||
AuxMetersRef []string `mapstructure:"aux"` // Auxiliary meters
|
||||
ConsumerMetersRef []string `mapstructure:"consumers"` // Consumer meters
|
||||
ConsumerMetersRef []string `mapstructure:"consumer"` // Consumer meters
|
||||
}
|
||||
|
||||
// NewSiteFromConfig creates a new site
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ func siteHandler(site site.API) http.HandlerFunc {
|
|||
Battery []string `json:"battery"`
|
||||
Aux []string `json:"aux"`
|
||||
Ext []string `json:"ext"`
|
||||
Consumers []string `json:"consumers"`
|
||||
Consumer []string `json:"consumer"`
|
||||
}{
|
||||
Title: site.GetTitle(),
|
||||
Grid: site.GetGridMeterRef(),
|
||||
|
|
@ -25,7 +25,7 @@ func siteHandler(site site.API) http.HandlerFunc {
|
|||
Battery: site.GetBatteryMeterRefs(),
|
||||
Aux: site.GetAuxMeterRefs(),
|
||||
Ext: site.GetExtMeterRefs(),
|
||||
Consumers: site.GetConsumerMeterRefs(),
|
||||
Consumer: site.GetConsumerMeterRefs(),
|
||||
}
|
||||
|
||||
jsonWrite(w, res)
|
||||
|
|
@ -52,7 +52,7 @@ func updateSiteHandler(site site.API) http.HandlerFunc {
|
|||
Battery *[]string
|
||||
Aux *[]string
|
||||
Ext *[]string
|
||||
Consumers *[]string
|
||||
Consumer *[]string
|
||||
}
|
||||
|
||||
if err := jsonDecoder(r.Body).Decode(&payload); err != nil {
|
||||
|
|
@ -109,12 +109,12 @@ func updateSiteHandler(site site.API) http.HandlerFunc {
|
|||
setConfigDirty()
|
||||
}
|
||||
|
||||
if payload.Consumers != nil {
|
||||
if !validateRefs(w, *payload.Consumers) {
|
||||
if payload.Consumer != nil {
|
||||
if !validateRefs(w, *payload.Consumer) {
|
||||
return
|
||||
}
|
||||
|
||||
site.SetConsumerMeterRefs(*payload.Consumers)
|
||||
site.SetConsumerMeterRefs(*payload.Consumer)
|
||||
setConfigDirty()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ site:
|
|||
title: Hello World
|
||||
meters:
|
||||
grid: grid
|
||||
consumers:
|
||||
consumer:
|
||||
- fridge
|
||||
aux:
|
||||
- heater
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue