Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

Commit

Permalink
dependencies fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
atomic7777 committed Jun 18, 2019
1 parent 8c07b42 commit 2face8b
Show file tree
Hide file tree
Showing 12 changed files with 1,093 additions and 1,188 deletions.
5 changes: 2 additions & 3 deletions .babelrc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"@babel/preset-env",
{
"modules": false,
"targets": {
"esmodules": true
}
"targets": "> 2.5%, not dead"

}
],
["minify"]
Expand Down
Empty file modified .eslintrc.js
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
30 changes: 8 additions & 22 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# atomic calendar card v0.7.9
# atomic calendar card v0.7.5
Advanced calendar card for Home Assistant with Lovelace

Calendar card with advanced settings. It loads calendar events from Home Assistant - Google calendar component.
Expand Down Expand Up @@ -64,11 +64,6 @@ If you have any suggestions about design or functionality, please let me know, o
| dateFormat | string | optional | v0.7.2 | `LL` Custom date format - see https://devhints.io/moment for examples
| hoursFormat | string | optional | v0.7.3 | `default` Custom hours format - you can set `12h` or `24h` or `default` (default for local HA language settings) or even provide your custom, like `HH:mm` or `h:mm A` - see https://devhints.io/moment for examples
| startDaysAhead | integer | optional | v0.7.3 | `0` If you set more than 0, events will be loaded starting `x` days from today. For example `1` - the component will show events starting from tomorrow.
| showHours | boolean | optional | v0.7.6 | `true` Show the time od duration of event (the bottom line)
| showCalNameInEvent | boolean | optional | v0.7.6 | `false` Show calendar name in event title, to distinguish between multiple calendars
| showNoEventsForToday | boolean | optional | v0.7.6 | `false` Show "no events for today" if no events (configurable text)
| noEventsForTodayText | string | optional | v0.7.6 | `No events for today` "no events for today" text, if showNoEventsForToday is enabled


### Text colors and fonts
| Name | Type | Since | Description |
Expand Down Expand Up @@ -99,13 +94,6 @@ If you have any suggestions about design or functionality, please let me know, o
| showProgressBar | boolean | optional | v0.5.5 | `true` Show event progress with moving icon. Don't enable when showCurrentEventLine - will look bad
| progressBarColor | string | v0.5.5 | `default color` Color of progress bar

### Entity options (configurations for each calendar)
| Name | Type | Since | Description |
|------|:----:|:-----:|-------------|
| type | string | optional | v0.5.5 | `` Type of calendar (in calendar mode) Icon1, Icon2, Icon3, Birthday. Explained below.
| blacklist | string | v0.7.9 | `` List of comma separated blacklisted keywords. Events containing any of them will not be shown.


## 3. Calendar Mode
The second mode of view - calendar mode - is to show full month calendar with simple events icons or colors, for most important, infrequent events, like holiday or birthday.
You can change mode by clicking "Calendar" title, or even make it default view.
Expand Down Expand Up @@ -219,21 +207,19 @@ This card will show maximum 5 events from each calendar. It's because of Home As

1. Go to your Home Assistant config directory (where you have configuration.yaml file)
2. Create a subdirectory `custom_components/google` and go inside:
3. Download files. Important: in Home Assistant 92.0 and above all 4 files are needed! It will be ignored if you have only calendar.py.
![calendar.py](https://raw.githubusercontent.com/home-assistant/home-assistant/master/homeassistant/components/google/calendar.py)
![services.yaml](https://raw.githubusercontent.com/home-assistant/home-assistant/master/homeassistant/components/google/services.yaml)
![manifest.json](https://raw.githubusercontent.com/home-assistant/home-assistant/master/homeassistant/components/google/manifest.json)
3. Download files. Important: in Home Assistant 89.0 and above all 3 files are needed! It will be ignored if you have only calendar.py. ![Google.py](https://raw.githubusercontent.com/home-assistant/home-assistant/master/homeassistant/components/google/calendar.py)
![__init__.py](https://raw.githubusercontent.com/home-assistant/home-assistant/master/homeassistant/components/google/__init__.py)
![tts.py](https://raw.githubusercontent.com/home-assistant/home-assistant/master/homeassistant/components/google/tts.py)


```
mkdir -p custom_components/google
cd custom_components/google
mkdir -p custom_components/calendar
cd custom_components/calendar
wget https://raw.githubusercontent.com/home-assistant/home-assistant/master/homeassistant/components/google/calendar.py
wget https://raw.githubusercontent.com/home-assistant/home-assistant/master/homeassistant/components/google/services.yaml
wget https://raw.githubusercontent.com/home-assistant/home-assistant/master/homeassistant/components/google/manifest.json
wget https://raw.githubusercontent.com/home-assistant/home-assistant/master/homeassistant/components/google/__init__.py
wget https://raw.githubusercontent.com/home-assistant/home-assistant/master/homeassistant/components/google/tts.py
```
4. Open the calendar.py file with text editor and change ``'maxResults': 5,`` to anything you want.
4. Open the Google.py file with text editor and change ``'maxResults': 5,`` to anything you want.
5. Save the file and restart Home Assistant.
## 7. Automatic update
Expand Down
73 changes: 22 additions & 51 deletions app.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class AtomicCalendar extends LitElement {
this.firstrun = true;
}



static get properties() {
return {
hass: Object,
Expand All @@ -32,15 +30,10 @@ class AtomicCalendar extends LitElement {
selectedMonth: Object
}
}



updated() {}

render() {


if(this.firstrun){
if(this.firstrun){
let timeFormat = moment.localeData(this.hass.language).longDateFormat('LT')
if (this.config.hoursFormat=='12h') timeFormat = 'h:mm A'
else if (this.config.hoursFormat=='24h') timeFormat = 'H:mm'
Expand All @@ -53,11 +46,8 @@ class AtomicCalendar extends LitElement {
LT: timeFormat
}
});
let timeOffset = new Date().getTimezoneOffset()
let start = moment().add(this.config.startDaysAhead, 'days').startOf('day').format('YYYY-MM-DDTHH:mm:ss');
let end = moment().add((this.config.maxDaysToShow + this.config.startDaysAhead), 'days').endOf('day').format('YYYY-MM-DDTHH:mm:ss');
this.firstrun=false
console.log("atomic_calendar v0.7.9 loaded")
console.log("atomic_calendar v0.8.1b loaded")
}


Expand Down Expand Up @@ -94,7 +84,7 @@ class AtomicCalendar extends LitElement {
<ha-card class="cal-card">
<div class="cal-titleContainer">
<div class="cal-title" @click='${e => this.handleToggle(e)}'>
<div class="cal-title" @click='${e => this.handleToggle()}'>
${this.config.title}
</div>
Expand All @@ -116,19 +106,14 @@ class AtomicCalendar extends LitElement {
</div>
</ha-card>`
}

static get styles() {

}

firstTimeConfig() {


}



handleToggle(e) {
handleToggle() {
if (this.config.enableModeChange) {
this.modeToggle == 1 ? this.modeToggle = 2 : this.modeToggle = 1
this.requestUpdate()
Expand Down Expand Up @@ -495,8 +480,7 @@ class AtomicCalendar extends LitElement {
* generate Event Title (summary) HTML
*
*/
getTitleHTML(event, isEventNext) {

getTitleHTML(event) {
const titletext = (this.config.showCalNameInEvent) ? event.eventClass.organizer.displayName+": " + event.title : event.title

const titleColor = (this.config.showColors && typeof event.config.titleColor != 'undefined') ? event.config.titleColor : this.config.titleColor
Expand Down Expand Up @@ -623,7 +607,7 @@ class AtomicCalendar extends LitElement {
<div>${currentEventLine}</div>
<div class="event-right">
<div class="event-main" >
${this.getTitleHTML(event,isEventNext)}
${this.getTitleHTML(event)}
${hoursHTML}
</div>
<div class="event-location">
Expand Down Expand Up @@ -654,7 +638,7 @@ class AtomicCalendar extends LitElement {
.replace(locale.format('YYYY'), '') // remove year
.replace(/\s\s+/g, ' ') // remove double spaces, if any
.trim() // remove spaces from the start and the end
.replace(/[рг]\./, '') // remove year letter from RU/UK locales
.replace(/[??]\./, '') // remove year letter from RU/UK locales
.replace(/de$/, '') // remove year prefix from PT
.replace(/b\.$/, '') // remove year prefix from SE
.trim() // remove spaces from the start and the end
Expand All @@ -668,12 +652,14 @@ class AtomicCalendar extends LitElement {
* @return {bool}
*/
checkFilter(str, filter) {
if(typeof filter != 'undefined' && filter!=''){
const keywords = filter.split(',')
return (keywords.some((keyword) => {
if (RegExp('(?:^|\\s)' + keyword.trim(), 'i').test(str))
return true
else return false
}))
} else return false

}

Expand All @@ -688,30 +674,16 @@ class AtomicCalendar extends LitElement {
let start = moment().add(this.config.startDaysAhead, 'days').startOf('day').add(timeOffset,'minutes').format('YYYY-MM-DDTHH:mm:ss');
let end = moment().add((this.config.maxDaysToShow + this.config.startDaysAhead), 'days').endOf('day').add(timeOffset,'minutes').format('YYYY-MM-DDTHH:mm:ss');
let calendarUrlList = []
this.config.entities.map(entity =>
calendarUrlList.push([`calendars/${entity.entity}?start=${start}Z&end=${end}Z`, entity.blacklist ])
)
this.config.entities.map(entity =>{
calendarUrlList.push([`calendars/${entity.entity}?start=${start}Z&end=${end}Z`])
})
try {
return await (Promise.all(calendarUrlList.map(url =>
this.hass.callApi('get', url[0]))).then((result, n) => {
this.hass.callApi('get', url[0]))).then((result) => {
let ev = [].concat.apply([], (result.map((singleCalEvents, i) => {
let singleEvent = []
let blacklist = calendarUrlList[1][1]
singleCalEvents.map(evt => {

if(!blacklist || (blacklist && !this.checkFilter(evt.summary, blacklist))){
singleEvent.push(new EventClass(evt, this.config.entities[i] ))
}


})
return singleEvent
//return singleCalEvents.map(evt => new EventClass(evt, this.config.entities[i], calendarUrlList[1] ))
return singleCalEvents.map(evt => new EventClass(evt, this.config.entities[i]))
})))

// sort events
ev = ev.sort((a, b) => moment(a.startTimeToShow) - moment(b.startTimeToShow))

// grouping events by days, returns object with days and events
const groupsOfEvents = ev.reduce(function (r, a) {
r[a.daysToSort] = r[a.daysToSort] || []
Expand All @@ -732,6 +704,7 @@ class AtomicCalendar extends LitElement {
}



/**
* gets events from HA to Calendar mode
*
Expand All @@ -744,22 +717,22 @@ class AtomicCalendar extends LitElement {
// calendarUrlList[url, type of event configured for this callendar,filters]
let calendarUrlList = []
this.config.entities.map(entity => {
if (entity.type) {
if (typeof entity.type != 'undefined') {
calendarUrlList.push([`calendars/${entity.entity}?start=${start}Z&end=${end}Z`, entity.type,
entity.blacklist ? entity.blacklist : ''
typeof entity.blacklist!= 'undefined' ? entity.blacklist : ''
])
}
})

Promise.all(calendarUrlList.map(url =>
this.hass.callApi('get', url[0]))).then((result, i) => {
this.hass.callApi('get', url[0]))).then((result) => {
if (monthToGet == this.monthToGet)
result.map((eventsArray, i) => {
this.month.map(m => {
const calendarTypes = calendarUrlList[i][1]
const calendarUrl = calendarUrlList[i][0]
const calendarBlacklist = calendarUrlList[i][2]
eventsArray.map((event, i) => {
const calendarBlacklist = (typeof calendarUrlList[i][2] != 'undefined') ? calendarUrlList[i][2] : ''
eventsArray.map((event) => {
const startTime = event.start.dateTime ? moment(event.start.dateTime) : moment(event.start.date).startOf('day')
const endTime = event.end.dateTime ? moment(event.end.dateTime) : moment(event.end.date).subtract(1, 'days').endOf('day')

Expand Down Expand Up @@ -811,9 +784,6 @@ class AtomicCalendar extends LitElement {
buildCalendar(selectedMonth) {
const firstDay = moment(selectedMonth).startOf('month')
const dayOfWeekNumber = firstDay.day()
const startDate = moment(firstDay).add(this.config.firstDayOfWeek - dayOfWeekNumber, 'days')
const endDate = moment(firstDay).add(42 - dayOfWeekNumber + this.config.firstDayOfWeek, 'days')

this.month = [];
let weekShift = 0;
(dayOfWeekNumber - this.config.firstDayOfWeek) >=0 ? weekShift = 0 : weekShift = 7
Expand Down Expand Up @@ -915,7 +885,7 @@ class AtomicCalendar extends LitElement {
const month = this.month
const weekDays = moment.weekdaysMin(true)
const htmlDayNames = weekDays.map((day) => html `
<th class="cal" style="padding-bottom: 8px;">${day}</th>`)
<th class="cal" style="padding-bottom: 8px; color: ${this.config.titleColor};">${day}</th>`)

this.content = html `
<div class="calTitleContainer">
Expand Down Expand Up @@ -1025,6 +995,7 @@ class EventClass {
this._startTime = this.eventClass.start.dateTime ? moment(this.eventClass.start.dateTime) : moment(this.eventClass.start.date).startOf('day')
this._endTime = this.eventClass.end.dateTime ? moment(this.eventClass.end.dateTime) : moment(this.eventClass.end.date).subtract(1, 'days').endOf('day')
this.isFinished = false;

}

get titleColor() {
Expand Down
1 change: 1 addition & 0 deletions atomic_calendar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/atomic_calendar.js

Large diffs are not rendered by default.

Loading

0 comments on commit 2face8b

Please sign in to comment.