mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 08:06:00 +01:00
Add unique id to nederlandse spoorwegen (#154013)
This commit is contained in:
committed by
GitHub
parent
a6e575ecfa
commit
f6fb4c8d5a
@@ -129,10 +129,13 @@ async def async_setup_entry(
|
||||
subentry.data[CONF_NAME],
|
||||
subentry.data[CONF_FROM],
|
||||
subentry.data[CONF_TO],
|
||||
subentry.subentry_id,
|
||||
subentry.data.get(CONF_VIA),
|
||||
parse_time(subentry.data[CONF_TIME])
|
||||
if CONF_TIME in subentry.data
|
||||
else None,
|
||||
(
|
||||
parse_time(subentry.data[CONF_TIME])
|
||||
if CONF_TIME in subentry.data
|
||||
else None
|
||||
),
|
||||
)
|
||||
],
|
||||
config_subentry_id=subentry.subentry_id,
|
||||
@@ -153,6 +156,7 @@ class NSDepartureSensor(SensorEntity):
|
||||
name: str,
|
||||
departure: str,
|
||||
heading: str,
|
||||
subentry_id: str,
|
||||
via: str | None,
|
||||
time: dt.time | None,
|
||||
) -> None:
|
||||
@@ -166,6 +170,7 @@ class NSDepartureSensor(SensorEntity):
|
||||
self._trips: list[Trip] | None = None
|
||||
self._first_trip: Trip | None = None
|
||||
self._next_trip: Trip | None = None
|
||||
self._attr_unique_id = f"{subentry_id}-actual_departure"
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
|
||||
@@ -12,7 +12,7 @@ from homeassistant.components.nederlandse_spoorwegen.const import (
|
||||
CONF_VIA,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigSubentryData
|
||||
from homeassistant.config_entries import ConfigSubentryDataWithId
|
||||
from homeassistant.const import CONF_API_KEY, CONF_NAME
|
||||
|
||||
from .const import API_KEY
|
||||
@@ -61,7 +61,7 @@ def mock_config_entry() -> MockConfigEntry:
|
||||
data={CONF_API_KEY: API_KEY},
|
||||
domain=DOMAIN,
|
||||
subentries_data=[
|
||||
ConfigSubentryData(
|
||||
ConfigSubentryDataWithId(
|
||||
data={
|
||||
CONF_NAME: "To work",
|
||||
CONF_FROM: "Ams",
|
||||
@@ -71,6 +71,7 @@ def mock_config_entry() -> MockConfigEntry:
|
||||
subentry_type="route",
|
||||
title="Test Route",
|
||||
unique_id=None,
|
||||
subentry_id="01K721DZPMEN39R5DK0ATBMSY8",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,5 +1,40 @@
|
||||
# serializer version: 1
|
||||
# name: test_sensor
|
||||
# name: test_sensor[sensor.to_work-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.to_work',
|
||||
'has_entity_name': False,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
|
||||
'original_icon': 'mdi:train',
|
||||
'original_name': 'To work',
|
||||
'platform': 'nederlandse_spoorwegen',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '01K721DZPMEN39R5DK0ATBMSY8-actual_departure',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor[sensor.to_work-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'arrival_delay': False,
|
||||
|
||||
@@ -15,13 +15,14 @@ from homeassistant.components.nederlandse_spoorwegen.const import (
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import CONF_API_KEY, CONF_NAME, CONF_PLATFORM
|
||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
||||
import homeassistant.helpers.entity_registry as er
|
||||
import homeassistant.helpers.issue_registry as ir
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import setup_integration
|
||||
from .const import API_KEY
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
async def test_config_import(
|
||||
@@ -65,8 +66,9 @@ async def test_sensor(
|
||||
mock_nsapi,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test sensor initialization."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert hass.states.get("sensor.to_work") == snapshot
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
Reference in New Issue
Block a user