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 <erik@montnemery.com>
This commit is contained in:
Alessandro Ghedini 2022-06-20 14:08:50 +01:00 committed by GitHub
parent b6d3e34ebc
commit 670bf0641a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -2,7 +2,7 @@
"domain": "london_underground", "domain": "london_underground",
"name": "London Underground", "name": "London Underground",
"documentation": "https://www.home-assistant.io/integrations/london_underground", "documentation": "https://www.home-assistant.io/integrations/london_underground",
"requirements": ["london-tube-status==0.2"], "requirements": ["london-tube-status==0.5"],
"codeowners": [], "codeowners": [],
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"loggers": ["london_tube_status"] "loggers": ["london_tube_status"]

View File

@ -9,6 +9,7 @@ import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
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_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType 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, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
add_entities: AddEntitiesCallback, async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up the Tube sensor.""" """Set up the Tube sensor."""
data = TubeData() session = async_get_clientsession(hass)
data.update()
data = TubeData(session)
await data.update()
sensors = [] sensors = []
for line in config[CONF_LINE]: for line in config[CONF_LINE]:
sensors.append(LondonTubeSensor(line, data)) sensors.append(LondonTubeSensor(line, data))
add_entities(sensors, True) async_add_entities(sensors, True)
class LondonTubeSensor(SensorEntity): class LondonTubeSensor(SensorEntity):
@ -92,8 +96,8 @@ class LondonTubeSensor(SensorEntity):
self.attrs["Description"] = self._description self.attrs["Description"] = self._description
return self.attrs return self.attrs
def update(self): async def async_update(self):
"""Update the sensor.""" """Update the sensor."""
self._data.update() await self._data.update()
self._state = self._data.data[self.name]["State"] self._state = self._data.data[self.name]["State"]
self._description = self._data.data[self.name]["Description"] self._description = self._data.data[self.name]["Description"]

View File

@ -969,7 +969,7 @@ locationsharinglib==4.1.5
logi_circle==0.2.3 logi_circle==0.2.3
# homeassistant.components.london_underground # homeassistant.components.london_underground
london-tube-status==0.2 london-tube-status==0.5
# homeassistant.components.recorder # homeassistant.components.recorder
lru-dict==1.1.7 lru-dict==1.1.7