This commit is contained in:
Thomas Lovén 2019-11-25 00:12:37 +01:00
parent 1dab4bd27f
commit f9064d6b56
3 changed files with 11 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@ -7,7 +7,7 @@ export class LightController extends Controller {
} }
get _value() { get _value() {
if (this.stateObj.state !== "on") return 0; if (!this.stateObj || this.stateObj.state !== "on") return 0;
switch (this.attribute) { switch (this.attribute) {
case "color_temp": case "color_temp":
return Math.ceil(this.stateObj.attributes.color_temp); return Math.ceil(this.stateObj.attributes.color_temp);
@ -46,7 +46,7 @@ export class LightController extends Controller {
get _min() { get _min() {
switch (this.attribute) { switch (this.attribute) {
case "color_temp": case "color_temp":
return this.stateObj.attributes.min_mireds; return this.stateObj ? this.stateObj.attributes.min_mireds : 0;
default: default:
return 0; return 0;
} }
@ -54,7 +54,7 @@ export class LightController extends Controller {
get _max() { get _max() {
switch (this.attribute) { switch (this.attribute) {
case "color_temp": case "color_temp":
return this.stateObj.attributes.max_mireds; return this.stateObj ? this.stateObj.attributes.max_mireds : 0;
case "red": case "red":
case "green": case "green":
case "blue": case "blue":
@ -63,13 +63,14 @@ export class LightController extends Controller {
case "hue": case "hue":
return 360; return 360;
case "effect": case "effect":
return this.stateObj.attributes.effect_list ? this.stateObj.attributes.effect_list.length - 1 : 0; return this.stateObj ? this.stateObj.attributes.effect_list ? this.stateObj.attributes.effect_list.length - 1 : 0 : 0;
default: default:
return 100; return 100;
} }
} }
set _value(value) { set _value(value) {
if(!this.stateObj) return;
let attr = this.attribute; let attr = this.attribute;
let on = true; let on = true;
let _value; let _value;
@ -115,7 +116,7 @@ export class LightController extends Controller {
} }
get string() { get string() {
if (this.stateObj.state === "off") if (this.stateObj && this.stateObj.state === "off")
return this._hass.localize("state.default.off"); return this._hass.localize("state.default.off");
switch (this.attribute) { switch (this.attribute) {
case "color_temp": case "color_temp":
@ -126,13 +127,14 @@ export class LightController extends Controller {
case "hue": case "hue":
return `${this.value} °`; return `${this.value} °`;
case "effect": case "effect":
return this.stateObj.attributes.effect; return this.stateObj ? this.stateObj.attributes.effect : "";
default: default:
return this.value; return this.value;
} }
} }
get hasSlider() { get hasSlider() {
if(!this.stateObj) return false;
switch (this.attribute) { switch (this.attribute) {
case "brightness": case "brightness":
if ("brightness" in this.stateObj.attributes) return true; if ("brightness" in this.stateObj.attributes) return true;

View File

@ -49,6 +49,7 @@ class SliderEntityRow extends LitElement {
pin pin
@change=${(ev) => c.value = this.shadowRoot.querySelector("ha-slider").value} @change=${(ev) => c.value = this.shadowRoot.querySelector("ha-slider").value}
class=${this._config.full_row ? "full" : ""} class=${this._config.full_row ? "full" : ""}
ignore-bar-touch
></ha-slider> ></ha-slider>
`; `;
const toggle = html` const toggle = html`