mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +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
|
__color_mode_reported = False
|
||||||
|
|
||||||
@property # type: ignore[misc]
|
@property
|
||||||
@final
|
@final
|
||||||
def state(self) -> str | None: # type: ignore[override]
|
def state(self) -> str | None:
|
||||||
"""Return the state."""
|
"""Return the light 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:
|
if (_is_on := self.is_on) is None:
|
||||||
return None
|
return None
|
||||||
return LightState.ON if _is_on else LightState.OFF
|
return LightState.ON if _is_on else LightState.OFF
|
||||||
|
@ -17,7 +17,7 @@ import sys
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from types import FunctionType
|
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
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -1664,8 +1664,7 @@ class ToggleEntity(
|
|||||||
_attr_state: None = None
|
_attr_state: None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@final
|
def state(self) -> str | None:
|
||||||
def state(self) -> Literal["on", "off"] | None:
|
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
if (is_on := self.is_on) is None:
|
if (is_on := self.is_on) is None:
|
||||||
return None
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user