Entur upgrade to v0.2.0: async polling, number of departures, omit non boarding departures (#22001)
* The Great Migration * removed outdated tests * Upgraded enturclient to v0.2.0 - client has gone async - configurable if non boarding departures should be omitted from result - configurable how many departures should be shown - more clear which attributes are included and when * reduced nesting and clearing of attributes * Removed test data * ensure attribution and stop id in attributes * docstring fixes * fix rebase errors went a bit too fast on continue on one of the conflicts.. * fix test requirements comment from gen
This commit is contained in:
1 parent
a1369c2fee
commit
f11f5255ae
9 files changed
+106
-249
No files matched your search
@@ -1 +0,0 @@
|
||||
"""Tests for the entur_public_transport component."""
|
||||
@@ -1,66 +0,0 @@
|
||||
"""The tests for the entur platform."""
|
||||
from datetime import datetime
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from enturclient.api import RESOURCE
|
||||
from enturclient.consts import ATTR_EXPECTED_AT, ATTR_ROUTE, ATTR_STOP_ID
|
||||
import requests_mock
|
||||
|
||||
from homeassistant.components.entur_public_transport.sensor import (
|
||||
CONF_EXPAND_PLATFORMS, CONF_STOP_IDS)
|
||||
from homeassistant.setup import setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import get_test_home_assistant, load_fixture
|
||||
|
||||
VALID_CONFIG = {
|
||||
'platform': 'entur_public_transport',
|
||||
CONF_EXPAND_PLATFORMS: False,
|
||||
CONF_STOP_IDS: [
|
||||
'NSR:StopPlace:548',
|
||||
'NSR:Quay:48550',
|
||||
]
|
||||
}
|
||||
|
||||
FIXTURE_FILE = 'entur_public_transport.json'
|
||||
TEST_TIMESTAMP = datetime(2018, 10, 10, 7, tzinfo=dt_util.UTC)
|
||||
|
||||
|
||||
class TestEnturPublicTransportSensor(unittest.TestCase):
|
||||
"""Test the entur platform."""
|
||||
|
||||
def setUp(self):
|
||||
"""Initialize values for this testcase class."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
@requests_mock.Mocker()
|
||||
@patch(
|
||||
'homeassistant.components.entur_public_transport.sensor.dt_util.now',
|
||||
return_value=TEST_TIMESTAMP)
|
||||
def test_setup(self, mock_req, mock_patch):
|
||||
"""Test for correct sensor setup with state and proper attributes."""
|
||||
mock_req.post(RESOURCE,
|
||||
text=load_fixture(FIXTURE_FILE),
|
||||
status_code=200)
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, 'sensor', {'sensor': VALID_CONFIG}))
|
||||
|
||||
state = self.hass.states.get('sensor.entur_bergen_stasjon')
|
||||
assert state.state == '28'
|
||||
assert state.attributes.get(ATTR_STOP_ID) == 'NSR:StopPlace:548'
|
||||
assert state.attributes.get(ATTR_ROUTE) == "59 Bergen"
|
||||
assert state.attributes.get(ATTR_EXPECTED_AT) \
|
||||
== '2018-10-10T09:28:00+0200'
|
||||
|
||||
state = self.hass.states.get('sensor.entur_fiskepiren_platform_2')
|
||||
assert state.state == '0'
|
||||
assert state.attributes.get(ATTR_STOP_ID) == 'NSR:Quay:48550'
|
||||
assert state.attributes.get(ATTR_ROUTE) \
|
||||
== "5 Stavanger Airport via Forum"
|
||||
assert state.attributes.get(ATTR_EXPECTED_AT) \
|
||||
== '2018-10-10T09:00:00+0200'
|
||||
-111
@@ -1,111 +0,0 @@
|
||||
{
|
||||
"data": {
|
||||
"stopPlaces": [
|
||||
{
|
||||
"id": "NSR:StopPlace:548",
|
||||
"name": "Bergen stasjon",
|
||||
"estimatedCalls": [
|
||||
{
|
||||
"realtime": false,
|
||||
"aimedArrivalTime": "2018-10-10T09:28:00+0200",
|
||||
"aimedDepartureTime": "2018-10-10T09:28:00+0200",
|
||||
"expectedArrivalTime": "2018-10-10T09:28:00+0200",
|
||||
"expectedDepartureTime": "2018-10-10T09:28:00+0200",
|
||||
"requestStop": false,
|
||||
"notices": [],
|
||||
"destinationDisplay": {
|
||||
"frontText": "Bergen"
|
||||
},
|
||||
"serviceJourney": {
|
||||
"journeyPattern": {
|
||||
"line": {
|
||||
"id": "NSB:Line:45",
|
||||
"name": "Vossabanen",
|
||||
"transportMode": "rail",
|
||||
"publicCode": "59"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"realtime": false,
|
||||
"aimedArrivalTime": "2018-10-10T09:35:00+0200",
|
||||
"aimedDepartureTime": "2018-10-10T09:35:00+0200",
|
||||
"expectedArrivalTime": "2018-10-10T09:35:00+0200",
|
||||
"expectedDepartureTime": "2018-10-10T09:35:00+0200",
|
||||
"requestStop": false,
|
||||
"notices": [],
|
||||
"destinationDisplay": {
|
||||
"frontText": "Arna"
|
||||
},
|
||||
"serviceJourney": {
|
||||
"journeyPattern": {
|
||||
"line": {
|
||||
"id": "NSB:Line:45",
|
||||
"name": "Vossabanen",
|
||||
"transportMode": "rail",
|
||||
"publicCode": "58"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"quays": [
|
||||
{
|
||||
"id": "NSR:Quay:48550",
|
||||
"name": "Fiskepiren",
|
||||
"publicCode": "2",
|
||||
"latitude": 59.960904,
|
||||
"longitude": 10.882942,
|
||||
"estimatedCalls": [
|
||||
{
|
||||
"realtime": false,
|
||||
"aimedArrivalTime": "2018-10-10T09:00:00+0200",
|
||||
"aimedDepartureTime": "2018-10-10T09:00:00+0200",
|
||||
"expectedArrivalTime": "2018-10-10T09:00:00+0200",
|
||||
"expectedDepartureTime": "2018-10-10T09:00:00+0200",
|
||||
"requestStop": false,
|
||||
"notices": [],
|
||||
"destinationDisplay": {
|
||||
"frontText": "Stavanger Airport via Forum"
|
||||
},
|
||||
"serviceJourney": {
|
||||
"journeyPattern": {
|
||||
"line": {
|
||||
"id": "KOL:Line:2900_234",
|
||||
"name": "Flybussen",
|
||||
"transportMode": "bus",
|
||||
"publicCode": "5"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"realtime": false,
|
||||
"aimedArrivalTime": "2018-10-10T09:06:00+0200",
|
||||
"aimedDepartureTime": "2018-10-10T09:06:00+0200",
|
||||
"expectedArrivalTime": "2018-10-10T09:06:00+0200",
|
||||
"expectedDepartureTime": "2018-10-10T09:06:00+0200",
|
||||
"requestStop": false,
|
||||
"notices": [],
|
||||
"destinationDisplay": {
|
||||
"frontText": "Stavanger"
|
||||
},
|
||||
"serviceJourney": {
|
||||
"journeyPattern": {
|
||||
"line": {
|
||||
"id": "KOL:Line:1000_234",
|
||||
"name": "1",
|
||||
"transportMode": "bus",
|
||||
"publicCode": "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user