Skip to content
3 changes: 3 additions & 0 deletions .homeychangelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,8 @@
},
"3.3.2": {
"en": "Dependency updates"
},
"3.3.3": {
"en": "Widget improvements: Fixed height option, auto-sync when new appointments are received, show per-calendar, height re-adjusts after (auto)refreshing."
}
}
2 changes: 1 addition & 1 deletion .homeycompose/app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "no.runely.calendar",
"version": "3.3.2",
"version": "3.3.3",
"compatibility": ">=12.9.0",
"sdk": 3,
"platforms": [
Expand Down
50 changes: 49 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_comment": "This file is generated. Please edit .homeycompose/app.json instead.",
"id": "no.runely.calendar",
"version": "3.3.2",
"version": "3.3.3",
"compatibility": ">=12.9.0",
"sdk": 3,
"platforms": [
Expand Down Expand Up @@ -6072,6 +6072,23 @@
},
"height": 400,
"settings": [
{
"id": "calendarToShow",
"type": "autocomplete",
"title": {
"en": "Calendar to show",
"no": "Kalender å vise",
"nl": "Kalender om te tonen",
"de": "Anzuzeigender Kalender",
"sv": "Kalender att visa",
"fr": "Calendrier à afficher",
"it": "Calendario da mostrare",
"es": "Calendario para mostrar",
"da": "Kalender at vise",
"pl": "Kalendarz do wyświetlenia",
"ko": "표시할 캘린더"
}
},
{
"id": "daysAhead",
"type": "number",
Expand Down Expand Up @@ -6209,6 +6226,37 @@
"value": 400,
"min": 150,
"max": 5000
},
{
"id": "useFixedHeight",
"type": "checkbox",
"title": {
"en": "Use fixed height",
"no": "Bruk fast høyde",
"nl": "Gebruik vaste hoogte",
"de": "Feste Höhe verwenden",
"sv": "Använd fast höjd",
"fr": "Utiliser une hauteur fixe",
"it": "Usa altezza fissa",
"es": "Usar altura fija",
"da": "Brug fast højde",
"pl": "Użyj stałej wysokości",
"ko": "고정 높이 사용"
},
"hint": {
"en": "Use fixed height (defined in Max Height).",
"no": "Bruk fast høyde (definert i Maks høyde).",
"nl": "Gebruik vaste hoogte (zoals gedefinieerd in Max Hoogte).",
"de": "Verwenden Sie eine feste Höhe (definiert in Maximalhöhe).",
"sv": "Använd fast höjd (definierad i Maxhöjd).",
"fr": "Utiliser une hauteur fixe (définie dans Hauteur Max).",
"it": "Usa un'altezza fissa (definita in Altezza Massima).",
"es": "Usar altura fija (definida en Altura Máxima).",
"da": "Brug fast højde (defineret i Maksimal Højde).",
"pl": "Użyj stałej wysokości (zdefiniowanej w Maksymalnej Wysokości).",
"ko": "최대 높이에서 정의된 고정 높이를 사용하세요."
},
"value": false
}
],
"api": {
Expand Down
28 changes: 23 additions & 5 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import sourceMapSupport from "source-map-support";

sourceMapSupport.install();

import type { Widget } from "homey";
import Homey from "homey";
import { DateTime } from "luxon";

Expand All @@ -22,14 +23,11 @@ import { varMgmt } from "./lib/variable-management.js";
import type { Calendar, SyncInterval } from "./types/IcalCalendar.type";
import type { VariableManagement } from "./types/VariableMgmt.type";

// The SDK Widget type is missing the emit method — narrow to just what we need.
type WidgetWithEmit = { emit(event: string): void };

const WIDGET_ID: string = "next-events";

let variableMgmt: VariableManagement | null = null;

class IcalCalendar extends Homey.App {
export class IcalCalendar extends Homey.App {
/**
* onInit is called when the app is initialized.
*/
Expand Down Expand Up @@ -72,6 +70,26 @@ class IcalCalendar extends Homey.App {
// setup actions
setupActions(this, variableMgmt);

const widget = this.homey.dashboards.getWidget(WIDGET_ID);

widget.registerSettingAutocompleteListener(
"calendarToShow",
async (query: string, _settings): Promise<Widget.SettingAutocompleteResults> => {
const results = [{ id: "", name: this.homey.__("calendar.all") }] as Widget.SettingAutocompleteResults;
const calendarsFiltered = this.getCalendars().filter(item =>
item.name.toLowerCase().includes(query.toLowerCase())
);

if (calendarsFiltered.length > 0) {
for (let IcalCalendar = 0; IcalCalendar < calendarsFiltered.length; IcalCalendar++) {
const calendar = calendarsFiltered[IcalCalendar];
results.push({ name: calendar.name });
}
}
return results;
}
Comment on lines +77 to +90

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are sending back way too much in results.. this.getCalendars() returns an array of calendars with their name and all of their events..

Also, don't use any. It defeats the purpose of using TypeScript!

);

this.log("onInit: Triggering getEvents and reregistering tokens");
getEvents(this, variableMgmt, true)
.then(() => this.broadcastCalendarUpdate())
Expand Down Expand Up @@ -355,7 +373,7 @@ class IcalCalendar extends Homey.App {

broadcastCalendarUpdate(): void {
try {
(this.homey.dashboards.getWidget(WIDGET_ID) as unknown as WidgetWithEmit).emit("update");
this.homey.api.realtime("update", null);
} catch (error) {
// widget may not be registered yet on first boot
this.error(`[WARN] broadcastCalendarUpdate: failed to emit 'update' for '${WIDGET_ID}' ->`, error);
Expand Down
7 changes: 5 additions & 2 deletions handlers/setup-actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { App, FlowCard, FlowCardAction } from "homey";
import type { FlowCard, FlowCardAction } from "homey";
import type { IcalCalendar } from "../app.js";

import { calendarAutocomplete } from "../lib/autocomplete.js";
import { newLocalEvent } from "../lib/generate-event-object.js";
Expand All @@ -21,7 +22,7 @@ const getDateTime = (value: string): string | null => {
return Array.isArray(match) && match.length > 0 ? match[0].toUpperCase() : null;
};

export const setupActions = (app: App, variableMgmt: VariableManagement): void => {
export const setupActions = (app: IcalCalendar, variableMgmt: VariableManagement): void => {
// register run listener on action flow cards
app.homey.flow.getActionCard("sync-calendar").registerRunListener(async (_, __) => {
app.log(
Expand All @@ -33,6 +34,8 @@ export const setupActions = (app: App, variableMgmt: VariableManagement): void =
throw new Error(getEventsFinished.join("\n\n"));
}

app.broadcastCalendarUpdate();

return true;
});

Expand Down
3 changes: 3 additions & 0 deletions locales/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@
"many": "__count__ aftaler"
}
}
},
"calendar": {
"all": "Alle"
}
}
3 changes: 3 additions & 0 deletions locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@
"many": "__count__ Termine"
}
}
},
"calendar": {
"all": "Alle"
}
}
3 changes: 3 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@
"many": "__count__ appointments"
}
}
},
"calendar": {
"all": "All"
}
}
3 changes: 3 additions & 0 deletions locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@
"many": "__count__ citas"
}
}
},
"calendar": {
"all": "Todo"
}
}
3 changes: 3 additions & 0 deletions locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@
"many": "__count__ rendez-vous"
}
}
},
"calendar": {
"all": "Tout"
}
}
3 changes: 3 additions & 0 deletions locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@
"many": "__count__ appuntamenti"
}
}
},
"calendar": {
"all": "Tutto"
}
}
3 changes: 3 additions & 0 deletions locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@
"many": "약속 __count__개"
}
}
},
"calendar": {
"all": "모두"
}
}
3 changes: 3 additions & 0 deletions locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@
"many": "__count__ afspraken"
}
}
},
"calendar": {
"all": "Alles"
}
}
3 changes: 3 additions & 0 deletions locales/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@
"many": "__count__ avtaler"
}
}
},
"calendar": {
"all": "Alle"
}
}
3 changes: 3 additions & 0 deletions locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@
"many": "__count__ spotkań"
}
}
},
"calendar": {
"all": "Wszystko"
}
}
3 changes: 3 additions & 0 deletions locales/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@
"many": "__count__ möten"
}
}
},
"calendar": {
"all": "Alla"
}
}
6 changes: 5 additions & 1 deletion widgets/next-events/api.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ const MS_PER_DAY: number = 24 * 60 * 60 * 1000;

export default {
async getEvents({ homey, query }: ReqNoBody): Promise<CalendarWidgetEvent[]> {
const calendarToShow: string = query.calendarToShow;
const app = homey.app as unknown as App;
const calendars = app.getCalendars();
let calendars = app.getCalendars();
if (calendars.length === 0) {
return [];
}
if (calendarToShow && calendarToShow!=='') {
calendars = calendars.filter(x=>x.name===calendarToShow);
}

const colors = app.getCalendarColors();

Expand Down
Loading