Skip to content

Commit

Permalink
Finetuning
Browse files Browse the repository at this point in the history
  • Loading branch information
vingerha committed Dec 4, 2023
1 parent 1254004 commit 3e1f20f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
15 changes: 12 additions & 3 deletions custom_components/gtfs2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from datetime import timedelta

from .const import DOMAIN, PLATFORMS, DEFAULT_PATH, DEFAULT_REFRESH_INTERVAL
from homeassistant.const import CONF_HOST
from .coordinator import GTFSUpdateCoordinator
import voluptuous as vol
from .gtfs_helper import get_gtfs
Expand Down Expand Up @@ -107,19 +108,27 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok


async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Remove a config entry."""
await hass.async_add_executor_job(_remove_token_file, hass, entry.data[CONF_HOST])
if DOMAIN in hass.data:
hass.data[DOMAIN].pop(entry.entry_id, None)
if not hass.data[DOMAIN]:
hass.data.pop(DOMAIN)

def setup(hass, config):
"""Setup the service example component."""
"""Setup the service component."""

def update_gtfs(call):
"""My GTFS service."""
_LOGGER.debug("Updating GTFS with: %s", call.data)
get_gtfs(hass, DEFAULT_PATH, call.data, True)
return True
return True

hass.services.register(
DOMAIN, "update_gtfs", update_gtfs)

return True

async def update_listener(hass: HomeAssistant, entry: ConfigEntry):
Expand Down
7 changes: 3 additions & 4 deletions custom_components/gtfs2/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ async def _async_update_data(self) -> dict[str, str]:
self._headers = None
self._headers = None
self.info = {}
try:
self._route_id = self._data["next_departure"]["route_id"]
except Exception as ex: # pylint: disable=broad-except
_LOGGER.error("Error getting entity route_id for realtime data, for origin: %s with error: %s", data["origin"], ex)
self._route_id = self._data["next_departure"].get("route_id", None)
if self._route_id == None:
_LOGGER.debug("GTFS RT: no route_id in sensor data, using route_id from config_entry")
self._route_id = data["route"].split(": ")[0]
self._stop_id = data["origin"].split(": ")[0]
self._destination_id = data["destination"].split(": ")[0]
Expand Down
3 changes: 1 addition & 2 deletions custom_components/gtfs2/gtfs_rt_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ 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"):
Expand Down Expand Up @@ -427,7 +426,7 @@ def update_geojson(self):
file = os.path.join(geojson_dir, self._route_dir + ".json")
_LOGGER.debug("GTFS RT geojson file: %s", file)
with open(file, "w") as outfile:
json.dump(self.geojson, outfile)
json.dump(self.geojson, outfile)



2 changes: 1 addition & 1 deletion custom_components/gtfs2/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/vingerha/gtfs2/issues",
"requirements": ["pygtfs==0.1.9","gtfs-realtime-bindings==1.0.0"],
"version": "0.1.6"
"version": "0.1.9"
}
2 changes: 1 addition & 1 deletion custom_components/gtfs2/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def _update_attrs(self): # noqa: C901 PLR0911
if "destination_stop_time" in self._departure:
_LOGGER.debug("Destination_stop_time %s", self._departure["destination_stop_time"])
else:
_LOGGER.warning("No destination_stop_time")
_LOGGER.debug("No destination_stop_time, possibly no service today")
prefix = "destination_stop"
if self._departure:
self.append_keys(self._departure["destination_stop_time"], prefix)
Expand Down

0 comments on commit 3e1f20f

Please sign in to comment.