2020-02-12 23:35:07 +00:00
|
|
|
"""The lock tests for the august platform."""
|
|
|
|
|
2020-02-21 05:06:24 +00:00
|
|
|
from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN
|
|
|
|
from homeassistant.const import (
|
|
|
|
ATTR_ENTITY_ID,
|
2020-02-23 21:54:35 +00:00
|
|
|
SERVICE_LOCK,
|
2020-02-21 05:06:24 +00:00
|
|
|
SERVICE_UNLOCK,
|
|
|
|
STATE_LOCKED,
|
2020-02-26 07:43:41 +00:00
|
|
|
STATE_UNKNOWN,
|
2020-02-21 05:06:24 +00:00
|
|
|
STATE_UNLOCKED,
|
2020-02-12 23:35:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
from tests.components.august.mocks import (
|
2020-02-21 05:06:24 +00:00
|
|
|
_create_august_with_devices,
|
2020-02-25 18:18:15 +00:00
|
|
|
_mock_doorsense_enabled_august_lock_detail,
|
2020-02-21 05:06:24 +00:00
|
|
|
_mock_lock_from_fixture,
|
2020-02-12 23:35:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-02-26 02:34:31 +00:00
|
|
|
async def test_lock_device_registry(hass):
|
|
|
|
"""Test creation of a lock with doorsense and bridge ands up in the registry."""
|
|
|
|
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
|
|
|
|
lock_details = [lock_one]
|
|
|
|
await _create_august_with_devices(hass, lock_details)
|
|
|
|
|
|
|
|
device_registry = await hass.helpers.device_registry.async_get_registry()
|
|
|
|
|
|
|
|
reg_device = device_registry.async_get_device(
|
|
|
|
identifiers={("august", "online_with_doorsense")}, connections=set()
|
|
|
|
)
|
|
|
|
assert "AUG-MD01" == reg_device.model
|
|
|
|
assert "undefined-4.3.0-1.8.14" == reg_device.sw_version
|
|
|
|
|
|
|
|
|
2020-02-23 21:54:35 +00:00
|
|
|
async def test_one_lock_operation(hass):
|
2020-02-21 05:06:24 +00:00
|
|
|
"""Test creation of a lock with doorsense and bridge."""
|
2020-02-25 18:18:15 +00:00
|
|
|
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
|
2020-02-21 05:06:24 +00:00
|
|
|
lock_details = [lock_one]
|
2020-02-23 21:54:35 +00:00
|
|
|
await _create_august_with_devices(hass, lock_details)
|
2020-02-12 23:35:07 +00:00
|
|
|
|
2020-02-25 18:18:15 +00:00
|
|
|
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name")
|
2020-02-12 23:35:07 +00:00
|
|
|
|
2020-02-25 18:18:15 +00:00
|
|
|
assert lock_online_with_doorsense_name.state == STATE_LOCKED
|
2020-02-12 23:35:07 +00:00
|
|
|
|
2020-02-25 18:18:15 +00:00
|
|
|
assert lock_online_with_doorsense_name.attributes.get("battery_level") == 92
|
|
|
|
assert (
|
|
|
|
lock_online_with_doorsense_name.attributes.get("friendly_name")
|
|
|
|
== "online_with_doorsense Name"
|
|
|
|
)
|
2020-02-12 23:35:07 +00:00
|
|
|
|
2020-02-21 05:06:24 +00:00
|
|
|
data = {}
|
2020-02-25 18:18:15 +00:00
|
|
|
data[ATTR_ENTITY_ID] = "lock.online_with_doorsense_name"
|
2020-02-21 05:06:24 +00:00
|
|
|
assert await hass.services.async_call(
|
|
|
|
LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True
|
2020-02-12 23:35:07 +00:00
|
|
|
)
|
|
|
|
|
2020-02-25 18:18:15 +00:00
|
|
|
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name")
|
|
|
|
assert lock_online_with_doorsense_name.state == STATE_UNLOCKED
|
2020-02-12 23:35:07 +00:00
|
|
|
|
2020-02-25 18:18:15 +00:00
|
|
|
assert lock_online_with_doorsense_name.attributes.get("battery_level") == 92
|
|
|
|
assert (
|
|
|
|
lock_online_with_doorsense_name.attributes.get("friendly_name")
|
|
|
|
== "online_with_doorsense Name"
|
|
|
|
)
|
2020-02-18 20:11:05 +00:00
|
|
|
|
2020-02-23 21:54:35 +00:00
|
|
|
assert await hass.services.async_call(
|
|
|
|
LOCK_DOMAIN, SERVICE_LOCK, data, blocking=True
|
|
|
|
)
|
|
|
|
|
2020-02-25 18:18:15 +00:00
|
|
|
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name")
|
|
|
|
assert lock_online_with_doorsense_name.state == STATE_LOCKED
|
|
|
|
|
|
|
|
|
|
|
|
async def test_one_lock_unknown_state(hass):
|
|
|
|
"""Test creation of a lock with doorsense and bridge."""
|
|
|
|
lock_one = await _mock_lock_from_fixture(
|
|
|
|
hass, "get_lock.online.unknown_state.json",
|
|
|
|
)
|
|
|
|
lock_details = [lock_one]
|
|
|
|
await _create_august_with_devices(hass, lock_details)
|
|
|
|
|
|
|
|
lock_brokenid_name = hass.states.get("lock.brokenid_name")
|
2020-02-26 07:43:41 +00:00
|
|
|
|
|
|
|
assert lock_brokenid_name.state == STATE_UNKNOWN
|