Add more august actions (#100667)

This commit is contained in:
Olen 2023-09-22 14:42:17 +02:00 committed by GitHub
parent 8474c25cf1
commit 2a49b6ca7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 278 additions and 5 deletions

View file

@ -1,6 +1,14 @@
"""The sensor tests for the august platform."""
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, PERCENTAGE, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from typing import Any
from homeassistant import core as ha
from homeassistant.const import (
ATTR_ENTITY_PICTURE,
ATTR_UNIT_OF_MEASUREMENT,
PERCENTAGE,
STATE_UNKNOWN,
)
from homeassistant.core import CoreState, HomeAssistant
from homeassistant.helpers import entity_registry as er
from .mocks import (
@ -11,6 +19,8 @@ from .mocks import (
_mock_lock_from_fixture,
)
from tests.common import mock_restore_cache_with_extra_data
async def test_create_doorbell(hass: HomeAssistant) -> None:
"""Test creation of a doorbell."""
@ -255,6 +265,30 @@ async def test_lock_operator_remote(hass: HomeAssistant) -> None:
)
async def test_lock_operator_manual(hass: HomeAssistant) -> None:
"""Test operation 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_from_manual.json"
)
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = er.async_get(hass)
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
assert lock_operator_sensor
state = hass.states.get("sensor.online_with_doorsense_name_operator")
assert state.state == "Your favorite elven princess"
assert state.attributes["manual"] is True
assert state.attributes["tag"] is False
assert state.attributes["remote"] is False
assert state.attributes["keypad"] is False
assert state.attributes["autorelock"] is False
assert state.attributes["method"] == "manual"
async def test_lock_operator_autorelock(hass: HomeAssistant) -> None:
"""Test operation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
@ -297,3 +331,101 @@ async def test_lock_operator_autorelock(hass: HomeAssistant) -> None:
]
== "autorelock"
)
async def test_unlock_operator_manual(hass: HomeAssistant) -> None:
"""Test operation of a lock manually."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
activities = await _mock_activities_from_fixture(
hass, "get_activity.unlock_from_manual.json"
)
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = er.async_get(hass)
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
assert lock_operator_sensor
state = hass.states.get("sensor.online_with_doorsense_name_operator")
assert state.state == "Your favorite elven princess"
assert state.attributes["manual"] is True
assert state.attributes["tag"] is False
assert state.attributes["remote"] is False
assert state.attributes["keypad"] is False
assert state.attributes["autorelock"] is False
assert state.attributes["method"] == "manual"
async def test_unlock_operator_tag(hass: HomeAssistant) -> None:
"""Test operation of a lock with a tag."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
activities = await _mock_activities_from_fixture(
hass, "get_activity.unlock_from_tag.json"
)
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = er.async_get(hass)
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
assert lock_operator_sensor
state = hass.states.get("sensor.online_with_doorsense_name_operator")
assert state.state == "Your favorite elven princess"
assert state.attributes["manual"] is False
assert state.attributes["tag"] is True
assert state.attributes["remote"] is False
assert state.attributes["keypad"] is False
assert state.attributes["autorelock"] is False
assert state.attributes["method"] == "tag"
async def test_restored_state(
hass: HomeAssistant, hass_storage: dict[str, Any]
) -> None:
"""Test restored state."""
entity_id = "sensor.online_with_doorsense_name_operator"
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
fake_state = ha.State(
entity_id,
state="Tag Unlock",
attributes={
"method": "tag",
"manual": False,
"remote": False,
"keypad": False,
"tag": True,
"autorelock": False,
ATTR_ENTITY_PICTURE: "image.png",
},
)
# Home assistant is not running yet
hass.state = CoreState.not_running
last_reset = "2023-09-22T00:00:00.000000+00:00"
mock_restore_cache_with_extra_data(
hass,
[
(
fake_state,
{
"last_reset": last_reset,
},
)
],
)
august_entry = await _create_august_with_devices(hass, [lock_one])
august_entry.add_to_hass(hass)
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state.state == "Tag Unlock"
assert state.attributes["method"] == "tag"
assert state.attributes[ATTR_ENTITY_PICTURE] == "image.png"