mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 01:11:51 -04:00
Deprecate unused helper function cover.is_closed (#164741)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user