mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-12 20:06:33 +00:00
Better error message
This commit is contained in:
parent
bdc2b31202
commit
1589c3fc51
@ -68,6 +68,7 @@ class StateBadge extends PolymerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_updateIconAppearance(newVal) {
|
_updateIconAppearance(newVal) {
|
||||||
|
var errorMessage = null;
|
||||||
const iconStyle = {
|
const iconStyle = {
|
||||||
color: "",
|
color: "",
|
||||||
filter: "",
|
filter: "",
|
||||||
@ -88,21 +89,21 @@ class StateBadge extends PolymerElement {
|
|||||||
}
|
}
|
||||||
if (newVal.attributes.brightness) {
|
if (newVal.attributes.brightness) {
|
||||||
const brightness = newVal.attributes.brightness;
|
const brightness = newVal.attributes.brightness;
|
||||||
if (typeof brightness !== "number" || isNaN(brightness)) {
|
if (typeof brightness !== "number") {
|
||||||
console.warn(
|
errorMessage = `Type error: state-badge expected number, but type of ${
|
||||||
"Type error: state-badge expected number, but type of " +
|
newVal.entity_id
|
||||||
newVal.entity_id +
|
}.attributes.brightness is ${typeof brightness} (${brightness})`;
|
||||||
".attributes.brightness is " +
|
console.warn(errorMessage);
|
||||||
typeof brightness
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// lowest brighntess will be around 50% (that's pretty dark)
|
|
||||||
iconStyle.filter = `brightness(${(brightness + 245) / 5}%)`;
|
|
||||||
}
|
}
|
||||||
|
// lowest brighntess will be around 50% (that's pretty dark)
|
||||||
|
iconStyle.filter = `brightness(${(brightness + 245) / 5}%)`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object.assign(this.$.icon.style, iconStyle);
|
Object.assign(this.$.icon.style, iconStyle);
|
||||||
Object.assign(this.style, hostStyle);
|
Object.assign(this.style, hostStyle);
|
||||||
|
if (errorMessage) {
|
||||||
|
throw new Error(`Frontend error: ${message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
customElements.define("state-badge", StateBadge);
|
customElements.define("state-badge", StateBadge);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user