Add launch status sensor for launch_library (#64382)

This commit is contained in:
Simon Hansen 2022-01-18 22:39:37 +01:00 committed by GitHub
parent 13fe5d8216
commit 57bcddbba2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -3,12 +3,13 @@
DOMAIN = "launch_library"
ATTR_LAUNCH_FACILITY = "facility"
ATTR_STREAM_LIVE = "stream_live"
ATTR_LAUNCH_PAD = "pad"
ATTR_LAUNCH_PAD_COUNTRY_CODE = "provider_country_code"
ATTR_LAUNCH_PROVIDER = "provider"
ATTR_WINDOW_START = "window_start"
ATTR_REASON = "reason"
ATTR_STREAM_LIVE = "stream_live"
ATTR_WINDOW_END = "window_end"
ATTR_WINDOW_START = "window_start"
ATTRIBUTION = "Data provided by Launch Library."
@ -17,3 +18,4 @@ DEFAULT_NAME = "Next launch"
NEXT_LAUNCH = "next_launch"
LAUNCH_TIME = "launch_time"
LAUNCH_PROBABILITY = "launch_probability"
LAUNCH_STATUS = "launch_status"

View File

@ -33,6 +33,7 @@ from .const import (
ATTR_LAUNCH_PAD,
ATTR_LAUNCH_PAD_COUNTRY_CODE,
ATTR_LAUNCH_PROVIDER,
ATTR_REASON,
ATTR_STREAM_LIVE,
ATTR_WINDOW_END,
ATTR_WINDOW_START,
@ -40,6 +41,7 @@ from .const import (
DEFAULT_NAME,
DOMAIN,
LAUNCH_PROBABILITY,
LAUNCH_STATUS,
LAUNCH_TIME,
NEXT_LAUNCH,
)
@ -102,6 +104,17 @@ SENSOR_DESCRIPTIONS: tuple[NextLaunchSensorEntityDescription, ...] = (
else STATE_UNKNOWN,
attributes_fn=lambda next_launch: None,
),
NextLaunchSensorEntityDescription(
key=LAUNCH_STATUS,
icon="mdi:rocket-launch",
name="Launch status",
value_fn=lambda next_launch: next_launch.status.name,
attributes_fn=lambda next_launch: {
ATTR_REASON: next_launch.holdreason,
}
if next_launch.inhold
else None,
),
)