mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-13 04:16:34 +00:00
Add JS support for device-local theme name (#358)
* Add JS support for device-local theme name * Keep themes in hass object * Make it actually work * Move themes from home-assistant-main to home-assistant
This commit is contained in:
parent
8787304ed4
commit
b57c86a29c
@ -125,6 +125,7 @@ Polymer({
|
||||
connected: true,
|
||||
states: null,
|
||||
config: null,
|
||||
themes: null,
|
||||
dockedSidebar: false,
|
||||
moreInfoEntityId: null,
|
||||
callService: function (domain, service, serviceData) {
|
||||
@ -186,11 +187,25 @@ Polymer({
|
||||
unsubConfig = unsub;
|
||||
});
|
||||
|
||||
var unsubThemes;
|
||||
|
||||
this.hass.callApi('get', 'themes').then(function (themes) {
|
||||
el.hass.themes = themes;
|
||||
window.hassUtil.applyThemesOnElement(el, themes);
|
||||
});
|
||||
conn.subscribeEvents(function (event) {
|
||||
el.hass.themes = event.data;
|
||||
window.hassUtil.applyThemesOnElement(el, event.data);
|
||||
}, 'themes_updated').then(function (unsub) {
|
||||
unsubThemes = unsub;
|
||||
});
|
||||
|
||||
this.unsubConnection = function () {
|
||||
conn.removeEventListener('ready', reconnected);
|
||||
conn.removeEventListener('disconnected', disconnected);
|
||||
unsubEntities();
|
||||
unsubConfig();
|
||||
unsubThemes();
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -111,20 +111,6 @@
|
||||
'hass-start-voice': 'handleStartVoice',
|
||||
},
|
||||
|
||||
ready: function () {
|
||||
if (!this.hass) return;
|
||||
var _this = this;
|
||||
this.hass.callApi('get', 'themes').then(
|
||||
function (themes) {
|
||||
window.hassUtil.applyThemesOnElement(_this, themes);
|
||||
});
|
||||
this.hass.connection.subscribeEvents(
|
||||
function (event) {
|
||||
window.hassUtil.applyThemesOnElement(_this, event.data);
|
||||
},
|
||||
'themes_updated');
|
||||
},
|
||||
|
||||
_routeChanged: function () {
|
||||
if (this.narrow) {
|
||||
this.$.drawer.closeDrawer();
|
||||
|
@ -492,15 +492,19 @@ window.hassUtil.computeLocationName = function (hass) {
|
||||
return hass && hass.config.core.location_name;
|
||||
};
|
||||
|
||||
window.hassUtil.applyThemesOnElement = function (element, themes) {
|
||||
window.hassUtil.applyThemesOnElement = function (element, themes, localTheme) {
|
||||
if (!element._themes) {
|
||||
element._themes = {};
|
||||
}
|
||||
if (themes.default_theme === 'default') {
|
||||
var themeName = themes.default_theme;
|
||||
if (localTheme === 'default' || (localTheme && themes.themes[localTheme])) {
|
||||
themeName = localTheme;
|
||||
}
|
||||
if (themeName === 'default') {
|
||||
element.updateStyles(element._themes);
|
||||
return;
|
||||
}
|
||||
var theme = themes.themes[themes.default_theme];
|
||||
var theme = themes.themes[themeName];
|
||||
var styles = Object.assign({}, element._themes);
|
||||
Object.keys(theme).forEach(function (key) {
|
||||
var prefixedKey = '--' + key;
|
||||
|
Loading…
x
Reference in New Issue
Block a user