diff --git a/.eslintrc b/.eslintrc index 7f3d3a0e39..a4113b98fb 100644 --- a/.eslintrc +++ b/.eslintrc @@ -21,6 +21,7 @@ "browser": true }, "rules": { + "class-methods-use-this": 0, "new-cap": 0, "prefer-template": 0, "object-shorthand": 0, diff --git a/src/components/ha-sidebar.html b/src/components/ha-sidebar.html index 195c2aa1ff..51d600dd34 100644 --- a/src/components/ha-sidebar.html +++ b/src/components/ha-sidebar.html @@ -1,4 +1,4 @@ - + @@ -8,6 +8,8 @@ + + @@ -173,42 +175,45 @@ diff --git a/src/home-assistant.html b/src/home-assistant.html index 6f1907b677..cfb52f7475 100644 --- a/src/home-assistant.html +++ b/src/home-assistant.html @@ -1,4 +1,4 @@ - + @@ -50,70 +50,70 @@ window.removeInitMsg = function () { } }; -Polymer({ - is: 'home-assistant', +class HomeAssistant extends Polymer.Element { - hostAttributes: { - icons: null, - }, + static get is() { return 'home-assistant'; } - properties: { - connectionPromise: { - type: Object, - value: window.hassConnection || null, - observer: 'handleConnectionPromise', - }, - connection: { - type: Object, - value: null, - observer: 'connectionChanged', - }, - hass: { - type: Object, - value: null, - }, - icons: { - type: String, - }, - iconsLoaded: { - type: Boolean, - value: false, - }, - showMain: { - type: Boolean, - computed: 'computeShowMain(hass, iconsLoaded)', - }, - }, + static get properties() { + return { + connectionPromise: { + type: Object, + value: window.hassConnection || null, + observer: 'handleConnectionPromise', + }, + connection: { + type: Object, + value: null, + observer: 'connectionChanged', + }, + hass: { + type: Object, + value: null, + }, + icons: { + type: String, + }, + iconsLoaded: { + type: Boolean, + value: false, + }, + showMain: { + type: Boolean, + computed: 'computeShowMain(hass, iconsLoaded)', + }, + }; + } - listeners: { - settheme: 'setTheme', - }, + ready() { + super.ready(); + this.addEventListener('settheme', e => this.setTheme(e)); + this.loadIcons(); + } - computeShowMain: function (hass, iconsLoaded) { + computeShowMain(hass, iconsLoaded) { return hass && hass.states && hass.config && iconsLoaded; - }, + } - computeShowLoading: function (connectionPromise, hass, iconsLoaded) { + computeShowLoading(connectionPromise, hass, iconsLoaded) { // Show loading when connecting or when connected but not all pieces loaded yet return (connectionPromise != null || (hass && (!hass.states || !hass.config || !iconsLoaded))); - }, + } - loadIcons: function () { + loadIcons() { // If the import fails, we'll try to import again, must be a server glitch // Since HTML imports only resolve once, we import another url. const success = () => { this.iconsLoaded = true; }; - this.importHref('/static/mdi-' + this.icons + '.html', + Polymer.importHref('/static/mdi-' + this.icons + '.html', success, - function () { - this.importHref('/static/mdi.html', success, success); - }); - }, + () => Polymer.importHref('/static/mdi.html', success, success), + true /* true for async */); + } - connectionChanged: function (conn, oldConn) { + connectionChanged(conn, oldConn) { if (oldConn) { this.unsubConnection(); this.unsubConnection = null; @@ -209,9 +209,9 @@ Polymer({ unsubConfig(); unsubThemes(); }; - }, + } - handleConnectionPromise: function (prom) { + handleConnectionPromise(prom) { if (!prom) return; prom.then((conn) => { @@ -219,25 +219,25 @@ Polymer({ }, () => { this.connectionPromise = null; }); - }, + } - handleMoreInfo: function (ev) { + handleMoreInfo(ev) { ev.stopPropagation(); this._updateHass({ moreInfoEntityId: ev.detail.entityId }); - }, + } - handleDockSidebar: function (ev) { + handleDockSidebar(ev) { ev.stopPropagation(); this._updateHass({ dockedSidebar: ev.detail.dock }); this.$.storage.storeState(); - }, + } - handleNotification: function (ev) { + handleNotification(ev) { this.$.notifications.showNotification(ev.detail.message); - }, + } - handleLogout: function () { + handleLogout() { delete localStorage.authToken; var conn = this.connection; this.connectionPromise = null; @@ -248,20 +248,18 @@ Polymer({ // However, after it is done, home-assistant-main is removed from the DOM by this element. } conn.close(); - }, + } - ready: function () { - this.loadIcons(); - }, - - setTheme: function (event) { + setTheme(event) { this._updateHass({ selectedTheme: event.detail }); window.hassUtil.applyThemesOnElement(this, this.hass.themes, this.hass.selectedTheme, true); this.$.storage.storeState(); - }, + } - _updateHass: function (obj) { + _updateHass(obj) { this.hass = Object.assign({}, this.hass, obj); - }, -}); + } +} + +customElements.define(HomeAssistant.is, HomeAssistant); diff --git a/src/util/hass-mixins.html b/src/util/hass-mixins.html new file mode 100644 index 0000000000..e387a88cf6 --- /dev/null +++ b/src/util/hass-mixins.html @@ -0,0 +1,14 @@ +