mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
State card for light will show actual color of light
This commit is contained in:
parent
86dc0a973c
commit
d1f3c84212
@ -27,13 +27,14 @@
|
|||||||
state-badge {
|
state-badge {
|
||||||
float: left;
|
float: left;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background-color .2s;
|
transition: background-color .2s ease-in-out, color .5s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
state-badge:hover {
|
state-badge:hover {
|
||||||
background-color: #039be5;
|
background-color: #039be5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Color the icon if light or sun is on */
|
||||||
state-badge[data-domain=light][data-state=on],
|
state-badge[data-domain=light][data-state=on],
|
||||||
state-badge[data-domain=sun][data-state=above_horizon] {
|
state-badge[data-domain=sun][data-state=above_horizon] {
|
||||||
color: #fff176;
|
color: #fff176;
|
||||||
@ -78,6 +79,7 @@
|
|||||||
|
|
||||||
<div class="entity">
|
<div class="entity">
|
||||||
<state-badge
|
<state-badge
|
||||||
|
id="badge"
|
||||||
domain="{{domain}}"
|
domain="{{domain}}"
|
||||||
state="{{state}}"
|
state="{{state}}"
|
||||||
data-domain="{{domain}}"
|
data-domain="{{domain}}"
|
||||||
@ -134,9 +136,23 @@
|
|||||||
state_unknown: false,
|
state_unknown: false,
|
||||||
toggleChecked: -1,
|
toggleChecked: -1,
|
||||||
|
|
||||||
// computed
|
computed: {
|
||||||
domain: "",
|
domain: "entity | parseDomain",
|
||||||
entity_id: "",
|
entity_id: "entity | parseEntityId",
|
||||||
|
last_changed_from_now: "last_changed | parseLastChangedFromNow"
|
||||||
|
},
|
||||||
|
|
||||||
|
parseDomain: function(entity) {
|
||||||
|
return entity.split('.')[0];
|
||||||
|
},
|
||||||
|
|
||||||
|
parseEntityId: function(entity) {
|
||||||
|
return entity.split('.')[1];
|
||||||
|
},
|
||||||
|
|
||||||
|
parseLastChangedFromNow: function(lastChanged) {
|
||||||
|
return moment(lastChanged, "HH:mm:ss DD-MM-YYYY").fromNow()
|
||||||
|
},
|
||||||
|
|
||||||
toggleCheckedChanged: function(oldVal, newVal) {
|
toggleCheckedChanged: function(oldVal, newVal) {
|
||||||
// to filter out init
|
// to filter out init
|
||||||
@ -154,24 +170,20 @@
|
|||||||
stateChanged: function(oldVal, newVal) {
|
stateChanged: function(oldVal, newVal) {
|
||||||
this.state_unknown = newVal == null;
|
this.state_unknown = newVal == null;
|
||||||
this.toggleChecked = newVal == "on"
|
this.toggleChecked = newVal == "on"
|
||||||
},
|
|
||||||
|
|
||||||
entityChanged: function(oldVal, newVal) {
|
// for domain light, set color of icon to light color if available
|
||||||
var parts = newVal.split(".")
|
if(this.domain == "light" && newVal == "on" &&
|
||||||
|
this.state_attr.brightness && this.state_attr.xy_color) {
|
||||||
|
|
||||||
if(parts.length == 1) {
|
var rgb = this.xyBriToRgb(this.state_attr.xy_color[0],
|
||||||
this.domain = ""
|
this.state_attr.xy_color[1],
|
||||||
this.entity_id = parts[0]
|
this.state_attr.brightness);
|
||||||
|
this.$.badge.style.color = "rgb(" + rgb.map(Math.floor).join(",") + ")";
|
||||||
} else {
|
} else {
|
||||||
this.domain = parts[0]
|
this.$.badge.style.color = null;
|
||||||
this.entity_id = parts.slice(1).join('.')
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
last_changedChanged: function(oldVal, newVal) {
|
|
||||||
this.last_changed_from_now = moment(this.last_changed, "HH:mm:ss DD-MM-YYYY").fromNow()
|
|
||||||
},
|
|
||||||
|
|
||||||
turn_on: function() {
|
turn_on: function() {
|
||||||
if(this.cb_turn_on) {
|
if(this.cb_turn_on) {
|
||||||
this.cb_turn_on(this.entity);
|
this.cb_turn_on(this.entity);
|
||||||
@ -213,6 +225,28 @@
|
|||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// from http://stackoverflow.com/questions/22894498/philips-hue-convert-xy-from-api-to-hex-or-rgb
|
||||||
|
xyBriToRgb: function (x, y, bri) {
|
||||||
|
z = 1.0 - x - y;
|
||||||
|
Y = bri / 255.0; // Brightness of lamp
|
||||||
|
X = (Y / y) * x;
|
||||||
|
Z = (Y / y) * z;
|
||||||
|
r = X * 1.612 - Y * 0.203 - Z * 0.302;
|
||||||
|
g = -X * 0.509 + Y * 1.412 + Z * 0.066;
|
||||||
|
b = X * 0.026 - Y * 0.072 + Z * 0.962;
|
||||||
|
r = r <= 0.0031308 ? 12.92 * r : (1.0 + 0.055) * Math.pow(r, (1.0 / 2.4)) - 0.055;
|
||||||
|
g = g <= 0.0031308 ? 12.92 * g : (1.0 + 0.055) * Math.pow(g, (1.0 / 2.4)) - 0.055;
|
||||||
|
b = b <= 0.0031308 ? 12.92 * b : (1.0 + 0.055) * Math.pow(b, (1.0 / 2.4)) - 0.055;
|
||||||
|
maxValue = Math.max(r,g,b);
|
||||||
|
r /= maxValue;
|
||||||
|
g /= maxValue;
|
||||||
|
b /= maxValue;
|
||||||
|
r = r * 255; if (r < 0) { r = 255 };
|
||||||
|
g = g * 255; if (g < 0) { g = 255 };
|
||||||
|
b = b * 255; if (b < 0) { b = 255 };
|
||||||
|
return [r, g, b]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user