Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions custom_components/mbtalive/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,15 @@

_LOGGER = logging.getLogger(__name__)

# --- Custom validator for train number ---
def validate_train_number(value: str | None) -> str | None:
"""Validate that train number is 2–4 alphanumeric characters or empty."""
if value in ("", None):
return None # normalize empty
value = str(value).strip().upper()
if not re.fullmatch(r"[A-Z0-9]{2,4}", value):
raise vol.Invalid("Train number must be 2–4 letters/numbers or empty")
return value


def get_user_schema(default_api_key: str = "") -> vol.Schema:
return vol.Schema({
vol.Required("depart_from", default=""): str,
vol.Required("arrive_at", default=""): str,
vol.Required("api_key", default=default_api_key): vol.All(str, vol.Length(min=32, max=32)),
vol.Optional("max_trips", default=2): int,
vol.Optional("train", default=""): validate_train_number,
vol.Optional("train"): vol.All(str,vol.Length(min=2, max=4))
})


class MBTAConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for the MBTA integration."""
VERSION = 1
Expand Down
2 changes: 1 addition & 1 deletion custom_components/mbtalive/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"loggers": ["MBTALive"],
"dependencies": [],
"requirements": ["MBTAclient>=1.1.31"],
"version": "2.1.4",
"version": "2.1.5",
"config_flow": true
}