@@ -105,7 +105,7 @@ def _remove_unwanted_departures(self, departures):
105105 )
106106
107107 return departures [: self ._max_items ]
108- except (KeyError , OSError ) as err :
108+ except (KeyError , TypeError , OSError ) as err :
109109 _LOGGER .info (
110110 "%s: Failed to process realtime departures: %s" ,
111111 self ._stop_code ,
@@ -235,7 +235,7 @@ def _data_to_display_format(self, data):
235235 }
236236 formatted_data .append (departure )
237237 return sorted (formatted_data , key = lambda x : x ["time_to_station" ])
238- except OSError as err :
238+ except ( OSError , ValueError ) as err :
239239 _LOGGER .debug ("%s: Failed to format data: %s" , self ._stop_code , err )
240240 return []
241241
@@ -298,7 +298,7 @@ def state(self) -> str:
298298 """Return the state of the sensor."""
299299 if len (self ._all_data ) > 0 :
300300 return self ._all_data [0 ]["departure" ]
301- return
301+ return "unknown"
302302
303303 @property
304304 def extra_state_attributes (self ):
@@ -400,9 +400,10 @@ def icon(self) -> str:
400400 @property
401401 def state (self ) -> str :
402402 """Return the state of the sensor."""
403- if len ( self . _alerts ) > 0 :
403+ try :
404404 return len (self ._alerts )
405- return 0
405+ except TypeError :
406+ return 0
406407
407408 @property
408409 def extra_state_attributes (self ):
0 commit comments