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 import logging
from typing import TypedDict from typing import TypedDict
from pylaunches import PyLaunches, PyLaunchesException from pylaunches import PyLaunches, PyLaunchesError
from pylaunches.objects.launch import Launch from pylaunches.types import Launch, StarshipResponse
from pylaunches.objects.starship import StarshipResponse
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform from homeassistant.const import Platform
@ -41,12 +40,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_update() -> LaunchLibraryData: async def async_update() -> LaunchLibraryData:
try: try:
return LaunchLibraryData( return LaunchLibraryData(
upcoming_launches=await launches.upcoming_launches( upcoming_launches=await launches.launch_upcoming(
filters={"limit": 1, "hide_recent_previous": "True"}, 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 raise UpdateFailed(ex) from ex
coordinator = DataUpdateCoordinator( coordinator = DataUpdateCoordinator(

View File

@ -4,8 +4,7 @@ from __future__ import annotations
from typing import Any from typing import Any
from pylaunches.objects.event import Event from pylaunches.types import Event, Launch
from pylaunches.objects.launch import Launch
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant 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: def _first_element(data: list[Launch | Event]) -> dict[str, Any] | None:
if not data: if not data:
return None return None
return data[0].raw_data_contents return data[0]
return { return {
"next_launch": _first_element(coordinator.data["upcoming_launches"]), "next_launch": _first_element(coordinator.data["upcoming_launches"]),

View File

@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/launch_library", "documentation": "https://www.home-assistant.io/integrations/launch_library",
"integration_type": "service", "integration_type": "service",
"iot_class": "cloud_polling", "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 datetime import datetime
from typing import Any from typing import Any
from pylaunches.objects.event import Event from pylaunches.types import Event, Launch
from pylaunches.objects.launch import Launch
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
SensorDeviceClass, SensorDeviceClass,
@ -45,12 +44,12 @@ SENSOR_DESCRIPTIONS: tuple[LaunchLibrarySensorEntityDescription, ...] = (
key="next_launch", key="next_launch",
icon="mdi:rocket-launch", icon="mdi:rocket-launch",
translation_key="next_launch", translation_key="next_launch",
value_fn=lambda nl: nl.name, value_fn=lambda nl: nl["name"],
attributes_fn=lambda nl: { attributes_fn=lambda nl: {
"provider": nl.launch_service_provider.name, "provider": nl["launch_service_provider"]["name"],
"pad": nl.pad.name, "pad": nl["pad"]["name"],
"facility": nl.pad.location.name, "facility": nl["pad"]["location"]["name"],
"provider_country_code": nl.pad.location.country_code, "provider_country_code": nl["pad"]["location"]["country_code"],
}, },
), ),
LaunchLibrarySensorEntityDescription( LaunchLibrarySensorEntityDescription(
@ -58,11 +57,11 @@ SENSOR_DESCRIPTIONS: tuple[LaunchLibrarySensorEntityDescription, ...] = (
icon="mdi:clock-outline", icon="mdi:clock-outline",
translation_key="launch_time", translation_key="launch_time",
device_class=SensorDeviceClass.TIMESTAMP, device_class=SensorDeviceClass.TIMESTAMP,
value_fn=lambda nl: parse_datetime(nl.net), value_fn=lambda nl: parse_datetime(nl["net"]),
attributes_fn=lambda nl: { attributes_fn=lambda nl: {
"window_start": nl.window_start, "window_start": nl["window_start"],
"window_end": nl.window_end, "window_end": nl["window_end"],
"stream_live": nl.webcast_live, "stream_live": nl["window_start"],
}, },
), ),
LaunchLibrarySensorEntityDescription( LaunchLibrarySensorEntityDescription(
@ -70,25 +69,25 @@ SENSOR_DESCRIPTIONS: tuple[LaunchLibrarySensorEntityDescription, ...] = (
icon="mdi:dice-multiple", icon="mdi:dice-multiple",
translation_key="launch_probability", translation_key="launch_probability",
native_unit_of_measurement=PERCENTAGE, 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, attributes_fn=lambda nl: None,
), ),
LaunchLibrarySensorEntityDescription( LaunchLibrarySensorEntityDescription(
key="launch_status", key="launch_status",
icon="mdi:rocket-launch", icon="mdi:rocket-launch",
translation_key="launch_status", translation_key="launch_status",
value_fn=lambda nl: nl.status.name, value_fn=lambda nl: nl["status"]["name"],
attributes_fn=lambda nl: {"reason": nl.holdreason} if nl.inhold else None, attributes_fn=lambda nl: {"reason": nl.get("holdreason")},
), ),
LaunchLibrarySensorEntityDescription( LaunchLibrarySensorEntityDescription(
key="launch_mission", key="launch_mission",
icon="mdi:orbit", icon="mdi:orbit",
translation_key="launch_mission", translation_key="launch_mission",
value_fn=lambda nl: nl.mission.name, value_fn=lambda nl: nl["mission"]["name"],
attributes_fn=lambda nl: { attributes_fn=lambda nl: {
"mission_type": nl.mission.type, "mission_type": nl["mission"]["type"],
"target_orbit": nl.mission.orbit.name, "target_orbit": nl["mission"]["orbit"]["name"],
"description": nl.mission.description, "description": nl["mission"]["description"],
}, },
), ),
LaunchLibrarySensorEntityDescription( LaunchLibrarySensorEntityDescription(
@ -96,12 +95,12 @@ SENSOR_DESCRIPTIONS: tuple[LaunchLibrarySensorEntityDescription, ...] = (
icon="mdi:rocket", icon="mdi:rocket",
translation_key="starship_launch", translation_key="starship_launch",
device_class=SensorDeviceClass.TIMESTAMP, device_class=SensorDeviceClass.TIMESTAMP,
value_fn=lambda sl: parse_datetime(sl.net), value_fn=lambda sl: parse_datetime(sl["net"]),
attributes_fn=lambda sl: { attributes_fn=lambda sl: {
"title": sl.mission.name, "title": sl["mission"]["name"],
"status": sl.status.name, "status": sl["status"]["name"],
"target_orbit": sl.mission.orbit.name, "target_orbit": sl["mission"]["orbit"]["name"],
"description": sl.mission.description, "description": sl["mission"]["description"],
}, },
), ),
LaunchLibrarySensorEntityDescription( LaunchLibrarySensorEntityDescription(
@ -109,12 +108,12 @@ SENSOR_DESCRIPTIONS: tuple[LaunchLibrarySensorEntityDescription, ...] = (
icon="mdi:calendar", icon="mdi:calendar",
translation_key="starship_event", translation_key="starship_event",
device_class=SensorDeviceClass.TIMESTAMP, device_class=SensorDeviceClass.TIMESTAMP,
value_fn=lambda se: parse_datetime(se.date), value_fn=lambda se: parse_datetime(se["date"]),
attributes_fn=lambda se: { attributes_fn=lambda se: {
"title": se.name, "title": se["name"],
"location": se.location, "location": se["location"],
"stream": se.video_url, "stream": se["video_url"],
"description": se.description, "description": se["description"],
}, },
), ),
) )
@ -190,9 +189,9 @@ class LaunchLibrarySensor(
def _handle_coordinator_update(self) -> None: def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator.""" """Handle updated data from the coordinator."""
if self.entity_description.key == "starship_launch": 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": elif self.entity_description.key == "starship_event":
events = self.coordinator.data["starship_events"].upcoming.events events = self.coordinator.data["starship_events"]["upcoming"]["events"]
else: else:
events = self.coordinator.data["upcoming_launches"] events = self.coordinator.data["upcoming_launches"]

View File

@ -1953,7 +1953,7 @@ pylacrosse==0.4
pylast==5.1.0 pylast==5.1.0
# homeassistant.components.launch_library # homeassistant.components.launch_library
pylaunches==1.4.0 pylaunches==2.0.0
# homeassistant.components.lg_netcast # homeassistant.components.lg_netcast
pylgnetcast==0.3.9 pylgnetcast==0.3.9

View File

@ -1528,7 +1528,7 @@ pykulersky==0.5.2
pylast==5.1.0 pylast==5.1.0
# homeassistant.components.launch_library # homeassistant.components.launch_library
pylaunches==1.4.0 pylaunches==2.0.0
# homeassistant.components.lg_netcast # homeassistant.components.lg_netcast
pylgnetcast==0.3.9 pylgnetcast==0.3.9