Rename LockDevice to LockEntity (#34594)

This commit is contained in:
Erik Montnemery 2020-04-25 18:02:41 +02:00 committed by GitHub
parent 62bc02fdda
commit b30d117e7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 82 additions and 57 deletions

View file

@ -1,7 +1,7 @@
"""Support for the Abode Security System locks."""
import abodepy.helpers.constants as CONST
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from . import AbodeDevice
from .const import DOMAIN
@ -19,7 +19,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(entities)
class AbodeLock(AbodeDevice, LockDevice):
class AbodeLock(AbodeDevice, LockEntity):
"""Representation of an Abode lock."""
def lock(self, **kwargs):

View file

@ -5,7 +5,7 @@ from august.activity import ActivityType
from august.lock import LockStatus
from august.util import update_lock_detail_from_activity
from homeassistant.components.lock import ATTR_CHANGED_BY, LockDevice
from homeassistant.components.lock import ATTR_CHANGED_BY, LockEntity
from homeassistant.const import ATTR_BATTERY_LEVEL
from homeassistant.core import callback
from homeassistant.helpers.restore_state import RestoreEntity
@ -28,7 +28,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(devices, True)
class AugustLock(AugustEntityMixin, RestoreEntity, LockDevice):
class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity):
"""Representation of an August lock."""
def __init__(self, data, device):

View file

@ -3,7 +3,7 @@ import logging
from bimmer_connected.state import LockState
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from homeassistant.const import ATTR_ATTRIBUTION, STATE_LOCKED, STATE_UNLOCKED
from . import DOMAIN as BMW_DOMAIN
@ -26,7 +26,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(devices, True)
class BMWLock(LockDevice):
class BMWLock(LockEntity):
"""Representation of a BMW vehicle lock."""
def __init__(self, account, vehicle, attribute: str, sensor_name):

View file

@ -1,5 +1,5 @@
"""Demo lock platform that has two fake locks."""
from homeassistant.components.lock import SUPPORT_OPEN, LockDevice
from homeassistant.components.lock import SUPPORT_OPEN, LockEntity
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
@ -19,7 +19,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
await async_setup_platform(hass, {}, async_add_entities)
class DemoLock(LockDevice):
class DemoLock(LockEntity):
"""Representation of a Demo lock."""
def __init__(self, name, state, openable=False):

View file

@ -3,7 +3,7 @@ import logging
from aiohomekit.model.characteristics import CharacteristicsTypes
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_LOCKED, STATE_UNLOCKED
from homeassistant.core import callback
@ -34,7 +34,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
conn.add_listener(async_add_service)
class HomeKitLock(HomeKitEntity, LockDevice):
class HomeKitLock(HomeKitEntity, LockEntity):
"""Representation of a HomeKit Controller Lock."""
def get_characteristic_types(self):

View file

@ -1,7 +1,7 @@
"""Support for Homematic locks."""
import logging
from homeassistant.components.lock import SUPPORT_OPEN, LockDevice
from homeassistant.components.lock import SUPPORT_OPEN, LockEntity
from .const import ATTR_DISCOVER_DEVICES
from .entity import HMDevice
@ -21,7 +21,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(devices, True)
class HMLock(HMDevice, LockDevice):
class HMLock(HMDevice, LockEntity):
"""Representation of a Homematic lock aka KeyMatic."""
@property

View file

@ -2,7 +2,7 @@
import logging
from typing import Callable
from homeassistant.components.lock import DOMAIN, LockDevice
from homeassistant.components.lock import DOMAIN, LockEntity
from homeassistant.const import STATE_LOCKED, STATE_UNKNOWN, STATE_UNLOCKED
from homeassistant.helpers.typing import ConfigType
@ -27,7 +27,7 @@ def setup_platform(
add_entities(devices)
class ISYLockDevice(ISYDevice, LockDevice):
class ISYLockDevice(ISYDevice, LockEntity):
"""Representation of an ISY994 lock device."""
def __init__(self, node) -> None:

View file

@ -1,7 +1,7 @@
"""Support for KEBA charging station switch."""
import logging
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from . import DOMAIN
@ -19,7 +19,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async_add_entities(sensors)
class KebaLock(LockDevice):
class KebaLock(LockEntity):
"""The entity class for KEBA charging stations switch."""
def __init__(self, keba, name, entity_type):

View file

@ -4,7 +4,7 @@ import logging
from kiwiki import KiwiClient, KiwiException
import voluptuous as vol
from homeassistant.components.lock import PLATFORM_SCHEMA, LockDevice
from homeassistant.components.lock import PLATFORM_SCHEMA, LockEntity
from homeassistant.const import (
ATTR_ID,
ATTR_LATITUDE,
@ -47,7 +47,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities([KiwiLock(lock, kiwi) for lock in available_locks], True)
class KiwiLock(LockDevice):
class KiwiLock(LockEntity):
"""Representation of a Kiwi lock."""
def __init__(self, kiwi_lock, client):

View file

@ -25,6 +25,8 @@ from homeassistant.helpers.entity_component import EntityComponent
# mypy: allow-untyped-defs, no-check-untyped-defs
_LOGGER = logging.getLogger(__name__)
ATTR_CHANGED_BY = "changed_by"
DOMAIN = "lock"
@ -75,7 +77,7 @@ async def async_unload_entry(hass, entry):
return await hass.data[DOMAIN].async_unload_entry(entry)
class LockDevice(Entity):
class LockEntity(Entity):
"""Representation of a lock."""
@property
@ -134,3 +136,14 @@ class LockDevice(Entity):
if locked is None:
return None
return STATE_LOCKED if locked else STATE_UNLOCKED
class LockDevice(LockEntity):
"""Representation of a lock (for backwards compatibility)."""
def __init_subclass__(cls, **kwargs):
"""Print deprecation warning."""
super().__init_subclass__(**kwargs)
_LOGGER.warning(
"LockDevice is deprecated, modify %s to extend LockEntity", cls.__name__,
)

View file

@ -4,7 +4,7 @@ import logging
import requests
import voluptuous as vol
from homeassistant.components.lock import PLATFORM_SCHEMA, LockDevice
from homeassistant.components.lock import PLATFORM_SCHEMA, LockEntity
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_ID, HTTP_OK
import homeassistant.helpers.config_validation as cv
@ -31,7 +31,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
_LOGGER.error("Error retrieving lock status during init: %s", response.text)
class Lockitron(LockDevice):
class Lockitron(LockEntity):
"""Representation of a Lockitron lock."""
LOCK_STATE = "lock"

View file

@ -4,7 +4,7 @@ import logging
import voluptuous as vol
from homeassistant.components import lock, mqtt
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from homeassistant.const import (
CONF_DEVICE,
CONF_NAME,
@ -108,7 +108,7 @@ class MqttLock(
MqttAvailability,
MqttDiscoveryUpdate,
MqttEntityDeviceInfo,
LockDevice,
LockEntity,
):
"""Representation of a lock that can be toggled using MQTT."""

View file

@ -5,7 +5,7 @@ import logging
from pynello.private import Nello
import voluptuous as vol
from homeassistant.components.lock import PLATFORM_SCHEMA, LockDevice
from homeassistant.components.lock import PLATFORM_SCHEMA, LockEntity
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
import homeassistant.helpers.config_validation as cv
@ -27,7 +27,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities([NelloLock(lock) for lock in nello.locations], True)
class NelloLock(LockDevice):
class NelloLock(LockEntity):
"""Representation of a Nello lock."""
def __init__(self, nello_lock):

View file

@ -6,7 +6,7 @@ from pynuki import NukiBridge
from requests.exceptions import RequestException
import voluptuous as vol
from homeassistant.components.lock import PLATFORM_SCHEMA, SUPPORT_OPEN, LockDevice
from homeassistant.components.lock import PLATFORM_SCHEMA, SUPPORT_OPEN, LockEntity
from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, CONF_PORT, CONF_TOKEN
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.service import extract_entity_ids
@ -71,7 +71,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(devices)
class NukiLock(LockDevice):
class NukiLock(LockEntity):
"""Representation of a Nuki lock."""
def __init__(self, nuki_lock):

View file

@ -4,7 +4,7 @@ from typing import Callable
import pysesame2
import voluptuous as vol
from homeassistant.components.lock import PLATFORM_SCHEMA, LockDevice
from homeassistant.components.lock import PLATFORM_SCHEMA, LockEntity
from homeassistant.const import (
ATTR_BATTERY_LEVEL,
CONF_API_KEY,
@ -32,7 +32,7 @@ def setup_platform(
)
class SesameDevice(LockDevice):
class SesameDevice(LockEntity):
"""Representation of a Sesame device."""
def __init__(self, sesame: object) -> None:

View file

@ -5,7 +5,7 @@ from simplipy.errors import SimplipyError
from simplipy.lock import LockStates
from simplipy.websocket import EVENT_LOCK_LOCKED, EVENT_LOCK_UNLOCKED
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from homeassistant.core import callback
from . import SimpliSafeEntity
@ -30,7 +30,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
)
class SimpliSafeLock(SimpliSafeEntity, LockDevice):
class SimpliSafeLock(SimpliSafeEntity, LockEntity):
"""Define a SimpliSafe lock."""
def __init__(self, simplisafe, system, lock):

View file

@ -3,7 +3,7 @@ from typing import Optional, Sequence
from pysmartthings import Attribute, Capability
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from . import SmartThingsEntity
from .const import DATA_BROKERS, DOMAIN
@ -38,7 +38,7 @@ def get_capabilities(capabilities: Sequence[str]) -> Optional[Sequence[str]]:
return None
class SmartThingsLock(SmartThingsEntity, LockDevice):
class SmartThingsLock(SmartThingsEntity, LockEntity):
"""Define a SmartThings lock."""
async def async_lock(self, **kwargs):

View file

@ -1,5 +1,5 @@
"""Support for StarLine lock."""
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from .account import StarlineAccount, StarlineDevice
from .const import DOMAIN
@ -19,7 +19,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
async_add_entities(entities)
class StarlineLock(StarlineEntity, LockDevice):
class StarlineLock(StarlineEntity, LockEntity):
"""Representation of a StarLine lock."""
def __init__(self, account: StarlineAccount, device: StarlineDevice):

View file

@ -2,7 +2,7 @@
from datetime import timedelta
import logging
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_LOCKED, STATE_UNLOCKED
from . import DOMAIN as TAHOMA_DOMAIN, TahomaDevice
@ -24,7 +24,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(devices, True)
class TahomaLock(TahomaDevice, LockDevice):
class TahomaLock(TahomaDevice, LockEntity):
"""Representation a Tahoma lock."""
def __init__(self, tahoma_device, controller):

View file

@ -3,7 +3,7 @@ import logging
import voluptuous as vol
from homeassistant.components.lock import PLATFORM_SCHEMA, LockDevice
from homeassistant.components.lock import PLATFORM_SCHEMA, LockEntity
from homeassistant.const import (
CONF_NAME,
CONF_OPTIMISTIC,
@ -72,7 +72,7 @@ async def async_setup_platform(hass, config, async_add_devices, discovery_info=N
)
class TemplateLock(LockDevice):
class TemplateLock(LockEntity):
"""Representation of a template lock."""
def __init__(

View file

@ -1,7 +1,7 @@
"""Support for Tesla door locks."""
import logging
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
from . import DOMAIN as TESLA_DOMAIN, TeslaDevice
@ -22,7 +22,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(entities, True)
class TeslaLock(TeslaDevice, LockDevice):
class TeslaLock(TeslaDevice, LockEntity):
"""Representation of a Tesla door lock."""
def __init__(self, tesla_device, controller, config_entry):

View file

@ -5,7 +5,7 @@ from typing import Callable, List
from homeassistant.components.lock import (
DOMAIN as PLATFORM_DOMAIN,
ENTITY_ID_FORMAT,
LockDevice,
LockEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
@ -36,7 +36,7 @@ async def async_setup_entry(
)
class VeraLock(VeraDevice, LockDevice):
class VeraLock(VeraDevice, LockEntity):
"""Representation of a Vera lock."""
def __init__(self, vera_device, controller):

View file

@ -2,7 +2,7 @@
import logging
from time import monotonic, sleep
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from homeassistant.const import ATTR_CODE, STATE_LOCKED, STATE_UNLOCKED
from . import CONF_CODE_DIGITS, CONF_DEFAULT_LOCK_CODE, CONF_LOCKS, HUB as hub
@ -25,7 +25,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(locks)
class VerisureDoorlock(LockDevice):
class VerisureDoorlock(LockEntity):
"""Representation of a Verisure doorlock."""
def __init__(self, device_label):

View file

@ -1,7 +1,7 @@
"""Support for Volvo On Call locks."""
import logging
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from . import DATA_KEY, VolvoEntity
@ -16,7 +16,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async_add_entities([VolvoLock(hass.data[DATA_KEY], *discovery_info)])
class VolvoLock(VolvoEntity, LockDevice):
class VolvoLock(VolvoEntity, LockEntity):
"""Represents a car lock."""
@property

View file

@ -4,7 +4,7 @@ import logging
import pywink
import voluptuous as vol
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from homeassistant.const import (
ATTR_CODE,
ATTR_ENTITY_ID,
@ -133,7 +133,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
)
class WinkLockDevice(WinkDevice, LockDevice):
class WinkLockDevice(WinkDevice, LockEntity):
"""Representation of a Wink lock."""
async def async_added_to_hass(self):

View file

@ -1,7 +1,7 @@
"""Support for Xiaomi Aqara locks."""
import logging
from homeassistant.components.lock import LockDevice
from homeassistant.components.lock import LockEntity
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
from homeassistant.core import callback
from homeassistant.helpers.event import async_call_later
@ -32,7 +32,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async_add_entities(devices)
class XiaomiAqaraLock(LockDevice, XiaomiDevice):
class XiaomiAqaraLock(LockEntity, XiaomiDevice):
"""Representation of a XiaomiAqaraLock."""
def __init__(self, device, name, xiaomi_hub):

View file

@ -8,7 +8,7 @@ from homeassistant.components.lock import (
DOMAIN,
STATE_LOCKED,
STATE_UNLOCKED,
LockDevice,
LockEntity,
)
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -49,7 +49,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
@STRICT_MATCH(channel_names=CHANNEL_DOORLOCK)
class ZhaDoorLock(ZhaEntity, LockDevice):
class ZhaDoorLock(ZhaEntity, LockEntity):
"""Representation of a ZHA lock."""
def __init__(self, unique_id, zha_device, channels, **kwargs):

View file

@ -3,7 +3,7 @@ import logging
import voluptuous as vol
from homeassistant.components.lock import DOMAIN, LockDevice
from homeassistant.components.lock import DOMAIN, LockEntity
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -239,7 +239,7 @@ def get_device(node, values, **kwargs):
return ZwaveLock(values)
class ZwaveLock(ZWaveDeviceEntity, LockDevice):
class ZwaveLock(ZWaveDeviceEntity, LockEntity):
"""Representation of a Z-Wave Lock."""
def __init__(self, values):

View file

@ -0,0 +1,12 @@
"""The tests for Lock."""
from homeassistant.components import lock
def test_deprecated_base_class(caplog):
"""Test deprecated base class."""
class CustomLock(lock.LockDevice):
pass
CustomLock()
assert "LockDevice is deprecated, modify CustomLock" in caplog.text

View file

@ -3,7 +3,7 @@ Provide a mock lock platform.
Call init before using it in your tests to ensure clean test data.
"""
from homeassistant.components.lock import SUPPORT_OPEN, LockDevice
from homeassistant.components.lock import SUPPORT_OPEN, LockEntity
from tests.common import MockEntity
@ -41,7 +41,7 @@ async def async_setup_platform(
async_add_entities_callback(list(ENTITIES.values()))
class MockLock(MockEntity, LockDevice):
class MockLock(MockEntity, LockEntity):
"""Mock Lock class."""
@property