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