Update pylaunches dependency to version 2.0.0 (#118362)

This commit is contained in:
Joakim Sørensen 2024-05-29 11:18:29 +02:00 committed by GitHub
parent 43f42dd512
commit d33068d00c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 39 additions and 42 deletions

View file

@ -6,9 +6,8 @@ from datetime import timedelta
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
@ -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(

View file

@ -4,8 +4,7 @@ from __future__ import annotations
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
@ -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"]),

View file

@ -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"]
}

View file

@ -7,8 +7,7 @@ from dataclasses import dataclass
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,
@ -45,12 +44,12 @@ SENSOR_DESCRIPTIONS: tuple[LaunchLibrarySensorEntityDescription, ...] = (
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(
@ -58,11 +57,11 @@ SENSOR_DESCRIPTIONS: tuple[LaunchLibrarySensorEntityDescription, ...] = (
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(
@ -70,25 +69,25 @@ SENSOR_DESCRIPTIONS: tuple[LaunchLibrarySensorEntityDescription, ...] = (
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(
@ -96,12 +95,12 @@ SENSOR_DESCRIPTIONS: tuple[LaunchLibrarySensorEntityDescription, ...] = (
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(
@ -109,12 +108,12 @@ SENSOR_DESCRIPTIONS: tuple[LaunchLibrarySensorEntityDescription, ...] = (
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"],
},
),
)
@ -190,9 +189,9 @@ class LaunchLibrarySensor(
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"]

View file

@ -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

View file

@ -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