forked from bouwew/clock-card
-
Notifications
You must be signed in to change notification settings - Fork 7
/
scotte-clock-card.js
81 lines (71 loc) · 2.3 KB
/
scotte-clock-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
77
78
79
80
81
class ClockCard extends Polymer.Element {
static get template() {
return Polymer.html`
<style>
:host {
cursor: pointer;
}
.content {
padding: 24px 16px;
display:flex;
}
.time {
font-family: var(--paper-font-headline_-_font-family);
-webkit-font-smoothing: var(--paper-font-headline_-_-webkit-font-smoothing);
font-size: 3em;
font-weight: var(--paper-font-headline_-_font-weight);
letter-spacing: var(--paper-font-headline_-_letter-spacing);
line-height: 1em;
text-rendering: var(--paper-font-common-expensive-kerning_-_text-rendering);
}
.date {
color: var(--accent-color);
font-family: var(--paper-font-headline_-_font-family);
-webkit-font-smoothing: var(--paper-font-headline_-_-webkit-font-smoothing);
font-size: 1.3em;
font-weight: var(--paper-font-headline_-_font-weight);
letter-spacing: var(--paper-font-headline_-_letter-spacing);
line-height: var(--paper-font-headline_-_line-height);
text-rendering: var(--paper-font-common-expensive-kerning_-_text-rendering);
}
</style>
<ha-card>
<div class="content">
<div class="clock">
<div class="time" id="time">3:45 PM</div>
<div class="date" id="date">Wednesday, December 3</div>
</div>
</div>
</ha-card>
`
}
static get properties() {
return {
_hass: Object
}
}
ready() {
super.ready();
this.time = this.$.time;
this.date = this.$.date;
this._updateTime();
setInterval(() => this._updateTime(), 500);
}
setConfig(config) {
this.config = config;
}
set hass(hass) {
this._hass = hass;
}
_updateTime() {
var time = new Date();
this.time.innerHTML = time.toLocaleTimeString('en-US', {hour12: true, hour: 'numeric', minute: 'numeric'});
this.date.innerHTML = time.toLocaleDateString('en-US', {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric'});
}
// The height of your card. Home Assistant uses this to automatically
// distribute all cards over the available columns.
getCardSize() {
return 3;
}
}
customElements.define('scotte-clock-card', ClockCard);