Skip to content

Commit 5c978d0

Browse files
committed
add AsyncUiWrapper
1 parent dd51ca8 commit 5c978d0

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

docs/integrations/mqtt-api.md docs/integrations/mqtt-api.mdx

+4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
sidebar_position: 2
33
---
44

5+
import AsyncUiWrapper from "../../src/components/AsyncUiWrapper";
6+
57
# MQTT API
68

79
Die MQTT API folgt der [REST API](./rest-api) Struktur.
810
Alle API IDs (z.B. die Loadpoint ID) beginnen bei `1`.
911

12+
<AsyncUiWrapper/>
13+
1014
- `evcc`: root topic
1115
- `evcc/status`: status (`online`/`offline`)
1216
- `evcc/updated`: timestamp of last update

src/components/AsyncUiWrapper.jsx

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import AsyncApiComponent from "@asyncapi/react-component";
2+
3+
const configs = {};
4+
const customCss = "";
5+
6+
export default () => {
7+
const containerRef = useRef(null);
8+
9+
useEffect(() => {
10+
if (containerRef.current?.attachShadow) {
11+
try {
12+
const shadowRoot = containerRef.current.attachShadow({ mode: "open" });
13+
const style = document.createElement("style");
14+
style.textContent = customCss;
15+
shadowRoot.appendChild(style);
16+
17+
const div = document.createElement("div");
18+
shadowRoot.appendChild(div);
19+
20+
const root = ReactDOM.createRoot(div);
21+
root.render(
22+
<AsyncApiComponent
23+
schema={{ url: "/mqtt-api.yaml" }}
24+
config={configs}
25+
/>,
26+
);
27+
} catch (e) {
28+
console.error(e);
29+
}
30+
}
31+
}, []);
32+
33+
return <div ref={containerRef}></div>;
34+
};

0 commit comments

Comments
 (0)