Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
Fixes issue when gtfs2 folder does not exist
Adds indexes (awaiting pygtfs PR)
  • Loading branch information
vingerha committed Nov 7, 2023
1 parent c0ddabd commit a70435a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion custom_components/gtfs2/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .const import DEFAULT_PATH, DEFAULT_REFRESH_INTERVAL
from .gtfs_helper import get_gtfs, get_next_departure
from .gtfs_helper import get_gtfs, get_next_departure, check_datasource_index

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -49,6 +49,10 @@ async def _async_update_data(self) -> dict[str, str]:
"gtfs_dir": DEFAULT_PATH,
"name": data["name"],
}

check_index = await self.hass.async_add_executor_job(
check_datasource_index, self._pygtfs
)

try:
self._data["next_departure"] = await self.hass.async_add_executor_job(
Expand Down
1 change: 1 addition & 0 deletions custom_components/gtfs2/gtfs_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def get_stop_list(schedule, route_id, direction):
def get_datasources(hass, path) -> dict[str]:
_LOGGER.debug(f"Datasources path: {path}")
gtfs_dir = hass.config.path(path)
os.makedirs(gtfs_dir, exist_ok=True)
_LOGGER.debug(f"Datasources folder: {gtfs_dir}")
files = os.listdir(gtfs_dir)
_LOGGER.debug(f"Datasources files: {files}")
Expand Down

0 comments on commit a70435a

Please sign in to comment.