-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
light profiles now pulled from lovelace variable
this makes updating the card easier
- Loading branch information
Showing
2 changed files
with
33 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
import { | ||
LitElement, | ||
html, | ||
css | ||
} from "https://unpkg.com/[email protected]/lit-element.js?module"; | ||
import { LitElement, html, css } from "https://unpkg.com/[email protected]/lit-element.js?module"; | ||
|
||
class LightWithProfiles extends LitElement { | ||
static get properties() { | ||
|
@@ -15,12 +11,7 @@ class LightWithProfiles extends LitElement { | |
constructor() { | ||
super(); | ||
|
||
this.lightProfiles = { | ||
// Add your profiles here to show what profile is active | ||
// bright: '0.457,0.408,254', | ||
// dimmed: '0.457,0.408,77', | ||
// nightlight: '0.509,0.411,1' | ||
}; | ||
this.lightProfiles = {}; | ||
} | ||
|
||
render() { | ||
|
@@ -90,6 +81,13 @@ class LightWithProfiles extends LitElement { | |
if (!config.entities) { | ||
throw new Error("You need to define entities"); | ||
} | ||
|
||
const ll = this.getLovelace(); | ||
|
||
if (ll.config && ll.config.light_profiles) { | ||
this.lightProfiles = ll.config.light_profiles; | ||
} | ||
|
||
this.config = config; | ||
} | ||
|
||
|
@@ -134,6 +132,24 @@ class LightWithProfiles extends LitElement { | |
} | ||
`; | ||
} | ||
// https://github.com/custom-cards/custom-card-helpers/blob/master/src/get-lovelace.ts | ||
getLovelace() { | ||
let root = document.querySelector('home-assistant'); | ||
root = root && root.shadowRoot; | ||
root = root && root.querySelector('home-assistant-main'); | ||
root = root && root.shadowRoot; | ||
root = root && root.querySelector('app-drawer-layout partial-panel-resolver'); | ||
root = root && root.shadowRoot || root; | ||
root = root && root.querySelector('ha-panel-lovelace'); | ||
root = root && root.shadowRoot; | ||
root = root && root.querySelector('hui-root'); | ||
if (root) { | ||
const ll = root.lovelace; | ||
ll.current_view = root.___curView; | ||
return ll; | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
customElements.define('light-with-profiles', LightWithProfiles); |