mirror of
https://github.com/home-assistant/frontend.git
synced 2025-06-22 10:06:34 +00:00

* chartjs test * [WIP] Modified for Chart.js * Tweaking styles ( tooltips and lines ) * Almost done TODO: Change tooltips to HTML tag Improve color function * More work on Tooltips * Improve update logic Fix linting * resolve conflict * [WIP] Create new tooltip mode hack. Add axis padding to top and botton to prevent axis cutoff * TODO: cleanup * FIXME: tooltip in history graph not working correctly reorganize some code * fix build problem * Fix color and tooltip issue Fix label max width for timeline chart * update dep * Fix strange color after build due to `uglify` bug with reference the minified version. Make line chart behavior more similar to Google Charts. Make the chart honor to `unknown` and other state by manually calculate point value. * fix bugs * Remove label for only one data in timeline chart. Fix bug for infinite loop in some cases * Add HTML legend to chart. * Fix isSingleDevice bug due to calculation. Add isSingleDevice property support. * fix for lint * Replace innerHTML code with polymer node. * Replace tooltip with HTML code * fix tooltip style * move default tooltip mode to plugin * LINTING * fix Move localize history data to Timeline Chart. Fix timeline static color. Rework on chart resize. * Bug fix: Chart may disappear on some case. Timeline chart calculation issue. Change timeline chart hidden logic. * fix tooltip rework for resize event * lint * element * Replace `var` to `let`. Move import and ChartJs injection code to `ha-chart-scripts.html`. * lint: convert more let to const * fix font fix undef * update bower.json * move * Load chart code on demand
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
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__;
|
|
window.HASS_ROOT = __ROOT__;
|
|
|
|
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}`;
|
|
const options = {
|
|
setupRetry: 10,
|
|
};
|
|
if (password !== undefined) {
|
|
options.authToken = password;
|
|
}
|
|
|
|
return HAWS.createConnection(url, options)
|
|
.then(function (conn) {
|
|
HAWS.subscribeEntities(conn);
|
|
HAWS.subscribeConfig(conn);
|
|
return conn;
|
|
});
|
|
};
|
|
|
|
if (window.noAuth === '1') {
|
|
window.hassConnection = init();
|
|
} else if (window.localStorage.authToken) {
|
|
window.hassConnection = init(window.localStorage.authToken);
|
|
} else {
|
|
window.hassConnection = null;
|
|
}
|
|
|
|
window.addEventListener('error', (e) => {
|
|
const homeAssistant = document.querySelector('home-assistant');
|
|
if (homeAssistant && homeAssistant.hass && homeAssistant.hass.callService) {
|
|
homeAssistant.hass.callService('system_log', 'write', {
|
|
logger: `frontend.${window.HASS_DEV ? 'js_dev' : 'js'}.${window.HASS_BUILD}.${window.HASS_VERSION.replace('.', '')}`,
|
|
message: `${e.filename}:${e.lineno}:${e.colno} ${e.message}`,
|
|
});
|
|
}
|
|
});
|