Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions homeassistant/components/demo/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import asyncio

from homeassistant.components.lock import SUPPORT_OPEN, LockEntity
from homeassistant.components.lock import LockEntity, LockEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
STATE_JAMMED,
Expand Down Expand Up @@ -60,7 +60,7 @@ def __init__(
"""Initialize the lock."""
self._attr_name = name
if openable:
self._attr_supported_features = SUPPORT_OPEN
self._attr_supported_features = LockEntityFeature.OPEN
self._state = state
self._openable = openable
self._jam_on_operation = jam_on_operation
Expand Down Expand Up @@ -113,5 +113,5 @@ async def async_open(self, **kwargs):
def supported_features(self):
"""Flag supported features."""
if self._openable:
return SUPPORT_OPEN
return LockEntityFeature.OPEN
return 0
11 changes: 10 additions & 1 deletion homeassistant/components/lock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from dataclasses import dataclass
from datetime import timedelta
from enum import IntEnum
import functools as ft
import logging
from typing import Any, final
Expand Down Expand Up @@ -46,7 +47,15 @@

LOCK_SERVICE_SCHEMA = make_entity_service_schema({vol.Optional(ATTR_CODE): cv.string})

# Bitfield of features supported by the lock entity

class LockEntityFeature(IntEnum):
"""Supported features of the lock entity."""

OPEN = 1


# The SUPPORT_OPEN constant is deprecated as of Home Assistant 2022.5.
# Please use the LockEntityFeature enum instead.
SUPPORT_OPEN = 1

PROP_TO_ATTR = {"changed_by": ATTR_CHANGED_BY, "code_format": ATTR_CODE_FORMAT}
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/lock/device_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import get_supported_features

from . import DOMAIN, SUPPORT_OPEN
from . import DOMAIN, LockEntityFeature

ACTION_TYPES = {"lock", "unlock", "open"}

Expand Down Expand Up @@ -54,7 +54,7 @@ async def async_get_actions(
actions.append({**base_action, CONF_TYPE: "lock"})
actions.append({**base_action, CONF_TYPE: "unlock"})

if supported_features & (SUPPORT_OPEN):
if supported_features & (LockEntityFeature.OPEN):
actions.append({**base_action, CONF_TYPE: "open"})

return actions
Expand Down
6 changes: 3 additions & 3 deletions tests/components/lock/test_device_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.lock import DOMAIN, SUPPORT_OPEN
from homeassistant.components.lock import DOMAIN, LockEntityFeature
from homeassistant.helpers import device_registry
from homeassistant.setup import async_setup_component

Expand Down Expand Up @@ -34,9 +34,9 @@ def entity_reg(hass):
"set_state,features_reg,features_state,expected_action_types",
[
(False, 0, 0, []),
(False, SUPPORT_OPEN, 0, ["open"]),
(False, LockEntityFeature.OPEN, 0, ["open"]),
(True, 0, 0, []),
(True, 0, SUPPORT_OPEN, ["open"]),
(True, 0, LockEntityFeature.OPEN, ["open"]),
],
)
async def test_get_actions(
Expand Down