Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ omit =
homeassistant/components/sensor/launch_library.py
homeassistant/components/sensor/linky.py
homeassistant/components/sensor/linux_battery.py
homeassistant/components/sensor/london_underground.py
homeassistant/components/sensor/loopenergy.py
homeassistant/components/sensor/luftdaten.py
homeassistant/components/sensor/lyft.py
Expand Down
46 changes: 3 additions & 43 deletions homeassistant/components/sensor/london_underground.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from datetime import timedelta

import voluptuous as vol
import requests

import homeassistant.helpers.config_validation as cv
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle

REQUIREMENTS = ['london-tube-status==0.2']

_LOGGER = logging.getLogger(__name__)

Expand All @@ -35,7 +35,6 @@
'TfL Rail',
'Victoria',
'Waterloo & City']
URL = 'https://api.tfl.gov.uk/line/mode/tube,overground,dlr,tflrail/status'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_LINE):
Expand All @@ -45,6 +44,7 @@

def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Tube sensor."""
from london_tube_status import TubeData
data = TubeData()
data.update()
sensors = []
Expand Down Expand Up @@ -93,43 +93,3 @@ def update(self):
self._data.update()
self._state = self._data.data[self.name]['State']
self._description = self._data.data[self.name]['Description']


class TubeData:
"""Get the latest tube data from TFL."""

def __init__(self):
"""Initialize the TubeData object."""
self.data = None

# Update only once in scan interval.
@Throttle(SCAN_INTERVAL)
def update(self):
"""Get the latest data from TFL."""
response = requests.get(URL)
if response.status_code != 200:
_LOGGER.warning("Invalid response from API")
else:
self.data = parse_api_response(response.json())


def parse_api_response(response):
"""Take in the TFL API json response."""
lines = [line['name'] for line in response]
data_dict = dict.fromkeys(lines)

for line in response:
statuses = [status['statusSeverityDescription']
for status in line['lineStatuses']]
state = ' + '.join(sorted(set(statuses)))

if state == 'Good Service':
reason = 'Nothing to report'
else:
reason = ' *** '.join(
[status['reason'] for status in line['lineStatuses']])

attr = {'State': state, 'Description': reason}
data_dict[line['name']] = attr

return data_dict
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,9 @@ locationsharinglib==3.0.9
# homeassistant.components.logi_circle
logi_circle==0.1.7

# homeassistant.components.sensor.london_underground
london-tube-status==0.2

# homeassistant.components.luftdaten
luftdaten==0.3.4

Expand Down
37 changes: 0 additions & 37 deletions tests/components/sensor/test_london_underground.py

This file was deleted.

Loading