def test_prune_destination(): ir = IrishRailRTPI() only_bray = ir._prune_trains(trains, destination="Bray") assert len(only_bray) == 1 for train in only_bray: assert train["destination"] == "Bray" only_greystones = ir._prune_trains(trains, destination="Greystones") assert len(only_greystones) == 2 for train in only_greystones: assert train["destination"] == "Greystones"
def test_prune_direction(): ir = IrishRailRTPI() only_southbound = ir._prune_trains(trains, direction="Southbound") assert len(only_southbound) == 2 for train in only_southbound: assert train["direction"] == "Southbound" only_northbound = ir._prune_trains(trains, direction="Northbound") assert len(only_northbound) == 1 for train in only_northbound: assert train["direction"] == "Northbound"
def main(): ir = IrishRailRTPI() print(json.dumps(ir.get_all_stations(), indent=4, sort_keys=True)) print("All Current Trains") print(json.dumps(ir.get_all_current_trains(), indent=4, sort_keys=True)) print("Tara Street") print( json.dumps(ir.get_station_by_name("Tara Street"), indent=4, sort_keys=True)) print("Tara Street southbound to Pearse Street") print( json.dumps(ir.get_station_by_name("Tara Street", direction="Southbound"), indent=4, sort_keys=True)) print("All stops for P671") print(json.dumps(ir.get_train_stops("P671"), indent=4, sort_keys=True)) print("Tara Street southbound stops at Dun Laoghaire in 30 minutes") print( json.dumps(ir.get_station_by_name("Tara Street", direction="Southbound", stops_at="Dun Laoghaire", num_minutes=30), indent=4, sort_keys=True)) return 0
def test_prune_both(): ir = IrishRailRTPI() only_bray = ir._prune_trains(trains, direction="Northbound", destination="Bray") assert len(only_bray) == 1 for train in only_bray: assert train['direction'] == "Northbound" assert train["destination"] == "Bray" only_greystones = ir._prune_trains(trains, direction="Southbound", destination="Greystones") assert len(only_greystones) == 2 for train in only_greystones: assert train['direction'] == "Southbound" assert train["destination"] == "Greystones" no_trains = ir._prune_trains(trains, direction="Northbound", destination="Greystones") assert len(no_trains) == 0
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Irish Rail transport sensor.""" from pyirishrail.pyirishrail import IrishRailRTPI station = config.get(CONF_STATION) direction = config.get(CONF_DIRECTION) destination = config.get(CONF_DESTINATION) stops_at = config.get(CONF_STOPS_AT) name = config.get(CONF_NAME) irish_rail = IrishRailRTPI() data = IrishRailTransportData( irish_rail, station, direction, destination, stops_at) add_entities([IrishRailTransportSensor( data, station, direction, destination, stops_at, name)], True)
def setup_platform( hass: HomeAssistant, config: ConfigType, add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Irish Rail transport sensor.""" station = config.get(CONF_STATION) direction = config.get(CONF_DIRECTION) destination = config.get(CONF_DESTINATION) stops_at = config.get(CONF_STOPS_AT) name = config.get(CONF_NAME) irish_rail = IrishRailRTPI() data = IrishRailTransportData(irish_rail, station, direction, destination, stops_at) add_entities( [ IrishRailTransportSensor(data, station, direction, destination, stops_at, name) ], True, )