diff --git a/custom_components/gtfs2/config_flow.py b/custom_components/gtfs2/config_flow.py index 45aa58f..415d394 100644 --- a/custom_components/gtfs2/config_flow.py +++ b/custom_components/gtfs2/config_flow.py @@ -525,7 +525,7 @@ async def async_step_real_time( vol.Optional(CONF_API_KEY, default=self.config_entry.options.get(CONF_API_KEY)) : str, vol.Optional(CONF_API_KEY_NAME, default=self.config_entry.options.get(CONF_API_KEY_NAME,DEFAULT_API_KEY_NAME)) : str, vol.Required(CONF_API_KEY_LOCATION, default=self.config_entry.options.get(CONF_API_KEY_LOCATION,DEFAULT_API_KEY_LOCATION)) : selector.SelectSelector(selector.SelectSelectorConfig(options=ATTR_API_KEY_LOCATIONS, translation_key="api_key_location")), - vol.Optional(CONF_ACCEPT_HEADER_PB, default = False): selector.BooleanSelector(), + vol.Optional(CONF_ACCEPT_HEADER_PB, default = self.config_entry.options.get(CONF_ACCEPT_HEADER_PB,False)): selector.BooleanSelector(), }, ), errors=errors, @@ -541,7 +541,7 @@ async def async_step_real_time( vol.Optional(CONF_API_KEY, default=self.config_entry.options.get(CONF_API_KEY)) : str, vol.Optional(CONF_API_KEY_NAME, default=self.config_entry.options.get(CONF_API_KEY_NAME,DEFAULT_API_KEY_NAME)) : str, vol.Required(CONF_API_KEY_LOCATION, default=self.config_entry.options.get(CONF_API_KEY_LOCATION,DEFAULT_API_KEY_LOCATION)) : selector.SelectSelector(selector.SelectSelectorConfig(options=ATTR_API_KEY_LOCATIONS, translation_key="api_key_location")), - vol.Optional(CONF_ACCEPT_HEADER_PB, default = False): selector.BooleanSelector(), + vol.Optional(CONF_ACCEPT_HEADER_PB, default = self.config_entry.options.get(CONF_ACCEPT_HEADER_PB,False)): selector.BooleanSelector(), }, ), errors=errors, diff --git a/custom_components/gtfs2/coordinator.py b/custom_components/gtfs2/coordinator.py index 36f0755..455f768 100644 --- a/custom_components/gtfs2/coordinator.py +++ b/custom_components/gtfs2/coordinator.py @@ -203,8 +203,8 @@ async def _async_update_data(self) -> dict[str, str]: self._headers = {options[CONF_API_KEY_NAME]: options[CONF_API_KEY]} self._headers[CONF_API_KEY_LOCATION] = options.get(CONF_API_KEY_LOCATION,None) self._headers[CONF_API_KEY_NAME] = options.get(CONF_API_KEY_NAME, None) - if options.get(CONF_ACCEPT_HEADER_PB, False): - self._headers["Accept"] = "application/x-protobuf" + self._headers[CONF_API_KEY] = options.get(CONF_API_KEY, None) + self._headers[CONF_ACCEPT_HEADER_PB] = options.get(CONF_ACCEPT_HEADER_PB, False) _LOGGER.debug("RT header: %s", self._headers) self._pygtfs = get_gtfs( self.hass, DEFAULT_PATH, data, False diff --git a/custom_components/gtfs2/gtfs_helper.py b/custom_components/gtfs2/gtfs_helper.py index db22eb4..4ca32b2 100644 --- a/custom_components/gtfs2/gtfs_helper.py +++ b/custom_components/gtfs2/gtfs_helper.py @@ -999,7 +999,7 @@ def get_local_stops_next_departures(self): # check if local file created if check != "ok": _LOGGER.error("Could not download RT data from: %s", self._trip_update_url) - return False + return {} else: # use local file created as new url self._trip_update_url = "file://" + DEFAULT_PATH_RT + "/" + self._data["name"] + "_localstop.rt" diff --git a/custom_components/gtfs2/gtfs_rt_helper.py b/custom_components/gtfs2/gtfs_rt_helper.py index 7d01889..7d3f7bb 100644 --- a/custom_components/gtfs2/gtfs_rt_helper.py +++ b/custom_components/gtfs2/gtfs_rt_helper.py @@ -401,9 +401,14 @@ def get_gtfs_rt(hass, path, data): try: r = requests.get(url, headers = _headers , allow_redirects=True) open(os.path.join(gtfs_dir, file), "wb").write(r.content) + if r.status_code != 200: + _LOGGER.error("Ìssues with downloading GTFS RT data, error: %s, content: %s", r.status_code, r.content) + return "no_rt_data_file" except Exception as ex: # pylint: disable=broad-except _LOGGER.error("Ìssues with downloading GTFS RT data to: %s", os.path.join(gtfs_dir, file)) return "no_rt_data_file" + + if data.get("debug_output", False): try: data_out = ""