Skip to content

Commit

Permalink
improved debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
FaserF committed Dec 24, 2024
1 parent 2f3dfa6 commit 4b85b10
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions custom_components/deutschebahn/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from deutsche_bahn_api.api_authentication import ApiAuthentication
from deutsche_bahn_api.station_helper import StationHelper
from deutsche_bahn_api.timetable_helper import TimetableHelper
#import deutsche_bahn_api

from homeassistant import config_entries, core
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
Expand Down Expand Up @@ -119,9 +118,10 @@ def native_value(self):
def extra_state_attributes(self):
"""Return the state attributes."""
attributes = {
"departures": self.connections,
"departures": self.connections if self.connections else "No connections found",
"last_update": datetime.now(),
}
_LOGGER.debug(f"Extra state attributes: {attributes}")
return attributes

async def async_added_to_hass(self):
Expand Down Expand Up @@ -156,6 +156,7 @@ async def async_update(self):
if not self.connections:
self.connections = []
self._available = True
self._state = "No connections available"

if self.connections:
# Log the first connection to inspect its structure
Expand All @@ -168,9 +169,11 @@ async def async_update(self):
departure_time = first_connection.departure
delay = getattr(first_connection, "delay", 0)
self._state = f"{departure_time} (+{delay})" if delay else departure_time
_LOGGER.debug(f"Set state: {self._state}")
else:
_LOGGER.error(f"First connection does not have the expected attributes: {first_connection}")

except Exception as e:
self._available = False
self._state = "Error retrieving data"
_LOGGER.exception(f"Error updating Deutsche Bahn data: {e}")

0 comments on commit 4b85b10

Please sign in to comment.