@@ -3,16 +3,33 @@ import moment from 'moment';
33import 'moment/min/locales' ;
44
55class AtomicCalendar extends LitElement {
6- static get properties ( ) {
76
7+
8+ set hass ( hass ) {
9+ this . _hass = hass
10+
11+ let timeFormat = moment . localeData ( this . _hass . language ) . longDateFormat ( 'LT' )
12+ if ( this . config . hoursFormat == '12h' ) timeFormat = 'h:mm A'
13+ else if ( this . config . hoursFormat == '24h' ) timeFormat = 'hh:mm'
14+ moment . updateLocale ( this . _hass . language , {
15+ week : {
16+ dow : this . config . firstDayOfWeek
17+ } ,
18+ longDateFormat : {
19+ LT : timeFormat
20+ }
21+ } ) ;
22+ }
23+
24+ static get properties ( ) {
825 return {
9- hass : Object ,
26+ _hass : { } ,
1027 config : Object ,
1128 content : Object ,
1229 selectedMonth : Object
1330 }
1431 }
15-
32+
1633 constructor ( ) {
1734 super ( ) ;
1835 this . lastCalendarUpdateTime ;
@@ -34,11 +51,8 @@ class AtomicCalendar extends LitElement {
3451 updated ( ) { }
3552
3653 render ( ) {
37- moment . updateLocale ( this . hass . language , {
38- week : {
39- dow : this . config . firstDayOfWeek
40- }
41- } ) ;
54+
55+
4256 if ( ! this . isUpdating && this . modeToggle == 1 ) {
4357 if ( ! this . lastEventsUpdateTime || moment ( ) . diff ( this . lastEventsUpdateTime , 'minutes' ) > 15 )
4458 ( async ( ) => {
@@ -93,6 +107,12 @@ class AtomicCalendar extends LitElement {
93107 static get styles ( ) {
94108
95109 }
110+
111+ firstTimeConfig ( ) {
112+
113+
114+ }
115+
96116
97117
98118 handleToggle ( e ) {
@@ -384,6 +404,8 @@ class AtomicCalendar extends LitElement {
384404 showCurrentEventLine : false , // show a line between last and next event
385405 showDate : false ,
386406 dateFormat : 'LL' ,
407+ hoursFormat : 'default' , // 12h / 24h / default time format. Default is HA language setting.
408+
387409
388410 // color and font settings
389411 dateColor : 'var(--primary-text-color)' , // Date text color (left side)
@@ -452,14 +474,15 @@ class AtomicCalendar extends LitElement {
452474 } ) ;
453475 }
454476
477+
455478 // The height of your card. Home Assistant uses this to automatically
456479 // distribute all cards over the available columns.
457480 getCardSize ( ) {
458481 return this . config . entities . length + 1 ;
459482 }
460483
461484 _toggle ( state ) {
462- this . hass . callService ( 'homeassistant' , 'toggle' , {
485+ this . _hass . callService ( 'homeassistant' , 'toggle' , {
463486 entity_id : state . entity_id
464487 } ) ;
465488 }
@@ -656,7 +679,7 @@ class AtomicCalendar extends LitElement {
656679 `calendars/${ entity . entity } ?start=${ start } Z&end=${ end } Z` )
657680 try {
658681 return await ( Promise . all ( calendarUrlList . map ( url =>
659- this . hass . callApi ( 'get' , url ) ) ) . then ( ( result ) => {
682+ this . _hass . callApi ( 'get' , url ) ) ) . then ( ( result ) => {
660683 let ev = [ ] . concat . apply ( [ ] , ( result . map ( ( singleCalEvents , i ) => {
661684 return singleCalEvents . map ( evt => new EventClass ( evt , this . config . entities [ i ] ) )
662685 } ) ) )
@@ -702,7 +725,7 @@ class AtomicCalendar extends LitElement {
702725
703726
704727 Promise . all ( calendarUrlList . map ( url =>
705- this . hass . callApi ( 'get' , url [ 0 ] ) ) ) . then ( ( result , i ) => {
728+ this . _hass . callApi ( 'get' , url [ 0 ] ) ) ) . then ( ( result , i ) => {
706729 if ( monthToGet == this . monthToGet )
707730 result . map ( ( eventsArray , i ) => {
708731 this . month . map ( m => {
@@ -798,7 +821,7 @@ class AtomicCalendar extends LitElement {
798821 return html `
799822 < div class ="calTitle ">
800823 < a href ="https://calendar.google.com/calendar/r/month/${ moment ( this . selectedMonth ) . format ( 'YYYY' ) } /${ moment ( this . selectedMonth ) . format ( 'MM' ) } /1 " style ="text-decoration: none; color: ${ this . config . titleColor } " target ="_blank ">
801- ${ moment ( this . selectedMonth ) . locale ( this . hass . language ) . format ( 'MMMM' ) } ${ moment ( this . selectedMonth ) . format ( 'YYYY' ) }
824+ ${ moment ( this . selectedMonth ) . locale ( this . _hass . language ) . format ( 'MMMM' ) } ${ moment ( this . selectedMonth ) . format ( 'YYYY' ) }
802825 </ a >
803826 </ div >
804827 < div class ="calButtons ">
@@ -875,6 +898,7 @@ class AtomicCalendar extends LitElement {
875898 </ div >
876899 `
877900 }
901+
878902}
879903
880904
@@ -1041,4 +1065,24 @@ class EventClass {
10411065 get link ( ) {
10421066 return this . eventClass . htmlLink
10431067 }
1068+
1069+
1070+
10441071}
1072+
1073+
1074+
1075+
1076+
1077+
1078+
1079+
1080+
1081+
1082+
1083+
1084+
1085+
1086+
1087+
1088+
0 commit comments