From 5b886d48cf33ff43e20ce5f30716cdad80558330 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Tue, 24 Sep 2024 18:56:21 +0000 Subject: [PATCH] Mod ToggleEntity and implement state in LightEntity --- homeassistant/components/light/__init__.py | 9 +++------ homeassistant/helpers/entity.py | 5 ++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 873829f93ab..f01df3f4df2 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -913,13 +913,10 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): __color_mode_reported = False - @property # type: ignore[misc] + @property @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. + def state(self) -> str | None: + """Return the light state.""" if (_is_on := self.is_on) is None: return None return LightState.ON if _is_on else LightState.OFF diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index dbc1a036ef6..974a8fa921d 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -17,7 +17,7 @@ import sys import threading import time from types import FunctionType -from typing import TYPE_CHECKING, Any, Final, Literal, NotRequired, TypedDict, final +from typing import TYPE_CHECKING, Any, Final, NotRequired, TypedDict, final import voluptuous as vol @@ -1664,8 +1664,7 @@ class ToggleEntity( _attr_state: None = None @property - @final - def state(self) -> Literal["on", "off"] | None: + def state(self) -> str | None: """Return the state.""" if (is_on := self.is_on) is None: return None