Skip to content

Commit

Permalink
Fix migration and reduce errors (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
vingerha committed Dec 15, 2023
1 parent 2e5ef1a commit 30f4488
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
20 changes: 16 additions & 4 deletions custom_components/gtfs2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry) -> bool:
new_options['x_api_key'] = ""
new_options['offset'] = 0
new_data.pop('offset')
new_data['route_type'] = '99'

config_entry.version = 5
config_entry.version = 6
hass.config_entries.async_update_entry(config_entry, data=new_data)
hass.config_entries.async_update_entry(config_entry, options=new_options)

Expand All @@ -46,8 +47,9 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry) -> bool:
new_options['x_api_key'] = ""
new_options['offset'] = 0
new_data.pop('offset')
new_data['route_type'] = '99'

config_entry.version = 5
config_entry.version = 6
hass.config_entries.async_update_entry(config_entry, options=new_options)
hass.config_entries.async_update_entry(config_entry, data=new_data)

Expand All @@ -59,21 +61,31 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry) -> bool:
new_options['x_api_key'] = ""
new_options['offset'] = 0
new_data.pop('offset')
new_data['route_type'] = '99'

config_entry.version = 5
config_entry.version = 6
hass.config_entries.async_update_entry(config_entry, options=new_options)
hass.config_entries.async_update_entry(config_entry, data=new_data)

if config_entry.version == 4:

new_options = {**config_entry.options}
new_data = {**config_entry.data}
new_data['route_type'] = '99'
new_options['offset'] = 0
new_data.pop('offset')

config_entry.version = 5
config_entry.version = 6
hass.config_entries.async_update_entry(config_entry, data=new_data)
hass.config_entries.async_update_entry(config_entry, options=new_options)

if config_entry.version == 5:

new_data = {**config_entry.data}
new_data['route_type'] = '99'

config_entry.version = 6
hass.config_entries.async_update_entry(config_entry, data=new_data)

_LOGGER.warning("Migration to version %s successful", config_entry.version)

Expand Down
18 changes: 9 additions & 9 deletions custom_components/gtfs2/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ async def _async_update_data(self) -> dict[str, str]:
self._trip_id = self._data.get('next_departure', {}).get('trip_id', None)
self._direction = data["direction"]
self._relative = False
#try:
self._get_rt_route_statuses = await self.hass.async_add_executor_job(get_rt_route_statuses, self)
self._get_rt_alerts = await self.hass.async_add_executor_job(get_rt_alerts, self)
self._get_next_service = await self.hass.async_add_executor_job(get_next_services, self)
self._data["next_departure_realtime_attr"] = self._get_next_service
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)
try:
self._get_rt_route_statuses = await self.hass.async_add_executor_job(get_rt_route_statuses, self)
self._get_rt_alerts = await self.hass.async_add_executor_job(get_rt_alerts, self)
self._get_next_service = await self.hass.async_add_executor_job(get_next_services, self)
self._data["next_departure_realtime_attr"] = self._get_next_service
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)
else:
_LOGGER.debug("GTFS RT: RealTime = false, selected in entity options")
else:
Expand Down

0 comments on commit 30f4488

Please sign in to comment.