Skip to content

Commit

Permalink
Merge pull request #6 from ViktorSchlaffer/estimated_arrival_time
Browse files Browse the repository at this point in the history
add option to show estimated arrival time when available
  • Loading branch information
amaximus authored Jan 19, 2022
2 parents d252cb5 + 9ed5748 commit 689698e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Configuration parameters:<br />
| entity | **N** | - | name of the sensor of bkk_stop platform|
| hide_in_mins | **Y** | `false` | Hide in_minutes information|
| hide_at_time | **Y** | `true` | Hide at_time information|
| hide_predicted_at_time | **Y** | `true` | If set to false, this will show predicted times with an '(est.)' suffix, when estimated arrival times are available, otherwise it will show the time according to schedule |
| name | **Y** | `` | If specified it will overwrite the card title/station name |
---

Expand All @@ -40,10 +41,15 @@ resources:
cards:
- type: custom:bkk-stop-card
entity: sensor.bkk7u
hide_in_mins: false
hide_in_mins: false # it makes sense to set this to false if hide_predicted_at_time is true, as in_mins is calculated from "scheduled" times
hide_at_time: false
hide_predicted_at_time: true
- type: custom:bkk-stop-card
entity: sensor.bkkxu
hide_in_mins: true
hide_at_time: true
hide_predicted_at_time: false
```

Lovelace UI:<br />
Expand Down
13 changes: 9 additions & 4 deletions bkk-stop-card.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

class BKKStopCard extends HTMLElement {

constructor() {
Expand Down Expand Up @@ -30,9 +31,10 @@ class BKKStopCard extends HTMLElement {
icon="bus"
} else if (icon == "rail") {
icon="train"
}
}
res.push({
attime: data1[i].attime,
predicted_attime: data1[i].predicted_attime,
bikes: bikes,
headsign: data1[i].headsign,
inmin: data1[i].in,
Expand All @@ -53,6 +55,7 @@ class BKKStopCard extends HTMLElement {
bikes: '',
icon: '',
attime: '',
predicted_attime: '',
station: station
});
}
Expand Down Expand Up @@ -139,14 +142,15 @@ class BKKStopCard extends HTMLElement {
this._config = cardConfig;
}

_updateContent(element, attributes, h_in_mins, h_at_time) {
_updateContent(element, attributes, h_in_mins, h_at_time, h_predicted_at_time) {
element.innerHTML = `
${attributes.map((attribute) => `
<tr>
<td class="${attribute.vehicle}"><ha-icon icon="mdi:${attribute.icon}"></td>
<td><span class="emp">${attribute.key}</span> to ${attribute.headsign}
${h_in_mins === false ? "in " + `${attribute.inmin}` + " mins" : ''}
${h_at_time === false ? "at " + `${attribute.attime}` : ''}
${h_predicted_at_time === false ? `${attribute.predicted_attime ? "at " + `${attribute.predicted_attime}` + "(est.)" : "at " + `${attribute.attime}`}`: '' }
${attribute.wheelchair}${attribute.bikes}</td>
</tr>
`).join('')}
Expand All @@ -164,7 +168,8 @@ class BKKStopCard extends HTMLElement {
set hass(hass) {
const config = this._config;
const root = this.shadowRoot;

let hide_predicted_at_time = false;
if (typeof config.hide_predicted_at_time != "undefined") hide_predicted_at_time=config.hide_predicted_at_time
let hide_in_mins = false;
if (typeof config.hide_in_mins != "undefined") hide_in_mins=config.hide_in_mins
let hide_at_time = true;
Expand All @@ -175,7 +180,7 @@ class BKKStopCard extends HTMLElement {
let attributes = this._getAttributes(hass, config.entity);

this._updateStation(root.getElementById('station'), attributes, name);
this._updateContent(root.getElementById('attributes'), attributes, hide_in_mins, hide_at_time);
this._updateContent(root.getElementById('attributes'), attributes, hide_in_mins, hide_at_time, hide_predicted_at_time);
}

getCardSize() {
Expand Down
Binary file modified bkk_lovelace.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Configuration parameters:<br />
| entity | **N** | - | name of the sensor of bkk_stop platform|
| hide_in_mins | **Y** | `false` | Hide in_minutes information|
| hide_at_time | **Y** | `true` | Hide at_time information|
| hide_predicted_at_time | **Y** | `true` | If set to false, this will show predicted times with an '(est.)' suffix, when estimated arrival times are available, otherwise it will show the time according to schedule |
| name | **Y** | `` | If specified it will overwrite the card title/station name |
---

Expand All @@ -40,10 +41,15 @@ resources:
cards:
- type: custom:bkk-stop-card
entity: sensor.bkk7u
hide_in_mins: false
hide_in_mins: false # it makes sense to set this to false if hide_predicted_at_time is true, as in_mins is calculated from "scheduled" times
hide_at_time: false
hide_predicted_at_time: true
- type: custom:bkk-stop-card
entity: sensor.bkkxu
hide_in_mins: true
hide_at_time: true
hide_predicted_at_time: false
```

Lovelace UI:<br />
Expand Down

0 comments on commit 689698e

Please sign in to comment.