Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
broadcastConnectionStatus("connected");
conn.addEventListener("ready", () => this.hassReconnected());
conn.addEventListener("disconnected", () => this.hassDisconnected());
// If we reconnect after losing connection and auth is no longer valid.
conn.addEventListener("reconnect-error", (_conn, err) => {
if (err === ERR_INVALID_AUTH) {
broadcastConnectionStatus("auth-invalid");
location.reload();
}
});
subscribeEntities(conn, (states) => this._updateHass({ states }));
subscribeConfig(conn, (config) => this._updateHass({ config }));
subscribeServices(conn, (services) => this._updateHass({ services }));
subscribePanels(conn, (panels) => this._updateHass({ panels }));
}
window.hassConnection.then(({ conn }) => {
const noop = () => {
// do nothing
};
subscribeEntities(conn, noop);
subscribeConfig(conn, noop);
subscribeServices(conn, noop);
subscribePanels(conn, noop);
subscribeThemes(conn, noop);
subscribeUser(conn, noop);
if (location.pathname === "/" || location.pathname.startsWith("/lovelace/")) {
(window as WindowWithLovelaceProm).llConfProm = fetchConfig(conn, false);
}
});
// Client events
this.client.addEventListener('ready', this.onClientOpen.bind(this));
this.client.addEventListener(
'disconnected',
this.onClientClose.bind(this)
);
this.client.addEventListener(
'reconnect-error',
this.onClientError.bind(this)
);
// Home Assistant Events
homeassistant.subscribeEntities(this.client, ent =>
this.onClientStates(ent)
);
homeassistant.subscribeServices(this.client, ent =>
this.onClientServices(ent)
);
homeassistant.subscribeConfig(this.client, config =>
this.onClientConfigUpdate(config)
);
return true;
}