Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bizkaibus, Biscays (Spain) bus service component #22934

Merged
merged 19 commits into from May 5, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Fixed the api call to use PyPI package

  • Loading branch information...
UgaitzEtxebarria committed Apr 14, 2019
commit 054eb8915d49a1a6d220bb6c74b710a4b2b333a0
@@ -1,2 +1,2 @@
"""The Bizkaibus, Biscays (Basque Country, Spain)
bus service, bus tracker component."""
# The Bizkaibus, Biscays (Basque Country, Spain)
# bus service, bus tracker component.
@@ -11,6 +11,7 @@
from homeassistant.const import CONF_NAME
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.helpers.entity import Entity
from bizkaibus import BizkaibusData

import xml.etree.ElementTree as ET

@@ -79,7 +80,7 @@ def update(self):
pass


class BizkaibusData:
class Bizkaibus:
"""The class for handling the data retrieval."""

def __init__(self, stop, route):
@@ -92,45 +93,6 @@ def __init__(self, stop, route):

def update(self):
"""Retrieve the information from API."""
params = {}
params['callback'] = ''
params['strLinea'] = self.route
params['strParada'] = self.stop

response = requests.get(_RESOURCE, params, timeout=10)

if response.status_code != 200:

self.info = [{ATTR_ROUTE_NAME: 'n/a',
ATTR_ROUTE: self.route,
ATTR_DUE_IN: 'n/a'}]
return

strJSON = response.text[1:-2].replace('\'', '"')
result = json.loads(strJSON)

if str(result['STATUS']) != 'OK':
self.info = [{ATTR_ROUTE_NAME: 'n/a',
ATTR_ROUTE: self.route,
ATTR_DUE_IN: 'n/a'}]
return

root = ET.fromstring(result['Resultado'])

self.info = []
for childBus in root.findall("PasoParada"):
route = childBus.find('linea').text
routeName = childBus.find('ruta').text
time = childBus.find('e1').find('minutos').text

if (routeName is not None and time is not None and
route is not None and route == self.route):
bus_data = {ATTR_ROUTE_NAME: routeName,
ATTR_ROUTE: route,
ATTR_DUE_IN: time}
self.info.append(bus_data)

if not self.info:
self.info = [{ATTR_ROUTE_NAME: 'n/a',
ATTR_ROUTE: self.route,
ATTR_DUE_IN: 'n/a'}]
bridge = BizkaibusData(self.stop, self.route)
bridge.getNextBus()
status = bridge.info
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.