Skip to content

Commit

Permalink
Fixing Upcoming Flights
Browse files Browse the repository at this point in the history
Moved upcoming flights logic out of for loop as it is not updated when no flights are returned.
  • Loading branch information
jampez77 committed Oct 24, 2023
1 parent 21a6c49 commit 9af5026
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion custom_components/ryanair/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"issue_tracker": "https://github.com/jampez77/Ryanair/issues",
"requirements": ["aztec-code-generator==0.11"],
"ssdp": [],
"version": "2023.10.1",
"version": "2023.10.2",
"zeroconf": []
}
24 changes: 11 additions & 13 deletions custom_components/ryanair/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ async def async_setup_platform(
sensors.append(RyanairProfileSensor(
profileCoordinator, name, profileDescription))

upcomingFlights = 0
if "items" in flightsCoordinator.data and len(flightsCoordinator.data["items"]) > 0:

bookingReferences = load_json_object(BOARDING_PASS_PERSISTENCE)
Expand Down Expand Up @@ -191,7 +192,6 @@ async def async_setup_platform(

itinerary["journeys"].insert(flight["journeyNum"], journey)

upcomingFlights = 0
for journey in itinerary["journeys"]:

checkInInfo = {
Expand All @@ -217,18 +217,18 @@ async def async_setup_platform(
sensors.append(RyanairFlightSensor(
flightsCoordinator, bookingRef, checkInInfo, flight, flightDescription))

flightCountDescription = SensorEntityDescription(
key=f"Ryanair_flight-count{name}",
name="Upcoming Flights",
)

name = getProfileName(profileCoordinator)
sensors.append(RyanairFlightCountSensor(
bookingRef, upcomingFlights, name, flightCountDescription))

bookingReferences[config[CONF_DEVICE_FINGERPRINT]] = userBookings
save_json(BOARDING_PASS_PERSISTENCE, bookingReferences)

flightCountDescription = SensorEntityDescription(
key=f"Ryanair_flight-count{name}",
name="Upcoming Flights",
)

name = getProfileName(profileCoordinator)
sensors.append(RyanairFlightCountSensor(
upcomingFlights, name, flightCountDescription))

async_add_entities(sensors, update_before_add=True)


Expand All @@ -237,16 +237,14 @@ class RyanairFlightCountSensor(SensorEntity):

def __init__(
self,
bookingRef: str,
upcomingFlights: int,
name: str,
description: SensorEntityDescription,
) -> None:
"""Initialize."""
self._name = "Upcoming Flights"
self.bookingRef = bookingRef
self._attr_device_info = self._attr_device_info = deviceInfo(name)
self._attr_unique_id = f"Ryanair_flight-count-{self.bookingRef}-{name}-{description.key}".lower(
self._attr_unique_id = f"Ryanair_flight-count-{name}-{description.key}".lower(
)
self._attrs: dict[str, Any] = {}
self.entity_description = description
Expand Down

0 comments on commit 9af5026

Please sign in to comment.