mirror of
https://github.com/home-assistant/core.git
synced 2025-06-25 01:21:51 +02:00
Move london underground coordinator to its own file (#99550)
This commit is contained in:
committed by
GitHub
parent
b9536732bc
commit
fa0b61e96a
@ -707,6 +707,7 @@ build.json @home-assistant/supervisor
|
||||
/tests/components/logger/ @home-assistant/core
|
||||
/homeassistant/components/logi_circle/ @evanjd
|
||||
/tests/components/logi_circle/ @evanjd
|
||||
/homeassistant/components/london_underground/ @jpbede
|
||||
/homeassistant/components/lookin/ @ANMalko @bdraco
|
||||
/tests/components/lookin/ @ANMalko @bdraco
|
||||
/homeassistant/components/loqed/ @mikewoudenberg
|
||||
|
26
homeassistant/components/london_underground/const.py
Normal file
26
homeassistant/components/london_underground/const.py
Normal file
@ -0,0 +1,26 @@
|
||||
"""Constants for the London underground integration."""
|
||||
from datetime import timedelta
|
||||
|
||||
DOMAIN = "london_underground"
|
||||
|
||||
CONF_LINE = "line"
|
||||
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=30)
|
||||
|
||||
TUBE_LINES = [
|
||||
"Bakerloo",
|
||||
"Central",
|
||||
"Circle",
|
||||
"District",
|
||||
"DLR",
|
||||
"Elizabeth line",
|
||||
"Hammersmith & City",
|
||||
"Jubilee",
|
||||
"London Overground",
|
||||
"Metropolitan",
|
||||
"Northern",
|
||||
"Piccadilly",
|
||||
"Victoria",
|
||||
"Waterloo & City",
|
||||
]
|
30
homeassistant/components/london_underground/coordinator.py
Normal file
30
homeassistant/components/london_underground/coordinator.py
Normal file
@ -0,0 +1,30 @@
|
||||
"""DataUpdateCoordinator for London underground integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import DOMAIN, SCAN_INTERVAL
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LondonTubeCoordinator(DataUpdateCoordinator):
|
||||
"""London Underground sensor coordinator."""
|
||||
|
||||
def __init__(self, hass, data):
|
||||
"""Initialize coordinator."""
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
name=DOMAIN,
|
||||
update_interval=SCAN_INTERVAL,
|
||||
)
|
||||
self._data = data
|
||||
|
||||
async def _async_update_data(self):
|
||||
async with asyncio.timeout(10):
|
||||
await self._data.update()
|
||||
return self._data.data
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"domain": "london_underground",
|
||||
"name": "London Underground",
|
||||
"codeowners": [],
|
||||
"codeowners": ["@jpbede"],
|
||||
"documentation": "https://www.home-assistant.io/integrations/london_underground",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["london_tube_status"],
|
||||
|
@ -1,8 +1,6 @@
|
||||
"""Sensor for checking the status of London Underground tube lines."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from london_tube_status import TubeData
|
||||
@ -15,37 +13,13 @@ 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
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import CONF_LINE, TUBE_LINES
|
||||
from .coordinator import LondonTubeCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = "london_underground"
|
||||
|
||||
CONF_LINE = "line"
|
||||
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=30)
|
||||
|
||||
TUBE_LINES = [
|
||||
"Bakerloo",
|
||||
"Central",
|
||||
"Circle",
|
||||
"District",
|
||||
"DLR",
|
||||
"Elizabeth line",
|
||||
"Hammersmith & City",
|
||||
"Jubilee",
|
||||
"London Overground",
|
||||
"Metropolitan",
|
||||
"Northern",
|
||||
"Piccadilly",
|
||||
"Victoria",
|
||||
"Waterloo & City",
|
||||
]
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{vol.Required(CONF_LINE): vol.All(cv.ensure_list, [vol.In(list(TUBE_LINES))])}
|
||||
)
|
||||
@ -76,25 +50,6 @@ async def async_setup_platform(
|
||||
async_add_entities(sensors)
|
||||
|
||||
|
||||
class LondonTubeCoordinator(DataUpdateCoordinator):
|
||||
"""London Underground sensor coordinator."""
|
||||
|
||||
def __init__(self, hass, data):
|
||||
"""Initialize coordinator."""
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
name=DOMAIN,
|
||||
update_interval=SCAN_INTERVAL,
|
||||
)
|
||||
self._data = data
|
||||
|
||||
async def _async_update_data(self):
|
||||
async with asyncio.timeout(10):
|
||||
await self._data.update()
|
||||
return self._data.data
|
||||
|
||||
|
||||
class LondonTubeSensor(CoordinatorEntity[LondonTubeCoordinator], SensorEntity):
|
||||
"""Sensor that reads the status of a line from Tube Data."""
|
||||
|
||||
|
Reference in New Issue
Block a user