mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
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
This commit is contained in:
parent
080827fb62
commit
64edf2fe33
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user