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

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