Skip to content

Commit

Permalink
Update pylaunches dependency to version 2.0.0 (#118362)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed May 29, 2024
1 parent 43f42dd commit d33068d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 42 deletions.
11 changes: 5 additions & 6 deletions homeassistant/components/launch_library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import logging
from typing import TypedDict

from pylaunches import PyLaunches, PyLaunchesException
from pylaunches.objects.launch import Launch
from pylaunches.objects.starship import StarshipResponse
from pylaunches import PyLaunches, PyLaunchesError
from pylaunches.types import Launch, StarshipResponse

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
Expand Down Expand Up @@ -41,12 +40,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_update() -> LaunchLibraryData:
try:
return LaunchLibraryData(
upcoming_launches=await launches.upcoming_launches(
upcoming_launches=await launches.launch_upcoming(
filters={"limit": 1, "hide_recent_previous": "True"},
),
starship_events=await launches.starship_events(),
starship_events=await launches.dashboard_starship(),
)
except PyLaunchesException as ex:
except PyLaunchesError as ex:
raise UpdateFailed(ex) from ex

coordinator = DataUpdateCoordinator(
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/launch_library/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from typing import Any

from pylaunches.objects.event import Event
from pylaunches.objects.launch import Launch
from pylaunches.types import Event, Launch

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
Expand All @@ -28,7 +27,7 @@ async def async_get_config_entry_diagnostics(
def _first_element(data: list[Launch | Event]) -> dict[str, Any] | None:
if not data:
return None
return data[0].raw_data_contents
return data[0]

return {
"next_launch": _first_element(coordinator.data["upcoming_launches"]),
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/launch_library/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/launch_library",
"integration_type": "service",
"iot_class": "cloud_polling",
"requirements": ["pylaunches==1.4.0"]
"requirements": ["pylaunches==2.0.0"]
}
59 changes: 29 additions & 30 deletions homeassistant/components/launch_library/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from datetime import datetime
from typing import Any

from pylaunches.objects.event import Event
from pylaunches.objects.launch import Launch
from pylaunches.types import Event, Launch

from homeassistant.components.sensor import (
SensorDeviceClass,
Expand Down Expand Up @@ -45,76 +44,76 @@ class LaunchLibrarySensorEntityDescription(SensorEntityDescription):
key="next_launch",
icon="mdi:rocket-launch",
translation_key="next_launch",
value_fn=lambda nl: nl.name,
value_fn=lambda nl: nl["name"],
attributes_fn=lambda nl: {
"provider": nl.launch_service_provider.name,
"pad": nl.pad.name,
"facility": nl.pad.location.name,
"provider_country_code": nl.pad.location.country_code,
"provider": nl["launch_service_provider"]["name"],
"pad": nl["pad"]["name"],
"facility": nl["pad"]["location"]["name"],
"provider_country_code": nl["pad"]["location"]["country_code"],
},
),
LaunchLibrarySensorEntityDescription(
key="launch_time",
icon="mdi:clock-outline",
translation_key="launch_time",
device_class=SensorDeviceClass.TIMESTAMP,
value_fn=lambda nl: parse_datetime(nl.net),
value_fn=lambda nl: parse_datetime(nl["net"]),
attributes_fn=lambda nl: {
"window_start": nl.window_start,
"window_end": nl.window_end,
"stream_live": nl.webcast_live,
"window_start": nl["window_start"],
"window_end": nl["window_end"],
"stream_live": nl["window_start"],
},
),
LaunchLibrarySensorEntityDescription(
key="launch_probability",
icon="mdi:dice-multiple",
translation_key="launch_probability",
native_unit_of_measurement=PERCENTAGE,
value_fn=lambda nl: None if nl.probability == -1 else nl.probability,
value_fn=lambda nl: None if nl["probability"] == -1 else nl["probability"],
attributes_fn=lambda nl: None,
),
LaunchLibrarySensorEntityDescription(
key="launch_status",
icon="mdi:rocket-launch",
translation_key="launch_status",
value_fn=lambda nl: nl.status.name,
attributes_fn=lambda nl: {"reason": nl.holdreason} if nl.inhold else None,
value_fn=lambda nl: nl["status"]["name"],
attributes_fn=lambda nl: {"reason": nl.get("holdreason")},
),
LaunchLibrarySensorEntityDescription(
key="launch_mission",
icon="mdi:orbit",
translation_key="launch_mission",
value_fn=lambda nl: nl.mission.name,
value_fn=lambda nl: nl["mission"]["name"],
attributes_fn=lambda nl: {
"mission_type": nl.mission.type,
"target_orbit": nl.mission.orbit.name,
"description": nl.mission.description,
"mission_type": nl["mission"]["type"],
"target_orbit": nl["mission"]["orbit"]["name"],
"description": nl["mission"]["description"],
},
),
LaunchLibrarySensorEntityDescription(
key="starship_launch",
icon="mdi:rocket",
translation_key="starship_launch",
device_class=SensorDeviceClass.TIMESTAMP,
value_fn=lambda sl: parse_datetime(sl.net),
value_fn=lambda sl: parse_datetime(sl["net"]),
attributes_fn=lambda sl: {
"title": sl.mission.name,
"status": sl.status.name,
"target_orbit": sl.mission.orbit.name,
"description": sl.mission.description,
"title": sl["mission"]["name"],
"status": sl["status"]["name"],
"target_orbit": sl["mission"]["orbit"]["name"],
"description": sl["mission"]["description"],
},
),
LaunchLibrarySensorEntityDescription(
key="starship_event",
icon="mdi:calendar",
translation_key="starship_event",
device_class=SensorDeviceClass.TIMESTAMP,
value_fn=lambda se: parse_datetime(se.date),
value_fn=lambda se: parse_datetime(se["date"]),
attributes_fn=lambda se: {
"title": se.name,
"location": se.location,
"stream": se.video_url,
"description": se.description,
"title": se["name"],
"location": se["location"],
"stream": se["video_url"],
"description": se["description"],
},
),
)
Expand Down Expand Up @@ -190,9 +189,9 @@ def available(self) -> bool:
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
if self.entity_description.key == "starship_launch":
events = self.coordinator.data["starship_events"].upcoming.launches
events = self.coordinator.data["starship_events"]["upcoming"]["launches"]
elif self.entity_description.key == "starship_event":
events = self.coordinator.data["starship_events"].upcoming.events
events = self.coordinator.data["starship_events"]["upcoming"]["events"]
else:
events = self.coordinator.data["upcoming_launches"]

Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ pylacrosse==0.4
pylast==5.1.0

# homeassistant.components.launch_library
pylaunches==1.4.0
pylaunches==2.0.0

# homeassistant.components.lg_netcast
pylgnetcast==0.3.9
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ pykulersky==0.5.2
pylast==5.1.0

# homeassistant.components.launch_library
pylaunches==1.4.0
pylaunches==2.0.0

# homeassistant.components.lg_netcast
pylgnetcast==0.3.9
Expand Down

0 comments on commit d33068d

Please sign in to comment.