From 670bf0641a06676ec90c38fcc90953e8572f6a21 Mon Sep 17 00:00:00 2001 From: Alessandro Ghedini Date: Mon, 20 Jun 2022 14:08:50 +0100 Subject: [PATCH] Update london-tube-status for TfL API breaking change (#73671) * Update london-tube-status for TfL API breaking change The TfL API used by the london_underground component (through the london-tube-status module) introduced breaking changes recently, which in turn broke the component, and require updating the london-tube-status dependency to fix. However the newer module versions also introduced other changes, including switching from requests to aiohttp, which require converting the london_underground component to use async APIs. Fixes #73442 * Update sensor.py Co-authored-by: Erik Montnemery --- .../london_underground/manifest.json | 2 +- .../components/london_underground/sensor.py | 18 +++++++++++------- requirements_all.txt | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/london_underground/manifest.json b/homeassistant/components/london_underground/manifest.json index eed2ec45dd7..e3223eb109f 100644 --- a/homeassistant/components/london_underground/manifest.json +++ b/homeassistant/components/london_underground/manifest.json @@ -2,7 +2,7 @@ "domain": "london_underground", "name": "London Underground", "documentation": "https://www.home-assistant.io/integrations/london_underground", - "requirements": ["london-tube-status==0.2"], + "requirements": ["london-tube-status==0.5"], "codeowners": [], "iot_class": "cloud_polling", "loggers": ["london_tube_status"] diff --git a/homeassistant/components/london_underground/sensor.py b/homeassistant/components/london_underground/sensor.py index a73909295b6..a4cc66a8447 100644 --- a/homeassistant/components/london_underground/sensor.py +++ b/homeassistant/components/london_underground/sensor.py @@ -9,6 +9,7 @@ import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.core import HomeAssistant +from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -43,21 +44,24 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( ) -def setup_platform( +async def async_setup_platform( hass: HomeAssistant, config: ConfigType, - add_entities: AddEntitiesCallback, + async_add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Tube sensor.""" - data = TubeData() - data.update() + session = async_get_clientsession(hass) + + data = TubeData(session) + await data.update() + sensors = [] for line in config[CONF_LINE]: sensors.append(LondonTubeSensor(line, data)) - add_entities(sensors, True) + async_add_entities(sensors, True) class LondonTubeSensor(SensorEntity): @@ -92,8 +96,8 @@ class LondonTubeSensor(SensorEntity): self.attrs["Description"] = self._description return self.attrs - def update(self): + async def async_update(self): """Update the sensor.""" - self._data.update() + await self._data.update() self._state = self._data.data[self.name]["State"] self._description = self._data.data[self.name]["Description"] diff --git a/requirements_all.txt b/requirements_all.txt index 7ad94a23ea2..1ffbe1a76ef 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -969,7 +969,7 @@ locationsharinglib==4.1.5 logi_circle==0.2.3 # homeassistant.components.london_underground -london-tube-status==0.2 +london-tube-status==0.5 # homeassistant.components.recorder lru-dict==1.1.7