mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Use websocket to fetch themes and translations (#1260)
* Use websocket to fetch themes and translations * Lint
This commit is contained in:
parent
10c997b7b2
commit
bf4d0e6bc9
@ -123,11 +123,16 @@ class HomeAssistant extends LocalizeMixin(PolymerElement) {
|
|||||||
if (!this.hass.language) return;
|
if (!this.hass.language) return;
|
||||||
|
|
||||||
const language = this.hass.selectedLanguage || this.hass.language;
|
const language = this.hass.selectedLanguage || this.hass.language;
|
||||||
this.hass.callApi('get', `translations/${language}`).then((result) => {
|
|
||||||
|
this.hass.connection.sendMessagePromise({
|
||||||
|
type: 'frontend/get_translations',
|
||||||
|
language,
|
||||||
|
})
|
||||||
|
.then((resp) => {
|
||||||
// If we've switched selected languages just ignore this response
|
// If we've switched selected languages just ignore this response
|
||||||
if ((this.hass.selectedLanguage || this.hass.language) !== language) return;
|
if ((this.hass.selectedLanguage || this.hass.language) !== language) return;
|
||||||
|
|
||||||
this._updateResources(language, result.resources);
|
this._updateResources(language, resp.result.resources);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,15 +277,19 @@ class HomeAssistant extends LocalizeMixin(PolymerElement) {
|
|||||||
|
|
||||||
var unsubThemes;
|
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(
|
applyThemesOnElement(
|
||||||
document.documentElement,
|
document.documentElement,
|
||||||
themes,
|
resp.result,
|
||||||
this.hass.selectedTheme,
|
this.hass.selectedTheme,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
conn.subscribeEvents((event) => {
|
conn.subscribeEvents((event) => {
|
||||||
this._updateHass({ themes: event.data });
|
this._updateHass({ themes: event.data });
|
||||||
applyThemesOnElement(
|
applyThemesOnElement(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user