Skip to content

Commit

Permalink
Merge pull request #6 from FamousWolf/1-card-mod-not-applied
Browse files Browse the repository at this point in the history
[BUGFIX] Fix config update and cleanup
  • Loading branch information
FamousWolf authored Mar 14, 2024
2 parents 80be93a + 0217b94 commit d4ef70f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Custom Home Assistant card displaying a responsive overview of multiple days wit
Add:
```yaml
resources:
- url: /local/week-planner-card.js?version=1.0.0
- url: /local/week-planner-card.js?version=1.0.1
type: module
```
- **Using the graphical editor**
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "week-planner-card",
"version": "1.0.0",
"version": "1.0.1",
"description": "Custom Home Assistant card to display events for a number of days from one or several calendars.",
"source": "src/index.js",
"module": "dist/week-planner-card.js",
Expand Down
50 changes: 25 additions & 25 deletions src/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import moment from 'moment';
export class WeekPlannerCard extends LitElement {
static styles = styles;

_hass;
_loading = 0;
_events = {};
_jsonDays = '';
_calendars;
_numberOfDays;
_updateInterval;
_noCardBackground;
_eventBackground;
_language;

/**
* Get properties
Expand All @@ -17,13 +22,8 @@ export class WeekPlannerCard extends LitElement {
*/
static get properties() {
return {
_calendars: { type: Array, state: true },
_numberOfDays: { type: Number, state: true },
_days: { type: Array, state: true },
_updateInterval: { type: Number, state: true },
_noCardBackground: { type: Boolean, state: true },
_eventBackground: { type: String, state: true },
_language: { type: Object, state: true }
_days: { type: Array },
_config: { type: Object }
}
}

Expand All @@ -33,6 +33,8 @@ export class WeekPlannerCard extends LitElement {
* @param {Object} config
*/
setConfig(config) {
this._config = config;

if (!config.calendars) {
throw new Error('No calendars are configured');
}
Expand Down Expand Up @@ -61,23 +63,14 @@ export class WeekPlannerCard extends LitElement {
);
}

/**
* Set hass
*
* @param {Object} hass
*/
set hass(hass) {
this._hass = hass;

this._updateEvents();
}

/**
* Render
*
* @return {Object}
*/
render() {
this._waitForHassAndConfig();

return html`
<ha-card class="${this._noCardBackground ? 'nobackground' : ''}" style="--event-background-color: ${this._eventBackground}">
<div class="card-content">
Expand Down Expand Up @@ -137,24 +130,31 @@ export class WeekPlannerCard extends LitElement {
`;
}

_updateEvents() {
if (this._loading > 0) {
_waitForHassAndConfig() {
if (!this.hass || !this._calendars) {
window.setTimeout(() => {
this._waitForHassAndConfig();
}, 50)
return;
}
this._loading++;

this._events = {};
this._updateEvents();
}

if (!this._calendars) {
_updateEvents() {
if (this._loading > 0) {
return;
}

this._loading++;
this._events = {};

let startDate = moment().startOf('day');
let endDate = moment().startOf('day').add(this._numberOfDays, 'days');

this._calendars.forEach(calendar => {
this._loading++;
this._hass.callApi(
this.hass.callApi(
'get',
'calendars/' + calendar.entity + '?start=' + startDate.format('YYYY-MM-DD[T]HH:mm:ss[Z]') + '&end=' + endDate.format('YYYY-MM-DD[T]HH:mm:ss[Z]')
).then(response => {
Expand Down

0 comments on commit d4ef70f

Please sign in to comment.