8
8
9
9
from pyrail import iRail
10
10
from pyrail .models import ConnectionDetails , LiveboardDeparture , StationDetails
11
- import voluptuous as vol
12
11
13
- from homeassistant .components .sensor import (
14
- PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA ,
15
- SensorEntity ,
16
- )
17
- from homeassistant .config_entries import SOURCE_IMPORT , ConfigEntry
12
+ from homeassistant .components .sensor import SensorEntity
13
+ from homeassistant .config_entries import ConfigEntry
18
14
from homeassistant .const import (
19
15
ATTR_LATITUDE ,
20
16
ATTR_LONGITUDE ,
21
17
CONF_NAME ,
22
- CONF_PLATFORM ,
23
18
CONF_SHOW_ON_MAP ,
24
19
UnitOfTime ,
25
20
)
26
- from homeassistant .core import DOMAIN as HOMEASSISTANT_DOMAIN , HomeAssistant
27
- from homeassistant .helpers import config_validation as cv
21
+ from homeassistant .core import HomeAssistant
28
22
from homeassistant .helpers .aiohttp_client import async_get_clientsession
29
- from homeassistant .helpers .entity_platform import (
30
- AddConfigEntryEntitiesCallback ,
31
- AddEntitiesCallback ,
32
- )
33
- from homeassistant .helpers .issue_registry import IssueSeverity , async_create_issue
34
- from homeassistant .helpers .typing import ConfigType , DiscoveryInfoType
23
+ from homeassistant .helpers .entity_platform import AddConfigEntryEntitiesCallback
35
24
from homeassistant .util import dt as dt_util
36
25
37
26
from .const import ( # noqa: F401
47
36
48
37
_LOGGER = logging .getLogger (__name__ )
49
38
50
- DEFAULT_NAME = "NMBS"
51
-
52
39
DEFAULT_ICON = "mdi:train"
53
40
DEFAULT_ICON_ALERT = "mdi:alert-octagon"
54
41
55
- PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA .extend (
56
- {
57
- vol .Required (CONF_STATION_FROM ): cv .string ,
58
- vol .Required (CONF_STATION_TO ): cv .string ,
59
- vol .Optional (CONF_STATION_LIVE ): cv .string ,
60
- vol .Optional (CONF_EXCLUDE_VIAS , default = False ): cv .boolean ,
61
- vol .Optional (CONF_NAME , default = DEFAULT_NAME ): cv .string ,
62
- vol .Optional (CONF_SHOW_ON_MAP , default = False ): cv .boolean ,
63
- }
64
- )
65
-
66
42
67
43
def get_time_until (departure_time : datetime | None = None ):
68
44
"""Calculate the time between now and a train's departure time."""
@@ -85,71 +61,6 @@ def get_ride_duration(departure_time: datetime, arrival_time: datetime, delay=0)
85
61
return duration_time + get_delay_in_minutes (delay )
86
62
87
63
88
- async def async_setup_platform (
89
- hass : HomeAssistant ,
90
- config : ConfigType ,
91
- async_add_entities : AddEntitiesCallback ,
92
- discovery_info : DiscoveryInfoType | None = None ,
93
- ) -> None :
94
- """Set up the NMBS sensor with iRail API."""
95
-
96
- if config [CONF_PLATFORM ] == DOMAIN :
97
- if CONF_SHOW_ON_MAP not in config :
98
- config [CONF_SHOW_ON_MAP ] = False
99
- if CONF_EXCLUDE_VIAS not in config :
100
- config [CONF_EXCLUDE_VIAS ] = False
101
-
102
- station_types = [CONF_STATION_FROM , CONF_STATION_TO , CONF_STATION_LIVE ]
103
-
104
- for station_type in station_types :
105
- station = (
106
- find_station_by_name (hass , config [station_type ])
107
- if station_type in config
108
- else None
109
- )
110
- if station is None and station_type in config :
111
- async_create_issue (
112
- hass ,
113
- DOMAIN ,
114
- "deprecated_yaml_import_issue_station_not_found" ,
115
- breaks_in_ha_version = "2025.7.0" ,
116
- is_fixable = False ,
117
- issue_domain = DOMAIN ,
118
- severity = IssueSeverity .WARNING ,
119
- translation_key = "deprecated_yaml_import_issue_station_not_found" ,
120
- translation_placeholders = {
121
- "domain" : DOMAIN ,
122
- "integration_title" : "NMBS" ,
123
- "station_name" : config [station_type ],
124
- "url" : "/config/integrations/dashboard/add?domain=nmbs" ,
125
- },
126
- )
127
- return
128
-
129
- hass .async_create_task (
130
- hass .config_entries .flow .async_init (
131
- DOMAIN ,
132
- context = {"source" : SOURCE_IMPORT },
133
- data = config ,
134
- )
135
- )
136
-
137
- async_create_issue (
138
- hass ,
139
- HOMEASSISTANT_DOMAIN ,
140
- f"deprecated_yaml_{ DOMAIN } " ,
141
- breaks_in_ha_version = "2025.7.0" ,
142
- is_fixable = False ,
143
- issue_domain = DOMAIN ,
144
- severity = IssueSeverity .WARNING ,
145
- translation_key = "deprecated_yaml" ,
146
- translation_placeholders = {
147
- "domain" : DOMAIN ,
148
- "integration_title" : "NMBS" ,
149
- },
150
- )
151
-
152
-
153
64
async def async_setup_entry (
154
65
hass : HomeAssistant ,
155
66
config_entry : ConfigEntry ,
0 commit comments