mirror of
https://github.com/home-assistant/core.git
synced 2026-04-02 08:26:41 +01:00
Fix typing in nsw_fuel_station (#165679)
This commit is contained in:
committed by
GitHub
parent
f8b4ffc0d7
commit
e35fc8267e
@@ -24,7 +24,7 @@ class StationPriceData:
|
||||
prices: dict[tuple[int, str], float]
|
||||
|
||||
|
||||
class NSWFuelStationCoordinator(DataUpdateCoordinator[StationPriceData | None]):
|
||||
class NSWFuelStationCoordinator(DataUpdateCoordinator[StationPriceData]):
|
||||
"""Class to manage fetching NSW fuel station data."""
|
||||
|
||||
config_entry: None
|
||||
@@ -40,14 +40,14 @@ class NSWFuelStationCoordinator(DataUpdateCoordinator[StationPriceData | None]):
|
||||
)
|
||||
self.client = client
|
||||
|
||||
async def _async_update_data(self) -> StationPriceData | None:
|
||||
async def _async_update_data(self) -> StationPriceData:
|
||||
"""Fetch data from API."""
|
||||
return await self.hass.async_add_executor_job(
|
||||
_fetch_station_price_data, self.client
|
||||
)
|
||||
|
||||
|
||||
def _fetch_station_price_data(client: FuelCheckClient) -> StationPriceData | None:
|
||||
def _fetch_station_price_data(client: FuelCheckClient) -> StationPriceData:
|
||||
"""Fetch fuel price and station data."""
|
||||
try:
|
||||
raw_price_data = client.get_fuel_prices()
|
||||
|
||||
@@ -65,10 +65,6 @@ def setup_platform(
|
||||
|
||||
coordinator: NSWFuelStationCoordinator = hass.data[DATA_NSW_FUEL_STATION]
|
||||
|
||||
if coordinator.data is None:
|
||||
_LOGGER.error("Initial fuel station price data not available")
|
||||
return
|
||||
|
||||
entities = []
|
||||
for fuel_type in fuel_types:
|
||||
if coordinator.data.prices.get((station_id, fuel_type)) is None:
|
||||
@@ -110,9 +106,6 @@ class StationPriceSensor(CoordinatorEntity[NSWFuelStationCoordinator], SensorEnt
|
||||
@property
|
||||
def native_value(self) -> float | None:
|
||||
"""Return the state of the sensor."""
|
||||
if self.coordinator.data is None:
|
||||
return None
|
||||
|
||||
prices = self.coordinator.data.prices
|
||||
return prices.get((self._station_id, self._fuel_type))
|
||||
|
||||
@@ -129,16 +122,13 @@ class StationPriceSensor(CoordinatorEntity[NSWFuelStationCoordinator], SensorEnt
|
||||
"""Return the units of measurement."""
|
||||
return f"{CURRENCY_CENT}/{UnitOfVolume.LITERS}"
|
||||
|
||||
def _get_station_name(self):
|
||||
default_name = f"station {self._station_id}"
|
||||
if self.coordinator.data is None:
|
||||
return default_name
|
||||
def _get_station_name(self) -> str:
|
||||
if (
|
||||
station := self.coordinator.data.stations.get(self._station_id)
|
||||
) is not None:
|
||||
return station.name
|
||||
|
||||
station = self.coordinator.data.stations.get(self._station_id)
|
||||
if station is None:
|
||||
return default_name
|
||||
|
||||
return station.name
|
||||
return f"station {self._station_id}"
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str | None:
|
||||
|
||||
Reference in New Issue
Block a user