Skip to content

Commit 7dd3704

Browse files
authored
Add heading and config options what to show (#9)
* Add heading and config options what to show * Heading added to the data table * Option to show/hide from, default is to show * Option to show hide heading, default is to hide * Document new config options * Add arriving station in docs
1 parent 36a1647 commit 7dd3704

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Styled entities using the Västtrafik theme in a lovelace entities card. All tra
66
This card also displays:
77
* When the next vehicle is leaving
88
* Departing station (which requires [this version](https://github.com/Miicroo/ha-vasttrafik) of the Västtrafik sensor)
9+
* Heading / arriving station
910
* When you have to leave home in order to catch the vehicle (also known as the sensor delay).
1011
* Sorting of entities, showing the next entity to depart first
1112

@@ -20,6 +21,8 @@ This card also displays:
2021
| title | string | Västtrafik | The title of the card
2122
| municipality | string | Göteborg | The municipality of the station(s), [more info here](https://github.com/Miicroo/lovelace-vasttrafik-card#municipality)
2223
| sort | boolean | true | Whether to sort the departures (earliest first), or keep the entities in the given order
24+
| showFrom | boolean | true | Whether to show the departing station or not
25+
| showTo | boolean | false | Whether to show the arriving station or not
2326

2427
## Municipality
2528
As there are many lines with the same name or number in Västra Götaland, the styles are split by municipality. For accuracy, choose the municipality of your departing sensor(s).

dist/vasttrafik-card.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,37 @@ customElements.whenDefined('card-tools').then(() => {
2323
'en': {
2424
'departureTime': 'Time',
2525
'departureStation': 'From',
26+
'heading': 'Heading to',
2627
'leaveHome': 'Leave in',
2728
},
2829
'sv': {
2930
'departureTime': 'Avgår kl.',
3031
'departureStation': 'Från',
32+
'heading': 'Till',
3133
'leaveHome': 'Gå om',
3234
},
3335
'nb': {
3436
'departureTime': 'Avgang kl.',
3537
'departureStation': 'Går fra',
38+
'heading': 'Til',
3639
'leaveHome': 'Gå om',
3740
},
3841
'nn': {
3942
'departureTime': 'Avgang kl.',
4043
'departureStation': 'Går fra',
44+
'heading': 'Til',
4145
'leaveHome': 'Gå om',
4246
},
4347
'da': {
4448
'departureTime': 'Afgang kl.',
4549
'departureStation': 'Afgår fra',
50+
'heading': 'Til',
4651
'leaveHome': 'Afsted om',
4752
},
4853
'nl': {
4954
'departureTime': 'Vertrektijd',
5055
'departureStation': 'Van',
56+
'heading': 'Naar',
5157
'leaveHome': 'Vertrek over',
5258
},
5359
};
@@ -56,6 +62,8 @@ customElements.whenDefined('card-tools').then(() => {
5662
setConfig(config) {
5763
this.title = config.title || 'Västtrafik';
5864
this.shouldSort = config.sort !== undefined ? !!(config.sort) : true;
65+
this.showFrom = config.showFrom !== undefined ? !!(config.showFrom) : true;
66+
this.showTo = config.showTo !== undefined ? !!(config.showTo) : false;
5967
this.municipality = config.municipality || 'Göteborg';
6068
this.entities = this._parseEntities(config.entities);
6169
this.config = config;
@@ -93,7 +101,8 @@ customElements.whenDefined('card-tools').then(() => {
93101
<tr>
94102
<th align="left"></th>
95103
<th align="left">${this._getTranslatedText('departureTime')}</th>
96-
<th align="left">${this._getTranslatedText('departureStation')}</th>
104+
${this.showFrom ? ct.LitHtml`<th align="left">${this._getTranslatedText('departureStation')}</th>` : ''}
105+
${this.showTo ? ct.LitHtml`<th align="left">${this._getTranslatedText('heading')}</th>` : ''}
97106
<th align="left">${this._getTranslatedText('leaveHome')}</th>
98107
</tr>
99108
${renderedEntities}
@@ -137,11 +146,13 @@ customElements.whenDefined('card-tools').then(() => {
137146
const departureTime = hassEntity.state;
138147
const timeUntilLeave = this._getTimeUntil(entity);
139148
const from = attributes.from || '';
149+
const heading = attributes.to || '';
140150

141151
return ct.LitHtml`<tr>
142152
<td class="${lineClass} line">${line}</td>
143153
<td>${departureTime}</td>
144-
<td>${from}</td>
154+
${this.showFrom ? ct.LitHtml`<td>${from}</td>` : ''}
155+
${this.showTo ? ct.LitHtml`<td>${heading}</td>` : ''}
145156
<td>${timeUntilLeave} minutes</td>
146157
</tr>`;
147158
}

0 commit comments

Comments
 (0)