mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Move imports in vasttrafik component (#27480)
This commit is contained in:
parent
54d63c63c3
commit
0a2ec30ce3
@ -2,6 +2,7 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import vasttrafik
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
@ -54,7 +55,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the departure sensor."""
|
"""Set up the departure sensor."""
|
||||||
import vasttrafik
|
|
||||||
|
|
||||||
planner = vasttrafik.JournyPlanner(config.get(CONF_KEY), config.get(CONF_SECRET))
|
planner = vasttrafik.JournyPlanner(config.get(CONF_KEY), config.get(CONF_SECRET))
|
||||||
sensors = []
|
sensors = []
|
||||||
@ -62,7 +62,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
for departure in config.get(CONF_DEPARTURES):
|
for departure in config.get(CONF_DEPARTURES):
|
||||||
sensors.append(
|
sensors.append(
|
||||||
VasttrafikDepartureSensor(
|
VasttrafikDepartureSensor(
|
||||||
vasttrafik,
|
|
||||||
planner,
|
planner,
|
||||||
departure.get(CONF_NAME),
|
departure.get(CONF_NAME),
|
||||||
departure.get(CONF_FROM),
|
departure.get(CONF_FROM),
|
||||||
@ -77,9 +76,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
class VasttrafikDepartureSensor(Entity):
|
class VasttrafikDepartureSensor(Entity):
|
||||||
"""Implementation of a Vasttrafik Departure Sensor."""
|
"""Implementation of a Vasttrafik Departure Sensor."""
|
||||||
|
|
||||||
def __init__(self, vasttrafik, planner, name, departure, heading, lines, delay):
|
def __init__(self, planner, name, departure, heading, lines, delay):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._vasttrafik = vasttrafik
|
|
||||||
self._planner = planner
|
self._planner = planner
|
||||||
self._name = name or departure
|
self._name = name or departure
|
||||||
self._departure = planner.location_name(departure)[0]
|
self._departure = planner.location_name(departure)[0]
|
||||||
@ -119,7 +117,7 @@ class VasttrafikDepartureSensor(Entity):
|
|||||||
direction=self._heading["id"] if self._heading else None,
|
direction=self._heading["id"] if self._heading else None,
|
||||||
date=now() + self._delay,
|
date=now() + self._delay,
|
||||||
)
|
)
|
||||||
except self._vasttrafik.Error:
|
except vasttrafik.Error:
|
||||||
_LOGGER.debug("Unable to read departure board, updating token")
|
_LOGGER.debug("Unable to read departure board, updating token")
|
||||||
self._planner.update_token()
|
self._planner.update_token()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user