forked from bradcrc/color-lite-card
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color-lite-card.js
76 lines (61 loc) · 1.66 KB
/
color-lite-card.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// COLOR LITE CARD
// Simple custom card for displaying lights on a picture elements floor plan
class ColorLite extends HTMLElement {
set hass(hass) {
if (!this.content) {
const card = document.createElement('ha-card');
this.content = document.createElement('div');
card.appendChild(this.content);
card.style.background = 'none';
this.appendChild(card);
}
const entityId = this.config.entity;
const state = hass.states[entityId];
// if the light is on
if(state){
if(state.state == 'on'){
const imageURLId = this.config.image;
var ImURL = imageURLId;
const imageURLCId = this.config.color_image;
var rgbval = state.attributes.rgb_color;
var hsval = state.attributes.hs_color;
var ctemp = state.attributes.color_temp;
var hsar = "";
var min_bright = (this.config.min_brightness * 2.5);
var bright = state.attributes.brightness;
if (hsval) {
if (ctemp || rgbval == "255,255,255") {
} else {
var hsar = ' hue-rotate(' + hsval[0] + 'deg)';
if (imageURLCId) {
ImURL = imageURLCId;
}
}
}
var bbritef = bright;
if (min_bright > bright) {
bbritef = min_bright;
}
var bbrite = (bbritef / 205);
this.content.innerHTML = `
<!-- Custom Lite Card 6 -->
<img src="${ImURL}" style="filter: opacity(${bbrite})${hsar}!important;" width="100%" height="100%">
`;
} else {
this.content.innerHTML = `
<!-- Custom Lite Card for ${entityId} is turned off -->
`;
}
}
}
setConfig(config) {
if (!config.entity) {
throw new Error('You need to define an entity');
}
this.config = config;
}
getCardSize() {
return 3;
}
}
customElements.define('color-lite-card', ColorLite);