-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from lukiffer/feature/themes
feature: Themes Support
- Loading branch information
Showing
26 changed files
with
944 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rsync -avi ./haiku/ pi@raspberrypi:/home/homeassistant/.homeassistant/www/haiku/ | ||
rsync -aviO -e "ssh -p $HA_SSH_PORT -o StrictHostKeyChecking=no" ./haiku/ $HA_SSH_USER@$HA_SSH_HOST:/home/homeassistant/.homeassistant/www/haiku/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { StorageService } from '../services/storage-service.js'; | ||
import { CustomizationService } from '../services/customization-service.js'; | ||
import '../elements/haiku-global-config-dialog.js'; | ||
import 'https://unpkg.com/[email protected]/lodash.js?module'; | ||
|
||
/** | ||
* Haiku global config UI | ||
*/ | ||
export class HaikuGlobalConfig extends HTMLElement { | ||
|
||
constructor() { | ||
super(); | ||
this.customizationService = new CustomizationService(this); | ||
} | ||
|
||
set hass(hass) { | ||
this.ha = hass; | ||
|
||
if (!this.initialized) { | ||
this.setAttribute('style', 'margin:0;'); | ||
this.initStylesheet(); | ||
this.initTheme(); | ||
this.initConfigButton(); | ||
this.initialized = true; | ||
} | ||
} | ||
|
||
initStylesheet() { | ||
if (!document.getElementById('haiku_global_css')) { | ||
const globalCss = document.createElement('link'); | ||
globalCss.setAttribute('id', 'haiku_global_css'); | ||
globalCss.setAttribute('href', '/local/haiku/haiku.css'); | ||
globalCss.setAttribute('rel', 'stylesheet'); | ||
document.head.appendChild(globalCss); | ||
} | ||
} | ||
|
||
initTheme() { | ||
const storageService = new StorageService(); | ||
let theme = storageService.getItem('theme'); | ||
if (!theme) { | ||
theme = 'haiku-dark'; | ||
storageService.setItem('theme', 'haiku-dark'); | ||
} | ||
const existingCssClasses = document.body.getAttribute('class'); | ||
if (!existingCssClasses) { | ||
document.body.setAttribute('class', theme); | ||
} | ||
else { | ||
let cssClasses = existingCssClasses.split(' '); | ||
cssClasses = _.filter(cssClasses, (cssClass) => { | ||
return cssClass.indexOf('haiku-') === -1; | ||
}); | ||
document.body.setAttribute('class', `${cssClasses.join(' ')} ${theme}`); | ||
} | ||
} | ||
|
||
initConfigButton() { | ||
if (!document.getElementById('haiku_config_button')) { | ||
const configButton = document.createElement('button'); | ||
configButton.setAttribute('class', 'haiku-config-button'); | ||
const icon = document.createElement('ha-icon'); | ||
icon.setAttribute('icon', 'mdi:settings'); | ||
configButton.appendChild(icon); | ||
configButton.onclick = () => { | ||
this._openGlobalConfigDialog(); | ||
}; | ||
document.body.appendChild(configButton); | ||
} | ||
} | ||
|
||
_openGlobalConfigDialog() { | ||
const $this = this; | ||
this.customizationService.openGlobalConfigDialog(() => { | ||
console.log('saved...'); | ||
$this.initTheme(); | ||
}); | ||
} | ||
|
||
setConfig(config) { | ||
this.config = config; | ||
} | ||
|
||
getCardSize() { | ||
return 0; | ||
} | ||
} | ||
|
||
customElements.define('haiku-global-config', HaikuGlobalConfig); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import 'https://unpkg.com/[email protected]/lodash.js?module'; | |
import '../elements/haiku-light-menu.js'; | ||
import '../elements/haiku-sensor-tile.js'; | ||
import '../elements/haiku-fan-tile.js'; | ||
import '../elements/haiku-thermostat-tile.js'; | ||
|
||
/** | ||
* A card that summarizes a rooms entities. | ||
|
@@ -29,6 +30,7 @@ export class HaikuRoomCard extends LitElement { | |
<ha-card class$="haiku-room-card ${ config.class || '' }" style$="${this.getCustomBackgroundStyle()}"> | ||
<haiku-light-menu hass="${ hass }" entities="${ this.getEntitiesByDomain('light') }"></haiku-light-menu> | ||
<div class="tiles"> | ||
${ this.renderThermostats() } | ||
${ this.renderSensors() } | ||
${ this.renderFans() } | ||
</div> | ||
|
@@ -42,6 +44,10 @@ export class HaikuRoomCard extends LitElement { | |
const states = []; | ||
_.each(this.config.entities, (key) => { | ||
const state = this.hass.states[key]; | ||
if (!state) { | ||
return; | ||
} | ||
|
||
const d = key.split('.')[0]; | ||
const t = state.attributes.haiku_type; | ||
if (d === domain || t === domain) { | ||
|
@@ -69,6 +75,17 @@ export class HaikuRoomCard extends LitElement { | |
`; | ||
} | ||
|
||
renderThermostats() { | ||
const thermostats = this.getEntitiesByDomain('climate'); | ||
return html` | ||
${_.map(thermostats, (thermostat) => this.renderThermostat(thermostat))} | ||
`; | ||
} | ||
|
||
renderThermostat(thermostat) { | ||
return html`<haiku-thermostat-tile hass="${ this.hass }" entity="${ thermostat }"></haiku-thermostat-tile>`; | ||
} | ||
|
||
renderSensors() { | ||
const sensors = this.getEntitiesByDomain('sensor'); | ||
return html` | ||
|
@@ -82,7 +99,7 @@ export class HaikuRoomCard extends LitElement { | |
|
||
getCustomBackgroundStyle() { | ||
if (this.config.background_image) { | ||
return `background-image: url("${this.config.background_image}");`; | ||
return `background-image: ${this.config.background_image};`; | ||
} | ||
else { | ||
return ''; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.