mirror of
https://github.com/home-assistant/core.git
synced 2025-06-25 01:21:51 +02:00
Fix Yandex transport Integration, add signature to requests (#37365)
This commit is contained in:
committed by
GitHub
parent
cee136ec55
commit
cecdce07cc
@ -467,7 +467,7 @@ homeassistant/components/xiaomi_miio/* @rytilahti @syssi
|
||||
homeassistant/components/xiaomi_tv/* @simse
|
||||
homeassistant/components/xmpp/* @fabaff @flowolf
|
||||
homeassistant/components/yamaha_musiccast/* @jalmeroth
|
||||
homeassistant/components/yandex_transport/* @rishatik92
|
||||
homeassistant/components/yandex_transport/* @rishatik92 @devbis
|
||||
homeassistant/components/yeelight/* @rytilahti @zewelor
|
||||
homeassistant/components/yeelightsunflower/* @lindsaymarkward
|
||||
homeassistant/components/yessssms/* @flowolf
|
||||
|
@ -2,6 +2,6 @@
|
||||
"domain": "yandex_transport",
|
||||
"name": "Yandex Transport",
|
||||
"documentation": "https://www.home-assistant.io/integrations/yandex_transport",
|
||||
"requirements": ["ya_ma==0.3.8"],
|
||||
"codeowners": ["@rishatik92"]
|
||||
"requirements": ["aioymaps==1.0.0"],
|
||||
"codeowners": ["@rishatik92", "@devbis"]
|
||||
}
|
||||
|
@ -3,11 +3,12 @@
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from aioymaps import YandexMapsRequester
|
||||
import voluptuous as vol
|
||||
from ya_ma import YandexMapsRequester
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, DEVICE_CLASS_TIMESTAMP
|
||||
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
import homeassistant.util.dt as dt_util
|
||||
@ -35,20 +36,21 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the Yandex transport sensor."""
|
||||
stop_id = config[CONF_STOP_ID]
|
||||
name = config[CONF_NAME]
|
||||
routes = config[CONF_ROUTE]
|
||||
|
||||
data = YandexMapsRequester(user_agent=USER_AGENT)
|
||||
add_entities([DiscoverMoscowYandexTransport(data, stop_id, routes, name)], True)
|
||||
client_session = async_create_clientsession(hass, requote_redirect_url=False)
|
||||
data = YandexMapsRequester(user_agent=USER_AGENT, client_session=client_session)
|
||||
async_add_entities([DiscoverYandexTransport(data, stop_id, routes, name)], True)
|
||||
|
||||
|
||||
class DiscoverMoscowYandexTransport(Entity):
|
||||
class DiscoverYandexTransport(Entity):
|
||||
"""Implementation of yandex_transport sensor."""
|
||||
|
||||
def __init__(self, requester, stop_id, routes, name):
|
||||
def __init__(self, requester: YandexMapsRequester, stop_id, routes, name):
|
||||
"""Initialize sensor."""
|
||||
self.requester = requester
|
||||
self._stop_id = stop_id
|
||||
@ -58,12 +60,12 @@ class DiscoverMoscowYandexTransport(Entity):
|
||||
self._name = name
|
||||
self._attrs = None
|
||||
|
||||
def update(self):
|
||||
async def async_update(self):
|
||||
"""Get the latest data from maps.yandex.ru and update the states."""
|
||||
attrs = {}
|
||||
closer_time = None
|
||||
yandex_reply = await self.requester.get_stop_info(self._stop_id)
|
||||
try:
|
||||
yandex_reply = self.requester.get_stop_info(self._stop_id)
|
||||
data = yandex_reply["data"]
|
||||
except KeyError as key_error:
|
||||
_LOGGER.warning(
|
||||
@ -71,8 +73,8 @@ class DiscoverMoscowYandexTransport(Entity):
|
||||
key_error,
|
||||
yandex_reply,
|
||||
)
|
||||
self.requester.set_new_session()
|
||||
data = self.requester.get_stop_info(self._stop_id)["data"]
|
||||
await self.requester.set_new_session()
|
||||
data = (await self.requester.get_stop_info(self._stop_id))["data"]
|
||||
stop_name = data["name"]
|
||||
transport_list = data["transports"]
|
||||
for transport in transport_list:
|
||||
|
@ -215,6 +215,9 @@ aioswitcher==1.2.0
|
||||
# homeassistant.components.unifi
|
||||
aiounifi==23
|
||||
|
||||
# homeassistant.components.yandex_transport
|
||||
aioymaps==1.0.0
|
||||
|
||||
# homeassistant.components.airly
|
||||
airly==0.0.2
|
||||
|
||||
@ -2229,9 +2232,6 @@ xmltodict==0.12.0
|
||||
# homeassistant.components.xs1
|
||||
xs1-api-client==3.0.0
|
||||
|
||||
# homeassistant.components.yandex_transport
|
||||
ya_ma==0.3.8
|
||||
|
||||
# homeassistant.components.yale_smart_alarm
|
||||
yalesmartalarmclient==0.1.6
|
||||
|
||||
|
@ -125,6 +125,9 @@ aioswitcher==1.2.0
|
||||
# homeassistant.components.unifi
|
||||
aiounifi==23
|
||||
|
||||
# homeassistant.components.yandex_transport
|
||||
aioymaps==1.0.0
|
||||
|
||||
# homeassistant.components.airly
|
||||
airly==0.0.2
|
||||
|
||||
@ -980,9 +983,6 @@ wled==0.4.3
|
||||
# homeassistant.components.zestimate
|
||||
xmltodict==0.12.0
|
||||
|
||||
# homeassistant.components.yandex_transport
|
||||
ya_ma==0.3.8
|
||||
|
||||
# homeassistant.components.zeroconf
|
||||
zeroconf==0.27.1
|
||||
|
||||
|
@ -9,7 +9,7 @@ from homeassistant.const import CONF_NAME
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.async_mock import AsyncMock, patch
|
||||
from tests.common import assert_setup_component, load_fixture
|
||||
|
||||
REPLY = json.loads(load_fixture("yandex_transport_reply.json"))
|
||||
@ -17,10 +17,10 @@ REPLY = json.loads(load_fixture("yandex_transport_reply.json"))
|
||||
|
||||
@pytest.fixture
|
||||
def mock_requester():
|
||||
"""Create a mock ya_ma module and YandexMapsRequester."""
|
||||
with patch("ya_ma.YandexMapsRequester") as requester:
|
||||
"""Create a mock for YandexMapsRequester."""
|
||||
with patch("aioymaps.YandexMapsRequester") as requester:
|
||||
instance = requester.return_value
|
||||
instance.get_stop_info.return_value = REPLY
|
||||
instance.get_stop_info = AsyncMock(return_value=REPLY)
|
||||
yield instance
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user