Use websocket to fetch themes and translations (#1260)

* Use websocket to fetch themes and translations

* Lint
This commit is contained in:
Paulus Schoutsen 2018-06-06 22:34:20 -04:00 committed by GitHub
parent 10c997b7b2
commit bf4d0e6bc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -123,12 +123,17 @@ class HomeAssistant extends LocalizeMixin(PolymerElement) {
if (!this.hass.language) return;
const language = this.hass.selectedLanguage || this.hass.language;
this.hass.callApi('get', `translations/${language}`).then((result) => {
// If we've switched selected languages just ignore this response
if ((this.hass.selectedLanguage || this.hass.language) !== language) return;
this._updateResources(language, result.resources);
});
this.hass.connection.sendMessagePromise({
type: 'frontend/get_translations',
language,
})
.then((resp) => {
// If we've switched selected languages just ignore this response
if ((this.hass.selectedLanguage || this.hass.language) !== language) return;
this._updateResources(language, resp.result.resources);
});
}
_updateResources(language, data) {
@ -272,15 +277,19 @@ class HomeAssistant extends LocalizeMixin(PolymerElement) {
var unsubThemes;
this.hass.callApi('get', 'themes').then((themes) => {
this._updateHass({ themes: themes });
this.hass.connection.sendMessagePromise({
type: 'frontend/get_themes',
}).then((resp) => {
this._updateHass({ themes: resp.result });
applyThemesOnElement(
document.documentElement,
themes,
resp.result,
this.hass.selectedTheme,
true
);
});
conn.subscribeEvents((event) => {
this._updateHass({ themes: event.data });
applyThemesOnElement(