Skip to content

Commit

Permalink
feat: add config for date range (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
idaho committed Dec 13, 2023
1 parent 8786a2d commit 3f9a970
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ All the options are available in the lovelace editor but you can use `yaml` if y
| `entity` | string | Required | Entity |
| `layout` | string | Optional | Layout of the card. Vertical, horizontal and default layout are supported |
| `fill_container` | boolean | `false` | Fill container or not. Useful when card is in a grid, vertical or horizontal layout |
| `next_days` | number | 2 | How many times the card will look into the future to find the next event |
| `settings` | [Settings](#settings) | Required | Settings to detect the kind of trash and how to display |


Expand Down
6 changes: 5 additions & 1 deletion src/cards/trash-card/trash-card-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { EntitySharedConfig } from 'lovelace-mushroom/src/shared/config/ent
import { layoutStruct } from 'lovelace-mushroom/src/utils/layout';
import type { LovelaceCardConfig } from 'lovelace-mushroom/src/ha';
import { lovelaceCardConfigStruct } from 'lovelace-mushroom/src/shared/config/lovelace-card-config';
import { assign, boolean, object, optional, string } from 'superstruct';
import { assign, boolean, integer, object, optional, string } from 'superstruct';

export interface TrashItem {
label?: string;
Expand All @@ -22,6 +22,8 @@ EntityWithOutIcon & {
others?: TrashItem;
};
// eslint-disable-next-line @typescript-eslint/naming-convention
next_days?: number;
// eslint-disable-next-line @typescript-eslint/naming-convention
full_size?: boolean;
};

Expand All @@ -35,6 +37,8 @@ export const entityCardConfigStruct = assign(
fill_container: optional(boolean()),
// eslint-disable-next-line @typescript-eslint/naming-convention
full_size: optional(boolean()),
// eslint-disable-next-line @typescript-eslint/naming-convention
next_days: optional(integer()),
settings: optional(
object({
organic: optional(
Expand Down
17 changes: 16 additions & 1 deletion src/cards/trash-card/trash-card-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const TRASH_LABELS = new Set([
'others.pattern'
]);

// eslint-disable-next-line @typescript-eslint/naming-convention
const OTHER_LABELS = new Set([
'next_days'
]);

// eslint-disable-next-line @typescript-eslint/naming-convention
const SCHEMA: HaFormSchema[] = [
{ name: 'entity', selector: { entity: { domain: 'calendar' }}},
Expand Down Expand Up @@ -136,7 +141,14 @@ const SCHEMA: HaFormSchema[] = [
schema: [
// eslint-disable-next-line @typescript-eslint/naming-convention
{ name: 'layout', selector: { mush_layout: {}}},
{ name: 'fill_container', selector: { boolean: {}}}
{ name: 'fill_container', selector: { boolean: {}}},
{ name: 'next_days',
selector: { number: {
min: 1,
max: 365,
step: 1,
mode: 'box'
}}}
]
}
];
Expand Down Expand Up @@ -192,6 +204,9 @@ export class TrashCardEditor extends LitElement implements LovelaceCardEditor {
if (schema.label && TRASH_LABELS.has(schema.label)) {
return customLocalize(`editor.card.trash.${schema.label}`);
}
if (schema.label && OTHER_LABELS.has(schema.label)) {
return customLocalize(`editor.card.generic.${schema.label}`);
}

return this.hass.localize(`ui.panel.lovelace.editor.card.generic.${schema.name}`);
};
Expand Down
2 changes: 1 addition & 1 deletion src/cards/trash-card/trash-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class TrashCard extends LitElement implements LovelaceCard {
const today = new Date();
const endDate = new Date();

endDate.setDate(endDate.getDate() + 2);
endDate.setDate(endDate.getDate() + (this.config?.next_days ?? 2));

const start = this.getDayFromDate(today);
const end = this.getDayFromDate(endDate);
Expand Down
3 changes: 2 additions & 1 deletion src/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"generic": {
"icon_color": "Icon-Farbe",
"layout": "Layout",
"fill_container": "Container ausfüllen"
"fill_container": "Container ausfüllen",
"next_days": "Tage in der Zukunft"
},
"trash": {
"organic": {
Expand Down
3 changes: 2 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"generic": {
"icon_color": "Icon color",
"layout": "Layout",
"fill_container": "Fill container"
"fill_container": "Fill container",
"next_days": "Days in the future"
},
"trash": {
"organic": {
Expand Down
3 changes: 2 additions & 1 deletion src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"generic": {
"icon_color": "Couleur de l'icône",
"layout": "Disposition",
"fill_container": "Remplir le conteneur"
"fill_container": "Remplir le conteneur",
"next_days": "Jours dans le futur"
},
"trash": {
"organic": {
Expand Down
3 changes: 2 additions & 1 deletion src/translations/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"generic": {
"icon_color": "Farba ikony",
"layout": "Rozloženie",
"fill_container": "Naplňte nádobu"
"fill_container": "Naplňte nádobu",
"next_days": "Dni v budúcnosti"
},
"trash": {
"organic": {
Expand Down

0 comments on commit 3f9a970

Please sign in to comment.