mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
implement comments from #157
This commit is contained in:
parent
4292c1f207
commit
512c4629b6
@ -92,8 +92,10 @@ class SwissPublicTransportSensor(Entity):
|
|||||||
def update(self):
|
def update(self):
|
||||||
""" Gets the latest data from opendata.ch and updates the states. """
|
""" Gets the latest data from opendata.ch and updates the states. """
|
||||||
times = self.data.update()
|
times = self.data.update()
|
||||||
if times is not None:
|
try:
|
||||||
self._state = ', '.join(times)
|
self._state = ', '.join(times)
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
@ -101,7 +103,6 @@ class PublicTransportData(object):
|
|||||||
""" Class for handling the data retrieval. """
|
""" Class for handling the data retrieval. """
|
||||||
|
|
||||||
def __init__(self, journey):
|
def __init__(self, journey):
|
||||||
self.times = ['n/a', 'n/a']
|
|
||||||
self.start = journey[0]
|
self.start = journey[0]
|
||||||
self.destination = journey[1]
|
self.destination = journey[1]
|
||||||
|
|
||||||
@ -117,14 +118,15 @@ class PublicTransportData(object):
|
|||||||
'fields[]=connections/from/departureTimestamp/&' +
|
'fields[]=connections/from/departureTimestamp/&' +
|
||||||
'fields[]=connections/')
|
'fields[]=connections/')
|
||||||
|
|
||||||
try:
|
connections = response.json()['connections'][:2]
|
||||||
self.times.insert(0, dt_util.timestamp_to_short_time_str(
|
|
||||||
response.json()['connections'][0]['from']
|
|
||||||
['departureTimestamp']))
|
|
||||||
self.times.insert(1, dt_util.timestamp_to_short_time_str(
|
|
||||||
response.json()['connections'][1]['from']
|
|
||||||
['departureTimestamp']))
|
|
||||||
return self.times
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
return [
|
||||||
|
dt_util.datetime_to_short_time_str(
|
||||||
|
dt_util.as_local(dt_util.utc_from_timestamp(
|
||||||
|
item['from']['departureTimestamp']))
|
||||||
|
)
|
||||||
|
for item in connections
|
||||||
|
]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return self.times
|
return ['n/a']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user