Move imports to top for seventeentrack (#29264)

* Move imports to top for seventeentrack

* Updated patch target path in test_sensor.py
This commit is contained in:
springstan 2019-12-01 18:19:17 +01:00 committed by Aaron Bach
parent 9927f6c17d
commit 22225cea4d
2 changed files with 8 additions and 6 deletions

View File

@ -1,7 +1,9 @@
"""Support for package tracking sensors from 17track.net."""
import logging
from datetime import timedelta
import logging
from py17track import Client as SeventeenTrackClient
from py17track.errors import SeventeenTrackError
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
@ -61,12 +63,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Configure the platform and add the sensors."""
from py17track import Client
from py17track.errors import SeventeenTrackError
websession = aiohttp_client.async_get_clientsession(hass)
client = Client(websession)
client = SeventeenTrackClient(websession)
try:
login_result = await client.profile.login(
@ -290,7 +290,6 @@ class SeventeenTrackData:
async def _async_update(self):
"""Get updated data from 17track.net."""
from py17track.errors import SeventeenTrackError
try:
packages = await self._client.profile.packages(

View File

@ -119,7 +119,10 @@ def fixture_mock_py17track():
@pytest.fixture(autouse=True, name="mock_client")
def fixture_mock_client(mock_py17track):
"""Mock py17track client."""
with mock.patch("py17track.Client", new=ClientMock):
with mock.patch(
"homeassistant.components.seventeentrack.sensor.SeventeenTrackClient",
new=ClientMock,
):
yield
ProfileMock.reset()