From 9020dbb09337565ef3f85e40ebfb82b0e078bfa3 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Thu, 14 Dec 2023 08:33:31 +0100 Subject: [PATCH] Remove context_recent_time property from entity base class (#105652) --- homeassistant/components/mqtt/mixins.py | 1 - homeassistant/helpers/entity.py | 10 +++------- pylint/plugins/hass_enforce_type_hints.py | 4 ---- tests/helpers/test_entity.py | 7 +++---- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/mqtt/mixins.py b/homeassistant/components/mqtt/mixins.py index 76300afb97a..ded9073ac57 100644 --- a/homeassistant/components/mqtt/mixins.py +++ b/homeassistant/components/mqtt/mixins.py @@ -139,7 +139,6 @@ CONF_JSON_ATTRS_TEMPLATE = "json_attributes_template" MQTT_ATTRIBUTES_BLOCKED = { "assumed_state", "available", - "context_recent_time", "device_class", "device_info", "entity_category", diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index cc709f4c754..4a12c012ca1 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -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 CAPABILITIES_UPDATE_LIMIT = 100 +CONTEXT_RECENT_TIME = timedelta(seconds=5) # Time that a context is considered recent + @callback def async_setup(hass: HomeAssistant) -> None: @@ -340,7 +342,6 @@ class Entity(ABC): _attr_attribution: str | None = None _attr_available: bool = True _attr_capability_attributes: Mapping[str, Any] | None = None - _attr_context_recent_time: timedelta = timedelta(seconds=5) _attr_device_class: str | None _attr_device_info: DeviceInfo | None = None _attr_entity_category: EntityCategory | None @@ -627,11 +628,6 @@ class Entity(ABC): """Flag 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 def entity_registry_enabled_default(self) -> bool: """Return if the entity should be enabled when first added. @@ -942,7 +938,7 @@ class Entity(ABC): if ( self._context_set is not None and hass.loop.time() - self._context_set - > self.context_recent_time.total_seconds() + > CONTEXT_RECENT_TIME.total_seconds() ): self._context = None self._context_set = None diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index f43dd9b6672..bd09f461881 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -631,10 +631,6 @@ _ENTITY_MATCH: list[TypeHintMatch] = [ function_name="supported_features", return_type=["int", None], ), - TypeHintMatch( - function_name="context_recent_time", - return_type="timedelta", - ), TypeHintMatch( function_name="entity_registry_enabled_default", return_type="bool", diff --git a/tests/helpers/test_entity.py b/tests/helpers/test_entity.py index e9d0906970a..911f41c0766 100644 --- a/tests/helpers/test_entity.py +++ b/tests/helpers/test_entity.py @@ -664,10 +664,9 @@ async def test_set_context_expired(hass: HomeAssistant) -> None: """Test setting context.""" context = Context() - with patch.object( - entity.Entity, "context_recent_time", new_callable=PropertyMock - ) as recent: - recent.return_value = timedelta(seconds=-5) + with patch( + "homeassistant.helpers.entity.CONTEXT_RECENT_TIME", timedelta(seconds=-5) + ): ent = entity.Entity() ent.hass = hass ent.entity_id = "hello.world"