Add link to docs

This commit is contained in:
Fabian Affolter 2016-02-28 15:35:20 +01:00
parent 9c4fe6e7fe
commit 9da8679dbd

View file

@ -1,10 +1,9 @@
''' """
homeassistant.components.sensor.bahn Support for information about the German trans system.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The deutsche_bahn sensor tells you if your next train is on time, or delayed.
'''
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.deutsche_bahn/
"""
import logging import logging
from datetime import timedelta, datetime from datetime import timedelta, datetime
from homeassistant.util import Throttle from homeassistant.util import Throttle
@ -12,15 +11,14 @@ from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['schiene==0.14'] REQUIREMENTS = ['schiene==0.14']
ICON = 'mdi:train' ICON = 'mdi:train'
# Return cached results if last scan was less then this time ago # Return cached results if last scan was less then this time ago.
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120) MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Add the Bahn Sensor. """ """Setup the Deutsche Bahn Sensor."""
start = config.get('from') start = config.get('from')
goal = config.get('to') goal = config.get('to')
@ -39,9 +37,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
class DeutscheBahnSensor(Entity): class DeutscheBahnSensor(Entity):
"""Implement a DeutscheBahn sensor """Implement a Deutsche Bahn sensor."""
start: starting station
goal: target station"""
def __init__(self, start, goal): def __init__(self, start, goal):
self._name = start + ' to ' + goal self._name = start + ' to ' + goal
self.data = SchieneData(start, goal) self.data = SchieneData(start, goal)
@ -49,25 +45,26 @@ class DeutscheBahnSensor(Entity):
@property @property
def name(self): def name(self):
""" return the name.""" """Return the name of the sensor."""
return self._name return self._name
@property @property
def icon(self): def icon(self):
""" Icon for the frontend""" """Return the icon for the frontend."""
return ICON return ICON
@property @property
def state(self): def state(self):
"""Return the depature time of the next train""" """Return the departure time of the next train."""
return self._state return self._state
@property @property
def state_attributes(self): def state_attributes(self):
"""Return the state attributes."""
return self.data.connections[0] return self.data.connections[0]
def update(self): def update(self):
""" Gets the latest delay from bahn.de and updates the state""" """Gets the latest delay from bahn.de and updates the state."""
self.data.update() self.data.update()
self._state = self.data.connections[0].get('departure', 'Unknown') self._state = self.data.connections[0].get('departure', 'Unknown')
delay = self.data.connections[0].get('delay', delay = self.data.connections[0].get('delay',
@ -79,7 +76,7 @@ class DeutscheBahnSensor(Entity):
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
class SchieneData(object): class SchieneData(object):
""" Pulls data from the bahn.de web page""" """Pulls data from the bahn.de web page."""
def __init__(self, start, goal): def __init__(self, start, goal):
import schiene import schiene
self.start = start self.start = start
@ -89,10 +86,11 @@ class SchieneData(object):
@Throttle(MIN_TIME_BETWEEN_UPDATES) @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self): def update(self):
""" update connection data""" """Update the connection data."""
self.connections = self.schiene.connections(self.start, self.connections = self.schiene.connections(self.start,
self.goal, self.goal,
datetime.now()) datetime.now())
for con in self.connections: for con in self.connections:
# Details info are not useful.
if 'details' in con: if 'details' in con:
con.pop('details') # details info is not usefull con.pop('details')