61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
from enum import StrEnum
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from ..idfm_interface import (
|
|
IdfmLineState,
|
|
IdfmState,
|
|
TransportMode as IdfmTransportMode,
|
|
TransportSubMode as IdfmTransportSubMode,
|
|
)
|
|
|
|
|
|
class TransportMode(StrEnum):
|
|
"""Computed transport mode from
|
|
idfm_interface.TransportMode and idfm_interface.TransportSubMode.
|
|
"""
|
|
|
|
bus = "bus"
|
|
tram = "tram"
|
|
metro = "metro"
|
|
funicular = "funicular"
|
|
# idfm_types.TransportMode.rail + idfm_types.TransportSubMode.regionalRail
|
|
rail_ter = "ter"
|
|
# idfm_types.TransportMode.rail + idfm_types.TransportSubMode.local
|
|
rail_rer = "rer"
|
|
# idfm_types.TransportMode.rail + idfm_types.TransportSubMode.suburbanRailway
|
|
rail_transilien = "transilien"
|
|
# idfm_types.TransportMode.rail + idfm_types.TransportSubMode.railShuttle
|
|
val = "val"
|
|
|
|
# Self return type replaced by "TransportMode" to fix following mypy error:
|
|
# Incompatible return value type (got "TransportMode", expected "Self")
|
|
# TODO: Is it the good fix ?
|
|
@classmethod
|
|
def from_idfm_transport_mode(cls, mode: str, sub_mode: str) -> "TransportMode":
|
|
if mode == IdfmTransportMode.rail:
|
|
if sub_mode == IdfmTransportSubMode.regionalRail:
|
|
return cls.rail_ter
|
|
if sub_mode == IdfmTransportSubMode.local:
|
|
return cls.rail_rer
|
|
if sub_mode == IdfmTransportSubMode.suburbanRailway:
|
|
return cls.rail_transilien
|
|
if sub_mode == IdfmTransportSubMode.railShuttle:
|
|
return cls.val
|
|
return cls(mode)
|
|
|
|
|
|
class Line(BaseModel):
|
|
id: int
|
|
shortName: str
|
|
name: str
|
|
status: IdfmLineState
|
|
transportMode: TransportMode
|
|
backColorHexa: str
|
|
foreColorHexa: str
|
|
operatorId: str
|
|
accessibility: IdfmState
|
|
visualSignsAvailable: IdfmState
|
|
audibleSignsAvailable: IdfmState
|
|
stopIds: list[str]
|