Migrate RMV to use httpx (#42560)

This commit is contained in:
Tobias Sauerwein 2021-01-27 15:57:58 +01:00 committed by GitHub
parent 8d572af77a
commit f14c4412b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 29 deletions

View File

@ -2,6 +2,10 @@
"domain": "rmvtransport", "domain": "rmvtransport",
"name": "RMV", "name": "RMV",
"documentation": "https://www.home-assistant.io/integrations/rmvtransport", "documentation": "https://www.home-assistant.io/integrations/rmvtransport",
"requirements": ["PyRMVtransport==0.2.9"], "requirements": [
"codeowners": ["@cgtobi"] "PyRMVtransport==0.2.10"
} ],
"codeowners": [
"@cgtobi"
]
}

View File

@ -10,7 +10,6 @@ import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, TIME_MINUTES from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, TIME_MINUTES
from homeassistant.exceptions import PlatformNotReady from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle from homeassistant.util import Throttle
@ -78,24 +77,20 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
"""Set up the RMV departure sensor.""" """Set up the RMV departure sensor."""
timeout = config.get(CONF_TIMEOUT) timeout = config.get(CONF_TIMEOUT)
session = async_get_clientsession(hass) sensors = [
RMVDepartureSensor(
sensors = [] next_departure[CONF_STATION],
for next_departure in config.get(CONF_NEXT_DEPARTURE): next_departure.get(CONF_DESTINATIONS),
sensors.append( next_departure.get(CONF_DIRECTION),
RMVDepartureSensor( next_departure.get(CONF_LINES),
session, next_departure.get(CONF_PRODUCTS),
next_departure[CONF_STATION], next_departure.get(CONF_TIME_OFFSET),
next_departure.get(CONF_DESTINATIONS), next_departure.get(CONF_MAX_JOURNEYS),
next_departure.get(CONF_DIRECTION), next_departure.get(CONF_NAME),
next_departure.get(CONF_LINES), timeout,
next_departure.get(CONF_PRODUCTS),
next_departure.get(CONF_TIME_OFFSET),
next_departure.get(CONF_MAX_JOURNEYS),
next_departure.get(CONF_NAME),
timeout,
)
) )
for next_departure in config.get(CONF_NEXT_DEPARTURE)
]
tasks = [sensor.async_update() for sensor in sensors] tasks = [sensor.async_update() for sensor in sensors]
if tasks: if tasks:
@ -112,7 +107,6 @@ class RMVDepartureSensor(Entity):
def __init__( def __init__(
self, self,
session,
station, station,
destinations, destinations,
direction, direction,
@ -128,7 +122,6 @@ class RMVDepartureSensor(Entity):
self._name = name self._name = name
self._state = None self._state = None
self.data = RMVDepartureData( self.data = RMVDepartureData(
session,
station, station,
destinations, destinations,
direction, direction,
@ -204,7 +197,6 @@ class RMVDepartureData:
def __init__( def __init__(
self, self,
session,
station_id, station_id,
destinations, destinations,
direction, direction,
@ -223,7 +215,7 @@ class RMVDepartureData:
self._products = products self._products = products
self._time_offset = time_offset self._time_offset = time_offset
self._max_journeys = max_journeys self._max_journeys = max_journeys
self.rmv = RMVtransport(session, timeout) self.rmv = RMVtransport(timeout)
self.departures = [] self.departures = []
self._error_notification = False self._error_notification = False
@ -263,10 +255,10 @@ class RMVDepartureData:
if not dest_found: if not dest_found:
continue continue
if self._lines and journey["number"] not in self._lines: elif self._lines and journey["number"] not in self._lines:
continue continue
if journey["minutes"] < self._time_offset: elif journey["minutes"] < self._time_offset:
continue continue
for attr in ["direction", "departure_time", "product", "minutes"]: for attr in ["direction", "departure_time", "product", "minutes"]:

View File

@ -49,7 +49,7 @@ PyNaCl==1.3.0
PyQRCode==1.2.1 PyQRCode==1.2.1
# homeassistant.components.rmvtransport # homeassistant.components.rmvtransport
PyRMVtransport==0.2.9 PyRMVtransport==0.2.10
# homeassistant.components.telegram_bot # homeassistant.components.telegram_bot
PySocks==1.7.1 PySocks==1.7.1

View File

@ -18,7 +18,7 @@ PyNaCl==1.3.0
PyQRCode==1.2.1 PyQRCode==1.2.1
# homeassistant.components.rmvtransport # homeassistant.components.rmvtransport
PyRMVtransport==0.2.9 PyRMVtransport==0.2.10
# homeassistant.components.transport_nsw # homeassistant.components.transport_nsw
PyTransportNSW==0.1.1 PyTransportNSW==0.1.1