Skip to content

Commit

Permalink
Add support for displaying 'due today|tomorrow'
Browse files Browse the repository at this point in the history
  • Loading branch information
amaximus committed Sep 8, 2020
1 parent 743a5ac commit 7b0d23b
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 65 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ homeassistant_config_dir/www/community/garbage-collection-card/ directory.<br />

#### Lovelace UI configuration
Configuration parameters:<br />

**entity** (required): name of the sensor of garbage_collection platform.<br />
**due_color** (optional): icon color on due date. Accepts both color names and RGB values. Defaults to red.<br />
**due_1_color** (optional): icon color on the day before due date. Accepts both color names and RGB values. Defaults to due_color.<br />
**icon_color** (optional): icon color. Accepts both color names and RGB values. Defaults to black.<br />
**icon_size** (optional): size of the icon. Defaults to 25px.<br />
**hide_date** (optional): hide date. Defaults to false.<br />
**hide_days** (optional): hide number of days. Defaults to false.<br />
**hide_before** (optional): hide entire card until x days before event. Defaults to not hiding card.<br />
**title_size** (optional): font size for the sensor's friendly name. Defaults to 17px.<br />
**details_size** (optional): font size for date and number of days. Defaults to 14px.<br />
---
| Name | Optional | `Default` | Description |
| :---- | :---- | :------- | :----------- |
| entity | **N** | - | name of the sensor of garbage_collection platform.|
| due_color | **Y**| `red` | icon color on due date. Accepts both color names and RGB values.|
| due_1_color | **Y** | due_color | icon color on the day before due date. Accepts both color names and RGB values.|
| due_txt | **Y** | `false` | For today/tomorrow pick-ups use 'Due today' or 'Due tomorrow'.|
| icon_color | **Y** | `black` | icon color. Accepts both color names and RGB values.|
| icon_size | **Y** | `25px` | size of the icon.|
| hide_date | **Y** | `false` | hide date.|
| hide_days | **Y** | `false`| hide number of days.|
| hide_before | **Y** | `false` | hide entire card until x days before event.|
| title_size | **Y** | `17px` | font size for the sensor's friendly name.|
| details_size | **Y** | `14px `| font size for date and number of days.|
---

Garbage collection cards supports some languages and displays the date information based on your locale setting.

Expand All @@ -42,9 +46,9 @@ Please add the card to the resources in configuration.yaml:

```
resources:
*When using HACS installation method
//When using HACS installation method
- {type: js, url: '/hacsfiles/garbage-collection-card/garbage-collection-card.js'}
*When using manual install method
//When using manual install method
- {type: js, url: '/local/garbage-collection-card.js'}
```

Expand Down
14 changes: 10 additions & 4 deletions dist/cs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"state": {
"today": "Dnes",
"tomorrow": "Zítra"
}
}
"today": "dnes",
"tomorrow": "zítra",
"Today": "Dnes",
"Tomorrow": "Zítra"
},
"other": {
"due": "do",
"Due": "Do",
"due_today_order": "true"
}
11 changes: 9 additions & 2 deletions dist/de.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"state": {
"today": "Heute",
"tomorrow": "Morgen"
"today": "heute",
"tomorrow": "morgen",
"Today": "Heute",
"Tomorrow": "Morgen"
},
"other": {
"due": "fällig",
"Due": "Fällig",
"due_today_order": "false"
}
}
13 changes: 10 additions & 3 deletions dist/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"state": {
"today": "Today",
"tomorrow": "Tomorrow"
"today": "today",
"tomorrow": "tomorrow",
"Today": "Today",
"Tomorrow": "Tomorrow"
},
"other": {
"due": "due",
"Due": "Due",
"due_today_order": "true"
}
}
}
11 changes: 9 additions & 2 deletions dist/es.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"state": {
"today": "Hoy",
"tomorrow": "Mañana"
"today": "hoy",
"tomorrow": "mañana",
"Today": "Hoy",
"Tomorrow": "Mañana"
},
"other": {
"due": "para",
"Due": "Para",
"due_today_order": "true"
}
}
11 changes: 9 additions & 2 deletions dist/fr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"state": {
"today": "Aujourd'hui",
"tomorrow": "Demain"
"today": "aujourd'hui",
"tomorrow": "demain",
"Today": "Aujourd'hui",
"Tomorrow": "Demain"
},
"other": {
"due": "",
"Due": "",
"due_today_order": "true"
}
}
53 changes: 41 additions & 12 deletions dist/garbage-collection-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class GarbageCollectionCard extends HTMLElement {
this.style.display = "none";
}

_updateContent(element, attributes, hdate, hdays, hcard) {
_updateContent(element, attributes, hdate, hdays, hcard, duetxt) {
const root = this.shadowRoot;
var today = new Date()
var date_option = { year: 'numeric', month: '2-digit', day: '2-digit'};
Expand All @@ -219,9 +219,13 @@ class GarbageCollectionCard extends HTMLElement {

root.getElementById('friendly_name').innerHTML = attributes[0].friendly_name;

root.getElementById('details').innerHTML = (hdate === false ? attributes[0].next_date : '') +
if ( parseInt(attributes[0].days) < 2 && duetxt === true ) {
root.getElementById('details').innerHTML = attributes[0].next_date
} else {
root.getElementById('details').innerHTML = (hdate === false ? attributes[0].next_date : '') +
(hdays === false ? " " + this._label('ui.components.relative_time.future.In', 'in') +
" " + attributes[0].days + " " + this._label('ui.duration.days', 'days') : '' )
}

this.style.display = hcard ? "none" : "block";

Expand Down Expand Up @@ -253,6 +257,8 @@ class GarbageCollectionCard extends HTMLElement {
let hide_card = false;
let hide_before = -1;
if (typeof config.hide_before != "undefined") hide_before=config.hide_before
let due_txt = false;
if (typeof config.due_txt != "undefined") due_txt=config.due_txt

let attributes = this._getAttributes(hass, config.entity.split(".")[1]);
if (hide_before>-1) {
Expand All @@ -278,17 +284,40 @@ class GarbageCollectionCard extends HTMLElement {
if ( attributes[0].days < 2 ) {
var translationJSONobj = JSON.parse(rawFile.responseText);
if ( typeof translationJSONobj != "undefined" ) {
var dday = this._stateObj.state == 0 ? "today":"tomorrow";
if ( typeof translationJSONobj.state[dday] != "undefined" ) {
attributes[0].next_date = translationJSONobj.state[dday];
}
}
}
}
}

this._updateContent(root.getElementById('attributes'), attributes, hide_date, hide_days, hide_card );
}
var dday = this._stateObj.state == 0 ? "today":"tomorrow";
if ( due_txt === true ) {
if ( typeof translationJSONobj.other['due_today_order'] != "undefined" ) {
if ( (/true/i).test(translationJSONobj.other['due_today_order']) ) {
if ( typeof translationJSONobj.other['Due'] != "undefined" ) {
attributes[0].next_date = translationJSONobj.other['Due'] + " ";
}
if ( typeof translationJSONobj.state[dday] != "undefined" ) {
attributes[0].next_date += translationJSONobj.state[dday];
}
} else {
var dday = this._stateObj.state == 0 ? "Today":"Tomorrow";
if ( typeof translationJSONobj.state[dday] != "undefined" ) {
attributes[0].next_date = translationJSONobj.state[dday] + " ";
}
if ( typeof translationJSONobj.other['due'] != "undefined" ) {
attributes[0].next_date += translationJSONobj.other['due'];
}
}
}
} else {
dday = this._stateObj.state == 0 ? "Today":"Tomorrow";
if ( typeof translationJSONobj.state[dday] != "undefined" ) {
attributes[0].next_date = translationJSONobj.state[dday];
}
}
}
}
}
}

this._updateContent(root.getElementById('attributes'), attributes, hide_date, hide_days, hide_card, due_txt );
}

getCardSize() {
return 1;
Expand Down
11 changes: 9 additions & 2 deletions dist/hu.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"state": {
"today": "Ma",
"tomorrow": "Holnap"
"today": "ma",
"tomorrow": "holnap",
"Today": "Ma",
"Tomorrow": "Holnap"
},
"other": {
"due": "esedékes",
"Due": "Esedékes",
"due_today_order": "true"
}
}
11 changes: 9 additions & 2 deletions dist/it.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"state": {
"today": "Oggi",
"tomorrow": "Domani"
"today": "oggi",
"tomorrow": "domani",
"Today": "Oggi",
"Tomorrow": "Domani"
},
"other": {
"due": "da fare",
"Due": "Da fare",
"due_today_order": "true"
}
}
11 changes: 9 additions & 2 deletions dist/nl.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"state": {
"today": "Vandaag",
"tomorrow": "Morgen"
"today": "vandaag",
"tomorrow": "morgen",
"Today": "Vandaag",
"Tomorrow": "Morgen"
},
"other": {
"due": "gebeuren",
"Due": "Gebeuren",
"due_today_order": "false"
}
}
11 changes: 9 additions & 2 deletions dist/ro.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"state": {
"today": "Azi",
"tomorrow": "Mâine"
"today": "azi",
"tomorrow": "mâine",
"Today": "Azi",
"Tomorrow": "Mâine"
},
"other": {
"due": "scadentă",
"Due": "Scadentă",
"due_today_order": "true"
}
}
13 changes: 10 additions & 3 deletions dist/sv.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"state": {
"today": "Idag",
"tomorrow": "Imorgon"
"today": "idag",
"tomorrow": "imorgon",
"Today": "Idag",
"Tomorrow": "Imorgon"
},
"other": {
"due": "förfaller",
"Due": "Förfaller",
"due_today_order": "true"
}
}
}
30 changes: 17 additions & 13 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ homeassistant_config_dir/www/community/garbage-collection-card/ directory.<br />

#### Lovelace UI configuration
Configuration parameters:<br />

**entity** (required): name of the sensor of garbage_collection platform.<br />
**due_color** (optional): icon color on due date. Accepts both color names and RGB values. Defaults to red.<br />
**due_1_color** (optional): icon color on the day before due date. Accepts both color names and RGB values. Defaults to due_color.<br />
**icon_color** (optional): icon color. Accepts both color names and RGB values. Defaults to black.<br />
**icon_size** (optional): size of the icon. Defaults to 25px.<br />
**hide_date** (optional): hide date. Defaults to false.<br />
**hide_days** (optional): hide number of days. Defaults to false.<br />
**hide_before** (optional): hide entire card until x days before event. Defaults to not hiding card.<br />
**title_size** (optional): font size for the sensor's friendly name. Defaults to 17px.<br />
**details_size** (optional): font size for date and number of days. Defaults to 14px.<br />
---
| Name | Optional | `Default` | Description |
| :---- | :---- | :------- | :----------- |
| entity | **N** | - | name of the sensor of garbage_collection platform.|
| due_color | **Y**| `red` | icon color on due date. Accepts both color names and RGB values.|
| due_1_color | **Y** | due_color | icon color on the day before due date. Accepts both color names and RGB values.|
| due_txt | **Y** | `false` | For today/tomorrow pick-ups use 'Due today' or 'Due tomorrow'.|
| icon_color | **Y** | `black` | icon color. Accepts both color names and RGB values.|
| icon_size | **Y** | `25px` | size of the icon.|
| hide_date | **Y** | `false` | hide date.|
| hide_days | **Y** | `false`| hide number of days.|
| hide_before | **Y** | `false` | hide entire card until x days before event.|
| title_size | **Y** | `17px` | font size for the sensor's friendly name.|
| details_size | **Y** | `14px `| font size for date and number of days.|
---

Garbage collection cards supports some languages and displays the date information based on your locale setting.

Expand All @@ -42,9 +46,9 @@ Please add the card to the resources in configuration.yaml:

```
resources:
*When using HACS installation method
//When using HACS installation method
- {type: js, url: '/hacsfiles/garbage-collection-card/garbage-collection-card.js'}
*When using manual install method
//When using manual install method
- {type: js, url: '/local/garbage-collection-card.js'}
```

Expand Down
6 changes: 3 additions & 3 deletions tracker.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"garbage-collection-card": {
"version": "1.8.0",
"updated_at": "2020-09-07",
"version": "1.9.0",
"updated_at": "2020-09-08",
"visit_repo": "https://github.com/amaximus/garbage-collection-card",
"changelog": "https://github.com/amaximus/garbage-collection0card/releases/1.8.0"
"changelog": "https://github.com/amaximus/garbage-collection0card/releases/1.9.0"
}
}

0 comments on commit 7b0d23b

Please sign in to comment.