Dynamic update panels (#3227)

This commit is contained in:
Paulus Schoutsen 2019-05-30 08:41:32 -07:00 committed by GitHub
parent 2b2d2effd2
commit d94223a61e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,14 +1,25 @@
import { createCollection, Connection } from "home-assistant-js-websocket";
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 = (
conn: Connection,
onChange: (panels: Panels) => void
) =>
createCollection<Panels>(
"_pnl",
() => conn.sendMessagePromise({ type: "get_panels" }),
undefined,
fetchPanels,
subscribeUpdates,
conn,
onChange
);