mirror of
https://github.com/home-assistant/frontend.git
synced 2025-06-15 14:46:35 +00:00
Small Polymer 2 tweaks
This commit is contained in:
parent
512b07963b
commit
17519cce30
@ -98,9 +98,9 @@ Polymer({
|
||||
loadIcons: function () {
|
||||
// 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.
|
||||
var success = function () {
|
||||
const success = () => {
|
||||
this.iconsLoaded = true;
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
this.importHref('/static/mdi-' + this.icons + '.html',
|
||||
success,
|
||||
@ -119,7 +119,6 @@ Polymer({
|
||||
return;
|
||||
}
|
||||
var notifications = this.$.notifications;
|
||||
var el = this;
|
||||
this.hass = Object.assign({
|
||||
connection: conn,
|
||||
connected: true,
|
||||
@ -128,14 +127,14 @@ Polymer({
|
||||
themes: null,
|
||||
dockedSidebar: false,
|
||||
moreInfoEntityId: null,
|
||||
callService: function (domain, service, serviceData) {
|
||||
return conn.callService(domain, service, serviceData || {})
|
||||
.then(function () {
|
||||
callService: (domain, service, serviceData) =>
|
||||
conn.callService(domain, service, serviceData || {})
|
||||
.then(() => {
|
||||
var message;
|
||||
var name;
|
||||
if (serviceData.entity_id && el.hass.states &&
|
||||
el.hass.states[serviceData.entity_id]) {
|
||||
name = window.hassUtil.computeStateName(el.hass.states[serviceData.entity_id]);
|
||||
if (serviceData.entity_id && this.hass.states &&
|
||||
this.hass.states[serviceData.entity_id]) {
|
||||
name = window.hassUtil.computeStateName(this.hass.states[serviceData.entity_id]);
|
||||
}
|
||||
if (service === 'turn_on' && serviceData.entity_id) {
|
||||
message = 'Turned on ' + (name || serviceData.entity_id) + '.';
|
||||
@ -150,52 +149,51 @@ Polymer({
|
||||
notifications.showNotification(
|
||||
'Failed to call service ' + domain + '/' + service);
|
||||
return Promise.reject();
|
||||
});
|
||||
},
|
||||
callApi: function (method, path, parameters) {
|
||||
}),
|
||||
callApi: (method, path, parameters) => {
|
||||
var host = window.location.protocol + '//' + window.location.host;
|
||||
var auth = conn.options.authToken ? conn.options : {};
|
||||
return window.hassCallApi(host, auth, method, path, parameters);
|
||||
},
|
||||
}, this.$.storage.getStoredState());
|
||||
|
||||
var reconnected = function () {
|
||||
var reconnected = () => {
|
||||
this.hass = Object.assign({}, this.hass, { connected: true });
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
conn.addEventListener('ready', reconnected);
|
||||
|
||||
var disconnected = function () {
|
||||
var disconnected = () => {
|
||||
this.hass = Object.assign({}, this.hass, { connected: false });
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
conn.addEventListener('disconnected', disconnected);
|
||||
|
||||
var unsubEntities;
|
||||
|
||||
window.HAWS.subscribeEntities(conn, function (states) {
|
||||
window.HAWS.subscribeEntities(conn, (states) => {
|
||||
this.hass = Object.assign({}, this.hass, { states: states });
|
||||
}.bind(this)).then(function (unsub) {
|
||||
}).then(function (unsub) {
|
||||
unsubEntities = unsub;
|
||||
});
|
||||
|
||||
var unsubConfig;
|
||||
|
||||
window.HAWS.subscribeConfig(conn, function (config) {
|
||||
window.HAWS.subscribeConfig(conn, (config) => {
|
||||
this.hass = Object.assign({}, this.hass, { config: config });
|
||||
}.bind(this)).then(function (unsub) {
|
||||
}).then(function (unsub) {
|
||||
unsubConfig = unsub;
|
||||
});
|
||||
|
||||
var unsubThemes;
|
||||
|
||||
this.hass.callApi('get', 'themes').then(function (themes) {
|
||||
el.hass.themes = themes;
|
||||
window.hassUtil.applyThemesOnElement(el, themes);
|
||||
this.hass.callApi('get', 'themes').then((themes) => {
|
||||
this.hass.themes = themes;
|
||||
window.hassUtil.applyThemesOnElement(this, themes);
|
||||
});
|
||||
conn.subscribeEvents(function (event) {
|
||||
el.hass.themes = event.data;
|
||||
window.hassUtil.applyThemesOnElement(el, event.data);
|
||||
conn.subscribeEvents((event) => {
|
||||
this.hass.themes = event.data;
|
||||
window.hassUtil.applyThemesOnElement(this, event.data);
|
||||
}, 'themes_updated').then(function (unsub) {
|
||||
unsubThemes = unsub;
|
||||
});
|
||||
@ -212,12 +210,10 @@ Polymer({
|
||||
handleConnectionPromise: function (prom) {
|
||||
if (!prom) return;
|
||||
|
||||
var el = this;
|
||||
|
||||
prom.then(function (conn) {
|
||||
el.connection = conn;
|
||||
}, function () {
|
||||
el.connectionPromise = null;
|
||||
prom.then((conn) => {
|
||||
this.connection = conn;
|
||||
}, () => {
|
||||
this.connectionPromise = null;
|
||||
});
|
||||
},
|
||||
|
||||
@ -256,10 +252,6 @@ Polymer({
|
||||
|
||||
ready: function () {
|
||||
this.loadIcons();
|
||||
|
||||
if (this.connectionPromise !== null) {
|
||||
this.handleConnectionPromise(this.connectionPromise);
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
@ -226,7 +226,7 @@ Polymer({
|
||||
},
|
||||
|
||||
areTabsHidden: function (views, showTabs) {
|
||||
return !views.length || !showTabs;
|
||||
return !views || !views.length || !showTabs;
|
||||
},
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user