mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
Dynamic update panels (#3227)
This commit is contained in:
parent
2b2d2effd2
commit
d94223a61e
@ -1,14 +1,25 @@
|
|||||||
import { createCollection, Connection } from "home-assistant-js-websocket";
|
import { createCollection, Connection } from "home-assistant-js-websocket";
|
||||||
import { Panels } from "../types";
|
import { Panels } from "../types";
|
||||||
|
|
||||||
|
const fetchPanels = (conn) =>
|
||||||
|
conn.sendMessagePromise({
|
||||||
|
type: "get_panels",
|
||||||
|
});
|
||||||
|
|
||||||
|
const subscribeUpdates = (conn, store) =>
|
||||||
|
conn.subscribeEvents(
|
||||||
|
() => fetchPanels(conn).then((panels) => store.setState(panels, true)),
|
||||||
|
"panels_updated"
|
||||||
|
);
|
||||||
|
|
||||||
export const subscribePanels = (
|
export const subscribePanels = (
|
||||||
conn: Connection,
|
conn: Connection,
|
||||||
onChange: (panels: Panels) => void
|
onChange: (panels: Panels) => void
|
||||||
) =>
|
) =>
|
||||||
createCollection<Panels>(
|
createCollection<Panels>(
|
||||||
"_pnl",
|
"_pnl",
|
||||||
() => conn.sendMessagePromise({ type: "get_panels" }),
|
fetchPanels,
|
||||||
undefined,
|
subscribeUpdates,
|
||||||
conn,
|
conn,
|
||||||
onChange
|
onChange
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user