mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-24 13:27:22 +00:00
Merge pull request #1807 from home-assistant/safer-icon-brightness
Safer brightness calculation for icons
This commit is contained in:
commit
11f4564465
@ -68,6 +68,7 @@ class StateBadge extends PolymerElement {
|
||||
}
|
||||
|
||||
_updateIconAppearance(newVal) {
|
||||
var errorMessage = null;
|
||||
const iconStyle = {
|
||||
color: "",
|
||||
filter: "",
|
||||
@ -88,12 +89,21 @@ class StateBadge extends PolymerElement {
|
||||
}
|
||||
if (newVal.attributes.brightness) {
|
||||
const brightness = newVal.attributes.brightness;
|
||||
if (typeof brightness !== "number") {
|
||||
errorMessage = `Type error: state-badge expected number, but type of ${
|
||||
newVal.entity_id
|
||||
}.attributes.brightness is ${typeof brightness} (${brightness})`;
|
||||
console.warn(errorMessage);
|
||||
}
|
||||
// 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.style, hostStyle);
|
||||
if (errorMessage) {
|
||||
throw new Error(`Frontend error: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
customElements.define("state-badge", StateBadge);
|
||||
|
Loading…
x
Reference in New Issue
Block a user