def setup_platform(hass, config, add_devices, discovery_info=None):
Get the GTFS sensor.
if config.get("origin") is None:
_LOGGER.error("Origin must be set in the GTFS configuration!")
return False
if config.get("destination") is None:
_LOGGER.error("Destination must be set in the GTFS configuration!")
return False
if config.get("data") is None:
_LOGGER.error("Data must be set in the GTFS configuration!")return False
gtfs_dir = hass.config.path("gtfs")
if not os.path.exists(gtfs_dir):
os.makedirs(gtfs_dir)
if not os.path.exists(os.path.join(gtfs_dir, config["data"])):
_LOGGER.error("The given GTFS data file/folder was not found!")
return False
import pygtfs
split_file_name = os.path.splitext(config["data"])
sqlite_file = "{}.sqlite".format(split_file_name[0])
joined_path = os.path.join(gtfs_dir, sqlite_file)
gtfs = pygtfs.Schedule(joined_path)
// pylint: disable=no-member
if len(gtfs.feeds) < 1:
pygtfs.append_feed(gtfs, os.path.join(gtfs_dir,
config["data"]))
dev = []dev.append(GTFSDepartureSensor(gtfs, config["origin"],
config["destination"]))
add_devices(dev)
// pylint: disable=too-many-instance-attributes,too-few-public-methods