From ddf7f08567874ca2e2d495c837388b44e06561a9 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Tue, 24 Sep 2024 18:45:18 +0000 Subject: [PATCH] light returns enum --- homeassistant/components/light/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 6ad4c248ab1..873829f93ab 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -913,6 +913,17 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): __color_mode_reported = False + @property # type: ignore[misc] + @final + def state(self) -> str | None: # type: ignore[override] + """Return the state.""" + # Implemented in Home Assistant 2024.10 to enable light entity + # to return an enum instead of a string. + # When ToggleEntity can return an enum this can be removed. + if (_is_on := self.is_on) is None: + return None + return LightState.ON if _is_on else LightState.OFF + @cached_property def brightness(self) -> int | None: """Return the brightness of this light between 0..255."""