Skip to content

Commit 8bca393

Browse files
Remove deprecated cover state constants (home-assistant#154037)
1 parent 0367a01 commit 8bca393

File tree

8 files changed

+41
-90
lines changed

8 files changed

+41
-90
lines changed

homeassistant/components/alexa/capabilities.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,10 +1472,10 @@ def get_property(self, name: str) -> Any:
14721472
# Return state instead of position when using ModeController.
14731473
mode = self.entity.state
14741474
if mode in (
1475-
cover.STATE_OPEN,
1476-
cover.STATE_OPENING,
1477-
cover.STATE_CLOSED,
1478-
cover.STATE_CLOSING,
1475+
cover.CoverState.OPEN,
1476+
cover.CoverState.OPENING,
1477+
cover.CoverState.CLOSED,
1478+
cover.CoverState.CLOSING,
14791479
STATE_UNKNOWN,
14801480
):
14811481
return f"{cover.ATTR_POSITION}.{mode}"
@@ -1594,11 +1594,11 @@ def capability_resources(self) -> dict[str, list[dict[str, Any]]]:
15941594
["Position", AlexaGlobalCatalog.SETTING_OPENING], False
15951595
)
15961596
self._resource.add_mode(
1597-
f"{cover.ATTR_POSITION}.{cover.STATE_OPEN}",
1597+
f"{cover.ATTR_POSITION}.{cover.CoverState.OPEN}",
15981598
[AlexaGlobalCatalog.VALUE_OPEN],
15991599
)
16001600
self._resource.add_mode(
1601-
f"{cover.ATTR_POSITION}.{cover.STATE_CLOSED}",
1601+
f"{cover.ATTR_POSITION}.{cover.CoverState.CLOSED}",
16021602
[AlexaGlobalCatalog.VALUE_CLOSE],
16031603
)
16041604
self._resource.add_mode(
@@ -1651,22 +1651,22 @@ def semantics(self) -> dict[str, Any] | None:
16511651
raise_labels.append(AlexaSemantics.ACTION_OPEN)
16521652
self._semantics.add_states_to_value(
16531653
[AlexaSemantics.STATES_CLOSED],
1654-
f"{cover.ATTR_POSITION}.{cover.STATE_CLOSED}",
1654+
f"{cover.ATTR_POSITION}.{cover.CoverState.CLOSED}",
16551655
)
16561656
self._semantics.add_states_to_value(
16571657
[AlexaSemantics.STATES_OPEN],
1658-
f"{cover.ATTR_POSITION}.{cover.STATE_OPEN}",
1658+
f"{cover.ATTR_POSITION}.{cover.CoverState.OPEN}",
16591659
)
16601660

16611661
self._semantics.add_action_to_directive(
16621662
lower_labels,
16631663
"SetMode",
1664-
{"mode": f"{cover.ATTR_POSITION}.{cover.STATE_CLOSED}"},
1664+
{"mode": f"{cover.ATTR_POSITION}.{cover.CoverState.CLOSED}"},
16651665
)
16661666
self._semantics.add_action_to_directive(
16671667
raise_labels,
16681668
"SetMode",
1669-
{"mode": f"{cover.ATTR_POSITION}.{cover.STATE_OPEN}"},
1669+
{"mode": f"{cover.ATTR_POSITION}.{cover.CoverState.OPEN}"},
16701670
)
16711671

16721672
return self._semantics.serialize_semantics()

homeassistant/components/alexa/handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,9 +1261,9 @@ async def async_api_set_mode(
12611261
elif instance == f"{cover.DOMAIN}.{cover.ATTR_POSITION}":
12621262
position = mode.split(".")[1]
12631263

1264-
if position == cover.STATE_CLOSED:
1264+
if position == cover.CoverState.CLOSED:
12651265
service = cover.SERVICE_CLOSE_COVER
1266-
elif position == cover.STATE_OPEN:
1266+
elif position == cover.CoverState.OPEN:
12671267
service = cover.SERVICE_OPEN_COVER
12681268
elif position == "custom":
12691269
service = cover.SERVICE_STOP_COVER

homeassistant/components/comelit/cover.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77
from aiocomelit import ComelitSerialBridgeObject
88
from aiocomelit.const import COVER, STATE_COVER, STATE_OFF, STATE_ON
99

10-
from homeassistant.components.cover import (
11-
STATE_CLOSED,
12-
STATE_CLOSING,
13-
STATE_OPEN,
14-
STATE_OPENING,
15-
CoverDeviceClass,
16-
CoverEntity,
17-
)
10+
from homeassistant.components.cover import CoverDeviceClass, CoverEntity, CoverState
1811
from homeassistant.core import HomeAssistant
1912
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2013
from homeassistant.helpers.restore_state import RestoreEntity
@@ -128,9 +121,9 @@ async def async_added_to_hass(self) -> None:
128121
await super().async_added_to_hass()
129122

130123
if (state := await self.async_get_last_state()) is not None:
131-
if state.state == STATE_CLOSED:
132-
self._last_action = STATE_COVER.index(STATE_CLOSING)
133-
if state.state == STATE_OPEN:
134-
self._last_action = STATE_COVER.index(STATE_OPENING)
124+
if state.state == CoverState.CLOSED:
125+
self._last_action = STATE_COVER.index(CoverState.CLOSING)
126+
if state.state == CoverState.OPEN:
127+
self._last_action = STATE_COVER.index(CoverState.OPENING)
135128

136-
self._attr_is_closed = state.state == STATE_CLOSED
129+
self._attr_is_closed = state.state == CoverState.CLOSED

homeassistant/components/cover/__init__.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import voluptuous as vol
1414

1515
from homeassistant.config_entries import ConfigEntry
16-
from homeassistant.const import ( # noqa: F401
16+
from homeassistant.const import (
1717
SERVICE_CLOSE_COVER,
1818
SERVICE_CLOSE_COVER_TILT,
1919
SERVICE_OPEN_COVER,
@@ -24,19 +24,9 @@
2424
SERVICE_STOP_COVER_TILT,
2525
SERVICE_TOGGLE,
2626
SERVICE_TOGGLE_COVER_TILT,
27-
STATE_CLOSED,
28-
STATE_CLOSING,
29-
STATE_OPEN,
30-
STATE_OPENING,
3127
)
3228
from homeassistant.core import HomeAssistant
3329
from homeassistant.helpers import config_validation as cv
34-
from homeassistant.helpers.deprecation import (
35-
DeprecatedConstantEnum,
36-
all_with_deprecated_constants,
37-
check_if_deprecated_constant,
38-
dir_with_deprecated_constants,
39-
)
4030
from homeassistant.helpers.entity import Entity, EntityDescription
4131
from homeassistant.helpers.entity_component import EntityComponent
4232
from homeassistant.helpers.typing import ConfigType
@@ -63,15 +53,6 @@ class CoverState(StrEnum):
6353
OPENING = "opening"
6454

6555

66-
# STATE_* below are deprecated as of 2024.11
67-
# when imported from homeassistant.components.cover
68-
# use the CoverState enum instead.
69-
_DEPRECATED_STATE_CLOSED = DeprecatedConstantEnum(CoverState.CLOSED, "2025.11")
70-
_DEPRECATED_STATE_CLOSING = DeprecatedConstantEnum(CoverState.CLOSING, "2025.11")
71-
_DEPRECATED_STATE_OPEN = DeprecatedConstantEnum(CoverState.OPEN, "2025.11")
72-
_DEPRECATED_STATE_OPENING = DeprecatedConstantEnum(CoverState.OPENING, "2025.11")
73-
74-
7556
class CoverDeviceClass(StrEnum):
7657
"""Device class for cover."""
7758

@@ -463,11 +444,3 @@ def _get_toggle_function[**_P, _R](
463444
return (
464445
fns["close"] if self._cover_is_last_toggle_direction_open else fns["open"]
465446
)
466-
467-
468-
# These can be removed if no deprecated constant are in this module anymore
469-
__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals())
470-
__dir__ = ft.partial(
471-
dir_with_deprecated_constants, module_globals_keys=[*globals().keys()]
472-
)
473-
__all__ = all_with_deprecated_constants(globals())

homeassistant/components/google_assistant/trait.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@
182182

183183
COVER_VALVE_STATES = {
184184
cover.DOMAIN: {
185-
"closed": cover.STATE_CLOSED,
186-
"closing": cover.STATE_CLOSING,
187-
"open": cover.STATE_OPEN,
188-
"opening": cover.STATE_OPENING,
185+
"closed": cover.CoverState.CLOSED.value,
186+
"closing": cover.CoverState.CLOSING.value,
187+
"open": cover.CoverState.OPEN.value,
188+
"opening": cover.CoverState.OPENING.value,
189189
},
190190
valve.DOMAIN: {
191191
"closed": valve.STATE_CLOSED,

tests/components/comelit/test_cover.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
SERVICE_CLOSE_COVER,
1515
SERVICE_OPEN_COVER,
1616
SERVICE_STOP_COVER,
17-
STATE_CLOSED,
18-
STATE_CLOSING,
19-
STATE_OPEN,
20-
STATE_OPENING,
2117
CoverState,
2218
)
2319
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN, Platform
@@ -79,7 +75,7 @@ async def test_cover_open(
7975
mock_serial_bridge.set_device_status.assert_called()
8076

8177
assert (state := hass.states.get(ENTITY_ID))
82-
assert state.state == STATE_OPENING
78+
assert state.state == CoverState.OPENING
8379

8480
# Finish opening, update status
8581
mock_serial_bridge.get_all_devices.return_value[COVER] = {
@@ -102,7 +98,7 @@ async def test_cover_open(
10298
await hass.async_block_till_done()
10399

104100
assert (state := hass.states.get(ENTITY_ID))
105-
assert state.state == STATE_OPEN
101+
assert state.state == CoverState.OPEN
106102

107103

108104
async def test_cover_close(
@@ -128,7 +124,7 @@ async def test_cover_close(
128124
mock_serial_bridge.set_device_status.assert_called()
129125

130126
assert (state := hass.states.get(ENTITY_ID))
131-
assert state.state == STATE_CLOSING
127+
assert state.state == CoverState.CLOSING
132128

133129
# Stop cover
134130
await hass.services.async_call(
@@ -140,7 +136,7 @@ async def test_cover_close(
140136
mock_serial_bridge.set_device_status.assert_called()
141137

142138
assert (state := hass.states.get(ENTITY_ID))
143-
assert state.state == STATE_CLOSED
139+
assert state.state == CoverState.CLOSED
144140

145141

146142
async def test_cover_stop_if_stopped(

tests/components/cover/test_init.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""The tests for Cover."""
22

3-
from enum import Enum
4-
53
from homeassistant.components import cover
64
from homeassistant.components.cover import CoverState
75
from homeassistant.const import ATTR_ENTITY_ID, CONF_PLATFORM, SERVICE_TOGGLE
@@ -11,7 +9,7 @@
119

1210
from .common import MockCover
1311

14-
from tests.common import help_test_all, setup_test_component_platform
12+
from tests.common import setup_test_component_platform
1513

1614

1715
async def test_services(
@@ -144,12 +142,3 @@ def is_closed(hass: HomeAssistant, ent: Entity) -> bool:
144142
def is_closing(hass: HomeAssistant, ent: Entity) -> bool:
145143
"""Return if the cover is closed based on the statemachine."""
146144
return hass.states.is_state(ent.entity_id, CoverState.CLOSING)
147-
148-
149-
def _create_tuples(enum: type[Enum], constant_prefix: str) -> list[tuple[Enum, str]]:
150-
return [(enum_field, constant_prefix) for enum_field in enum]
151-
152-
153-
def test_all() -> None:
154-
"""Test module.__all__ is correctly set."""
155-
help_test_all(cover)

tests/components/google_assistant/test_trait.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,10 @@ async def test_startstop_lawn_mower(hass: HomeAssistant) -> None:
665665
[
666666
(
667667
cover.DOMAIN,
668-
cover.STATE_OPEN,
669-
cover.STATE_CLOSED,
670-
cover.STATE_OPENING,
671-
cover.STATE_CLOSING,
668+
cover.CoverState.OPEN,
669+
cover.CoverState.CLOSED,
670+
cover.CoverState.OPENING,
671+
cover.CoverState.CLOSING,
672672
CoverEntityFeature.STOP
673673
| CoverEntityFeature.OPEN
674674
| CoverEntityFeature.CLOSE,
@@ -789,10 +789,10 @@ async def test_startstop_cover_valve(
789789
[
790790
(
791791
cover.DOMAIN,
792-
cover.STATE_OPEN,
793-
cover.STATE_CLOSED,
794-
cover.STATE_OPENING,
795-
cover.STATE_CLOSING,
792+
cover.CoverState.OPEN,
793+
cover.CoverState.CLOSED,
794+
cover.CoverState.OPENING,
795+
cover.CoverState.CLOSING,
796796
CoverEntityFeature.STOP
797797
| CoverEntityFeature.OPEN
798798
| CoverEntityFeature.CLOSE,
@@ -3202,7 +3202,7 @@ async def test_openclose_cover_valve_unknown_state(
32023202
cover.DOMAIN,
32033203
cover.SERVICE_SET_COVER_POSITION,
32043204
CoverEntityFeature.SET_POSITION,
3205-
cover.STATE_OPEN,
3205+
cover.CoverState.OPEN,
32063206
),
32073207
(
32083208
valve.DOMAIN,
@@ -3251,7 +3251,7 @@ async def test_openclose_cover_valve_assumed_state(
32513251
[
32523252
(
32533253
cover.DOMAIN,
3254-
cover.STATE_OPEN,
3254+
cover.CoverState.OPEN,
32553255
),
32563256
(
32573257
valve.DOMAIN,
@@ -3298,8 +3298,8 @@ async def test_openclose_cover_valve_query_only(
32983298
[
32993299
(
33003300
cover.DOMAIN,
3301-
cover.STATE_OPEN,
3302-
cover.STATE_CLOSED,
3301+
cover.CoverState.OPEN,
3302+
cover.CoverState.CLOSED,
33033303
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE,
33043304
cover.SERVICE_OPEN_COVER,
33053305
cover.SERVICE_CLOSE_COVER,
@@ -3400,7 +3400,7 @@ async def test_openclose_cover_secure(hass: HomeAssistant, device_class) -> None
34003400
hass,
34013401
State(
34023402
"cover.bla",
3403-
cover.STATE_OPEN,
3403+
cover.CoverState.OPEN,
34043404
{
34053405
ATTR_DEVICE_CLASS: device_class,
34063406
ATTR_SUPPORTED_FEATURES: CoverEntityFeature.SET_POSITION,

0 commit comments

Comments
 (0)