8000 Remove NMBS YAML import (#145733) · home-assistant/core@434179a · GitHub
[go: up one dir, main page]

Skip to content

Commit 434179a

Browse files
authored
Remove NMBS YAML import (#145733)
* Remove NMBS YAML import * Remove NMBS YAML import
1 parent eb53277 commit 434179a

File tree

4 files changed

+5
-359
lines changed

4 files changed

+5
-359
lines changed

homeassistant/components/nmbs/config_flow.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import voluptuous as vol
88

99
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
10-
from homeassistant.const import Platform
11-
from homeassistant.helpers import entity_registry as er
1210
from homeassistant.helpers.aiohttp_client import async_get_clientsession
1311
from homeassistant.helpers.selector import (
1412
BooleanSelector,
@@ -22,7 +20,6 @@
2220
CONF_EXCLUDE_VIAS,
2321
CONF_SHOW_ON_MAP,
2422
CONF_STATION_FROM,
25-
CONF_STATION_LIVE,
2623
CONF_STATION_TO,
2724
DOMAIN,
2825
)
@@ -115,68 +112,6 @@ async def async_step_user(
115112
errors=errors,
116113
)
117114

118-
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
119-
"""Import configuration from yaml."""
120-
try:
121-
self.stations = await self._fetch_stations()
122-
except CannotConnect:
123-
return self.async_abort(reason="api_unavailable")
124-
125-
station_from = None
126-
station_to = None
127-
station_live = None
128-
for station in self.stations:
129-
if user_input[CONF_STATION_FROM] in (
130-
station.standard_name,
131-
station.name,
132-
):
133-
station_from = station
134-
if user_input[CONF_STATION_TO] in (
135-
station.standard_name,
136-
station.name,
137-
):
138-
station_to = station
139-
if CONF_STATION_LIVE in user_input and user_input[CONF_STATION_LIVE] in (
140-
station.standard_name,
141-
station.name,
142-
):
143-
station_live = station
144-
145-
if station_from is None or station_to is None:
146-
return self.async_abort(reason="invalid_station")
147-
if station_from == station_to:
148-
return self.async_abort(reason="same_station")
149-
150-
# config flow uses id and not the standard name
151-
user_input[CONF_STATION_FROM] = station_from.id
152-
user_input[CONF_STATION_TO] = station_to.id
153-
154-
if station_live:
155-
user_input[CONF_STATION_LIVE] = station_live.id
156-
entity_registry = er.async_get(self.hass)
157-
prefix = "live"
158-
vias = "_excl_vias" if user_input.get(CONF_EXCLUDE_VIAS, False) else ""
159-
if entity_id := entity_registry.async_get_entity_id(
160-
Platform.SENSOR,
161-
DOMAIN,
162-
f"{prefix}_{station_live.standard_name}_{station_from.standard_name}_{station_to.standard_name}",
163-
):
164-
new_unique_id = f"{DOMAIN}_{prefix}_{station_live.id}_{station_from.id}_{station_to.id}{vias}"
165-
entity_registry.async_update_entity(
166-
entity_id, new_unique_id=new_unique_id
167-
)
168-
if entity_id := entity_registry.async_get_entity_id(
169-
Platform.SENSOR,
170-
DOMAIN,
171-
f"{prefix}_{station_live.name}_{station_from.name}_{station_to.name}",
172-
):
173-
new_unique_id = f"{DOMAIN}_{prefix}_{station_live.id}_{station_from.id}_{station_to.id}{vias}"
174-
entity_registry.async_update_entity(
175-
entity_id, new_unique_id=new_unique_id
176-
)
177-
178-
return await self.async_step_user(user_input)
179-
180115

181116
class CannotConnect(Exception):
182117
"""Error to indicate we cannot connect to NMBS."""

homeassistant/components/nmbs/sensor.py

Lines changed: 4 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,19 @@
88

99
from pyrail import iRail
1010
from pyrail.models import ConnectionDetails, LiveboardDeparture, StationDetails
11-
import voluptuous as vol
1211

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
1814
from homeassistant.const import (
1915
ATTR_LATITUDE,
2016
ATTR_LONGITUDE,
2117
CONF_NAME,
22-
CONF_PLATFORM,
2318
CONF_SHOW_ON_MAP,
2419
UnitOfTime,
2520
)
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
2822
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
3524
from homeassistant.util import dt as dt_util
3625

3726
from .const import ( # noqa: F401
@@ -47,22 +36,9 @@
4736

4837
_LOGGER = logging.getLogger(__name__)
4938

50-
DEFAULT_NAME = "NMBS"
51-
5239
DEFAULT_ICON = "mdi:train"
5340
DEFAULT_ICON_ALERT = "mdi:alert-octagon"
5441

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-
6642

6743
def get_time_until(departure_time: datetime | None = None):
6844
"""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)
8561
return duration_time + get_delay_in_minutes(delay)
8662

8763

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-
15364
async def async_setup_entry(
15465
hass: HomeAssistant,
15566
config_entry: ConfigEntry,

homeassistant/components/nmbs/strings.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,5 @@
2525
}
2626
}
2727
}
28-
},
29-
"issues": {
30-
"deprecated_yaml_import_issue_station_not_found": {
31-
"title": "The {integration_title} YAML configuration import failed",
32-
"description": "Configuring {integration_title} using YAML is being removed but there was a problem importing your YAML configuration.\n\nThe used station \"{station_name}\" could not be found. Fix it or remove the {integration_title} YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually."
33-
}
3428
}
3529
}

0 commit comments

Comments
 (0)
0