From 64edf2fe33d31320a4e22c389e800174aea03437 Mon Sep 17 00:00:00 2001 From: Thibault Maekelbergh <6213695+thibmaek@users.noreply.github.com> Date: Wed, 29 Jan 2020 12:12:40 +0100 Subject: [PATCH] Create truly live unique id (#31078) * Create truly live unique id * Do not generate unique id on basis of name * Add the station to the default station live name --- homeassistant/components/nmbs/sensor.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/nmbs/sensor.py b/homeassistant/components/nmbs/sensor.py index a91ff511b07..4865b0a9839 100644 --- a/homeassistant/components/nmbs/sensor.py +++ b/homeassistant/components/nmbs/sensor.py @@ -80,7 +80,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None): ] if station_live is not None: - sensors.append(NMBSLiveBoard(api_client, station_live)) + sensors.append( + NMBSLiveBoard(api_client, station_live, station_from, station_to) + ) add_entities(sensors, True) @@ -88,23 +90,26 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class NMBSLiveBoard(Entity): """Get the next train from a station's liveboard.""" - def __init__(self, api_client, live_station): + def __init__(self, api_client, live_station, station_from, station_to): """Initialize the sensor for getting liveboard data.""" self._station = live_station self._api_client = api_client - self._unique_id = f"nmbs_live_{self._station}" + self._station_from = station_from + self._station_to = station_to self._attrs = {} self._state = None @property def name(self): """Return the sensor default name.""" - return "NMBS Live" + return f"NMBS Live ({self._station})" @property def unique_id(self): """Return a unique ID.""" - return self._unique_id + unique_id = f"{self._station}_{self._station_from}_{self._station_to}" + + return f"nmbs_live_{unique_id}" @property def icon(self):