From 9119d5808fb0137b6b48b07d6ee4e982a0d25a55 Mon Sep 17 00:00:00 2001 From: Nuhser Date: Mon, 26 Jan 2026 09:46:47 +0100 Subject: [PATCH 01/10] #4 Fix undefined property access --- rmv-card.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/rmv-card.js b/rmv-card.js index 638be78..4e0166c 100644 --- a/rmv-card.js +++ b/rmv-card.js @@ -1,9 +1,9 @@ class RmvCard extends HTMLElement { sec2time(timeInSeconds) { - var pad = function(num, size) { return ('000' + num).slice(size * -1); }, - time = parseFloat(timeInSeconds).toFixed(3), - hours = Math.floor(time / 60 / 60), - minutes = Math.floor(time / 60) % 60; + var pad = function (num, size) { return ('000' + num).slice(size * -1); }, + time = parseFloat(timeInSeconds).toFixed(3), + hours = Math.floor(time / 60 / 60), + minutes = Math.floor(time / 60) % 60; return pad(hours, 2) + ':' + pad(minutes, 2); } @@ -11,8 +11,13 @@ class RmvCard extends HTMLElement { set hass(hass) { const entityId = this.config.entity const state = hass.states[entityId] - if (this.config.friendly_name) { var name = this.config.friendly_name } - else { var name = state.attributes['friendly_name'] } + + if (this.config.friendly_name) { + var name = this.config.friendly_name + } + else { + var name = state?.attributes['friendly_name'] ?? entityId + } if (!this.content) { const card = document.createElement('ha-card') @@ -75,6 +80,7 @@ class RmvCard extends HTMLElement { 'direction': state.attributes['direction'] } const journeys = [next].concat(state.attributes['next_departures']) + for (const journey of journeys) { var destination = journey['destination'] if (typeof journey['destination'] === 'undefined') { @@ -85,7 +91,7 @@ class RmvCard extends HTMLElement { const jtime = new Date(journey['departure_time'] + 'Z') const time = jtime.toISOString().substr(11, 5) - const departureIn = this.config.convert_minutes ? this.sec2time(parseInt(journey['minutes'])*60) : parseInt(journey['minutes']) + const departureIn = this.config.convert_minutes ? this.sec2time(parseInt(journey['minutes']) * 60) : parseInt(journey['minutes']) tablehtml += ` @@ -93,10 +99,11 @@ class RmvCard extends HTMLElement { ${destination} ` tablehtml += ` ` + if (!this.config.hide_minutes) { tablehtml += `${departureIn}` } if (this.config.show_time) { tablehtml += ` (${time})` } - tablehtml += `` + tablehtml += `` tablehtml += ` ` } tablehtml += ` From 979380b769bc70bbe83522373c557deddebffcdf Mon Sep 17 00:00:00 2001 From: Nuhser Date: Mon, 26 Jan 2026 09:50:15 +0100 Subject: [PATCH 02/10] #4 Don't show content when state is undefined --- rmv-card.js | 74 ++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/rmv-card.js b/rmv-card.js index 4e0166c..ec70e52 100644 --- a/rmv-card.js +++ b/rmv-card.js @@ -67,48 +67,52 @@ class RmvCard extends HTMLElement { this.appendChild(card) } - var tablehtml = ` - - ` - - const next = { - 'line': state.attributes['line'], - 'product': state.attributes['product'], - 'destination': state.attributes['destination'], - 'departure_time': state.attributes['departure_time'], - 'minutes': state.attributes['minutes'], - 'direction': state.attributes['direction'] - } - const journeys = [next].concat(state.attributes['next_departures']) + var tablehtml = '' + + if (state) { + tablehtml += ` +
+ ` - for (const journey of journeys) { - var destination = journey['destination'] - if (typeof journey['destination'] === 'undefined') { - destination = journey['direction'] + const next = { + 'line': state.attributes['line'], + 'product': state.attributes['product'], + 'destination': state.attributes['destination'], + 'departure_time': state.attributes['departure_time'], + 'minutes': state.attributes['minutes'], + 'direction': state.attributes['direction'] } - const linename = journey['line'] - const product = journey['product'] + const journeys = [next].concat(state.attributes['next_departures']) - const jtime = new Date(journey['departure_time'] + 'Z') - const time = jtime.toISOString().substr(11, 5) - const departureIn = this.config.convert_minutes ? this.sec2time(parseInt(journey['minutes']) * 60) : parseInt(journey['minutes']) + for (const journey of journeys) { + var destination = journey['destination'] + if (typeof journey['destination'] === 'undefined') { + destination = journey['direction'] + } + const linename = journey['line'] + const product = journey['product'] - tablehtml += ` - - - - ` - tablehtml += ` + + + ` + tablehtml += ` ` - tablehtml += ` ` + tablehtml += `` + tablehtml += ` ` + } + tablehtml += ` +
${linename}${destination}` + const jtime = new Date(journey['departure_time'] + 'Z') + const time = jtime.toISOString().substr(11, 5) + const departureIn = this.config.convert_minutes ? this.sec2time(parseInt(journey['minutes']) * 60) : parseInt(journey['minutes']) + + tablehtml += ` +
${linename}${destination}` - if (!this.config.hide_minutes) { tablehtml += `${departureIn}` } - if (this.config.show_time) { tablehtml += ` (${time})` } + if (!this.config.hide_minutes) { tablehtml += `${departureIn}` } + if (this.config.show_time) { tablehtml += ` (${time})` } - tablehtml += `
+ ` } - tablehtml += ` - - ` this.content.innerHTML = tablehtml } From 512776582489f451af84b74817d604552a3ef201 Mon Sep 17 00:00:00 2001 From: Nuhser Date: Mon, 26 Jan 2026 09:52:45 +0100 Subject: [PATCH 03/10] #4 Add test log --- rmv-card.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rmv-card.js b/rmv-card.js index ec70e52..ca00410 100644 --- a/rmv-card.js +++ b/rmv-card.js @@ -12,6 +12,8 @@ class RmvCard extends HTMLElement { const entityId = this.config.entity const state = hass.states[entityId] + console.log(`state of ${entityId}: ${state}`) + if (this.config.friendly_name) { var name = this.config.friendly_name } @@ -69,7 +71,7 @@ class RmvCard extends HTMLElement { var tablehtml = '' - if (state) { + if (typeof state !== 'undefined') { tablehtml += ` ` From 85b6eb154bc1da290f4fa50a8834e03b81d7dc86 Mon Sep 17 00:00:00 2001 From: Nuhser Date: Mon, 26 Jan 2026 10:01:25 +0100 Subject: [PATCH 04/10] #4 remove test log --- rmv-card.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/rmv-card.js b/rmv-card.js index ca00410..4c4234b 100644 --- a/rmv-card.js +++ b/rmv-card.js @@ -12,8 +12,6 @@ class RmvCard extends HTMLElement { const entityId = this.config.entity const state = hass.states[entityId] - console.log(`state of ${entityId}: ${state}`) - if (this.config.friendly_name) { var name = this.config.friendly_name } From a1f87f69f76ea2235ca2998cab1118e6b3882526 Mon Sep 17 00:00:00 2001 From: Nuhser Date: Mon, 26 Jan 2026 10:01:57 +0100 Subject: [PATCH 05/10] #4 Add error state to card --- rmv-card.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/rmv-card.js b/rmv-card.js index 4c4234b..1386335 100644 --- a/rmv-card.js +++ b/rmv-card.js @@ -61,6 +61,24 @@ class RmvCard extends HTMLElement { span.Bahn { background-color: #000000; } + .error-container { + display: flex; + align-items: center; + padding: 12px; + gap: 12px; + border-radius: 8px; + background-color: var(--error-color); + color: var(--text-primary-color); + font-weight: 500; + margin: 8px 0; + } + ha-icon { + --mdc-icon-size: 24px; + flex-shrink: 0; + } + .error-message { + font-size: 0.9em; + } ` card.appendChild(style) card.appendChild(this.content) @@ -113,6 +131,14 @@ class RmvCard extends HTMLElement {
` } + else { + tablehtml += ` +
+ + Configuration Error: Couldn't get state of entity ${entityId}. Please ccheck your RMV integration. +
+ ` + } this.content.innerHTML = tablehtml } From 6365897906e24fc97dcca08dd05db897375b54b5 Mon Sep 17 00:00:00 2001 From: Nuhser Date: Mon, 26 Jan 2026 10:02:57 +0100 Subject: [PATCH 06/10] #4 Fix typo --- rmv-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmv-card.js b/rmv-card.js index 1386335..3a9ada9 100644 --- a/rmv-card.js +++ b/rmv-card.js @@ -135,7 +135,7 @@ class RmvCard extends HTMLElement { tablehtml += `
- Configuration Error: Couldn't get state of entity ${entityId}. Please ccheck your RMV integration. + Error: Couldn't get state of entity ${entityId}. Please check your RMV integration.
` } From 36c1ac38854c928f70f31b7ab44b53d40bc9dbb2 Mon Sep 17 00:00:00 2001 From: Nuhser Date: Mon, 26 Jan 2026 10:04:04 +0100 Subject: [PATCH 07/10] #4 Improve error message styling --- rmv-card.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rmv-card.js b/rmv-card.js index 3a9ada9..4b54436 100644 --- a/rmv-card.js +++ b/rmv-card.js @@ -70,7 +70,7 @@ class RmvCard extends HTMLElement { background-color: var(--error-color); color: var(--text-primary-color); font-weight: 500; - margin: 8px 0; + margin: 8px; } ha-icon { --mdc-icon-size: 24px; @@ -135,7 +135,7 @@ class RmvCard extends HTMLElement { tablehtml += `
- Error: Couldn't get state of entity ${entityId}. Please check your RMV integration. + Error: Couldn't get state of entity ${entityId}.
Please check your RMV integration.
` } From a0d8752ef0ed9d50f46de2fa70196a1de183cb48 Mon Sep 17 00:00:00 2001 From: Nuhser Date: Mon, 26 Jan 2026 10:25:13 +0100 Subject: [PATCH 08/10] #4 Improve code and formatting --- rmv-card.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/rmv-card.js b/rmv-card.js index 4b54436..0a6f68d 100644 --- a/rmv-card.js +++ b/rmv-card.js @@ -88,9 +88,7 @@ class RmvCard extends HTMLElement { var tablehtml = '' if (typeof state !== 'undefined') { - tablehtml += ` - - ` + tablehtml += '
' const next = { 'line': state.attributes['line'], @@ -111,31 +109,30 @@ class RmvCard extends HTMLElement { const product = journey['product'] const jtime = new Date(journey['departure_time'] + 'Z') - const time = jtime.toISOString().substr(11, 5) + const time = jtime.toISOString().slice(11, 5) const departureIn = this.config.convert_minutes ? this.sec2time(parseInt(journey['minutes']) * 60) : parseInt(journey['minutes']) tablehtml += ` - + ` - tablehtml += ` ` - tablehtml += ` ` + tablehtml += '' } - tablehtml += ` -
${linename} + ${linename} + ${destination}` + tablehtml += '' if (!this.config.hide_minutes) { tablehtml += `${departureIn}` } if (this.config.show_time) { tablehtml += ` (${time})` } - tablehtml += `
- ` + tablehtml += '' } else { tablehtml += `
- - Error: Couldn't get state of entity ${entityId}.
Please check your RMV integration.
+ + Error: Couldn't get state of entity ${entityId}.
Please check your RMV integration.
` } From 8eded3efe44b29d3b701b89ea26b0fb38fe463c7 Mon Sep 17 00:00:00 2001 From: Nuhser Date: Mon, 26 Jan 2026 10:27:37 +0100 Subject: [PATCH 09/10] Revert "#4 Improve code and formatting" This reverts commit a0d8752ef0ed9d50f46de2fa70196a1de183cb48. --- rmv-card.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/rmv-card.js b/rmv-card.js index 0a6f68d..4b54436 100644 --- a/rmv-card.js +++ b/rmv-card.js @@ -88,7 +88,9 @@ class RmvCard extends HTMLElement { var tablehtml = '' if (typeof state !== 'undefined') { - tablehtml += '' + tablehtml += ` +
+ ` const next = { 'line': state.attributes['line'], @@ -109,30 +111,31 @@ class RmvCard extends HTMLElement { const product = journey['product'] const jtime = new Date(journey['departure_time'] + 'Z') - const time = jtime.toISOString().slice(11, 5) + const time = jtime.toISOString().substr(11, 5) const departureIn = this.config.convert_minutes ? this.sec2time(parseInt(journey['minutes']) * 60) : parseInt(journey['minutes']) tablehtml += ` - + ` - tablehtml += '' + tablehtml += `` + tablehtml += ` ` } - tablehtml += '
- ${linename} - ${linename} ${destination}' + tablehtml += ` ` if (!this.config.hide_minutes) { tablehtml += `${departureIn}` } if (this.config.show_time) { tablehtml += ` (${time})` } - tablehtml += '
' + tablehtml += ` + + ` } else { tablehtml += `
- - Error: Couldn't get state of entity ${entityId}.
Please check your RMV integration.
+ + Error: Couldn't get state of entity ${entityId}.
Please check your RMV integration.
` } From 5a475c50a1d38708cf70a69d4a3484607f23d714 Mon Sep 17 00:00:00 2001 From: Nuhser Date: Mon, 26 Jan 2026 10:31:07 +0100 Subject: [PATCH 10/10] #4 Improve error message formatting --- rmv-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmv-card.js b/rmv-card.js index 4b54436..a77e9ce 100644 --- a/rmv-card.js +++ b/rmv-card.js @@ -135,7 +135,7 @@ class RmvCard extends HTMLElement { tablehtml += `
- Error: Couldn't get state of entity ${entityId}.
Please check your RMV integration.
+ Error: Couldn't get state of entity ${entityId}.
Please check your RMV integration.
` }