Remove plant id required on startup (#5029)
This commit is contained in:
parent
7d3619f8f7
commit
69f6685e4e
7 changed files with 83 additions and 62 deletions
|
|
@ -1,35 +1,48 @@
|
|||
<!-- eslint-disable vue/no-v-html -->
|
||||
<template>
|
||||
<div class="form-check form-switch my-3">
|
||||
<input
|
||||
id="telemetryEnabled"
|
||||
:checked="enabled"
|
||||
v-model="enabled"
|
||||
class="form-check-input"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
:disabled="!sponsor"
|
||||
@change="change"
|
||||
/>
|
||||
<label class="form-check-label" for="telemetryEnabled">
|
||||
{{ $t("footer.telemetry.optIn") }}
|
||||
<i18n-t v-if="sponsor" tag="span" keypath="footer.telemetry.optInMoreDetails">
|
||||
<a href="https://docs.evcc.io/docs/guides/setup/#telemetry--community-daten">
|
||||
{{ $t("footer.telemetry.optInMoreDetailsLink") }}
|
||||
</a>
|
||||
</i18n-t>
|
||||
<span v-else>{{ $t("footer.telemetry.optInSponsorship") }}</span>
|
||||
</label>
|
||||
<div class="form-check-label">
|
||||
<label for="telemetryEnabled">
|
||||
{{ $t("footer.telemetry.optIn") }}
|
||||
<i18n-t v-if="sponsor" tag="span" keypath="footer.telemetry.optInMoreDetails">
|
||||
<a href="https://docs.evcc.io/docs/guides/setup/#telemetry--community-daten">
|
||||
{{ $t("footer.telemetry.optInMoreDetailsLink") }}
|
||||
</a>
|
||||
</i18n-t>
|
||||
<span v-else>{{ $t("footer.telemetry.optInSponsorship") }}</span>
|
||||
</label>
|
||||
<div v-if="error" class="errorMessage my-1 text-danger" v-html="error" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import api from "../api";
|
||||
|
||||
function parseMarkdown(markdownText) {
|
||||
const htmlText = markdownText
|
||||
.replace(/\*\*(.*)\*\*/gim, "<b>$1</b>")
|
||||
.replace(/\*(.*)\*/gim, "<i>$1</i>")
|
||||
.replace(/`(.*)`/gim, "<pre>$1</pre>");
|
||||
return htmlText.trim();
|
||||
}
|
||||
|
||||
export default {
|
||||
name: "TelemetrySettings",
|
||||
props: { sponsor: String },
|
||||
data() {
|
||||
return {
|
||||
enabled: null,
|
||||
enabled: false,
|
||||
error: null,
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
|
|
@ -38,12 +51,14 @@ export default {
|
|||
methods: {
|
||||
async change(e) {
|
||||
try {
|
||||
this.error = null;
|
||||
const response = await api.post(`settings/telemetry/${e.target.checked}`);
|
||||
this.enabled = response.data.result;
|
||||
} catch (err) {
|
||||
window.app.error({
|
||||
message: `Unable to update telemetry setting: ${err.message}`,
|
||||
});
|
||||
if (err.response) {
|
||||
this.error = parseMarkdown("**Error:** " + err.response.data.error);
|
||||
this.enabled = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
async update() {
|
||||
|
|
@ -61,4 +76,11 @@ export default {
|
|||
.form-check {
|
||||
min-height: inherit !important;
|
||||
}
|
||||
.form-check-label {
|
||||
max-width: 100%;
|
||||
}
|
||||
.errorMessage::v-deep pre {
|
||||
text-overflow: ellipsis;
|
||||
font-size: 1em;
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ network:
|
|||
port: 7070
|
||||
|
||||
log: debug
|
||||
plant: 683fd96cb7de8cf3080e1d79a12ffedd03d66d7c39be742350559817833ae6f7
|
||||
|
||||
interval: 3s
|
||||
|
||||
|
|
|
|||
11
cmd/setup.go
11
cmd/setup.go
|
|
@ -95,13 +95,10 @@ func configureEnvironment(cmd *cobra.Command, conf config) (err error) {
|
|||
|
||||
// setup telemetry
|
||||
if err == nil {
|
||||
err = telemetry.Create(conf.Plant)
|
||||
}
|
||||
|
||||
// deprecated: enable telemetry if its in the config
|
||||
if err == nil && conf.Telemetry {
|
||||
log.WARN.Println("Enabling telementry in config is deprecated. Use UI instead.")
|
||||
err = telemetry.Enable(true)
|
||||
telemetry.Create(conf.Plant)
|
||||
if conf.Telemetry {
|
||||
err = telemetry.Enable(true)
|
||||
}
|
||||
}
|
||||
|
||||
// setup mqtt client listener
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
4
dist/index.html
vendored
4
dist/index.html
vendored
|
|
@ -20,8 +20,8 @@
|
|||
<meta name="theme-color" content="#020318" />
|
||||
|
||||
<title>evcc</title>
|
||||
<script type="module" crossorigin src="./assets/index.fc0aa81e.js"></script>
|
||||
<link rel="stylesheet" href="./assets/index.d482998a.css">
|
||||
<script type="module" crossorigin src="./assets/index.2e41d610.js"></script>
|
||||
<link rel="stylesheet" href="./assets/index.ab3ceb62.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
|||
|
|
@ -12,38 +12,41 @@ import (
|
|||
"github.com/evcc-io/evcc/util/sponsor"
|
||||
)
|
||||
|
||||
const api = "https://api.evcc.io"
|
||||
const (
|
||||
api = "https://api.evcc.io"
|
||||
enabledSetting = "telemetry"
|
||||
)
|
||||
|
||||
var instanceID string
|
||||
|
||||
func Enabled() bool {
|
||||
enabled, _ := settings.Bool("telemetry.enabled")
|
||||
return enabled && sponsor.IsAuthorized()
|
||||
enabled, _ := settings.Bool(enabledSetting)
|
||||
return enabled && sponsor.IsAuthorized() && instanceID != ""
|
||||
}
|
||||
|
||||
func Enable(enable bool) error {
|
||||
if enable && !sponsor.IsAuthorized() {
|
||||
return errors.New("telemetry requires sponsorship")
|
||||
}
|
||||
settings.SetBool("telemetry.enabled", enable)
|
||||
// TODO: remove once settings has central persistance mechanism
|
||||
err := settings.Persist()
|
||||
return err
|
||||
}
|
||||
|
||||
func Create(machineID string) error {
|
||||
if machineID == "" {
|
||||
var err error
|
||||
if machineID, err = machine.ProtectedID("evcc-api"); err != nil {
|
||||
return err
|
||||
if enable {
|
||||
if !sponsor.IsAuthorized() {
|
||||
return errors.New("telemetry requires sponsorship")
|
||||
}
|
||||
if instanceID == "" {
|
||||
return fmt.Errorf("using docker? Telemetry requires a unique instance ID. Add this to your config: `plant: %s`", machine.RandomID())
|
||||
}
|
||||
}
|
||||
|
||||
instanceID = machineID
|
||||
settings.SetBool(enabledSetting, enable)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Create(machineID string) {
|
||||
if machineID == "" {
|
||||
machineID, _ = machine.ProtectedID("evcc-api")
|
||||
}
|
||||
|
||||
instanceID = machineID
|
||||
}
|
||||
|
||||
func UpdateChargeProgress(log *util.Logger, power, deltaCharged, deltaGreen float64) {
|
||||
log.DEBUG.Printf("telemetry: charge: Δ%.0f/%.0fWh @ %.0fW", deltaGreen*1e3, deltaCharged*1e3, power)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue