Skip to content

Commit 6b60b12

Browse files
authoredNov 20, 2024
Merge pull request #195 from FamousWolf/dev
[MERGE] Changes for 1.10.0
2 parents 4481805 + 93d6cd3 commit 6b60b12

File tree

8 files changed

+422
-22
lines changed

8 files changed

+422
-22
lines changed
 

‎README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Custom Home Assistant card displaying a responsive overview of multiple days wit
3939
Add:
4040
```yaml
4141
resources:
42-
- url: /local/week-planner-card.js?version=1.9.0
42+
- url: /local/week-planner-card.js?version=1.10.0
4343
type: module
4444
```
4545
- **Using the graphical editor**
@@ -79,6 +79,7 @@ Custom Home Assistant card displaying a responsive overview of multiple days wit
7979
| `hideDaysWithoutEvents` | boolean | false | `false` \| `true` | Do not show days without events, except for today | 1.4.0 |
8080
| `hideTodayWithoutEvents` | boolean | false | `false` \| `true` | Also do not show today without events if `hideDaysWithoutEvents` is set | 1.8.0 |
8181
| `filter` | string | optional | Any regular expression | Remove events that match the regular expression | 1.7.0 |
82+
| `filterText` | string | optional | Any regular expression | Remove text from events | 1.10.0 |
8283
| `combineSimilarEvents` | boolean | false | `false` \| `true` | Combine events with the same start date/time, end date/time and title | 1.9.0 |
8384
| `showLegend` | boolean | false | `false` \| `true` | Show calendar legend | 1.7.0 |
8485

@@ -89,7 +90,9 @@ Custom Home Assistant card displaying a responsive overview of multiple days wit
8990
| `entity` | string | **Required** | `calendar.my_calendar` | Entity ID | 1.0.0 |
9091
| `name` | string | optional | Any text | Name of the calendar | 1.7.0 |
9192
| `color` | string | optional | Any CSS color | Color used for events from the calendar | 1.0.0 |
93+
| `icon` | string | optional | Any icon | Icon used for events from the calendar | 1.10.0 |
9294
| `filter` | string | optional | Any regular expression | Remove events that match the regular expression | 1.8.0 |
95+
| `filterText` | string | optional | Any regular expression | Remove text from events | 1.10.0 |
9396
| `hideInLegend` | boolean | false | `false` \| `true` | Do not show the calendar in the legend | 1.8.0 |
9497

9598
### Texts

‎package-lock.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "week-planner-card",
3-
"version": "1.9.0",
3+
"version": "1.10.0",
44
"description": "Custom Home Assistant card to display events for a number of days from one or several calendars.",
55
"source": "src/index.js",
66
"module": "dist/week-planner-card.js",

‎src/card.js

+93-14
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,51 @@ export class WeekPlannerCard extends LitElement {
7878
_hideDaysWithoutEvents;
7979
_hideTodayWithoutEvents;
8080
_filter;
81+
_filterText;
8182
_combineSimilarEvents;
8283
_showLegend;
8384
_actions;
8485

86+
/**
87+
* Get config element
88+
*
89+
* @returns {HTMLElement}
90+
*/
91+
static getConfigElement() {
92+
// Create and return an editor element
93+
return document.createElement("week-planner-card-editor");
94+
}
95+
96+
/**
97+
* Get stub config
98+
*
99+
* @returns {}
100+
*/
101+
static getStubConfig() {
102+
return {
103+
calendars: [],
104+
days: 7,
105+
startingDay: 'today',
106+
startingDayOffset: 0,
107+
hideWeekend: false,
108+
noCardBackground: false,
109+
compact: false,
110+
weather: {
111+
showCondition: true,
112+
showTemperature: false,
113+
showLowTemperature: false,
114+
useTwiceDaily: false,
115+
},
116+
locale: 'en',
117+
showLocation: false,
118+
hidePastEvents: false,
119+
hideDaysWithoutEvents: false,
120+
hideTodayWithoutEvents: false,
121+
combineSimilarEvents: false,
122+
showLegend: false
123+
};
124+
}
125+
85126
/**
86127
* Get properties
87128
*
@@ -130,6 +171,7 @@ export class WeekPlannerCard extends LitElement {
130171
this._hideDaysWithoutEvents = config.hideDaysWithoutEvents ?? false;
131172
this._hideTodayWithoutEvents = config.hideTodayWithoutEvents ?? false;
132173
this._filter = config.filter ?? false;
174+
this._filterText = config.filterText ?? false;
133175
this._combineSimilarEvents = config.combineSimilarEvents ?? false;
134176
this._showLegend = config.showLegend ?? false;
135177
this._actions = config.actions ?? false;
@@ -177,6 +219,10 @@ export class WeekPlannerCard extends LitElement {
177219
Object.assign(configuration, weatherConfiguration);
178220
}
179221

222+
if (!configuration.hasOwnProperty('entity') || configuration.entity === null) {
223+
return null;
224+
}
225+
180226
return configuration;
181227
}
182228

@@ -235,7 +281,11 @@ export class WeekPlannerCard extends LitElement {
235281
${this._calendars.map((calendar) => {
236282
if (!calendar.hideInLegend) {
237283
return html`
238-
<li style="--legend-calendar-color: ${calendar.color}">
284+
<li class="${calendar.icon ? 'icon' : 'noIcon'}" style="--legend-calendar-color: ${calendar.color}">
285+
${calendar.icon ?
286+
html`<ha-icon icon="${calendar.icon}"></ha-icon>` :
287+
''
288+
}
239289
${calendar.name ?? calendar.entity}
240290
</li>
241291
`;
@@ -339,26 +389,34 @@ export class WeekPlannerCard extends LitElement {
339389
<div class="inner">
340390
<div class="time">
341391
${event.fullDay ?
342-
html`${this._language.fullDay}` :
343-
html`
344-
${event.start.toFormat(this._timeFormat)}
345-
${event.end ? ' - ' + event.end.toFormat(this._timeFormat) : ''}
346-
`
392+
html`${this._language.fullDay}` :
393+
html`
394+
${event.start.toFormat(this._timeFormat)}
395+
${event.end ? ' - ' + event.end.toFormat(this._timeFormat) : ''}
396+
`
347397
}
348398
</div>
349399
<div class="title">
350400
${event.summary}
351401
</div>
352402
${this._showLocation && event.location ?
353-
html`
354-
<div class="location">
355-
<ha-icon icon="mdi:map-marker"></ha-icon>
356-
${event.location}
357-
</div>
358-
` :
359-
''
403+
html`
404+
<div class="location">
405+
<ha-icon icon="mdi:map-marker"></ha-icon>
406+
${event.location}
407+
</div>
408+
` :
409+
''
360410
}
361411
</div>
412+
${event.icon ?
413+
html`
414+
<div class="icon">
415+
<ha-icon icon="${event.icon}"></ha-icon>
416+
</div>
417+
` :
418+
''
419+
}
362420
</div>
363421
`
364422
}
@@ -523,6 +581,10 @@ export class WeekPlannerCard extends LitElement {
523581

524582
let calendarNumber = 0;
525583
this._calendars.forEach(calendar => {
584+
if (!calendar.entity || !this.hass.states[calendar.entity]) {
585+
return;
586+
}
587+
526588
if (!calendar.name) {
527589
calendar = {
528590
...calendar,
@@ -616,7 +678,7 @@ export class WeekPlannerCard extends LitElement {
616678
}
617679
} else {
618680
this._calendarEvents[eventKey] = {
619-
summary: event.summary ?? null,
681+
summary: this._filterEventSummary(event.summary ?? null, calendar),
620682
description: event.description ?? null,
621683
location: event.location ?? null,
622684
start: startDate,
@@ -625,6 +687,7 @@ export class WeekPlannerCard extends LitElement {
625687
originalEnd: this._convertApiDate(event.end),
626688
fullDay: fullDay,
627689
color: calendar.color ?? 'inherit',
690+
icon: calendar.icon ?? null,
628691
otherColors: [],
629692
calendar: calendar.entity,
630693
otherCalendars: [],
@@ -636,6 +699,22 @@ export class WeekPlannerCard extends LitElement {
636699
}
637700
}
638701

702+
_filterEventSummary(summary, calendar) {
703+
if (!summary) {
704+
return '';
705+
}
706+
707+
if (calendar.filterText) {
708+
summary = summary.replace(new RegExp(calendar.filterText), '');
709+
}
710+
711+
if (this._filterText) {
712+
summary = summary.replace(new RegExp(this._filterText), '');
713+
}
714+
715+
return summary;
716+
}
717+
639718
_getEventClass(startDate, endDate, fullDay) {
640719
let classes = [];
641720
let now = DateTime.now();

‎src/card.styles.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ export default css`
6868
6969
.container .legend ul li {
7070
display: block;
71+
--mdc-icon-size: 16px;
72+
}
73+
74+
.container .legend ul li ha-icon {
75+
color: var(--legend-calendar-color, var(--divider-color, #ffffff));
7176
}
7277
73-
.container .legend ul li:before {
78+
.container .legend ul li.noIcon:before {
7479
content: '';
7580
display: inline-block;
7681
width: var(--legend-dot-size);
@@ -159,6 +164,10 @@ export default css`
159164
background-color: var(--event-additional-color);
160165
}
161166
167+
.container .day .events .event .icon {
168+
padding: var(--event-padding);
169+
}
170+
162171
.container .day .events .event .inner {
163172
flex-grow: 1;
164173
padding: var(--event-padding);

0 commit comments

Comments
 (0)