mirror of https://github.com/home-assistant/core
Add Bizkaibus, Biscays (Spain) bus service component (#22934)
* Updated to the current version of dev * Added the component to .coveragerc * Added __init__.py and manifest.json * Changed the manifest to comply the json format * Changes in for complete the PEP8 Code * Fixed the api call to use PyPI package * Fixed API correrct call * Fixes for complete the requirements * Added dependencies in manifest.json * Changed the __init__.py to complete PEP8 * Simplified the __init__.py * Runned codeowner script * executed gen_requirements_all.py * Direct call for dicts and unit changed to minutes * Fixed the optional dict call, sorry, my bad, I did not that * Deleted unused vars * Changed optional parameter to required * Remove blank first line
This commit is contained in:
parent
9712bbc91c
commit
8da600adff
|
@ -53,6 +53,7 @@ omit =
|
||||||
homeassistant/components/bbox/sensor.py
|
homeassistant/components/bbox/sensor.py
|
||||||
homeassistant/components/bh1750/sensor.py
|
homeassistant/components/bh1750/sensor.py
|
||||||
homeassistant/components/bitcoin/sensor.py
|
homeassistant/components/bitcoin/sensor.py
|
||||||
|
homeassistant/components/bizkaibus/sensor.py
|
||||||
homeassistant/components/blink/*
|
homeassistant/components/blink/*
|
||||||
homeassistant/components/blinksticklight/light.py
|
homeassistant/components/blinksticklight/light.py
|
||||||
homeassistant/components/blinkt/light.py
|
homeassistant/components/blinkt/light.py
|
||||||
|
|
|
@ -33,6 +33,7 @@ homeassistant/components/automation/* @home-assistant/core
|
||||||
homeassistant/components/aws/* @awarecan @robbiet480
|
homeassistant/components/aws/* @awarecan @robbiet480
|
||||||
homeassistant/components/axis/* @kane610
|
homeassistant/components/axis/* @kane610
|
||||||
homeassistant/components/bitcoin/* @fabaff
|
homeassistant/components/bitcoin/* @fabaff
|
||||||
|
homeassistant/components/bizkaibus/* @UgaitzEtxebarria
|
||||||
homeassistant/components/blink/* @fronzbot
|
homeassistant/components/blink/* @fronzbot
|
||||||
homeassistant/components/bmw_connected_drive/* @ChristianKuehnel
|
homeassistant/components/bmw_connected_drive/* @ChristianKuehnel
|
||||||
homeassistant/components/braviatv/* @robbiet480
|
homeassistant/components/braviatv/* @robbiet480
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
"""The Bizkaibus bus tracker component."""
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"domain": "bizkaibus",
|
||||||
|
"name": "Bizkaibus",
|
||||||
|
"documentation": "https://www.home-assistant.io/components/bizkaibus",
|
||||||
|
"dependencies": [],
|
||||||
|
"codeowners": ["@UgaitzEtxebarria"],
|
||||||
|
"requirements": ["bizkaibus==0.1.1"]
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
"""Support for Bizkaibus, Biscay (Basque Country, Spain) Bus service."""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
from bizkaibus.bizkaibus import BizkaibusData
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
|
from homeassistant.const import CONF_NAME
|
||||||
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
ATTR_DUE_IN = 'Due in'
|
||||||
|
|
||||||
|
CONF_STOP_ID = 'stopid'
|
||||||
|
CONF_ROUTE = 'route'
|
||||||
|
|
||||||
|
DEFAULT_NAME = 'Next bus'
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_STOP_ID): cv.string,
|
||||||
|
vol.Required(CONF_ROUTE): cv.string,
|
||||||
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
|
"""Set up the Bizkaibus public transport sensor."""
|
||||||
|
name = config.get(CONF_NAME)
|
||||||
|
stop = config[CONF_STOP_ID]
|
||||||
|
route = config[CONF_ROUTE]
|
||||||
|
|
||||||
|
data = Bizkaibus(stop, route)
|
||||||
|
add_entities([BizkaibusSensor(data, stop, route, name)], True)
|
||||||
|
|
||||||
|
|
||||||
|
class BizkaibusSensor(Entity):
|
||||||
|
"""The class for handling the data."""
|
||||||
|
|
||||||
|
def __init__(self, data, stop, route, name):
|
||||||
|
"""Initialize the sensor."""
|
||||||
|
self.data = data
|
||||||
|
self.stop = stop
|
||||||
|
self.route = route
|
||||||
|
self._name = name
|
||||||
|
self._state = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Return the name of the sensor."""
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state(self):
|
||||||
|
"""Return the state of the sensor."""
|
||||||
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unit_of_measurement(self):
|
||||||
|
"""Return the unit of measurement of the sensor."""
|
||||||
|
return 'minutes'
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Get the latest data from the webservice."""
|
||||||
|
self.data.update()
|
||||||
|
try:
|
||||||
|
self._state = self.data.info[0][ATTR_DUE_IN]
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Bizkaibus:
|
||||||
|
"""The class for handling the data retrieval."""
|
||||||
|
|
||||||
|
def __init__(self, stop, route):
|
||||||
|
"""Initialize the data object."""
|
||||||
|
self.stop = stop
|
||||||
|
self.route = route
|
||||||
|
self.info = None
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Retrieve the information from API."""
|
||||||
|
bridge = BizkaibusData(self.stop, self.route)
|
||||||
|
bridge.getNextBus()
|
||||||
|
self.info = bridge.info
|
|
@ -229,6 +229,9 @@ bellows-homeassistant==0.7.2
|
||||||
# homeassistant.components.bmw_connected_drive
|
# homeassistant.components.bmw_connected_drive
|
||||||
bimmer_connected==0.5.3
|
bimmer_connected==0.5.3
|
||||||
|
|
||||||
|
# homeassistant.components.bizkaibus
|
||||||
|
bizkaibus==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.blink
|
# homeassistant.components.blink
|
||||||
blinkpy==0.13.1
|
blinkpy==0.13.1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue