mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-23 04:47:19 +00:00

* Update typescript, prettier, tslint -> eslint * Organize imports * Use glob for eslint fix react import
26 lines
572 B
TypeScript
26 lines
572 B
TypeScript
import { Connection, createCollection } 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",
|
|
fetchPanels,
|
|
subscribeUpdates,
|
|
conn,
|
|
onChange
|
|
);
|