-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load registries in core, wait them to be loaded before generating das… (
#19356) * load registries in core, wait them to be loaded before generating dashboard * import * improve * Split out subscribe functions
- Loading branch information
1 parent
b9069b2
commit 03751d2
Showing
8 changed files
with
153 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Connection, createCollection } from "home-assistant-js-websocket"; | ||
import { Store } from "home-assistant-js-websocket/dist/store"; | ||
import { stringCompare } from "../common/string/compare"; | ||
import { AreaRegistryEntry } from "./area_registry"; | ||
import { debounce } from "../common/util/debounce"; | ||
|
||
const fetchAreaRegistry = (conn: Connection) => | ||
conn | ||
.sendMessagePromise({ | ||
type: "config/area_registry/list", | ||
}) | ||
.then((areas) => | ||
(areas as AreaRegistryEntry[]).sort((ent1, ent2) => | ||
stringCompare(ent1.name, ent2.name) | ||
) | ||
); | ||
|
||
const subscribeAreaRegistryUpdates = ( | ||
conn: Connection, | ||
store: Store<AreaRegistryEntry[]> | ||
) => | ||
conn.subscribeEvents( | ||
debounce( | ||
() => | ||
fetchAreaRegistry(conn).then((areas: AreaRegistryEntry[]) => | ||
store.setState(areas, true) | ||
), | ||
500, | ||
true | ||
), | ||
"area_registry_updated" | ||
); | ||
|
||
export const subscribeAreaRegistry = ( | ||
conn: Connection, | ||
onChange: (areas: AreaRegistryEntry[]) => void | ||
) => | ||
createCollection<AreaRegistryEntry[]>( | ||
"_areaRegistry", | ||
fetchAreaRegistry, | ||
subscribeAreaRegistryUpdates, | ||
conn, | ||
onChange | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Connection, createCollection } from "home-assistant-js-websocket"; | ||
import { Store } from "home-assistant-js-websocket/dist/store"; | ||
import { DeviceRegistryEntry } from "./device_registry"; | ||
import { debounce } from "../common/util/debounce"; | ||
|
||
export const fetchDeviceRegistry = (conn: Connection) => | ||
conn.sendMessagePromise<DeviceRegistryEntry[]>({ | ||
type: "config/device_registry/list", | ||
}); | ||
|
||
const subscribeDeviceRegistryUpdates = ( | ||
conn: Connection, | ||
store: Store<DeviceRegistryEntry[]> | ||
) => | ||
conn.subscribeEvents( | ||
debounce( | ||
() => | ||
fetchDeviceRegistry(conn).then((devices) => | ||
store.setState(devices, true) | ||
), | ||
500, | ||
true | ||
), | ||
"device_registry_updated" | ||
); | ||
|
||
export const subscribeDeviceRegistry = ( | ||
conn: Connection, | ||
onChange: (devices: DeviceRegistryEntry[]) => void | ||
) => | ||
createCollection<DeviceRegistryEntry[]>( | ||
"_dr", | ||
fetchDeviceRegistry, | ||
subscribeDeviceRegistryUpdates, | ||
conn, | ||
onChange | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Connection, createCollection } from "home-assistant-js-websocket"; | ||
import { Store } from "home-assistant-js-websocket/dist/store"; | ||
import { | ||
EntityRegistryDisplayEntryResponse, | ||
fetchEntityRegistryDisplay, | ||
} from "./entity_registry"; | ||
import { debounce } from "../common/util/debounce"; | ||
|
||
const subscribeEntityRegistryDisplayUpdates = ( | ||
conn: Connection, | ||
store: Store<EntityRegistryDisplayEntryResponse> | ||
) => | ||
conn.subscribeEvents( | ||
debounce( | ||
() => | ||
fetchEntityRegistryDisplay(conn).then((entities) => | ||
store.setState(entities, true) | ||
), | ||
500, | ||
true | ||
), | ||
"entity_registry_updated" | ||
); | ||
|
||
export const subscribeEntityRegistryDisplay = ( | ||
conn: Connection, | ||
onChange: (entities: EntityRegistryDisplayEntryResponse) => void | ||
) => | ||
createCollection<EntityRegistryDisplayEntryResponse>( | ||
"_entityRegistryDisplay", | ||
fetchEntityRegistryDisplay, | ||
subscribeEntityRegistryDisplayUpdates, | ||
conn, | ||
onChange | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters