From 3b0a35f571216c23482370ca3ba9774304398ac3 Mon Sep 17 00:00:00 2001 From: deisi Date: Sun, 24 Apr 2016 06:43:25 +0200 Subject: [PATCH] Ontime and delay attribute are allways present in deutsche_bahn sensor (#1875) --- .../components/sensor/deutsche_bahn.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/sensor/deutsche_bahn.py b/homeassistant/components/sensor/deutsche_bahn.py index 67a77d0720e..189eb6ef167 100644 --- a/homeassistant/components/sensor/deutsche_bahn.py +++ b/homeassistant/components/sensor/deutsche_bahn.py @@ -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)