Skip to content

Commit

Permalink
Fixed nightly refreshes, fixed issue with custom color rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
robertraaijmakers committed Feb 4, 2025
1 parent e8299a5 commit 05cf1dd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .homeychangelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"en": "Updated APIs for new year. Notice: your municipality might have changed from provider/API and you might need to reconfigure the app.",
"nl": "APIs waar nodig bijgewerkt voor het nieuwe jaar. Let op: het kan zijn dat je gemeente van API gewijzigd is en je zaken opnieuw moet instellen!"
},
"5.0.5": {
"5.0.6": {
"en": "Complete rebuild of the app based on new development best practices from Athom.",
"nl": "De app is volledig opnieuw opgebouwd om nog meer APIs te kunnen ondersteunen in de toekomst."
}
Expand Down
2 changes: 1 addition & 1 deletion .homeycompose/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"nl": "Afval Herinnering 2.0",
"sv": "Avfallspåminnelse 2.0"
},
"version": "5.0.5",
"version": "5.0.6",
"platforms": [
"local"
],
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"nl": "Afval Herinnering 2.0",
"sv": "Avfallspåminnelse 2.0"
},
"version": "5.0.5",
"version": "5.0.6",
"platforms": [
"local"
],
Expand Down
29 changes: 22 additions & 7 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ module.exports = class TrashCollectionReminder extends Homey.App {
*/
async onInit() {
// Update manual input dates when settings change.
this.homey.settings.on('set', this.onSettingsChanged);
this.homey.settings.on('set', (settingName) => {
this.onSettingsChanged(settingName);
});

this.homey.settings.on('set', () => {
this.homey.api.realtime('settings_changed', '{}');
});
Expand Down Expand Up @@ -81,13 +84,9 @@ module.exports = class TrashCollectionReminder extends Homey.App {
this.onUpdateData();
}, 48 * 60 * 60 * 1000);

// Update the labels every 10 minutes
this.homey.setInterval(() => {
this.onUpdateLabel();
}, 10 * 60 * 1000);

// Manually kick off data retrieval
await this.onUpdateData();
await this.dailyRefresh();

this.log('App initialized');
}
Expand Down Expand Up @@ -210,6 +209,9 @@ module.exports = class TrashCollectionReminder extends Homey.App {
this.log('App setings where changed: ', settingName);

// Do something with the fact that the settings where changed
if (settingName === 'labelSettings') {
await this.onUpdateLabel();
}
}

async onUpdateData() {
Expand Down Expand Up @@ -321,7 +323,20 @@ module.exports = class TrashCollectionReminder extends Homey.App {
await this.onUpdateLabel();
}

// Recalculatees the whole set of dates based on the latest settings
async dailyRefresh() {
await this.onUpdateLabel(); // Update labels on daily interval
this.homey.api.realtime('settings_changed', '{}'); // Trigger daily widget refresh

// Set new timeout to midnight
const localDate = await this.getLocalDate();
const msToMidnight = new Date(localDate.getFullYear(), localDate.getMonth(), localDate.getDate() + 1, 0, 0, 0, 0).getTime() - localDate.getTime();

this.homey.setTimeout(() => {
this.dailyRefresh();
}, msToMidnight + 1000);
}

// Recalculates the whole set of dates based on the latest settings
async recalculate() {
await this.onUpdateData();
}
Expand Down
4 changes: 2 additions & 2 deletions widgets/trash-reminder-list/public/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class WidgetScript {
const trashTypeText = this.settings.displayRule === 'trashprovider' ? trashItem.localText || trashItem.settingText : trashItem.settingText;
const trashColor =
this.settings.displayRule === 'settings-iconscolors' || this.settings.displayRule === 'trashprovider'
? `style="color: ${trashItem.color || trashItem.settingColor}"`
: `style="color: ${trashItem.settingColor}"`;
? `style="background-color: ${trashItem.color || trashItem.settingColor}"`
: `style="background-color: ${trashItem.settingColor}"`;

if (this.settings.layoutType === 'large') {
tbody.innerHTML += `
Expand Down

0 comments on commit 05cf1dd

Please sign in to comment.