Deprecate unused helper function cover.is_closed (#164741)

This commit is contained in:
Erik Montnemery
2026-09-02 14:29:53 +02:00
committed by GitHub
parent e78b254292
commit 182cdb39e7
2 changed files with 20 additions and 0 deletions
@@ -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)
+16
View File
@@ -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