Use string formatting and remove already global disabled pylint issue (#6801)

This commit is contained in:
Fabian Affolter 2017-03-26 21:13:38 +02:00 committed by GitHub
parent 78b5eb7aac
commit 84287872bb

View File

@ -4,34 +4,33 @@ Support for real-time departure information for public transport in Munich.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.mvglive/ https://home-assistant.io/components/sensor.mvglive/
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta
import voluptuous as vol import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.util import Throttle from homeassistant.util import Throttle
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import STATE_UNKNOWN from homeassistant.const import STATE_UNKNOWN
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['PyMVGLive==1.1.3']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
# A typo in the file name of the PyPI version prevents installation from PyPI
REQUIREMENTS = ["PyMVGLive==1.1.3"]
ICON = 'mdi:bus'
# Return cached results if last scan was less then this time ago. CONF_BUS = 'bus'
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=15)
CONF_STATION = 'station'
CONF_DEST = 'destination' CONF_DEST = 'destination'
CONF_LINE = 'line' CONF_LINE = 'line'
CONF_OFFSET = 'offset' CONF_OFFSET = 'offset'
CONF_UBAHN = 'ubahn'
CONF_TRAM = 'tram'
CONF_BUS = 'bus'
CONF_SBAHN = 'sbahn' CONF_SBAHN = 'sbahn'
CONF_STATION = 'station'
CONF_TRAM = 'tram'
CONF_UBAHN = 'ubahn'
ICON = 'mdi:bus'
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=15)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_STATION): cv.string, vol.Required(CONF_STATION): cv.string,
@ -46,7 +45,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the MVG Live Sensor.""" """Set up the MVG Live Sensor."""
station = config.get(CONF_STATION) station = config.get(CONF_STATION)
destination = config.get(CONF_DEST) destination = config.get(CONF_DEST)
line = config.get(CONF_LINE) line = config.get(CONF_LINE)
@ -56,11 +55,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
bus = config.get(CONF_BUS) bus = config.get(CONF_BUS)
sbahn = config.get(CONF_SBAHN) sbahn = config.get(CONF_SBAHN)
add_devices([MVGLiveSensor(station, destination, line, add_devices([MVGLiveSensor(
offset, ubahn, tram, bus, sbahn)], True) station, destination, line, offset, ubahn, tram, bus, sbahn)], True)
# pylint: disable=too-few-public-methods
class MVGLiveSensor(Entity): class MVGLiveSensor(Entity):
"""Implementation of an MVG Live sensor.""" """Implementation of an MVG Live sensor."""
@ -83,9 +81,9 @@ class MVGLiveSensor(Entity):
# 'Hauptbahnhof-Marienplatz (S1)' # 'Hauptbahnhof-Marienplatz (S1)'
namestr = self._station namestr = self._station
if self._destination: if self._destination:
namestr = namestr + '-' + self._destination namestr = '{}-{}'.format(namestr, self._destination)
if self._line: if self._line:
namestr = namestr + ' (' + self._line + ')' namestr = '{} ({})'.format(namestr, self._line)
return namestr return namestr
@property @property
@ -134,11 +132,9 @@ class MVGLiveData(object):
def update(self): def update(self):
"""Update the connection data.""" """Update the connection data."""
try: try:
_departures = self.mvg.getlivedata(station=self._station, _departures = self.mvg.getlivedata(
ubahn=self._ubahn, station=self._station, ubahn=self._ubahn, tram=self._tram,
tram=self._tram, bus=self._bus, sbahn=self._sbahn)
bus=self._bus,
sbahn=self._sbahn)
except ValueError: except ValueError:
self.nextdeparture = {} self.nextdeparture = {}
_LOGGER.warning("Returned data not understood.") _LOGGER.warning("Returned data not understood.")