mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Mod ToggleEntity and implement state in LightEntity
This commit is contained in:
parent
ddf7f08567
commit
5b886d48cf
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user