Skip to content

Commit

Permalink
Adding option for Alerts when only route affected
Browse files Browse the repository at this point in the history
  • Loading branch information
vingerha committed Dec 2, 2023
1 parent 5ec5f6d commit 1254004
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion custom_components/gtfs2/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def _async_update_data(self) -> dict[str, str]:
self._data["next_departure_realtime_attr"]["gtfs_rt_updated_at"] = dt_util.utcnow()
self._data["alert"] = self._get_rt_alerts
except Exception as ex: # pylint: disable=broad-except
_LOGGER.error("Error getting gtfs realtime data, for origin: %s with error: %s", data["origin"], ex)
_LOGGER.error("Error getting gtfs realtime data, for origin: %s with error: %s", data["origin"], ex)
else:
_LOGGER.debug("GTFS RT: RealTime = false, selected in entity options")
else:
Expand Down
7 changes: 7 additions & 0 deletions custom_components/gtfs2/gtfs_rt_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,13 @@ def get_rt_alerts(self):
label="alerts",
)
for entity in feed_entities:
_LOGGER.debug("RT Alert entity: %s", entity)
if entity.HasField("alert"):
for x in entity.alert.informed_entity:
if x.HasField("stop_id"):
stop_id = x.stop_id
else:
stop_id = "unknown"
if x.HasField("stop_id"):
route_id = x.route_id
else:
Expand All @@ -410,6 +413,10 @@ def get_rt_alerts(self):
if stop_id == self._destination_id and (route_id == "unknown" or route_id == self._route_id):
_LOGGER.debug("RT Alert for route: %s, stop: %s, alert: %s", route_id, stop_id, entity.alert.header_text)
rt_alerts["destination_stop_alert"] = (str(entity.alert.header_text).split('text: "')[1]).split('"',1)[0].replace(':','').replace('\n','')
if stop_id == "unknown" and route_id == self._route_id:
_LOGGER.debug("RT Alert for route: %s, stop: %s, alert: %s", route_id, stop_id, entity.alert.header_text)
rt_alerts["origin_stop_alert"] = (str(entity.alert.header_text).split('text: "')[1]).split('"',1)[0].replace(':','').replace('\n','')
rt_alerts["destination_stop_alert"] = (str(entity.alert.header_text).split('text: "')[1]).split('"',1)[0].replace(':','').replace('\n','')

return rt_alerts

Expand Down

0 comments on commit 1254004

Please sign in to comment.