Now possible to get collection objects, instead of just subscribing to them.
// Will only initialize one collection per connection.
getCollection<State>(
conn: Connection,
key: string,
fetchCollection: (conn: Connection) => Promise<State>,
subscribeUpdates: (
conn: Connection,
store: Store<State>
) => Promise<UnsubscribeFunc>,
): Collection<State>
// Returns object with following type
class Collection<State> {
state: State;
async refresh(): Promise<void>;
subscribe(subscriber: (state: State) => void): UnsubscribeFunc;
}
You can also import the service, config and entities collections:
import { entitiesColl, servicesColl, configColl } from 'home-assistant-js-websocket';