-
Notifications
You must be signed in to change notification settings - Fork 0
/
floor-plan-card.ts
192 lines (172 loc) · 4.77 KB
/
floor-plan-card.ts
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import {
LitElement,
html,
css,
} from "lit";
// import {state} from "lit/decorators";
// import { HassEntity } from "home-assistant-js-websocket";
// export class ClockController implements ReactiveController {
// host: ReactiveControllerHost;
// value = new Date();
// timeout: number;
// private _timerID?: number;
// constructor(host: ReactiveControllerHost, timeout = 1000) {
// (this.host = host).addController(this);
// this.timeout = timeout;
// }
// hostConnected() {
// // Start a timer when the host is connected
// this._timerID = setInterval(() => {
// this.value = new Date();
// // Update the host with new value
// this.host.requestUpdate();
// }, this.timeout);
// }
// hostDisconnected() {
// // Clear the timer when the host is disconnected
// clearInterval(this._timerID);
// this._timerID = undefined;
// }
// }
// function loadCSS(url) {
// const link = document.createElement("link");
// link.type = "text/css";
// link.rel = "stylesheet";
// link.href = url;
// document.head.appendChild(link);
// }
// loadCSS("https://fonts.googleapis.com/css?family=Gloria+Hallelujah");
// interface Config {
// header: string;
// entity: string;
// }
class FloorPlanCard extends LitElement {
// static get properties() {
// return {
// hass: {},
// config: {},
// };
// }
// @state() private _state: HassEntity;
hass: any
// @state()
config: any
render() {
var _this = this;
const bitmap = this.config.entities.map(function(entity) {return _this.hass.states[entity].state == "on" ? "1" : "0"}).join("")
console.log(_this.config)
return html`
<ha-card>
<img src="/local/images/floor_plan_lights/${bitmap}.jpg" class='floor-plan'>
${this.config.elements.map((e) => {
return html`
<img src='/local/images/bulb-off.png' @click=${() => {console.log('clicked', _this._toggle(e.entity))}} class='element ${_this.hass.states[e.entity].state}' style='left:${e.style.left};top:${e.style.top}' >
`}
)}
</ha-card>
`;
}
setConfig(config) {
if (!config.entities) {
throw new Error("You need to define entities");
}
var _this = this
this.config = config;
}
// The height of your card. Home Assistant uses this to automatically
// distribute all cards over the available columns.
getCardSize() {
return 2;
}
_toggle(entity_id) {
this.hass.callService("homeassistant", "toggle", {
entity_id: entity_id,
});
}
static get styles() {
return css`
.floor-plan{
max-width: 100%;
max-height: 100%;
// position:absolute;
top:0;
left:0
}
.element{
cursor: pointer;
position: absolute;
transform: translate(-50%, -50%);
width: 5%;
}
.on{
filter: invert(1);
}
`;
}
}
// class ContentCardExample extends LitElement {
// static get properties() {
// return {
// hass: {},
// config: {},
// };
// }
// // 1111101101
// // 0000000
// render(){
// const entities = this.config.entities;
// // const state = hass.states[entityId];
// // const stateStr = state ? state.state : "unavailable";
// const bitmap = entities.map(function(entity) {return hass.states[entity].state == "on" ? "1" : "0"}).join("")
// return html`
// <p>The state of ${bitmap}!</p>
// <br><br>
// <img src="/local/images/floor_plan_lights/${bitmap}.jpg" class='floor-plan' width='400px'>
// `;
// }
// // The user supplied configuration. Throw an exception and Home Assistant
// // will render an error card.
// setConfig(config) {
// if (!config.entities) {
// throw new Error("You need to define entities");
// }
// this.config = config;
// }
// // The height of your card. Home Assistant uses this to automatically
// // distribute all cards over the available columns.
// getCardSize() {
// return 3;
// }
// _toggle(state) {
// this.hass.callService("homeassistant", "toggle", {
// entity_id: state.entity_id,
// });
// }
// static get styles() {
// return css`
// .card-content{
// width: 400px;
// }
// img{
// max-width: 100%;
// max-height: 100%;
// object-fit: cover;
// }
// p {
// color:red;
// }
// `;
// }
// }
customElements.define("floor-plan-card", FloorPlanCard);
declare global {
interface Window {
customCards: Array<Object>;
}
}
window.customCards = window.customCards || [];
window.customCards.push({
type: "floor-plan-card",
name: "Bringing the Floor plan card to HACS",
description: "Create a floor plan",
});