Skip to content

Commit

Permalink
add caching for hass configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
vol4tim committed Mar 13, 2024
1 parent 5f47631 commit ec6115c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/utils/libp2p/libp2p.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { noise } from "@chainsafe/libp2p-noise";
import { circuitRelayTransport } from "@libp2p/circuit-relay-v2";
import { identify } from "@libp2p/identify";
import { mplex } from "@libp2p/mplex";
import { webRTC } from "@libp2p/webrtc";
import { webSockets } from "@libp2p/websockets";
import * as filters from "@libp2p/websockets/filters";
import { multiaddr } from "@multiformats/multiaddr";
import { createLibp2p } from "libp2p";
import { circuitRelayTransport } from "@libp2p/circuit-relay-v2";
import { identify } from "@libp2p/identify";
import { createHa } from "./ha";

export async function createNode() {
Expand Down Expand Up @@ -68,6 +68,7 @@ export async function start() {
console.log("disconected", event.detail.remoteAddr.toString());
updateConnectionsList();
if (
connection &&
event.detail.remoteAddr.toString() === connection.remoteAddr.toString()
) {
reconnect(connection.remoteAddr.toString());
Expand Down
23 changes: 19 additions & 4 deletions src/views/telemetry/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export const useLastDatalog = () => {
};

export const useConfig = () => {
const cid = ref(null);
const config = ref(null);

const store = useStore();
Expand All @@ -167,6 +166,16 @@ export const useConfig = () => {

(async () => {
if (controller.value) {
const haconfig = localStorage.getItem(
`haconfig:${controller.value.address}`
);
if (haconfig) {
try {
config.value = JSON.parse(haconfig);
} catch (error) {
console.log(error);
}
}
notify(store, "Find twin id");
const datalog = await getLastDatalog(
robonomics,
Expand All @@ -184,24 +193,30 @@ export const useConfig = () => {
notify(store, `Twin id #${twin_id}`);

notify(store, `Start load config`);
cid.value = await getConfigCid(
const cid = await getConfigCid(
robonomics,
controller.value.address,
twin_id
);

config.value = await catFileController(
cid.value,
cid,
controller.value,
store,
ipfs
);

localStorage.setItem(
`haconfig:${controller.value.address}`,
JSON.stringify(config.value)
);

notify(store, `Config loaded`);
} else {
notify(store, "Error: not found twin id");
}
}
})();

return { config, cid };
return { config };
};

0 comments on commit ec6115c

Please sign in to comment.