Add launch mission sensor for launch_library (#64387)

pull/64419/head
Simon Hansen 2022-01-19 09:28:07 +01:00 committed by GitHub
parent 2f5f6cc05e
commit 6fcf643d5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -2,12 +2,15 @@
DOMAIN = "launch_library"
ATTR_DESCRIPTION = "description"
ATTR_LAUNCH_FACILITY = "facility"
ATTR_LAUNCH_PAD = "pad"
ATTR_LAUNCH_PAD_COUNTRY_CODE = "provider_country_code"
ATTR_LAUNCH_PROVIDER = "provider"
ATTR_ORBIT = "target_orbit"
ATTR_REASON = "reason"
ATTR_STREAM_LIVE = "stream_live"
ATTR_TYPE = "mission_type"
ATTR_WINDOW_END = "window_end"
ATTR_WINDOW_START = "window_start"
@ -19,3 +22,4 @@ NEXT_LAUNCH = "next_launch"
LAUNCH_TIME = "launch_time"
LAUNCH_PROBABILITY = "launch_probability"
LAUNCH_STATUS = "launch_status"
LAUNCH_MISSION = "launch_mission"

View File

@ -29,17 +29,21 @@ from homeassistant.helpers.update_coordinator import (
from homeassistant.util.dt import parse_datetime
from .const import (
ATTR_DESCRIPTION,
ATTR_LAUNCH_FACILITY,
ATTR_LAUNCH_PAD,
ATTR_LAUNCH_PAD_COUNTRY_CODE,
ATTR_LAUNCH_PROVIDER,
ATTR_ORBIT,
ATTR_REASON,
ATTR_STREAM_LIVE,
ATTR_TYPE,
ATTR_WINDOW_END,
ATTR_WINDOW_START,
ATTRIBUTION,
DEFAULT_NAME,
DOMAIN,
LAUNCH_MISSION,
LAUNCH_PROBABILITY,
LAUNCH_STATUS,
LAUNCH_TIME,
@ -115,6 +119,17 @@ SENSOR_DESCRIPTIONS: tuple[NextLaunchSensorEntityDescription, ...] = (
if next_launch.inhold
else None,
),
NextLaunchSensorEntityDescription(
key=LAUNCH_MISSION,
icon="mdi:orbit",
name="Launch mission",
value_fn=lambda next_launch: next_launch.mission.name,
attributes_fn=lambda next_launch: {
ATTR_TYPE: next_launch.mission.type,
ATTR_ORBIT: next_launch.mission.orbit.name,
ATTR_DESCRIPTION: next_launch.mission.description,
},
),
)