Skip to content

Instantly share code, notes, and snippets.

@thomasloven
Last active March 1, 2019 21:36
Show Gist options
  • Save thomasloven/a488eab3f1da851ce99e3bbc02aab41e to your computer and use it in GitHub Desktop.
Save thomasloven/a488eab3f1da851ce99e3bbc02aab41e to your computer and use it in GitHub Desktop.
class DimImageElement extends Polymer.Element {
async setConfig(config) {
this.dim_entity = config.dim_entity;
this.img = document.createElement('hui-image-element')
this.img.setConfig(config);
this.appendChild(this.img)
}
set hass(hass) {
this.img.hass = hass;
this.img.updateComplete.then(() => {
if(this.img.shadowRoot) {
let value;
let state = hass.states[this.dim_entity]
if(this.dim_entity.startsWith("light.")) {
value = (state.state === 'on') ? state.attributes['brightness']/2.55 : 0;
} else {
value = state.state;
}
this.img.shadowRoot.querySelector("hui-image").$.image.style.filter = `opacity(${value}%)`;
}
});
}
}
customElements.define('dim-image-element', DimImageElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment