Add device action support to the lock integration (#27499)

* Add device action support to the lock integration

* Check that the enitity supports open service
This commit is contained in:
Erik Montnemery authored and Paulus Schoutsen committed 2019-10-17 17:20:10 -07:00
1 parent bd0403c65e
commit 6d083969c2
4 files changed
+321

No files matched your search

@@ -0,0 +1,54 @@
"""
Provide a mock lock platform.
Call init before using it in your tests to ensure clean test data.
"""
from homeassistant.components.lock import LockDevice, SUPPORT_OPEN
from tests.common import MockEntity
ENTITIES = {}
def init(empty=False):
"""Initialize the platform with entities."""
global ENTITIES
ENTITIES = (
{}
if empty
else {
"support_open": MockLock(
name=f"Support open Lock",
is_locked=True,
supported_features=SUPPORT_OPEN,
unique_id="unique_support_open",
),
"no_support_open": MockLock(
name=f"No support open Lock",
is_locked=True,
supported_features=0,
unique_id="unique_no_support_open",
),
}
)
async def async_setup_platform(
hass, config, async_add_entities_callback, discovery_info=None
):
"""Return mock entities."""
async_add_entities_callback(list(ENTITIES.values()))
class MockLock(MockEntity, LockDevice):
"""Mock Lock class."""
@property
def is_locked(self):
"""Return true if the lock is locked."""
return self._handle("is_locked")
@property
def supported_features(self):
"""Return the class of this sensor."""
return self._handle("supported_features")