mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +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:
|
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)
|
add_entities(sensors, True)
|
||||||
|
|
||||||
@ -88,23 +90,26 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
class NMBSLiveBoard(Entity):
|
class NMBSLiveBoard(Entity):
|
||||||
"""Get the next train from a station's liveboard."""
|
"""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."""
|
"""Initialize the sensor for getting liveboard data."""
|
||||||
self._station = live_station
|
self._station = live_station
|
||||||
self._api_client = api_client
|
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._attrs = {}
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the sensor default name."""
|
"""Return the sensor default name."""
|
||||||
return "NMBS Live"
|
return f"NMBS Live ({self._station})"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return a unique ID."""
|
"""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
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user