ha-frontend/js/core.js

34 lines
922 B
JavaScript
Raw Normal View History

import * as HAWS from 'home-assistant-js-websocket';
window.HAWS = HAWS;
window.HASS_DEMO = __DEMO__;
window.HASS_DEV = __DEV__;
window.HASS_BUILD = __BUILD__;
window.HASS_VERSION = __VERSION__;
const init = window.createHassConnection = function (password) {
const proto = window.location.protocol === 'https:' ? 'wss' : 'ws';
const url = `${proto}://${window.location.host}/api/websocket?${window.HASS_BUILD}`;
2017-02-01 09:09:50 +01:00
const options = {
setupRetry: 10,
};
if (password !== undefined) {
options.authToken = password;
2016-05-29 03:32:42 +02:00
}
return HAWS.createConnection(url, options)
.then(function (conn) {
HAWS.subscribeEntities(conn);
HAWS.subscribeConfig(conn);
return conn;
});
};
2016-05-29 03:32:42 +02:00
2017-11-21 06:52:35 +01:00
if (window.noAuth === '1') {
window.hassConnection = init();
} else if (window.localStorage.authToken) {
window.hassConnection = init(window.localStorage.authToken);
} else {
window.hassConnection = null;
2016-07-20 08:33:03 +02:00
}