Restore august lock changed_by state on restart (#32340)

* Various code review items from previous PRs

* Add a test for fetching the doorbell camera image

* Switch to using UNIT_PERCENTAGE for battery charge unit

* Add tests for changed_by
This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-02-29 12:12:50 +01:00
1 parent e9a7b66df6
commit be14b94705
8 files changed
+112 -50

No files matched your search

+6 -12
View File
@@ -23,16 +23,14 @@ async def test_doorsense(hass):
lock_one = await _mock_lock_from_fixture(
hass, "get_lock.online_with_doorsense.json"
)
lock_details = [lock_one]
await _create_august_with_devices(hass, lock_details)
await _create_august_with_devices(hass, [lock_one])
binary_sensor_online_with_doorsense_name = hass.states.get(
"binary_sensor.online_with_doorsense_name_open"
)
assert binary_sensor_online_with_doorsense_name.state == STATE_ON
data = {}
data[ATTR_ENTITY_ID] = "lock.online_with_doorsense_name"
data = {ATTR_ENTITY_ID: "lock.online_with_doorsense_name"}
assert await hass.services.async_call(
LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True
)
@@ -57,8 +55,7 @@ async def test_doorsense(hass):
async def test_create_doorbell(hass):
"""Test creation of a doorbell."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json")
doorbell_details = [doorbell_one]
await _create_august_with_devices(hass, doorbell_details)
await _create_august_with_devices(hass, [doorbell_one])
binary_sensor_k98gidt45gul_name_motion = hass.states.get(
"binary_sensor.k98gidt45gul_name_motion"
@@ -81,8 +78,7 @@ async def test_create_doorbell(hass):
async def test_create_doorbell_offline(hass):
"""Test creation of a doorbell that is offline."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json")
doorbell_details = [doorbell_one]
await _create_august_with_devices(hass, doorbell_details)
await _create_august_with_devices(hass, [doorbell_one])
binary_sensor_tmt100_name_motion = hass.states.get(
"binary_sensor.tmt100_name_motion"
@@ -99,11 +95,10 @@ async def test_create_doorbell_offline(hass):
async def test_create_doorbell_with_motion(hass):
"""Test creation of a doorbell."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json")
doorbell_details = [doorbell_one]
activities = await _mock_activities_from_fixture(
hass, "get_activity.doorbell_motion.json"
)
await _create_august_with_devices(hass, doorbell_details, activities=activities)
await _create_august_with_devices(hass, [doorbell_one], activities=activities)
binary_sensor_k98gidt45gul_name_motion = hass.states.get(
"binary_sensor.k98gidt45gul_name_motion"
@@ -122,8 +117,7 @@ async def test_create_doorbell_with_motion(hass):
async def test_doorbell_device_registry(hass):
"""Test creation of a lock with doorsense and bridge ands up in the registry."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json")
doorbell_details = [doorbell_one]
await _create_august_with_devices(hass, doorbell_details)
await _create_august_with_devices(hass, [doorbell_one])
device_registry = await hass.helpers.device_registry.async_get_registry()
+22 -5
View File
@@ -1,5 +1,7 @@
"""The camera tests for the august platform."""
from asynctest import mock
from homeassistant.const import STATE_IDLE
from tests.components.august.mocks import (
@@ -8,11 +10,26 @@ from tests.components.august.mocks import (
)
async def test_create_doorbell(hass):
async def test_create_doorbell(hass, aiohttp_client):
"""Test creation of a doorbell."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json")
doorbell_details = [doorbell_one]
await _create_august_with_devices(hass, doorbell_details)
camera_k98gidt45gul_name_camera = hass.states.get("camera.k98gidt45gul_name_camera")
assert camera_k98gidt45gul_name_camera.state == STATE_IDLE
with mock.patch.object(
doorbell_one, "get_doorbell_image", create=False, return_value="image"
):
await _create_august_with_devices(hass, [doorbell_one])
camera_k98gidt45gul_name_camera = hass.states.get(
"camera.k98gidt45gul_name_camera"
)
assert camera_k98gidt45gul_name_camera.state == STATE_IDLE
url = hass.states.get("camera.k98gidt45gul_name_camera").attributes[
"entity_picture"
]
client = await aiohttp_client(hass.http.app)
resp = await client.get(url)
assert resp.status == 200
body = await resp.text()
assert body == "image"
+22 -8
View File
@@ -12,6 +12,7 @@ from homeassistant.const import (
from tests.components.august.mocks import (
_create_august_with_devices,
_mock_activities_from_fixture,
_mock_doorsense_enabled_august_lock_detail,
_mock_lock_from_fixture,
)
@@ -20,8 +21,7 @@ from tests.components.august.mocks import (
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)
await _create_august_with_devices(hass, [lock_one])
device_registry = await hass.helpers.device_registry.async_get_registry()
@@ -34,11 +34,27 @@ async def test_lock_device_registry(hass):
assert reg_device.manufacturer == "August"
async def test_lock_changed_by(hass):
"""Test creation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
activities = await _mock_activities_from_fixture(hass, "get_activity.lock.json")
await _create_august_with_devices(hass, [lock_one], activities=activities)
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name")
assert lock_online_with_doorsense_name.state == STATE_LOCKED
assert (
lock_online_with_doorsense_name.attributes.get("changed_by")
== "Your favorite elven princess"
)
async def test_one_lock_operation(hass):
"""Test creation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
lock_details = [lock_one]
await _create_august_with_devices(hass, lock_details)
await _create_august_with_devices(hass, [lock_one])
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name")
@@ -50,8 +66,7 @@ async def test_one_lock_operation(hass):
== "online_with_doorsense Name"
)
data = {}
data[ATTR_ENTITY_ID] = "lock.online_with_doorsense_name"
data = {ATTR_ENTITY_ID: "lock.online_with_doorsense_name"}
assert await hass.services.async_call(
LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True
)
@@ -78,8 +93,7 @@ async def test_one_lock_unknown_state(hass):
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)
await _create_august_with_devices(hass, [lock_one])
lock_brokenid_name = hass.states.get("lock.brokenid_name")