diff --git a/src/layouts/home-assistant-main.html b/src/layouts/home-assistant-main.html
index a2b18a40b8..c0bcd5d578 100644
--- a/src/layouts/home-assistant-main.html
+++ b/src/layouts/home-assistant-main.html
@@ -14,6 +14,7 @@
+
@@ -108,6 +109,20 @@ Polymer({
'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();
diff --git a/src/util/hass-util.html b/src/util/hass-util.html
index 75d8d9ba17..ab14ccfb3b 100644
--- a/src/util/hass-util.html
+++ b/src/util/hass-util.html
@@ -473,4 +473,21 @@ window.hassUtil.computeLocationName = function (hass) {
return hass && hass.config.core.location_name;
};
+window.hassUtil.applyThemesOnElement = function (element, themes) {
+ if (!element._themes) {
+ element._themes = {};
+ }
+ if (themes.default_theme === 'default') {
+ element.updateStyles(element._themes);
+ return;
+ }
+ var theme = themes.themes[themes.default_theme];
+ var styles = Object.assign({}, element._themes);
+ Object.keys(theme).forEach(function (key) {
+ var prefixedKey = '--' + key;
+ element._themes[prefixedKey] = '';
+ styles[prefixedKey] = theme[key];
+ });
+ element.updateStyles(styles);
+};