1 """Sensor for checking the status of London Underground tube lines."""
3 from __future__
import annotations
8 from london_tube_status
import TubeData
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
23 from .const
import CONF_LINE, TUBE_LINES
24 from .coordinator
import LondonTubeCoordinator
26 _LOGGER = logging.getLogger(__name__)
28 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
29 {vol.Required(CONF_LINE): vol.All(cv.ensure_list, [vol.In(
list(TUBE_LINES))])}
36 async_add_entities: AddEntitiesCallback,
37 discovery_info: DiscoveryInfoType |
None =
None,
39 """Set up the Tube sensor."""
43 data = TubeData(session)
46 await coordinator.async_refresh()
48 if not coordinator.last_update_success:
49 raise PlatformNotReady
57 """Sensor that reads the status of a line from Tube Data."""
59 _attr_attribution =
"Powered by TfL Open Data"
60 _attr_icon =
"mdi:subway"
62 def __init__(self, coordinator: LondonTubeCoordinator, name: str) ->
None:
63 """Initialize the London Underground sensor."""
69 """Return the name of the sensor."""
70 return self.
_name_name
74 """Return the state of the sensor."""
75 return self.coordinator.data[self.
namenamenamename][
"State"]
79 """Return other details about the sensor state."""
80 return {
"Description": self.coordinator.data[self.
namenamenamename][
"Description"]}
None __init__(self, LondonTubeCoordinator coordinator, str name)
dict[str, Any] extra_state_attributes(self)
str|UndefinedType|None name(self)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)