mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Remove context_recent_time property from entity base class (#105652)
This commit is contained in:
parent
aafdca88c9
commit
9020dbb093
@ -139,7 +139,6 @@ CONF_JSON_ATTRS_TEMPLATE = "json_attributes_template"
|
|||||||
MQTT_ATTRIBUTES_BLOCKED = {
|
MQTT_ATTRIBUTES_BLOCKED = {
|
||||||
"assumed_state",
|
"assumed_state",
|
||||||
"available",
|
"available",
|
||||||
"context_recent_time",
|
|
||||||
"device_class",
|
"device_class",
|
||||||
"device_info",
|
"device_info",
|
||||||
"entity_category",
|
"entity_category",
|
||||||
|
@ -79,6 +79,8 @@ FLOAT_PRECISION = abs(int(math.floor(math.log10(abs(sys.float_info.epsilon)))))
|
|||||||
# How many times per hour we allow capabilities to be updated before logging a warning
|
# How many times per hour we allow capabilities to be updated before logging a warning
|
||||||
CAPABILITIES_UPDATE_LIMIT = 100
|
CAPABILITIES_UPDATE_LIMIT = 100
|
||||||
|
|
||||||
|
CONTEXT_RECENT_TIME = timedelta(seconds=5) # Time that a context is considered recent
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_setup(hass: HomeAssistant) -> None:
|
def async_setup(hass: HomeAssistant) -> None:
|
||||||
@ -340,7 +342,6 @@ class Entity(ABC):
|
|||||||
_attr_attribution: str | None = None
|
_attr_attribution: str | None = None
|
||||||
_attr_available: bool = True
|
_attr_available: bool = True
|
||||||
_attr_capability_attributes: Mapping[str, Any] | None = None
|
_attr_capability_attributes: Mapping[str, Any] | None = None
|
||||||
_attr_context_recent_time: timedelta = timedelta(seconds=5)
|
|
||||||
_attr_device_class: str | None
|
_attr_device_class: str | None
|
||||||
_attr_device_info: DeviceInfo | None = None
|
_attr_device_info: DeviceInfo | None = None
|
||||||
_attr_entity_category: EntityCategory | None
|
_attr_entity_category: EntityCategory | None
|
||||||
@ -627,11 +628,6 @@ class Entity(ABC):
|
|||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return self._attr_supported_features
|
return self._attr_supported_features
|
||||||
|
|
||||||
@property
|
|
||||||
def context_recent_time(self) -> timedelta:
|
|
||||||
"""Time that a context is considered recent."""
|
|
||||||
return self._attr_context_recent_time
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def entity_registry_enabled_default(self) -> bool:
|
def entity_registry_enabled_default(self) -> bool:
|
||||||
"""Return if the entity should be enabled when first added.
|
"""Return if the entity should be enabled when first added.
|
||||||
@ -942,7 +938,7 @@ class Entity(ABC):
|
|||||||
if (
|
if (
|
||||||
self._context_set is not None
|
self._context_set is not None
|
||||||
and hass.loop.time() - self._context_set
|
and hass.loop.time() - self._context_set
|
||||||
> self.context_recent_time.total_seconds()
|
> CONTEXT_RECENT_TIME.total_seconds()
|
||||||
):
|
):
|
||||||
self._context = None
|
self._context = None
|
||||||
self._context_set = None
|
self._context_set = None
|
||||||
|
@ -631,10 +631,6 @@ _ENTITY_MATCH: list[TypeHintMatch] = [
|
|||||||
function_name="supported_features",
|
function_name="supported_features",
|
||||||
return_type=["int", None],
|
return_type=["int", None],
|
||||||
),
|
),
|
||||||
TypeHintMatch(
|
|
||||||
function_name="context_recent_time",
|
|
||||||
return_type="timedelta",
|
|
||||||
),
|
|
||||||
TypeHintMatch(
|
TypeHintMatch(
|
||||||
function_name="entity_registry_enabled_default",
|
function_name="entity_registry_enabled_default",
|
||||||
return_type="bool",
|
return_type="bool",
|
||||||
|
@ -664,10 +664,9 @@ async def test_set_context_expired(hass: HomeAssistant) -> None:
|
|||||||
"""Test setting context."""
|
"""Test setting context."""
|
||||||
context = Context()
|
context = Context()
|
||||||
|
|
||||||
with patch.object(
|
with patch(
|
||||||
entity.Entity, "context_recent_time", new_callable=PropertyMock
|
"homeassistant.helpers.entity.CONTEXT_RECENT_TIME", timedelta(seconds=-5)
|
||||||
) as recent:
|
):
|
||||||
recent.return_value = timedelta(seconds=-5)
|
|
||||||
ent = entity.Entity()
|
ent = entity.Entity()
|
||||||
ent.hass = hass
|
ent.hass = hass
|
||||||
ent.entity_id = "hello.world"
|
ent.entity_id = "hello.world"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user