chore: use yamlsource (#27466)
Co-authored-by: Michael Geers <michael@geers.tv>
This commit is contained in:
parent
50c5e9ac97
commit
9293cdef3e
13 changed files with 60 additions and 51 deletions
|
|
@ -20,11 +20,19 @@ import (
|
|||
|
||||
// ConfigStatus for publishing config, status and source to UI and external systems
|
||||
type ConfigStatus struct {
|
||||
Config any `json:"config,omitempty"`
|
||||
Status any `json:"status,omitempty"`
|
||||
FromYaml bool `json:"fromYaml,omitempty"`
|
||||
Config any `json:"config,omitempty"`
|
||||
Status any `json:"status,omitempty"`
|
||||
YamlSource YamlSource `json:"yamlSource,omitempty"`
|
||||
}
|
||||
|
||||
type YamlSource string
|
||||
|
||||
const (
|
||||
YamlSourceFile YamlSource = "file"
|
||||
YamlSourceDb YamlSource = "db"
|
||||
YamlSourceNone YamlSource = ""
|
||||
)
|
||||
|
||||
type All struct {
|
||||
Network Network
|
||||
Ocpp ocpp.Config
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@
|
|||
<script lang="ts">
|
||||
import type { PropType } from "vue";
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import type { EebusConfig, EebusStatus } from "@/types/evcc";
|
||||
import type { EebusConfig, EebusStatus, YamlSource } from "@/types/evcc";
|
||||
import JsonModal from "./JsonModal.vue";
|
||||
import FormRow from "./FormRow.vue";
|
||||
import PropertyField from "./PropertyField.vue";
|
||||
|
|
@ -140,9 +140,14 @@ export default {
|
|||
type: Object as PropType<EebusStatus>,
|
||||
default: () => ({}),
|
||||
},
|
||||
fromYaml: Boolean,
|
||||
yamlSource: String as PropType<YamlSource>,
|
||||
},
|
||||
emits: ["changed"],
|
||||
computed: {
|
||||
fromYaml(): boolean {
|
||||
return this.yamlSource === "file";
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
formId(s: string) {
|
||||
return `eebus-${s}`;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ export default {
|
|||
components: { YamlModal },
|
||||
mixins: [formatter],
|
||||
props: {
|
||||
fromYaml: Boolean,
|
||||
yamlSource: String,
|
||||
},
|
||||
emits: ["changed"],
|
||||
data() {
|
||||
|
|
@ -57,6 +57,9 @@ export default {
|
|||
};
|
||||
},
|
||||
computed: {
|
||||
fromYaml() {
|
||||
return this.yamlSource === "file";
|
||||
},
|
||||
sessionCount() {
|
||||
return this.sessions.length;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ export default {
|
|||
return this.sponsor?.status?.token;
|
||||
},
|
||||
fromYaml() {
|
||||
return this.sponsor?.fromYaml;
|
||||
return !!this.sponsor?.yamlSource;
|
||||
},
|
||||
name() {
|
||||
return this.sponsor?.status?.name || "";
|
||||
|
|
|
|||
|
|
@ -24,10 +24,6 @@ export default {
|
|||
control: "text",
|
||||
description: "Sponsor token (optional)",
|
||||
},
|
||||
fromYaml: {
|
||||
control: "boolean",
|
||||
description: "Whether the sponsor config comes from YAML",
|
||||
},
|
||||
},
|
||||
} as Meta<typeof Sponsor>;
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,6 @@ export default defineComponent({
|
|||
name: "Sponsor",
|
||||
props: {
|
||||
status: Object as PropType<SponsorStatus>,
|
||||
fromYaml: Boolean,
|
||||
},
|
||||
computed: {
|
||||
name() {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
<i18n-t
|
||||
tag="span"
|
||||
:keypath="
|
||||
fromYaml
|
||||
!!yamlSource
|
||||
? 'settings.sponsorToken.expiresUpdateYaml'
|
||||
: 'settings.sponsorToken.expiresUpdateUi'
|
||||
"
|
||||
|
|
@ -34,14 +34,14 @@
|
|||
import formatter from "@/mixins/formatter";
|
||||
import { TRIAL } from "./Sponsor.vue";
|
||||
import { defineComponent, type PropType } from "vue";
|
||||
import type { SponsorStatus } from "@/types/evcc";
|
||||
import type { SponsorStatus, YamlSource } from "@/types/evcc";
|
||||
|
||||
export default defineComponent({
|
||||
name: "SponsorTokenExpires",
|
||||
mixins: [formatter],
|
||||
props: {
|
||||
status: Object as PropType<SponsorStatus>,
|
||||
fromYaml: Boolean,
|
||||
yamlSource: String as PropType<YamlSource>,
|
||||
},
|
||||
computed: {
|
||||
expiresSoon() {
|
||||
|
|
|
|||
|
|
@ -60,6 +60,6 @@ TokenExpires.args = {
|
|||
expiresAt: new Date().toISOString(),
|
||||
expiresSoon: true,
|
||||
},
|
||||
fromYaml: false,
|
||||
yamlSource: "file",
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -41,11 +41,7 @@ export interface HemsStatus {
|
|||
maxPower: number;
|
||||
}
|
||||
|
||||
export interface Hems {
|
||||
status?: HemsStatus;
|
||||
config: HemsConfig;
|
||||
fromYaml: boolean;
|
||||
}
|
||||
export type Hems = ConfigStatus<HemsConfig, HemsStatus>;
|
||||
|
||||
export interface ShmConfig {
|
||||
vendorId: string;
|
||||
|
|
@ -99,6 +95,14 @@ export interface State {
|
|||
ocpp?: Ocpp;
|
||||
}
|
||||
|
||||
export interface ConfigStatus<C, S> {
|
||||
config?: C;
|
||||
status?: S;
|
||||
yamlSource?: YamlSource;
|
||||
}
|
||||
|
||||
export type YamlSource = "file" | "db" | undefined;
|
||||
|
||||
export interface OcppConfig {
|
||||
port: number;
|
||||
}
|
||||
|
|
@ -393,10 +397,7 @@ export interface SponsorStatus {
|
|||
token?: string;
|
||||
}
|
||||
|
||||
export interface Sponsor {
|
||||
status?: SponsorStatus;
|
||||
fromYaml: boolean;
|
||||
}
|
||||
export type Sponsor = ConfigStatus<any, SponsorStatus>;
|
||||
|
||||
export type VehicleOption = {
|
||||
key?: string | null;
|
||||
|
|
@ -445,11 +446,7 @@ export type Certificate = {
|
|||
private: string;
|
||||
};
|
||||
|
||||
export type Eebus = {
|
||||
config: EebusConfig;
|
||||
status: EebusStatus;
|
||||
fromYaml?: boolean;
|
||||
};
|
||||
export type Eebus = ConfigStatus<EebusConfig, EebusStatus>;
|
||||
|
||||
export type EebusConfig = {
|
||||
uri: string;
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@
|
|||
<MqttModal @changed="loadDirty" />
|
||||
<NetworkModal @changed="loadDirty" />
|
||||
<ControlModal @changed="loadDirty" />
|
||||
<HemsModal :fromYaml="hems?.fromYaml" @changed="yamlChanged" />
|
||||
<HemsModal :yamlSource="hems?.yamlSource" @changed="yamlChanged" />
|
||||
<ShmModal @changed="loadDirty" />
|
||||
<MessagingModal @changed="yamlChanged" />
|
||||
<TariffsModal @changed="yamlChanged" />
|
||||
|
|
@ -352,7 +352,7 @@
|
|||
/>
|
||||
<EebusModal
|
||||
:status="eebus?.status"
|
||||
:from-yaml="eebus?.fromYaml"
|
||||
:yamlSource="eebus?.yamlSource"
|
||||
@changed="yamlChanged"
|
||||
/>
|
||||
<OcppModal :ocpp="ocpp" />
|
||||
|
|
|
|||
16
cmd/root.go
16
cmd/root.go
|
|
@ -361,9 +361,9 @@ func runRoot(cmd *cobra.Command, args []string) {
|
|||
|
||||
// publish initial settings
|
||||
valueChan <- util.Param{Key: keys.EEBus, Val: globalconfig.ConfigStatus{
|
||||
Config: conf.EEBus.Redacted(),
|
||||
Status: eebus.GetStatus(),
|
||||
FromYaml: fromYaml.eebus,
|
||||
Config: conf.EEBus.Redacted(),
|
||||
Status: eebus.GetStatus(),
|
||||
YamlSource: yamlSource.eebus,
|
||||
}}
|
||||
valueChan <- util.Param{Key: keys.Shm, Val: conf.SHM}
|
||||
valueChan <- util.Param{Key: keys.Influx, Val: conf.Influx}
|
||||
|
|
@ -377,14 +377,14 @@ func runRoot(cmd *cobra.Command, args []string) {
|
|||
Status: ocpp.GetStatus(),
|
||||
}}
|
||||
valueChan <- util.Param{Key: keys.Sponsor, Val: globalconfig.ConfigStatus{
|
||||
Status: sponsor.RedactedStatus(),
|
||||
FromYaml: fromYaml.sponsor,
|
||||
Status: sponsor.RedactedStatus(),
|
||||
YamlSource: yamlSource.sponsor,
|
||||
}}
|
||||
|
||||
valueChan <- util.Param{Key: keys.Hems, Val: globalconfig.ConfigStatus{
|
||||
Config: conf.HEMS.Redacted(),
|
||||
Status: hemsapi.GetStatus(hems),
|
||||
FromYaml: fromYaml.hems,
|
||||
Config: conf.HEMS.Redacted(),
|
||||
Status: hemsapi.GetStatus(hems),
|
||||
YamlSource: yamlSource.hems,
|
||||
}}
|
||||
|
||||
// publish system infos
|
||||
|
|
|
|||
15
cmd/setup.go
15
cmd/setup.go
|
|
@ -81,10 +81,10 @@ var conf = globalconfig.All{
|
|||
},
|
||||
}
|
||||
|
||||
var fromYaml struct {
|
||||
sponsor bool
|
||||
hems bool
|
||||
eebus bool
|
||||
var yamlSource struct {
|
||||
sponsor globalconfig.YamlSource
|
||||
hems globalconfig.YamlSource
|
||||
eebus globalconfig.YamlSource
|
||||
}
|
||||
|
||||
var nameRE = regexp.MustCompile(`^[a-zA-Z0-9_.:-]+$`)
|
||||
|
|
@ -505,7 +505,7 @@ func configureSponsorship(token string) (err error) {
|
|||
return err
|
||||
}
|
||||
} else if token != "" {
|
||||
fromYaml.sponsor = true
|
||||
yamlSource.sponsor = globalconfig.YamlSourceFile
|
||||
}
|
||||
|
||||
return sponsor.ConfigureSponsorship(token)
|
||||
|
|
@ -715,9 +715,10 @@ func configureHEMS(conf *globalconfig.Hems, site *core.Site) (hemsapi.API, error
|
|||
if err := settings.Yaml(keys.Hems, new(map[string]any), &conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
yamlSource.hems = globalconfig.YamlSourceDb
|
||||
}
|
||||
} else {
|
||||
fromYaml.hems = true
|
||||
yamlSource.hems = globalconfig.YamlSourceFile
|
||||
}
|
||||
|
||||
if conf.Type == "" {
|
||||
|
|
@ -785,7 +786,7 @@ func configureEEBus(conf *eebus.Config) error {
|
|||
return err
|
||||
}
|
||||
} else if conf.IsConfigured() {
|
||||
fromYaml.eebus = true
|
||||
yamlSource.eebus = globalconfig.YamlSourceFile
|
||||
}
|
||||
|
||||
if !conf.IsConfigured() {
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ func updateSponsortokenHandler(pub publisher) func(w http.ResponseWriter, r *htt
|
|||
}
|
||||
|
||||
pub(keys.Sponsor, globalconfig.ConfigStatus{
|
||||
Status: sponsor.RedactedStatus(),
|
||||
FromYaml: false,
|
||||
Status: sponsor.RedactedStatus(),
|
||||
YamlSource: globalconfig.YamlSourceNone,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -59,8 +59,8 @@ func deleteSponsorTokenHandler(pub publisher) func(w http.ResponseWriter, r *htt
|
|||
settings.SetString(keys.SponsorToken, "")
|
||||
|
||||
pub(keys.Sponsor, globalconfig.ConfigStatus{
|
||||
Status: sponsor.Status{},
|
||||
FromYaml: false,
|
||||
Status: sponsor.Status{},
|
||||
YamlSource: globalconfig.YamlSourceNone,
|
||||
})
|
||||
|
||||
setConfigDirty()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue