mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-18 23:06:40 +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,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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user