Site: add config UI (BC) (#9812)

This commit is contained in:
andig 2024-01-27 13:38:16 +01:00 • committed by GitHub
parent 09d7e76312
commit 186ba62db7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 3910 additions and 1653 deletions

View file

@ -10,6 +10,38 @@ let state = {
vehicles: [{ soc: 0, range: 0 }],
};
const stateApiMiddleware = (req, res, next) => {
if (req.method === "POST" && req.originalUrl === "/api/state") {
console.log("POST /api/state", req.body);
state = req.body;
res.end();
} else if (req.method === "POST" && req.originalUrl === "/api/shutdown") {
console.log("POST /api/shutdown", req.body);
res.end();
process.exit();
} else if (req.originalUrl === "/api/state") {
res.end(JSON.stringify(state));
} else {
next();
}
};
const openemsMiddleware = (req, res, next) => {
const endpoints = {
"/rest/channel/_sum/GridActivePower": { value: state.site.grid.power },
"/rest/channel/_sum/ProductionActivePower": { value: state.site.pv.power },
"/rest/channel/_sum/EssDischargePower": { value: state.site.battery.power },
"/rest/channel/_sum/EssSoc": { value: state.site.battery.soc },
};
const endpoint = endpoints[req.originalUrl];
if (req.method === "GET" && endpoint) {
console.log("GET", req.originalUrl, endpoint);
res.end(JSON.stringify(endpoint));
} else {
next();
}
};
export default () => ({
name: "api",
enforce: "pre",
@ -17,21 +49,8 @@ export default () => ({
console.log("configureServer");
return () => {
server.middlewares.use(bodyParser.json());
server.middlewares.use((req, res, next) => {
if (req.method === "POST" && req.originalUrl === "/api/state") {
console.log("POST /api/state", req.body);
state = req.body;
res.end();
} else if (req.method === "POST" && req.originalUrl === "/api/shutdown") {
console.log("POST /api/shutdown", req.body);
res.end();
process.exit();
} else if (req.originalUrl === "/api/state") {
res.end(JSON.stringify(state));
} else {
next();
}
});
server.middlewares.use(stateApiMiddleware);
server.middlewares.use(openemsMiddleware);
};
},
});

View file

@ -38,11 +38,11 @@
</div>
<div class="row">
<label for="gridPower" class="col-sm-6 col-form-label">Battery Power</label>
<label for="batteryPower" class="col-sm-6 col-form-label">Battery Power</label>
<div class="col-sm-6">
<div class="input-group mb-3">
<input
id="gridPower"
id="batteryPower"
v-model.number="state.site.battery.power"
type="number"
class="form-control"
@ -53,11 +53,11 @@
</div>
<div class="row">
<label for="gridPower" class="col-sm-6 col-form-label">Battery SoC</label>
<label for="batterySoc" class="col-sm-6 col-form-label">Battery SoC</label>
<div class="col-sm-6">
<div class="input-group mb-3">
<input
id="gridPower"
id="batterySoc"
v-model.number="state.site.battery.soc"
type="number"
class="form-control"