1
mirror of https://github.com/home-assistant/core synced 2024-09-06 10:29:55 +02:00

Ontime and delay attribute are allways present in deutsche_bahn sensor (#1875)

This commit is contained in:
deisi 2016-04-24 06:43:25 +02:00 committed by Paulus Schoutsen
parent 448edecdd1
commit 3b0a35f571

View File

@ -69,11 +69,10 @@ class DeutscheBahnSensor(Entity):
"""Get the latest delay from bahn.de and updates the state."""
self.data.update()
self._state = self.data.connections[0].get('departure', 'Unknown')
delay = self.data.connections[0].get('delay',
{'delay_departure': 0,
'delay_arrival': 0})
if delay['delay_departure'] != 0:
self._state += " + {}".format(delay['delay_departure'])
if self.data.connections[0]['delay'] != 0:
self._state += " + {}".format(
self.data.connections[0]['delay']
)
# pylint: disable=too-few-public-methods
@ -95,6 +94,14 @@ class SchieneData(object):
self.goal,
datetime.now())
for con in self.connections:
# Details info are not useful.
# Details info is not useful.
# Having a more consistent interface simplifies
# usage of Template sensors later on
if 'details' in con:
con.pop('details')
delay = con.get('delay',
{'delay_departure': 0,
'delay_arrival': 0})
# IMHO only delay_departure is usefull
con['delay'] = delay['delay_departure']
con['ontime'] = con.get('ontime', False)