From 57bcddbba2d6f4fa12a3b4a222d38ccb605f0326 Mon Sep 17 00:00:00 2001 From: Simon Hansen <67142049+DurgNomis-drol@users.noreply.github.com> Date: Tue, 18 Jan 2022 22:39:37 +0100 Subject: [PATCH] Add launch status sensor for launch_library (#64382) --- homeassistant/components/launch_library/const.py | 6 ++++-- homeassistant/components/launch_library/sensor.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/launch_library/const.py b/homeassistant/components/launch_library/const.py index 9ea4b8c56ee..db8927bb978 100644 --- a/homeassistant/components/launch_library/const.py +++ b/homeassistant/components/launch_library/const.py @@ -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" diff --git a/homeassistant/components/launch_library/sensor.py b/homeassistant/components/launch_library/sensor.py index ffdf9acae18..ee982fe5b21 100644 --- a/homeassistant/components/launch_library/sensor.py +++ b/homeassistant/components/launch_library/sensor.py @@ -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, + ), )