Skip to content

Commit

Permalink
Added x_api_key parameter
Browse files Browse the repository at this point in the history
Added x_api_key parameter
  • Loading branch information
mark1foley committed Oct 22, 2022
1 parent e8be792 commit 94c89dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Configuration variables:
- **update_frequency** (*Optional*): Frequency (in seconds) that updates occur. Default is 60
- **vehicle_position_url** (*Optional*): Provides live position tracking on the home assistant map
- **api_key** (*Optional*): If provided, this key will be sent with API requests in an "Authorization" header.
- **x_api_key** (*Optional*): If provided, this key will be sent with API requests in an "Authorization" header.
- **route_delimiter** (*Optional*): If provided, the text in the feed's route id before the delimiter is used as the route id. Useful if the provider incorporates calendar ids into their route ids.
- **departures** (*Required*): A list of routes and departure locations to watch
- **name** (*Required*): The name of the sensor in HA. When displaying on the map card HA generates the name using the first letters of the first 3 words. So, 1<space>0<space>7<space>Bus shows as "107" on the map. Different labels can be defined when displaying the sensor on an entiry card etc.
Expand Down
8 changes: 6 additions & 2 deletions custom_components/gtfs_rt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ATTR_ICON = "Icon"

CONF_API_KEY = 'api_key'
CONF_X_API_KEY = 'x_api_key'
CONF_STOP_ID = 'stopid'
CONF_ROUTE = 'route'
CONF_DEPARTURES = 'departures'
Expand All @@ -39,6 +40,7 @@
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_TRIP_UPDATE_URL): cv.string,
vol.Optional(CONF_API_KEY): cv.string,
vol.Optional(CONF_X_API_KEY): cv.string,
vol.Optional(CONF_VEHICLE_POSITION_URL): cv.string,
vol.Optional(CONF_ROUTE_DELIMITER): cv.string,
vol.Optional(CONF_DEPARTURES): [{
Expand All @@ -60,7 +62,7 @@ def due_in_minutes(timestamp):
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Get the public transport sensor."""

data = PublicTransportData(config.get(CONF_TRIP_UPDATE_URL), config.get(CONF_VEHICLE_POSITION_URL), config.get(CONF_ROUTE_DELIMITER), config.get(CONF_API_KEY))
data = PublicTransportData(config.get(CONF_TRIP_UPDATE_URL), config.get(CONF_VEHICLE_POSITION_URL), config.get(CONF_ROUTE_DELIMITER), config.get(CONF_API_KEY, config.get(CONF_X_API_KEY)))
sensors = []
for departure in config.get(CONF_DEPARTURES):
sensors.append(PublicTransportSensor(
Expand Down Expand Up @@ -164,13 +166,15 @@ def update(self):
class PublicTransportData(object):
"""The Class for handling the data retrieval."""

def __init__(self, trip_update_url, vehicle_position_url=None, route_delimiter=None, api_key=None):
def __init__(self, trip_update_url, vehicle_position_url=None, route_delimiter=None, api_key=None, x_api_key=None):
"""Initialize the info object."""
self._trip_update_url = trip_update_url
self._vehicle_position_url = vehicle_position_url
self._route_delimiter = route_delimiter
if api_key is not None:
self._headers = {'Authorization': api_key}
elif x_api_key is not None:
self._headers = {'x-api-key': x_api_key}
else:
self._headers = None
self.info = {}
Expand Down

0 comments on commit 94c89dc

Please sign in to comment.