mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Deprecate deprecated cover constants (#106098)
This commit is contained in:
parent
c9c072ff3e
commit
9830f77e9e
@ -32,6 +32,11 @@ from homeassistant.helpers.config_validation import ( # noqa: F401
|
|||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
PLATFORM_SCHEMA_BASE,
|
PLATFORM_SCHEMA_BASE,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.deprecation import (
|
||||||
|
DeprecatedConstantEnum,
|
||||||
|
check_if_deprecated_constant,
|
||||||
|
dir_with_deprecated_constants,
|
||||||
|
)
|
||||||
from homeassistant.helpers.entity import Entity, EntityDescription
|
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
@ -69,16 +74,32 @@ DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.Coerce(CoverDeviceClass))
|
|||||||
# DEVICE_CLASS* below are deprecated as of 2021.12
|
# DEVICE_CLASS* below are deprecated as of 2021.12
|
||||||
# use the CoverDeviceClass enum instead.
|
# use the CoverDeviceClass enum instead.
|
||||||
DEVICE_CLASSES = [cls.value for cls in CoverDeviceClass]
|
DEVICE_CLASSES = [cls.value for cls in CoverDeviceClass]
|
||||||
DEVICE_CLASS_AWNING = CoverDeviceClass.AWNING.value
|
_DEPRECATED_DEVICE_CLASS_AWNING = DeprecatedConstantEnum(
|
||||||
DEVICE_CLASS_BLIND = CoverDeviceClass.BLIND.value
|
CoverDeviceClass.AWNING, "2025.1"
|
||||||
DEVICE_CLASS_CURTAIN = CoverDeviceClass.CURTAIN.value
|
)
|
||||||
DEVICE_CLASS_DAMPER = CoverDeviceClass.DAMPER.value
|
_DEPRECATED_DEVICE_CLASS_BLIND = DeprecatedConstantEnum(
|
||||||
DEVICE_CLASS_DOOR = CoverDeviceClass.DOOR.value
|
CoverDeviceClass.BLIND, "2025.1"
|
||||||
DEVICE_CLASS_GARAGE = CoverDeviceClass.GARAGE.value
|
)
|
||||||
DEVICE_CLASS_GATE = CoverDeviceClass.GATE.value
|
_DEPRECATED_DEVICE_CLASS_CURTAIN = DeprecatedConstantEnum(
|
||||||
DEVICE_CLASS_SHADE = CoverDeviceClass.SHADE.value
|
CoverDeviceClass.CURTAIN, "2025.1"
|
||||||
DEVICE_CLASS_SHUTTER = CoverDeviceClass.SHUTTER.value
|
)
|
||||||
DEVICE_CLASS_WINDOW = CoverDeviceClass.WINDOW.value
|
_DEPRECATED_DEVICE_CLASS_DAMPER = DeprecatedConstantEnum(
|
||||||
|
CoverDeviceClass.DAMPER, "2025.1"
|
||||||
|
)
|
||||||
|
_DEPRECATED_DEVICE_CLASS_DOOR = DeprecatedConstantEnum(CoverDeviceClass.DOOR, "2025.1")
|
||||||
|
_DEPRECATED_DEVICE_CLASS_GARAGE = DeprecatedConstantEnum(
|
||||||
|
CoverDeviceClass.GARAGE, "2025.1"
|
||||||
|
)
|
||||||
|
_DEPRECATED_DEVICE_CLASS_GATE = DeprecatedConstantEnum(CoverDeviceClass.GATE, "2025.1")
|
||||||
|
_DEPRECATED_DEVICE_CLASS_SHADE = DeprecatedConstantEnum(
|
||||||
|
CoverDeviceClass.SHADE, "2025.1"
|
||||||
|
)
|
||||||
|
_DEPRECATED_DEVICE_CLASS_SHUTTER = DeprecatedConstantEnum(
|
||||||
|
CoverDeviceClass.SHUTTER, "2025.1"
|
||||||
|
)
|
||||||
|
_DEPRECATED_DEVICE_CLASS_WINDOW = DeprecatedConstantEnum(
|
||||||
|
CoverDeviceClass.WINDOW, "2025.1"
|
||||||
|
)
|
||||||
|
|
||||||
# mypy: disallow-any-generics
|
# mypy: disallow-any-generics
|
||||||
|
|
||||||
@ -98,14 +119,28 @@ class CoverEntityFeature(IntFlag):
|
|||||||
|
|
||||||
# These SUPPORT_* constants are deprecated as of Home Assistant 2022.5.
|
# These SUPPORT_* constants are deprecated as of Home Assistant 2022.5.
|
||||||
# Please use the CoverEntityFeature enum instead.
|
# Please use the CoverEntityFeature enum instead.
|
||||||
SUPPORT_OPEN = 1
|
_DEPRECATED_SUPPORT_OPEN = DeprecatedConstantEnum(CoverEntityFeature.OPEN, "2025.1")
|
||||||
SUPPORT_CLOSE = 2
|
_DEPRECATED_SUPPORT_CLOSE = DeprecatedConstantEnum(CoverEntityFeature.CLOSE, "2025.1")
|
||||||
SUPPORT_SET_POSITION = 4
|
_DEPRECATED_SUPPORT_SET_POSITION = DeprecatedConstantEnum(
|
||||||
SUPPORT_STOP = 8
|
CoverEntityFeature.SET_POSITION, "2025.1"
|
||||||
SUPPORT_OPEN_TILT = 16
|
)
|
||||||
SUPPORT_CLOSE_TILT = 32
|
_DEPRECATED_SUPPORT_STOP = DeprecatedConstantEnum(CoverEntityFeature.STOP, "2025.1")
|
||||||
SUPPORT_STOP_TILT = 64
|
_DEPRECATED_SUPPORT_OPEN_TILT = DeprecatedConstantEnum(
|
||||||
SUPPORT_SET_TILT_POSITION = 128
|
CoverEntityFeature.OPEN_TILT, "2025.1"
|
||||||
|
)
|
||||||
|
_DEPRECATED_SUPPORT_CLOSE_TILT = DeprecatedConstantEnum(
|
||||||
|
CoverEntityFeature.CLOSE_TILT, "2025.1"
|
||||||
|
)
|
||||||
|
_DEPRECATED_SUPPORT_STOP_TILT = DeprecatedConstantEnum(
|
||||||
|
CoverEntityFeature.STOP_TILT, "2025.1"
|
||||||
|
)
|
||||||
|
_DEPRECATED_SUPPORT_SET_TILT_POSITION = DeprecatedConstantEnum(
|
||||||
|
CoverEntityFeature.SET_TILT_POSITION, "2025.1"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Both can be removed if no deprecated constant are in this module anymore
|
||||||
|
__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals())
|
||||||
|
__dir__ = ft.partial(dir_with_deprecated_constants, module_globals=globals())
|
||||||
|
|
||||||
ATTR_CURRENT_POSITION = "current_position"
|
ATTR_CURRENT_POSITION = "current_position"
|
||||||
ATTR_CURRENT_TILT_POSITION = "current_tilt_position"
|
ATTR_CURRENT_TILT_POSITION = "current_tilt_position"
|
||||||
|
@ -24,18 +24,7 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.helpers.entity import get_supported_features
|
from homeassistant.helpers.entity import get_supported_features
|
||||||
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
||||||
|
|
||||||
from . import (
|
from . import ATTR_POSITION, ATTR_TILT_POSITION, DOMAIN, CoverEntityFeature
|
||||||
ATTR_POSITION,
|
|
||||||
ATTR_TILT_POSITION,
|
|
||||||
DOMAIN,
|
|
||||||
SUPPORT_CLOSE,
|
|
||||||
SUPPORT_CLOSE_TILT,
|
|
||||||
SUPPORT_OPEN,
|
|
||||||
SUPPORT_OPEN_TILT,
|
|
||||||
SUPPORT_SET_POSITION,
|
|
||||||
SUPPORT_SET_TILT_POSITION,
|
|
||||||
SUPPORT_STOP,
|
|
||||||
)
|
|
||||||
|
|
||||||
CMD_ACTION_TYPES = {"open", "close", "stop", "open_tilt", "close_tilt"}
|
CMD_ACTION_TYPES = {"open", "close", "stop", "open_tilt", "close_tilt"}
|
||||||
POSITION_ACTION_TYPES = {"set_position", "set_tilt_position"}
|
POSITION_ACTION_TYPES = {"set_position", "set_tilt_position"}
|
||||||
@ -88,20 +77,20 @@ async def async_get_actions(
|
|||||||
CONF_ENTITY_ID: entry.id,
|
CONF_ENTITY_ID: entry.id,
|
||||||
}
|
}
|
||||||
|
|
||||||
if supported_features & SUPPORT_SET_POSITION:
|
if supported_features & CoverEntityFeature.SET_POSITION:
|
||||||
actions.append({**base_action, CONF_TYPE: "set_position"})
|
actions.append({**base_action, CONF_TYPE: "set_position"})
|
||||||
if supported_features & SUPPORT_OPEN:
|
if supported_features & CoverEntityFeature.OPEN:
|
||||||
actions.append({**base_action, CONF_TYPE: "open"})
|
actions.append({**base_action, CONF_TYPE: "open"})
|
||||||
if supported_features & SUPPORT_CLOSE:
|
if supported_features & CoverEntityFeature.CLOSE:
|
||||||
actions.append({**base_action, CONF_TYPE: "close"})
|
actions.append({**base_action, CONF_TYPE: "close"})
|
||||||
if supported_features & SUPPORT_STOP:
|
if supported_features & CoverEntityFeature.STOP:
|
||||||
actions.append({**base_action, CONF_TYPE: "stop"})
|
actions.append({**base_action, CONF_TYPE: "stop"})
|
||||||
|
|
||||||
if supported_features & SUPPORT_SET_TILT_POSITION:
|
if supported_features & CoverEntityFeature.SET_TILT_POSITION:
|
||||||
actions.append({**base_action, CONF_TYPE: "set_tilt_position"})
|
actions.append({**base_action, CONF_TYPE: "set_tilt_position"})
|
||||||
if supported_features & SUPPORT_OPEN_TILT:
|
if supported_features & CoverEntityFeature.OPEN_TILT:
|
||||||
actions.append({**base_action, CONF_TYPE: "open_tilt"})
|
actions.append({**base_action, CONF_TYPE: "open_tilt"})
|
||||||
if supported_features & SUPPORT_CLOSE_TILT:
|
if supported_features & CoverEntityFeature.CLOSE_TILT:
|
||||||
actions.append({**base_action, CONF_TYPE: "close_tilt"})
|
actions.append({**base_action, CONF_TYPE: "close_tilt"})
|
||||||
|
|
||||||
return actions
|
return actions
|
||||||
|
@ -26,13 +26,7 @@ from homeassistant.helpers.config_validation import DEVICE_CONDITION_BASE_SCHEMA
|
|||||||
from homeassistant.helpers.entity import get_supported_features
|
from homeassistant.helpers.entity import get_supported_features
|
||||||
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
||||||
|
|
||||||
from . import (
|
from . import DOMAIN, CoverEntityFeature
|
||||||
DOMAIN,
|
|
||||||
SUPPORT_CLOSE,
|
|
||||||
SUPPORT_OPEN,
|
|
||||||
SUPPORT_SET_POSITION,
|
|
||||||
SUPPORT_SET_TILT_POSITION,
|
|
||||||
)
|
|
||||||
|
|
||||||
# mypy: disallow-any-generics
|
# mypy: disallow-any-generics
|
||||||
|
|
||||||
@ -78,7 +72,9 @@ async def async_get_conditions(
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
supported_features = get_supported_features(hass, entry.entity_id)
|
supported_features = get_supported_features(hass, entry.entity_id)
|
||||||
supports_open_close = supported_features & (SUPPORT_OPEN | SUPPORT_CLOSE)
|
supports_open_close = supported_features & (
|
||||||
|
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
|
||||||
|
)
|
||||||
|
|
||||||
# Add conditions for each entity that belongs to this integration
|
# Add conditions for each entity that belongs to this integration
|
||||||
base_condition = {
|
base_condition = {
|
||||||
@ -92,9 +88,9 @@ async def async_get_conditions(
|
|||||||
conditions += [
|
conditions += [
|
||||||
{**base_condition, CONF_TYPE: cond} for cond in STATE_CONDITION_TYPES
|
{**base_condition, CONF_TYPE: cond} for cond in STATE_CONDITION_TYPES
|
||||||
]
|
]
|
||||||
if supported_features & SUPPORT_SET_POSITION:
|
if supported_features & CoverEntityFeature.SET_POSITION:
|
||||||
conditions.append({**base_condition, CONF_TYPE: "is_position"})
|
conditions.append({**base_condition, CONF_TYPE: "is_position"})
|
||||||
if supported_features & SUPPORT_SET_TILT_POSITION:
|
if supported_features & CoverEntityFeature.SET_TILT_POSITION:
|
||||||
conditions.append({**base_condition, CONF_TYPE: "is_tilt_position"})
|
conditions.append({**base_condition, CONF_TYPE: "is_tilt_position"})
|
||||||
|
|
||||||
return conditions
|
return conditions
|
||||||
|
@ -29,13 +29,7 @@ from homeassistant.helpers.entity import get_supported_features
|
|||||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from . import (
|
from . import DOMAIN, CoverEntityFeature
|
||||||
DOMAIN,
|
|
||||||
SUPPORT_CLOSE,
|
|
||||||
SUPPORT_OPEN,
|
|
||||||
SUPPORT_SET_POSITION,
|
|
||||||
SUPPORT_SET_TILT_POSITION,
|
|
||||||
)
|
|
||||||
|
|
||||||
POSITION_TRIGGER_TYPES = {"position", "tilt_position"}
|
POSITION_TRIGGER_TYPES = {"position", "tilt_position"}
|
||||||
STATE_TRIGGER_TYPES = {"opened", "closed", "opening", "closing"}
|
STATE_TRIGGER_TYPES = {"opened", "closed", "opening", "closing"}
|
||||||
@ -80,7 +74,9 @@ async def async_get_triggers(
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
supported_features = get_supported_features(hass, entry.entity_id)
|
supported_features = get_supported_features(hass, entry.entity_id)
|
||||||
supports_open_close = supported_features & (SUPPORT_OPEN | SUPPORT_CLOSE)
|
supports_open_close = supported_features & (
|
||||||
|
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
|
||||||
|
)
|
||||||
|
|
||||||
# Add triggers for each entity that belongs to this integration
|
# Add triggers for each entity that belongs to this integration
|
||||||
base_trigger = {
|
base_trigger = {
|
||||||
@ -98,14 +94,14 @@ async def async_get_triggers(
|
|||||||
}
|
}
|
||||||
for trigger in STATE_TRIGGER_TYPES
|
for trigger in STATE_TRIGGER_TYPES
|
||||||
]
|
]
|
||||||
if supported_features & SUPPORT_SET_POSITION:
|
if supported_features & CoverEntityFeature.SET_POSITION:
|
||||||
triggers.append(
|
triggers.append(
|
||||||
{
|
{
|
||||||
**base_trigger,
|
**base_trigger,
|
||||||
CONF_TYPE: "position",
|
CONF_TYPE: "position",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if supported_features & SUPPORT_SET_TILT_POSITION:
|
if supported_features & CoverEntityFeature.SET_TILT_POSITION:
|
||||||
triggers.append(
|
triggers.append(
|
||||||
{
|
{
|
||||||
**base_trigger,
|
**base_trigger,
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
"""The tests for Cover."""
|
"""The tests for Cover."""
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
import homeassistant.components.cover as cover
|
import homeassistant.components.cover as cover
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
@ -12,6 +16,8 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from tests.common import import_and_test_deprecated_constant_enum
|
||||||
|
|
||||||
|
|
||||||
async def test_services(hass: HomeAssistant, enable_custom_integrations: None) -> None:
|
async def test_services(hass: HomeAssistant, enable_custom_integrations: None) -> None:
|
||||||
"""Test the provided services."""
|
"""Test the provided services."""
|
||||||
@ -112,3 +118,26 @@ def is_closed(hass, ent):
|
|||||||
def is_closing(hass, ent):
|
def is_closing(hass, ent):
|
||||||
"""Return if the cover is closed based on the statemachine."""
|
"""Return if the cover is closed based on the statemachine."""
|
||||||
return hass.states.is_state(ent.entity_id, STATE_CLOSING)
|
return hass.states.is_state(ent.entity_id, STATE_CLOSING)
|
||||||
|
|
||||||
|
|
||||||
|
def _create_tuples(enum: Enum, constant_prefix: str) -> list[tuple[Enum, str]]:
|
||||||
|
result = []
|
||||||
|
for enum in enum:
|
||||||
|
result.append((enum, constant_prefix))
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("enum", "constant_prefix"),
|
||||||
|
_create_tuples(cover.CoverEntityFeature, "SUPPORT_")
|
||||||
|
+ _create_tuples(cover.CoverDeviceClass, "DEVICE_CLASS_"),
|
||||||
|
)
|
||||||
|
def test_deprecated_constants(
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
enum: Enum,
|
||||||
|
constant_prefix: str,
|
||||||
|
) -> None:
|
||||||
|
"""Test deprecated constants."""
|
||||||
|
import_and_test_deprecated_constant_enum(
|
||||||
|
caplog, cover, enum, constant_prefix, "2025.1"
|
||||||
|
)
|
||||||
|
@ -35,16 +35,16 @@ from tests.common import async_fire_mqtt_message
|
|||||||
from tests.typing import MqttMockHAClient, MqttMockPahoClient
|
from tests.typing import MqttMockHAClient, MqttMockPahoClient
|
||||||
|
|
||||||
COVER_SUPPORT = (
|
COVER_SUPPORT = (
|
||||||
cover.SUPPORT_OPEN
|
cover.CoverEntityFeature.OPEN
|
||||||
| cover.SUPPORT_CLOSE
|
| cover.CoverEntityFeature.CLOSE
|
||||||
| cover.SUPPORT_STOP
|
| cover.CoverEntityFeature.STOP
|
||||||
| cover.SUPPORT_SET_POSITION
|
| cover.CoverEntityFeature.SET_POSITION
|
||||||
)
|
)
|
||||||
TILT_SUPPORT = (
|
TILT_SUPPORT = (
|
||||||
cover.SUPPORT_OPEN_TILT
|
cover.CoverEntityFeature.OPEN_TILT
|
||||||
| cover.SUPPORT_CLOSE_TILT
|
| cover.CoverEntityFeature.CLOSE_TILT
|
||||||
| cover.SUPPORT_STOP_TILT
|
| cover.CoverEntityFeature.STOP_TILT
|
||||||
| cover.SUPPORT_SET_TILT_POSITION
|
| cover.CoverEntityFeature.SET_TILT_POSITION
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,17 +2,7 @@
|
|||||||
|
|
||||||
Call init before using it in your tests to ensure clean test data.
|
Call init before using it in your tests to ensure clean test data.
|
||||||
"""
|
"""
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import CoverEntity, CoverEntityFeature
|
||||||
SUPPORT_CLOSE,
|
|
||||||
SUPPORT_CLOSE_TILT,
|
|
||||||
SUPPORT_OPEN,
|
|
||||||
SUPPORT_OPEN_TILT,
|
|
||||||
SUPPORT_SET_POSITION,
|
|
||||||
SUPPORT_SET_TILT_POSITION,
|
|
||||||
SUPPORT_STOP,
|
|
||||||
SUPPORT_STOP_TILT,
|
|
||||||
CoverEntity,
|
|
||||||
)
|
|
||||||
from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING
|
from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING
|
||||||
|
|
||||||
from tests.common import MockEntity
|
from tests.common import MockEntity
|
||||||
@ -32,38 +22,38 @@ def init(empty=False):
|
|||||||
name="Simple cover",
|
name="Simple cover",
|
||||||
is_on=True,
|
is_on=True,
|
||||||
unique_id="unique_cover",
|
unique_id="unique_cover",
|
||||||
supported_features=SUPPORT_OPEN | SUPPORT_CLOSE,
|
supported_features=CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE,
|
||||||
),
|
),
|
||||||
MockCover(
|
MockCover(
|
||||||
name="Set position cover",
|
name="Set position cover",
|
||||||
is_on=True,
|
is_on=True,
|
||||||
unique_id="unique_set_pos_cover",
|
unique_id="unique_set_pos_cover",
|
||||||
current_cover_position=50,
|
current_cover_position=50,
|
||||||
supported_features=SUPPORT_OPEN
|
supported_features=CoverEntityFeature.OPEN
|
||||||
| SUPPORT_CLOSE
|
| CoverEntityFeature.CLOSE
|
||||||
| SUPPORT_STOP
|
| CoverEntityFeature.STOP
|
||||||
| SUPPORT_SET_POSITION,
|
| CoverEntityFeature.SET_POSITION,
|
||||||
),
|
),
|
||||||
MockCover(
|
MockCover(
|
||||||
name="Simple tilt cover",
|
name="Simple tilt cover",
|
||||||
is_on=True,
|
is_on=True,
|
||||||
unique_id="unique_tilt_cover",
|
unique_id="unique_tilt_cover",
|
||||||
supported_features=SUPPORT_OPEN
|
supported_features=CoverEntityFeature.OPEN
|
||||||
| SUPPORT_CLOSE
|
| CoverEntityFeature.CLOSE
|
||||||
| SUPPORT_OPEN_TILT
|
| CoverEntityFeature.OPEN_TILT
|
||||||
| SUPPORT_CLOSE_TILT,
|
| CoverEntityFeature.CLOSE_TILT,
|
||||||
),
|
),
|
||||||
MockCover(
|
MockCover(
|
||||||
name="Set tilt position cover",
|
name="Set tilt position cover",
|
||||||
is_on=True,
|
is_on=True,
|
||||||
unique_id="unique_set_pos_tilt_cover",
|
unique_id="unique_set_pos_tilt_cover",
|
||||||
current_cover_tilt_position=50,
|
current_cover_tilt_position=50,
|
||||||
supported_features=SUPPORT_OPEN
|
supported_features=CoverEntityFeature.OPEN
|
||||||
| SUPPORT_CLOSE
|
| CoverEntityFeature.CLOSE
|
||||||
| SUPPORT_OPEN_TILT
|
| CoverEntityFeature.OPEN_TILT
|
||||||
| SUPPORT_CLOSE_TILT
|
| CoverEntityFeature.CLOSE_TILT
|
||||||
| SUPPORT_STOP_TILT
|
| CoverEntityFeature.STOP_TILT
|
||||||
| SUPPORT_SET_TILT_POSITION,
|
| CoverEntityFeature.SET_TILT_POSITION,
|
||||||
),
|
),
|
||||||
MockCover(
|
MockCover(
|
||||||
name="All functions cover",
|
name="All functions cover",
|
||||||
@ -71,14 +61,14 @@ def init(empty=False):
|
|||||||
unique_id="unique_all_functions_cover",
|
unique_id="unique_all_functions_cover",
|
||||||
current_cover_position=50,
|
current_cover_position=50,
|
||||||
current_cover_tilt_position=50,
|
current_cover_tilt_position=50,
|
||||||
supported_features=SUPPORT_OPEN
|
supported_features=CoverEntityFeature.OPEN
|
||||||
| SUPPORT_CLOSE
|
| CoverEntityFeature.CLOSE
|
||||||
| SUPPORT_STOP
|
| CoverEntityFeature.STOP
|
||||||
| SUPPORT_SET_POSITION
|
| CoverEntityFeature.SET_POSITION
|
||||||
| SUPPORT_OPEN_TILT
|
| CoverEntityFeature.OPEN_TILT
|
||||||
| SUPPORT_CLOSE_TILT
|
| CoverEntityFeature.CLOSE_TILT
|
||||||
| SUPPORT_STOP_TILT
|
| CoverEntityFeature.STOP_TILT
|
||||||
| SUPPORT_SET_TILT_POSITION,
|
| CoverEntityFeature.SET_TILT_POSITION,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -97,7 +87,7 @@ class MockCover(MockEntity, CoverEntity):
|
|||||||
@property
|
@property
|
||||||
def is_closed(self):
|
def is_closed(self):
|
||||||
"""Return if the cover is closed or not."""
|
"""Return if the cover is closed or not."""
|
||||||
if self.supported_features & SUPPORT_STOP:
|
if self.supported_features & CoverEntityFeature.STOP:
|
||||||
return self.current_cover_position == 0
|
return self.current_cover_position == 0
|
||||||
|
|
||||||
if "state" in self._values:
|
if "state" in self._values:
|
||||||
@ -107,7 +97,7 @@ class MockCover(MockEntity, CoverEntity):
|
|||||||
@property
|
@property
|
||||||
def is_opening(self):
|
def is_opening(self):
|
||||||
"""Return if the cover is opening or not."""
|
"""Return if the cover is opening or not."""
|
||||||
if self.supported_features & SUPPORT_STOP:
|
if self.supported_features & CoverEntityFeature.STOP:
|
||||||
if "state" in self._values:
|
if "state" in self._values:
|
||||||
return self._values["state"] == STATE_OPENING
|
return self._values["state"] == STATE_OPENING
|
||||||
|
|
||||||
@ -116,7 +106,7 @@ class MockCover(MockEntity, CoverEntity):
|
|||||||
@property
|
@property
|
||||||
def is_closing(self):
|
def is_closing(self):
|
||||||
"""Return if the cover is closing or not."""
|
"""Return if the cover is closing or not."""
|
||||||
if self.supported_features & SUPPORT_STOP:
|
if self.supported_features & CoverEntityFeature.STOP:
|
||||||
if "state" in self._values:
|
if "state" in self._values:
|
||||||
return self._values["state"] == STATE_CLOSING
|
return self._values["state"] == STATE_CLOSING
|
||||||
|
|
||||||
@ -124,14 +114,14 @@ class MockCover(MockEntity, CoverEntity):
|
|||||||
|
|
||||||
def open_cover(self, **kwargs) -> None:
|
def open_cover(self, **kwargs) -> None:
|
||||||
"""Open cover."""
|
"""Open cover."""
|
||||||
if self.supported_features & SUPPORT_STOP:
|
if self.supported_features & CoverEntityFeature.STOP:
|
||||||
self._values["state"] = STATE_OPENING
|
self._values["state"] = STATE_OPENING
|
||||||
else:
|
else:
|
||||||
self._values["state"] = STATE_OPEN
|
self._values["state"] = STATE_OPEN
|
||||||
|
|
||||||
def close_cover(self, **kwargs) -> None:
|
def close_cover(self, **kwargs) -> None:
|
||||||
"""Close cover."""
|
"""Close cover."""
|
||||||
if self.supported_features & SUPPORT_STOP:
|
if self.supported_features & CoverEntityFeature.STOP:
|
||||||
self._values["state"] = STATE_CLOSING
|
self._values["state"] = STATE_CLOSING
|
||||||
else:
|
else:
|
||||||
self._values["state"] = STATE_CLOSED
|
self._values["state"] = STATE_CLOSED
|
||||||
|
Loading…
x
Reference in New Issue
Block a user