diff --git a/homeassistant/components/cover/__init__.py b/homeassistant/components/cover/__init__.py index fe94a1d65efc..d7bdf90324c9 100644 --- a/homeassistant/components/cover/__init__.py +++ b/homeassistant/components/cover/__init__.py @@ -25,6 +25,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.exceptions import ServiceValidationError from homeassistant.helpers import config_validation as cv +from homeassistant.helpers.deprecation import deprecated_function from homeassistant.helpers.entity import Entity, EntityDescription from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.typing import ConfigType @@ -91,6 +92,9 @@ __all__ = [ ] +@deprecated_function( + "hass.states.is_state(entity_id, 'closed')", breaks_in_ha_version="2027.10" +) def is_closed(hass: HomeAssistant, entity_id: str) -> bool: """Return if the cover is closed based on the statemachine.""" return hass.states.is_state(entity_id, CoverState.CLOSED) diff --git a/tests/components/cover/test_init.py b/tests/components/cover/test_init.py index e6694a860cc9..7ccffa0ceeab 100644 --- a/tests/components/cover/test_init.py +++ b/tests/components/cover/test_init.py @@ -320,3 +320,19 @@ async def test_services_with_speed( blocking=True, ) assert ent2.last_kwargs == {"position": 49} + + +async def test_deprecated_is_closed( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: + """Test the deprecated is_closed helper.""" + hass.states.async_set("cover.test", CoverState.CLOSED) + assert cover.is_closed(hass, "cover.test") is True + + hass.states.async_set("cover.test", CoverState.OPEN) + assert cover.is_closed(hass, "cover.test") is False + + assert ( + "The deprecated function is_closed was called. It will be removed in HA Core " + "2027.10. Use hass.states.is_state(entity_id, 'closed') instead" + ) in caplog.text