Address august review comments (#124819)

* Address august review comments

Followup to https://github.com/home-assistant/core/pull/124677

* cleanup loop

* drop mixin name

* event entity add cleanup

* remove duplicate prop

* pep0695 type

* remove some not needed block till done

* cleanup august tests

* switch to freezegun

* snapshots for dev reg

* SOURCE_USER nit

* snapshots

* pytest.raises

* not loaded check
This commit is contained in:
J. Nick Koston 2024-08-29 07:32:13 -10:00 committed by GitHub
parent 149aebb0bc
commit a04970bd54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 312 additions and 422 deletions

View File

@ -24,7 +24,7 @@ from .util import async_create_august_clientsession
type AugustConfigEntry = ConfigEntry[AugustData] type AugustConfigEntry = ConfigEntry[AugustData]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: AugustConfigEntry) -> bool:
"""Set up August from a config entry.""" """Set up August from a config entry."""
session = async_create_august_clientsession(hass) session = async_create_august_clientsession(hass)
august_gateway = AugustGateway(Path(hass.config.config_dir), session) august_gateway = AugustGateway(Path(hass.config.config_dir), session)

View File

@ -109,12 +109,11 @@ async def async_setup_entry(
for description in SENSOR_TYPES_DOORBELL for description in SENSOR_TYPES_DOORBELL
) )
for doorbell in data.doorbells: entities.extend(
entities.extend( AugustDoorbellBinarySensor(data, doorbell, description)
AugustDoorbellBinarySensor(data, doorbell, description) for description in SENSOR_TYPES_DOORBELL + SENSOR_TYPES_VIDEO_DOORBELL
for description in SENSOR_TYPES_DOORBELL + SENSOR_TYPES_VIDEO_DOORBELL for doorbell in data.doorbells
) )
async_add_entities(entities) async_add_entities(entities)

View File

@ -5,7 +5,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import AugustConfigEntry from . import AugustConfigEntry
from .entity import AugustEntityMixin from .entity import AugustEntity
async def async_setup_entry( async def async_setup_entry(
@ -18,7 +18,7 @@ async def async_setup_entry(
async_add_entities(AugustWakeLockButton(data, lock, "wake") for lock in data.locks) async_add_entities(AugustWakeLockButton(data, lock, "wake") for lock in data.locks)
class AugustWakeLockButton(AugustEntityMixin, ButtonEntity): class AugustWakeLockButton(AugustEntity, ButtonEntity):
"""Representation of an August lock wake button.""" """Representation of an August lock wake button."""
_attr_translation_key = "wake" _attr_translation_key = "wake"

View File

@ -16,7 +16,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import AugustConfigEntry, AugustData from . import AugustConfigEntry, AugustData
from .const import DEFAULT_NAME, DEFAULT_TIMEOUT from .const import DEFAULT_NAME, DEFAULT_TIMEOUT
from .entity import AugustEntityMixin from .entity import AugustEntity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -38,7 +38,7 @@ async def async_setup_entry(
) )
class AugustCamera(AugustEntityMixin, Camera): class AugustCamera(AugustEntity, Camera):
"""An implementation of an August security camera.""" """An implementation of an August security camera."""
_attr_translation_key = "camera" _attr_translation_key = "camera"

View File

@ -20,7 +20,7 @@ from .const import MANUFACTURER
DEVICE_TYPES = ["keypad", "lock", "camera", "doorbell", "door", "bell"] DEVICE_TYPES = ["keypad", "lock", "camera", "doorbell", "door", "bell"]
class AugustEntityMixin(Entity): class AugustEntity(Entity):
"""Base implementation for August device.""" """Base implementation for August device."""
_attr_should_poll = False _attr_should_poll = False
@ -87,7 +87,7 @@ class AugustEntityMixin(Entity):
self._update_from_data() self._update_from_data()
class AugustDescriptionEntity(AugustEntityMixin): class AugustDescriptionEntity(AugustEntity):
"""An August entity with a description.""" """An August entity with a description."""
def __init__( def __init__(

View File

@ -63,22 +63,17 @@ async def async_setup_entry(
) -> None: ) -> None:
"""Set up the august event platform.""" """Set up the august event platform."""
data = config_entry.runtime_data data = config_entry.runtime_data
entities: list[AugustEventEntity] = [] entities: list[AugustEventEntity] = [
AugustEventEntity(data, lock, description)
for lock in data.locks: for description in TYPES_DOORBELL
detail = data.get_device_detail(lock.device_id) for lock in data.locks
if detail.doorbell: if (detail := data.get_device_detail(lock.device_id)) and detail.doorbell
entities.extend( ]
AugustEventEntity(data, lock, description) entities.extend(
for description in TYPES_DOORBELL AugustEventEntity(data, doorbell, description)
) for description in TYPES_DOORBELL + TYPES_VIDEO_DOORBELL
for doorbell in data.doorbells
for doorbell in data.doorbells: )
entities.extend(
AugustEventEntity(data, doorbell, description)
for description in TYPES_DOORBELL + TYPES_VIDEO_DOORBELL
)
async_add_entities(entities) async_add_entities(entities)
@ -86,7 +81,6 @@ class AugustEventEntity(AugustDescriptionEntity, EventEntity):
"""An august event entity.""" """An august event entity."""
entity_description: AugustEventEntityDescription entity_description: AugustEventEntityDescription
_attr_has_entity_name = True
_last_activity: Activity | None = None _last_activity: Activity | None = None
@callback @callback

View File

@ -19,7 +19,7 @@ from homeassistant.helpers.restore_state import RestoreEntity
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from . import AugustConfigEntry, AugustData from . import AugustConfigEntry, AugustData
from .entity import AugustEntityMixin from .entity import AugustEntity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -36,7 +36,7 @@ async def async_setup_entry(
async_add_entities(AugustLock(data, lock) for lock in data.locks) async_add_entities(AugustLock(data, lock) for lock in data.locks)
class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity): class AugustLock(AugustEntity, RestoreEntity, LockEntity):
"""Representation of an August lock.""" """Representation of an August lock."""
_attr_name = None _attr_name = None

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Generic, TypeVar, cast from typing import Any, cast
from yalexs.activity import ActivityType, LockOperationActivity from yalexs.activity import ActivityType, LockOperationActivity
from yalexs.doorbell import Doorbell from yalexs.doorbell import Doorbell
@ -42,7 +42,7 @@ from .const import (
OPERATION_METHOD_REMOTE, OPERATION_METHOD_REMOTE,
OPERATION_METHOD_TAG, OPERATION_METHOD_TAG,
) )
from .entity import AugustDescriptionEntity, AugustEntityMixin from .entity import AugustDescriptionEntity, AugustEntity
def _retrieve_device_battery_state(detail: LockDetail) -> int: def _retrieve_device_battery_state(detail: LockDetail) -> int:
@ -55,14 +55,13 @@ def _retrieve_linked_keypad_battery_state(detail: KeypadDetail) -> int | None:
return detail.battery_percentage return detail.battery_percentage
_T = TypeVar("_T", LockDetail, KeypadDetail)
@dataclass(frozen=True, kw_only=True) @dataclass(frozen=True, kw_only=True)
class AugustSensorEntityDescription(SensorEntityDescription, Generic[_T]): class AugustSensorEntityDescription[T: LockDetail | KeypadDetail](
SensorEntityDescription
):
"""Mixin for required keys.""" """Mixin for required keys."""
value_fn: Callable[[_T], int | None] value_fn: Callable[[T], int | None]
SENSOR_TYPE_DEVICE_BATTERY = AugustSensorEntityDescription[LockDetail]( SENSOR_TYPE_DEVICE_BATTERY = AugustSensorEntityDescription[LockDetail](
@ -114,7 +113,7 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class AugustOperatorSensor(AugustEntityMixin, RestoreSensor): class AugustOperatorSensor(AugustEntity, RestoreSensor):
"""Representation of an August lock operation sensor.""" """Representation of an August lock operation sensor."""
_attr_translation_key = "operator" _attr_translation_key = "operator"
@ -198,10 +197,12 @@ class AugustOperatorSensor(AugustEntityMixin, RestoreSensor):
self._operated_autorelock = last_attrs[ATTR_OPERATION_AUTORELOCK] self._operated_autorelock = last_attrs[ATTR_OPERATION_AUTORELOCK]
class AugustBatterySensor(AugustDescriptionEntity, SensorEntity, Generic[_T]): class AugustBatterySensor[T: LockDetail | KeypadDetail](
AugustDescriptionEntity, SensorEntity
):
"""Representation of an August sensor.""" """Representation of an August sensor."""
entity_description: AugustSensorEntityDescription[_T] entity_description: AugustSensorEntityDescription[T]
_attr_device_class = SensorDeviceClass.BATTERY _attr_device_class = SensorDeviceClass.BATTERY
_attr_native_unit_of_measurement = PERCENTAGE _attr_native_unit_of_measurement = PERCENTAGE

View File

@ -63,16 +63,11 @@ def _activity_time_based(latest: Activity) -> Activity | None:
"""Get the latest state of the sensor.""" """Get the latest state of the sensor."""
start = latest.activity_start_time start = latest.activity_start_time
end = latest.activity_end_time + TIME_TO_DECLARE_DETECTION end = latest.activity_end_time + TIME_TO_DECLARE_DETECTION
if start <= _native_datetime() <= end: if start <= datetime.now() <= end:
return latest return latest
return None return None
def _native_datetime() -> datetime:
"""Return time in the format august uses without timezone."""
return datetime.now()
def retrieve_online_state( def retrieve_online_state(
data: AugustData, detail: DoorbellDetail | LockDetail data: AugustData, detail: DoorbellDetail | LockDetail
) -> bool: ) -> bool:

View File

@ -0,0 +1,33 @@
# serializer version: 1
# name: test_doorbell_device_registry
DeviceRegistryEntrySnapshot({
'area_id': 'tmt100_name',
'config_entries': <ANY>,
'configuration_url': 'https://account.august.com',
'connections': set({
}),
'disabled_by': None,
'entry_type': None,
'hw_version': None,
'id': <ANY>,
'identifiers': set({
tuple(
'august',
'tmt100',
),
}),
'is_new': False,
'labels': set({
}),
'manufacturer': 'August Home Inc.',
'model': 'hydra1',
'model_id': None,
'name': 'tmt100 Name',
'name_by_user': None,
'primary_config_entry': <ANY>,
'serial_number': None,
'suggested_area': 'tmt100 Name',
'sw_version': '3.1.0-HYDRC75+201909251139',
'via_device_id': None,
})
# ---

View File

@ -0,0 +1,37 @@
# serializer version: 1
# name: test_lock_device_registry
DeviceRegistryEntrySnapshot({
'area_id': 'online_with_doorsense_name',
'config_entries': <ANY>,
'configuration_url': 'https://account.august.com',
'connections': set({
tuple(
'bluetooth',
'12:22',
),
}),
'disabled_by': None,
'entry_type': None,
'hw_version': None,
'id': <ANY>,
'identifiers': set({
tuple(
'august',
'online_with_doorsense',
),
}),
'is_new': False,
'labels': set({
}),
'manufacturer': 'August Home Inc.',
'model': 'AUG-MD01',
'model_id': None,
'name': 'online_with_doorsense Name',
'name_by_user': None,
'primary_config_entry': <ANY>,
'serial_number': None,
'suggested_area': 'online_with_doorsense Name',
'sw_version': 'undefined-4.3.0-1.8.14',
'via_device_id': None,
})
# ---

View File

@ -1,8 +1,10 @@
"""The binary_sensor tests for the august platform.""" """The binary_sensor tests for the august platform."""
import datetime import datetime
from unittest.mock import Mock, patch from unittest.mock import Mock
from freezegun.api import FrozenDateTimeFactory
from syrupy import SnapshotAssertion
from yalexs.pubnub_async import AugustPubNub from yalexs.pubnub_async import AugustPubNub
from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN
@ -36,28 +38,20 @@ async def test_doorsense(hass: HomeAssistant) -> None:
hass, "get_lock.online_with_doorsense.json" hass, "get_lock.online_with_doorsense.json"
) )
await _create_august_with_devices(hass, [lock_one]) await _create_august_with_devices(hass, [lock_one])
states = hass.states
binary_sensor_online_with_doorsense_name = hass.states.get( assert states.get("binary_sensor.online_with_doorsense_name_door").state == STATE_ON
"binary_sensor.online_with_doorsense_name_door"
)
assert binary_sensor_online_with_doorsense_name.state == STATE_ON
data = {ATTR_ENTITY_ID: "lock.online_with_doorsense_name"} data = {ATTR_ENTITY_ID: "lock.online_with_doorsense_name"}
await hass.services.async_call(LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True)
await hass.async_block_till_done()
binary_sensor_online_with_doorsense_name = hass.states.get( assert states.get("binary_sensor.online_with_doorsense_name_door").state == STATE_ON
"binary_sensor.online_with_doorsense_name_door"
)
assert binary_sensor_online_with_doorsense_name.state == STATE_ON
await hass.services.async_call(LOCK_DOMAIN, SERVICE_LOCK, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_LOCK, data, blocking=True)
await hass.async_block_till_done()
binary_sensor_online_with_doorsense_name = hass.states.get( assert (
"binary_sensor.online_with_doorsense_name_door" states.get("binary_sensor.online_with_doorsense_name_door").state == STATE_OFF
) )
assert binary_sensor_online_with_doorsense_name.state == STATE_OFF
async def test_lock_bridge_offline(hass: HomeAssistant) -> None: async def test_lock_bridge_offline(hass: HomeAssistant) -> None:
@ -69,113 +63,82 @@ async def test_lock_bridge_offline(hass: HomeAssistant) -> None:
hass, "get_activity.bridge_offline.json" hass, "get_activity.bridge_offline.json"
) )
await _create_august_with_devices(hass, [lock_one], activities=activities) await _create_august_with_devices(hass, [lock_one], activities=activities)
states = hass.states
binary_sensor_online_with_doorsense_name = hass.states.get( assert (
"binary_sensor.online_with_doorsense_name_door" states.get("binary_sensor.online_with_doorsense_name_door").state
== STATE_UNAVAILABLE
) )
assert binary_sensor_online_with_doorsense_name.state == STATE_UNAVAILABLE
async def test_create_doorbell(hass: HomeAssistant) -> None: async def test_create_doorbell(hass: HomeAssistant) -> None:
"""Test creation of a doorbell.""" """Test creation of a doorbell."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json") doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json")
await _create_august_with_devices(hass, [doorbell_one]) await _create_august_with_devices(hass, [doorbell_one])
states = hass.states
binary_sensor_k98gidt45gul_name_motion = hass.states.get( assert states.get("binary_sensor.k98gidt45gul_name_motion").state == STATE_OFF
"binary_sensor.k98gidt45gul_name_motion" assert (
states.get("binary_sensor.k98gidt45gul_name_image_capture").state == STATE_OFF
) )
assert binary_sensor_k98gidt45gul_name_motion.state == STATE_OFF assert states.get("binary_sensor.k98gidt45gul_name_connectivity").state == STATE_ON
binary_sensor_k98gidt45gul_name_image_capture = hass.states.get( assert (
"binary_sensor.k98gidt45gul_name_image_capture" states.get("binary_sensor.k98gidt45gul_name_doorbell_ding").state == STATE_OFF
) )
assert binary_sensor_k98gidt45gul_name_image_capture.state == STATE_OFF assert states.get("binary_sensor.k98gidt45gul_name_motion").state == STATE_OFF
binary_sensor_k98gidt45gul_name_online = hass.states.get( assert (
"binary_sensor.k98gidt45gul_name_connectivity" states.get("binary_sensor.k98gidt45gul_name_image_capture").state == STATE_OFF
) )
assert binary_sensor_k98gidt45gul_name_online.state == STATE_ON
binary_sensor_k98gidt45gul_name_ding = hass.states.get(
"binary_sensor.k98gidt45gul_name_doorbell_ding"
)
assert binary_sensor_k98gidt45gul_name_ding.state == STATE_OFF
binary_sensor_k98gidt45gul_name_motion = hass.states.get(
"binary_sensor.k98gidt45gul_name_motion"
)
assert binary_sensor_k98gidt45gul_name_motion.state == STATE_OFF
binary_sensor_k98gidt45gul_name_image_capture = hass.states.get(
"binary_sensor.k98gidt45gul_name_image_capture"
)
assert binary_sensor_k98gidt45gul_name_image_capture.state == STATE_OFF
async def test_create_doorbell_offline(hass: HomeAssistant) -> None: async def test_create_doorbell_offline(hass: HomeAssistant) -> None:
"""Test creation of a doorbell that is offline.""" """Test creation of a doorbell that is offline."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json") doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json")
await _create_august_with_devices(hass, [doorbell_one]) await _create_august_with_devices(hass, [doorbell_one])
states = hass.states
binary_sensor_tmt100_name_motion = hass.states.get( assert states.get("binary_sensor.tmt100_name_motion").state == STATE_UNAVAILABLE
"binary_sensor.tmt100_name_motion" assert states.get("binary_sensor.tmt100_name_connectivity").state == STATE_OFF
assert (
states.get("binary_sensor.tmt100_name_doorbell_ding").state == STATE_UNAVAILABLE
) )
assert binary_sensor_tmt100_name_motion.state == STATE_UNAVAILABLE
binary_sensor_tmt100_name_online = hass.states.get(
"binary_sensor.tmt100_name_connectivity"
)
assert binary_sensor_tmt100_name_online.state == STATE_OFF
binary_sensor_tmt100_name_ding = hass.states.get(
"binary_sensor.tmt100_name_doorbell_ding"
)
assert binary_sensor_tmt100_name_ding.state == STATE_UNAVAILABLE
async def test_create_doorbell_with_motion(hass: HomeAssistant) -> None: async def test_create_doorbell_with_motion(
hass: HomeAssistant, freezer: FrozenDateTimeFactory
) -> None:
"""Test creation of a doorbell.""" """Test creation of a doorbell."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json") doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json")
activities = await _mock_activities_from_fixture( activities = await _mock_activities_from_fixture(
hass, "get_activity.doorbell_motion.json" hass, "get_activity.doorbell_motion.json"
) )
await _create_august_with_devices(hass, [doorbell_one], activities=activities) await _create_august_with_devices(hass, [doorbell_one], activities=activities)
states = hass.states
binary_sensor_k98gidt45gul_name_motion = hass.states.get( assert states.get("binary_sensor.k98gidt45gul_name_motion").state == STATE_ON
"binary_sensor.k98gidt45gul_name_motion" assert states.get("binary_sensor.k98gidt45gul_name_connectivity").state == STATE_ON
assert (
states.get("binary_sensor.k98gidt45gul_name_doorbell_ding").state == STATE_OFF
) )
assert binary_sensor_k98gidt45gul_name_motion.state == STATE_ON freezer.tick(40)
binary_sensor_k98gidt45gul_name_online = hass.states.get( async_fire_time_changed(hass)
"binary_sensor.k98gidt45gul_name_connectivity" await hass.async_block_till_done()
) assert states.get("binary_sensor.k98gidt45gul_name_motion").state == STATE_OFF
assert binary_sensor_k98gidt45gul_name_online.state == STATE_ON
binary_sensor_k98gidt45gul_name_ding = hass.states.get(
"binary_sensor.k98gidt45gul_name_doorbell_ding"
)
assert binary_sensor_k98gidt45gul_name_ding.state == STATE_OFF
new_time = dt_util.utcnow() + datetime.timedelta(seconds=40)
native_time = datetime.datetime.now() + datetime.timedelta(seconds=40)
with patch(
"homeassistant.components.august.util._native_datetime",
return_value=native_time,
):
async_fire_time_changed(hass, new_time)
await hass.async_block_till_done()
binary_sensor_k98gidt45gul_name_motion = hass.states.get(
"binary_sensor.k98gidt45gul_name_motion"
)
assert binary_sensor_k98gidt45gul_name_motion.state == STATE_OFF
async def test_doorbell_update_via_pubnub(hass: HomeAssistant) -> None: async def test_doorbell_update_via_pubnub(
hass: HomeAssistant, freezer: FrozenDateTimeFactory
) -> None:
"""Test creation of a doorbell that can be updated via pubnub.""" """Test creation of a doorbell that can be updated via pubnub."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json") doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json")
pubnub = AugustPubNub() pubnub = AugustPubNub()
await _create_august_with_devices(hass, [doorbell_one], pubnub=pubnub) await _create_august_with_devices(hass, [doorbell_one], pubnub=pubnub)
assert doorbell_one.pubsub_channel == "7c7a6672-59c8-3333-ffff-dcd98705cccc" assert doorbell_one.pubsub_channel == "7c7a6672-59c8-3333-ffff-dcd98705cccc"
states = hass.states
binary_sensor_k98gidt45gul_name_motion = hass.states.get( assert states.get("binary_sensor.k98gidt45gul_name_motion").state == STATE_OFF
"binary_sensor.k98gidt45gul_name_motion" assert (
states.get("binary_sensor.k98gidt45gul_name_doorbell_ding").state == STATE_OFF
) )
assert binary_sensor_k98gidt45gul_name_motion.state == STATE_OFF
binary_sensor_k98gidt45gul_name_ding = hass.states.get(
"binary_sensor.k98gidt45gul_name_doorbell_ding"
)
assert binary_sensor_k98gidt45gul_name_ding.state == STATE_OFF
pubnub.message( pubnub.message(
pubnub, pubnub,
@ -198,10 +161,7 @@ async def test_doorbell_update_via_pubnub(hass: HomeAssistant) -> None:
await hass.async_block_till_done() await hass.async_block_till_done()
binary_sensor_k98gidt45gul_name_image_capture = hass.states.get( assert states.get("binary_sensor.k98gidt45gul_name_image_capture").state == STATE_ON
"binary_sensor.k98gidt45gul_name_image_capture"
)
assert binary_sensor_k98gidt45gul_name_image_capture.state == STATE_ON
pubnub.message( pubnub.message(
pubnub, pubnub,
@ -235,29 +195,19 @@ async def test_doorbell_update_via_pubnub(hass: HomeAssistant) -> None:
await hass.async_block_till_done() await hass.async_block_till_done()
binary_sensor_k98gidt45gul_name_motion = hass.states.get( assert states.get("binary_sensor.k98gidt45gul_name_motion").state == STATE_ON
"binary_sensor.k98gidt45gul_name_motion"
)
assert binary_sensor_k98gidt45gul_name_motion.state == STATE_ON
binary_sensor_k98gidt45gul_name_ding = hass.states.get( assert (
"binary_sensor.k98gidt45gul_name_doorbell_ding" states.get("binary_sensor.k98gidt45gul_name_doorbell_ding").state == STATE_OFF
) )
assert binary_sensor_k98gidt45gul_name_ding.state == STATE_OFF
new_time = dt_util.utcnow() + datetime.timedelta(seconds=40) freezer.tick(40)
native_time = datetime.datetime.now() + datetime.timedelta(seconds=40) async_fire_time_changed(hass)
with patch( await hass.async_block_till_done()
"homeassistant.components.august.util._native_datetime",
return_value=native_time,
):
async_fire_time_changed(hass, new_time)
await hass.async_block_till_done()
binary_sensor_k98gidt45gul_name_image_capture = hass.states.get( assert (
"binary_sensor.k98gidt45gul_name_image_capture" states.get("binary_sensor.k98gidt45gul_name_image_capture").state == STATE_OFF
) )
assert binary_sensor_k98gidt45gul_name_image_capture.state == STATE_OFF
pubnub.message( pubnub.message(
pubnub, pubnub,
@ -271,37 +221,25 @@ async def test_doorbell_update_via_pubnub(hass: HomeAssistant) -> None:
) )
await hass.async_block_till_done() await hass.async_block_till_done()
binary_sensor_k98gidt45gul_name_ding = hass.states.get( assert states.get("binary_sensor.k98gidt45gul_name_doorbell_ding").state == STATE_ON
"binary_sensor.k98gidt45gul_name_doorbell_ding" freezer.tick(40)
) async_fire_time_changed(hass)
assert binary_sensor_k98gidt45gul_name_ding.state == STATE_ON await hass.async_block_till_done()
new_time = dt_util.utcnow() + datetime.timedelta(seconds=40)
native_time = datetime.datetime.now() + datetime.timedelta(seconds=40)
with patch(
"homeassistant.components.august.util._native_datetime",
return_value=native_time,
):
async_fire_time_changed(hass, new_time)
await hass.async_block_till_done()
binary_sensor_k98gidt45gul_name_ding = hass.states.get( assert (
"binary_sensor.k98gidt45gul_name_doorbell_ding" states.get("binary_sensor.k98gidt45gul_name_doorbell_ding").state == STATE_OFF
) )
assert binary_sensor_k98gidt45gul_name_ding.state == STATE_OFF
async def test_doorbell_device_registry( async def test_doorbell_device_registry(
hass: HomeAssistant, device_registry: dr.DeviceRegistry hass: HomeAssistant, device_registry: dr.DeviceRegistry, snapshot: SnapshotAssertion
) -> None: ) -> None:
"""Test creation of a lock with doorsense and bridge ands up in the registry.""" """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_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json")
await _create_august_with_devices(hass, [doorbell_one]) await _create_august_with_devices(hass, [doorbell_one])
reg_device = device_registry.async_get_device(identifiers={("august", "tmt100")}) reg_device = device_registry.async_get_device(identifiers={("august", "tmt100")})
assert reg_device.model == "hydra1" assert reg_device == snapshot
assert reg_device.name == "tmt100 Name"
assert reg_device.manufacturer == "August Home Inc."
assert reg_device.sw_version == "3.1.0-HYDRC75+201909251139"
async def test_door_sense_update_via_pubnub(hass: HomeAssistant) -> None: async def test_door_sense_update_via_pubnub(hass: HomeAssistant) -> None:
@ -314,11 +252,9 @@ async def test_door_sense_update_via_pubnub(hass: HomeAssistant) -> None:
config_entry = await _create_august_with_devices( config_entry = await _create_august_with_devices(
hass, [lock_one], activities=activities, pubnub=pubnub hass, [lock_one], activities=activities, pubnub=pubnub
) )
states = hass.states
binary_sensor_online_with_doorsense_name = hass.states.get( assert states.get("binary_sensor.online_with_doorsense_name_door").state == STATE_ON
"binary_sensor.online_with_doorsense_name_door"
)
assert binary_sensor_online_with_doorsense_name.state == STATE_ON
pubnub.message( pubnub.message(
pubnub, pubnub,
@ -330,10 +266,9 @@ async def test_door_sense_update_via_pubnub(hass: HomeAssistant) -> None:
) )
await hass.async_block_till_done() await hass.async_block_till_done()
binary_sensor_online_with_doorsense_name = hass.states.get( assert (
"binary_sensor.online_with_doorsense_name_door" states.get("binary_sensor.online_with_doorsense_name_door").state == STATE_OFF
) )
assert binary_sensor_online_with_doorsense_name.state == STATE_OFF
pubnub.message( pubnub.message(
pubnub, pubnub,
@ -344,33 +279,22 @@ async def test_door_sense_update_via_pubnub(hass: HomeAssistant) -> None:
), ),
) )
await hass.async_block_till_done() await hass.async_block_till_done()
binary_sensor_online_with_doorsense_name = hass.states.get( assert states.get("binary_sensor.online_with_doorsense_name_door").state == STATE_ON
"binary_sensor.online_with_doorsense_name_door"
)
assert binary_sensor_online_with_doorsense_name.state == STATE_ON
async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(seconds=30)) async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(seconds=30))
await hass.async_block_till_done() await hass.async_block_till_done()
binary_sensor_online_with_doorsense_name = hass.states.get( assert states.get("binary_sensor.online_with_doorsense_name_door").state == STATE_ON
"binary_sensor.online_with_doorsense_name_door"
)
assert binary_sensor_online_with_doorsense_name.state == STATE_ON
pubnub.connected = True pubnub.connected = True
async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(seconds=30)) async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(seconds=30))
await hass.async_block_till_done() await hass.async_block_till_done()
binary_sensor_online_with_doorsense_name = hass.states.get( assert states.get("binary_sensor.online_with_doorsense_name_door").state == STATE_ON
"binary_sensor.online_with_doorsense_name_door"
)
assert binary_sensor_online_with_doorsense_name.state == STATE_ON
# Ensure pubnub status is always preserved # Ensure pubnub status is always preserved
async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(hours=2)) async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(hours=2))
await hass.async_block_till_done() await hass.async_block_till_done()
binary_sensor_online_with_doorsense_name = hass.states.get(
"binary_sensor.online_with_doorsense_name_door" assert states.get("binary_sensor.online_with_doorsense_name_door").state == STATE_ON
)
assert binary_sensor_online_with_doorsense_name.state == STATE_ON
pubnub.message( pubnub.message(
pubnub, pubnub,
@ -381,17 +305,11 @@ async def test_door_sense_update_via_pubnub(hass: HomeAssistant) -> None:
), ),
) )
await hass.async_block_till_done() await hass.async_block_till_done()
binary_sensor_online_with_doorsense_name = hass.states.get( assert states.get("binary_sensor.online_with_doorsense_name_door").state == STATE_ON
"binary_sensor.online_with_doorsense_name_door"
)
assert binary_sensor_online_with_doorsense_name.state == STATE_ON
async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(hours=4)) async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(hours=4))
await hass.async_block_till_done() await hass.async_block_till_done()
binary_sensor_online_with_doorsense_name = hass.states.get( assert states.get("binary_sensor.online_with_doorsense_name_door").state == STATE_ON
"binary_sensor.online_with_doorsense_name_door"
)
assert binary_sensor_online_with_doorsense_name.state == STATE_ON
await hass.config_entries.async_unload(config_entry.entry_id) await hass.config_entries.async_unload(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -402,7 +320,10 @@ async def test_create_lock_with_doorbell(hass: HomeAssistant) -> None:
lock_one = await _mock_lock_from_fixture(hass, "lock_with_doorbell.online.json") lock_one = await _mock_lock_from_fixture(hass, "lock_with_doorbell.online.json")
await _create_august_with_devices(hass, [lock_one]) await _create_august_with_devices(hass, [lock_one])
ding_sensor = hass.states.get( states = hass.states
"binary_sensor.a6697750d607098bae8d6baa11ef8063_name_doorbell_ding" assert (
states.get(
"binary_sensor.a6697750d607098bae8d6baa11ef8063_name_doorbell_ding"
).state
== STATE_OFF
) )
assert ding_sensor.state == STATE_OFF

View File

@ -20,5 +20,4 @@ async def test_wake_lock(hass: HomeAssistant) -> None:
await hass.services.async_call( await hass.services.async_call(
BUTTON_DOMAIN, SERVICE_PRESS, {ATTR_ENTITY_ID: entity_id}, blocking=True BUTTON_DOMAIN, SERVICE_PRESS, {ATTR_ENTITY_ID: entity_id}, blocking=True
) )
await hass.async_block_till_done()
api_instance.async_status_async.assert_called_once() api_instance.async_status_async.assert_called_once()

View File

@ -25,14 +25,10 @@ async def test_create_doorbell(
): ):
await _create_august_with_devices(hass, [doorbell_one], brand=Brand.AUGUST) await _create_august_with_devices(hass, [doorbell_one], brand=Brand.AUGUST)
camera_k98gidt45gul_name_camera = hass.states.get( camera_state = hass.states.get("camera.k98gidt45gul_name_camera")
"camera.k98gidt45gul_name_camera" assert camera_state.state == STATE_IDLE
)
assert camera_k98gidt45gul_name_camera.state == STATE_IDLE
url = hass.states.get("camera.k98gidt45gul_name_camera").attributes[ url = camera_state.attributes["entity_picture"]
"entity_picture"
]
client = await hass_client_no_auth() client = await hass_client_no_auth()
resp = await client.get(url) resp = await client.get(url)

View File

@ -5,7 +5,6 @@ from unittest.mock import patch
from yalexs.authenticator_common import ValidationResult from yalexs.authenticator_common import ValidationResult
from yalexs.manager.exceptions import CannotConnect, InvalidAuth, RequireValidation from yalexs.manager.exceptions import CannotConnect, InvalidAuth, RequireValidation
from homeassistant import config_entries
from homeassistant.components.august.const import ( from homeassistant.components.august.const import (
CONF_ACCESS_TOKEN_CACHE_FILE, CONF_ACCESS_TOKEN_CACHE_FILE,
CONF_BRAND, CONF_BRAND,
@ -14,6 +13,7 @@ from homeassistant.components.august.const import (
DOMAIN, DOMAIN,
VERIFICATION_CODE_KEY, VERIFICATION_CODE_KEY,
) )
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
@ -25,7 +25,7 @@ async def test_form(hass: HomeAssistant) -> None:
"""Test we get the form.""" """Test we get the form."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": SOURCE_USER}
) )
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["errors"] == {} assert result["errors"] == {}
@ -66,7 +66,7 @@ async def test_form(hass: HomeAssistant) -> None:
async def test_form_invalid_auth(hass: HomeAssistant) -> None: async def test_form_invalid_auth(hass: HomeAssistant) -> None:
"""Test we handle invalid auth.""" """Test we handle invalid auth."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": SOURCE_USER}
) )
with patch( with patch(
@ -90,7 +90,7 @@ async def test_form_invalid_auth(hass: HomeAssistant) -> None:
async def test_user_unexpected_exception(hass: HomeAssistant) -> None: async def test_user_unexpected_exception(hass: HomeAssistant) -> None:
"""Test we handle an unexpected exception.""" """Test we handle an unexpected exception."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": SOURCE_USER}
) )
with patch( with patch(
@ -115,7 +115,7 @@ async def test_user_unexpected_exception(hass: HomeAssistant) -> None:
async def test_form_cannot_connect(hass: HomeAssistant) -> None: async def test_form_cannot_connect(hass: HomeAssistant) -> None:
"""Test we handle cannot connect error.""" """Test we handle cannot connect error."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": SOURCE_USER}
) )
with patch( with patch(
@ -138,7 +138,7 @@ async def test_form_cannot_connect(hass: HomeAssistant) -> None:
async def test_form_needs_validate(hass: HomeAssistant) -> None: async def test_form_needs_validate(hass: HomeAssistant) -> None:
"""Test we present validation when we need to validate.""" """Test we present validation when we need to validate."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": SOURCE_USER}
) )
with ( with (
@ -367,7 +367,7 @@ async def test_switching_brands(hass: HomeAssistant) -> None:
) )
entry.add_to_hass(hass) entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": SOURCE_USER}
) )
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["errors"] == {} assert result["errors"] == {}

View File

@ -1,13 +1,12 @@
"""The event tests for the august.""" """The event tests for the august."""
import datetime from unittest.mock import Mock
from unittest.mock import Mock, patch
from freezegun.api import FrozenDateTimeFactory
from yalexs.pubnub_async import AugustPubNub from yalexs.pubnub_async import AugustPubNub
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.util.dt as dt_util
from .mocks import ( from .mocks import (
_create_august_with_devices, _create_august_with_devices,
@ -45,7 +44,9 @@ async def test_create_doorbell_offline(hass: HomeAssistant) -> None:
assert doorbell_state.state == STATE_UNAVAILABLE assert doorbell_state.state == STATE_UNAVAILABLE
async def test_create_doorbell_with_motion(hass: HomeAssistant) -> None: async def test_create_doorbell_with_motion(
hass: HomeAssistant, freezer: FrozenDateTimeFactory
) -> None:
"""Test creation of a doorbell.""" """Test creation of a doorbell."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json") doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json")
activities = await _mock_activities_from_fixture( activities = await _mock_activities_from_fixture(
@ -61,19 +62,16 @@ async def test_create_doorbell_with_motion(hass: HomeAssistant) -> None:
assert doorbell_state is not None assert doorbell_state is not None
assert doorbell_state.state == STATE_UNKNOWN assert doorbell_state.state == STATE_UNKNOWN
new_time = dt_util.utcnow() + datetime.timedelta(seconds=40) freezer.tick(40)
native_time = datetime.datetime.now() + datetime.timedelta(seconds=40) async_fire_time_changed(hass)
with patch( await hass.async_block_till_done()
"homeassistant.components.august.util._native_datetime",
return_value=native_time,
):
async_fire_time_changed(hass, new_time)
await hass.async_block_till_done()
motion_state = hass.states.get("event.k98gidt45gul_name_motion") motion_state = hass.states.get("event.k98gidt45gul_name_motion")
assert motion_state.state == isotime assert motion_state.state == isotime
async def test_doorbell_update_via_pubnub(hass: HomeAssistant) -> None: async def test_doorbell_update_via_pubnub(
hass: HomeAssistant, freezer: FrozenDateTimeFactory
) -> None:
"""Test creation of a doorbell that can be updated via pubnub.""" """Test creation of a doorbell that can be updated via pubnub."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json") doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json")
pubnub = AugustPubNub() pubnub = AugustPubNub()
@ -125,14 +123,9 @@ async def test_doorbell_update_via_pubnub(hass: HomeAssistant) -> None:
assert motion_state.state != STATE_UNKNOWN assert motion_state.state != STATE_UNKNOWN
isotime = motion_state.state isotime = motion_state.state
new_time = dt_util.utcnow() + datetime.timedelta(seconds=40) freezer.tick(40)
native_time = datetime.datetime.now() + datetime.timedelta(seconds=40) async_fire_time_changed(hass)
with patch( await hass.async_block_till_done()
"homeassistant.components.august.util._native_datetime",
return_value=native_time,
):
async_fire_time_changed(hass, new_time)
await hass.async_block_till_done()
motion_state = hass.states.get("event.k98gidt45gul_name_motion") motion_state = hass.states.get("event.k98gidt45gul_name_motion")
assert motion_state is not None assert motion_state is not None
@ -155,14 +148,9 @@ async def test_doorbell_update_via_pubnub(hass: HomeAssistant) -> None:
assert doorbell_state.state != STATE_UNKNOWN assert doorbell_state.state != STATE_UNKNOWN
isotime = motion_state.state isotime = motion_state.state
new_time = dt_util.utcnow() + datetime.timedelta(seconds=40) freezer.tick(40)
native_time = datetime.datetime.now() + datetime.timedelta(seconds=40) async_fire_time_changed(hass)
with patch( await hass.async_block_till_done()
"homeassistant.components.august.util._native_datetime",
return_value=native_time,
):
async_fire_time_changed(hass, new_time)
await hass.async_block_till_done()
doorbell_state = hass.states.get("event.k98gidt45gul_name_doorbell") doorbell_state = hass.states.get("event.k98gidt45gul_name_doorbell")
assert doorbell_state is not None assert doorbell_state is not None

View File

@ -122,16 +122,16 @@ async def test_unlock_throws_august_api_http_error(hass: HomeAssistant) -> None:
"unlock_return_activities": _unlock_return_activities_side_effect "unlock_return_activities": _unlock_return_activities_side_effect
}, },
) )
last_err = None
data = {ATTR_ENTITY_ID: "lock.a6697750d607098bae8d6baa11ef8063_name"} data = {ATTR_ENTITY_ID: "lock.a6697750d607098bae8d6baa11ef8063_name"}
try:
with pytest.raises(
HomeAssistantError,
match=(
"A6697750D607098BAE8D6BAA11EF8063 Name: This should bubble up as its user"
" consumable"
),
):
await hass.services.async_call(LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True)
except HomeAssistantError as err:
last_err = err
assert str(last_err) == (
"A6697750D607098BAE8D6BAA11EF8063 Name: This should bubble up as its user"
" consumable"
)
async def test_lock_throws_august_api_http_error(hass: HomeAssistant) -> None: async def test_lock_throws_august_api_http_error(hass: HomeAssistant) -> None:
@ -152,16 +152,15 @@ async def test_lock_throws_august_api_http_error(hass: HomeAssistant) -> None:
"lock_return_activities": _lock_return_activities_side_effect "lock_return_activities": _lock_return_activities_side_effect
}, },
) )
last_err = None
data = {ATTR_ENTITY_ID: "lock.a6697750d607098bae8d6baa11ef8063_name"} data = {ATTR_ENTITY_ID: "lock.a6697750d607098bae8d6baa11ef8063_name"}
try: with pytest.raises(
HomeAssistantError,
match=(
"A6697750D607098BAE8D6BAA11EF8063 Name: This should bubble up as its user"
" consumable"
),
):
await hass.services.async_call(LOCK_DOMAIN, SERVICE_LOCK, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_LOCK, data, blocking=True)
except HomeAssistantError as err:
last_err = err
assert str(last_err) == (
"A6697750D607098BAE8D6BAA11EF8063 Name: This should bubble up as its user"
" consumable"
)
async def test_open_throws_hass_service_not_supported_error( async def test_open_throws_hass_service_not_supported_error(
@ -371,6 +370,7 @@ async def test_load_unload(hass: HomeAssistant) -> None:
await hass.config_entries.async_unload(config_entry.entry_id) await hass.config_entries.async_unload(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.NOT_LOADED
async def test_load_triggers_ble_discovery( async def test_load_triggers_ble_discovery(

View File

@ -6,6 +6,7 @@ from unittest.mock import Mock
from aiohttp import ClientResponseError from aiohttp import ClientResponseError
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
import pytest import pytest
from syrupy import SnapshotAssertion
from yalexs.manager.activity import INITIAL_LOCK_RESYNC_TIME from yalexs.manager.activity import INITIAL_LOCK_RESYNC_TIME
from yalexs.pubnub_async import AugustPubNub from yalexs.pubnub_async import AugustPubNub
@ -43,7 +44,7 @@ from tests.common import async_fire_time_changed
async def test_lock_device_registry( async def test_lock_device_registry(
hass: HomeAssistant, device_registry: dr.DeviceRegistry hass: HomeAssistant, device_registry: dr.DeviceRegistry, snapshot: SnapshotAssertion
) -> None: ) -> None:
"""Test creation of a lock with doorsense and bridge ands up in the registry.""" """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_one = await _mock_doorsense_enabled_august_lock_detail(hass)
@ -52,10 +53,7 @@ async def test_lock_device_registry(
reg_device = device_registry.async_get_device( reg_device = device_registry.async_get_device(
identifiers={("august", "online_with_doorsense")} identifiers={("august", "online_with_doorsense")}
) )
assert reg_device.model == "AUG-MD01" assert reg_device == snapshot
assert reg_device.sw_version == "undefined-4.3.0-1.8.14"
assert reg_device.name == "online_with_doorsense Name"
assert reg_device.manufacturer == "August Home Inc."
async def test_lock_changed_by(hass: HomeAssistant) -> None: async def test_lock_changed_by(hass: HomeAssistant) -> None:
@ -65,14 +63,10 @@ async def test_lock_changed_by(hass: HomeAssistant) -> None:
activities = await _mock_activities_from_fixture(hass, "get_activity.lock.json") activities = await _mock_activities_from_fixture(hass, "get_activity.lock.json")
await _create_august_with_devices(hass, [lock_one], activities=activities) await _create_august_with_devices(hass, [lock_one], activities=activities)
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") lock_state = hass.states.get("lock.online_with_doorsense_name")
assert lock_online_with_doorsense_name.state == STATE_LOCKED assert lock_state.state == STATE_LOCKED
assert lock_state.attributes["changed_by"] == "Your favorite elven princess"
assert (
lock_online_with_doorsense_name.attributes.get("changed_by")
== "Your favorite elven princess"
)
async def test_state_locking(hass: HomeAssistant) -> None: async def test_state_locking(hass: HomeAssistant) -> None:
@ -82,9 +76,7 @@ async def test_state_locking(hass: HomeAssistant) -> None:
activities = await _mock_activities_from_fixture(hass, "get_activity.locking.json") activities = await _mock_activities_from_fixture(hass, "get_activity.locking.json")
await _create_august_with_devices(hass, [lock_one], activities=activities) await _create_august_with_devices(hass, [lock_one], activities=activities)
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert hass.states.get("lock.online_with_doorsense_name").state == STATE_LOCKING
assert lock_online_with_doorsense_name.state == STATE_LOCKING
async def test_state_unlocking(hass: HomeAssistant) -> None: async def test_state_unlocking(hass: HomeAssistant) -> None:
@ -96,9 +88,7 @@ async def test_state_unlocking(hass: HomeAssistant) -> None:
) )
await _create_august_with_devices(hass, [lock_one], activities=activities) await _create_august_with_devices(hass, [lock_one], activities=activities)
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert hass.states.get("lock.online_with_doorsense_name").state == STATE_UNLOCKING
assert lock_online_with_doorsense_name.state == STATE_UNLOCKING
async def test_state_jammed(hass: HomeAssistant) -> None: async def test_state_jammed(hass: HomeAssistant) -> None:
@ -108,9 +98,7 @@ async def test_state_jammed(hass: HomeAssistant) -> None:
activities = await _mock_activities_from_fixture(hass, "get_activity.jammed.json") activities = await _mock_activities_from_fixture(hass, "get_activity.jammed.json")
await _create_august_with_devices(hass, [lock_one], activities=activities) await _create_august_with_devices(hass, [lock_one], activities=activities)
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert hass.states.get("lock.online_with_doorsense_name").state == STATE_JAMMED
assert lock_online_with_doorsense_name.state == STATE_JAMMED
async def test_one_lock_operation( async def test_one_lock_operation(
@ -119,35 +107,27 @@ async def test_one_lock_operation(
"""Test creation of a lock with doorsense and bridge.""" """Test creation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass) lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
await _create_august_with_devices(hass, [lock_one]) await _create_august_with_devices(hass, [lock_one])
states = hass.states
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") lock_state = states.get("lock.online_with_doorsense_name")
assert lock_online_with_doorsense_name.state == STATE_LOCKED assert lock_state.state == STATE_LOCKED
assert lock_online_with_doorsense_name.attributes.get("battery_level") == 92 assert lock_state.attributes["battery_level"] == 92
assert ( assert lock_state.attributes["friendly_name"] == "online_with_doorsense Name"
lock_online_with_doorsense_name.attributes.get("friendly_name")
== "online_with_doorsense Name"
)
data = {ATTR_ENTITY_ID: "lock.online_with_doorsense_name"} data = {ATTR_ENTITY_ID: "lock.online_with_doorsense_name"}
await hass.services.async_call(LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True)
await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") lock_state = states.get("lock.online_with_doorsense_name")
assert lock_online_with_doorsense_name.state == STATE_UNLOCKED assert lock_state.state == STATE_UNLOCKED
assert lock_online_with_doorsense_name.attributes.get("battery_level") == 92 assert lock_state.attributes["battery_level"] == 92
assert ( assert lock_state.attributes["friendly_name"] == "online_with_doorsense Name"
lock_online_with_doorsense_name.attributes.get("friendly_name")
== "online_with_doorsense Name"
)
await hass.services.async_call(LOCK_DOMAIN, SERVICE_LOCK, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_LOCK, data, blocking=True)
await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert states.get("lock.online_with_doorsense_name").state == STATE_LOCKED
assert lock_online_with_doorsense_name.state == STATE_LOCKED
# No activity means it will be unavailable until the activity feed has data # No activity means it will be unavailable until the activity feed has data
lock_operator_sensor = entity_registry.async_get( lock_operator_sensor = entity_registry.async_get(
@ -155,8 +135,7 @@ async def test_one_lock_operation(
) )
assert lock_operator_sensor assert lock_operator_sensor
assert ( assert (
hass.states.get("sensor.online_with_doorsense_name_operator").state states.get("sensor.online_with_doorsense_name_operator").state == STATE_UNKNOWN
== STATE_UNKNOWN
) )
@ -170,7 +149,6 @@ async def test_open_lock_operation(hass: HomeAssistant) -> None:
data = {ATTR_ENTITY_ID: "lock.online_with_unlatch_name"} data = {ATTR_ENTITY_ID: "lock.online_with_unlatch_name"}
await hass.services.async_call(LOCK_DOMAIN, SERVICE_OPEN, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_OPEN, data, blocking=True)
await hass.async_block_till_done()
lock_online_with_unlatch_name = hass.states.get("lock.online_with_unlatch_name") lock_online_with_unlatch_name = hass.states.get("lock.online_with_unlatch_name")
assert lock_online_with_unlatch_name.state == STATE_UNLOCKED assert lock_online_with_unlatch_name.state == STATE_UNLOCKED
@ -189,12 +167,10 @@ async def test_open_lock_operation_pubnub_connected(
await _create_august_with_devices(hass, [lock_with_unlatch], pubnub=pubnub) await _create_august_with_devices(hass, [lock_with_unlatch], pubnub=pubnub)
pubnub.connected = True pubnub.connected = True
lock_online_with_unlatch_name = hass.states.get("lock.online_with_unlatch_name") assert hass.states.get("lock.online_with_unlatch_name").state == STATE_LOCKED
assert lock_online_with_unlatch_name.state == STATE_LOCKED
data = {ATTR_ENTITY_ID: "lock.online_with_unlatch_name"} data = {ATTR_ENTITY_ID: "lock.online_with_unlatch_name"}
await hass.services.async_call(LOCK_DOMAIN, SERVICE_OPEN, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_OPEN, data, blocking=True)
await hass.async_block_till_done()
pubnub.message( pubnub.message(
pubnub, pubnub,
@ -209,8 +185,7 @@ async def test_open_lock_operation_pubnub_connected(
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.async_block_till_done() await hass.async_block_till_done()
lock_online_with_unlatch_name = hass.states.get("lock.online_with_unlatch_name") assert hass.states.get("lock.online_with_unlatch_name").state == STATE_UNLOCKED
assert lock_online_with_unlatch_name.state == STATE_UNLOCKED
await hass.async_block_till_done() await hass.async_block_till_done()
@ -227,19 +202,15 @@ async def test_one_lock_operation_pubnub_connected(
await _create_august_with_devices(hass, [lock_one], pubnub=pubnub) await _create_august_with_devices(hass, [lock_one], pubnub=pubnub)
pubnub.connected = True pubnub.connected = True
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") lock_state = hass.states.get("lock.online_with_doorsense_name")
assert lock_online_with_doorsense_name.state == STATE_LOCKED assert lock_state.state == STATE_LOCKED
assert lock_online_with_doorsense_name.attributes.get("battery_level") == 92 assert lock_state.attributes["battery_level"] == 92
assert ( assert lock_state.attributes["friendly_name"] == "online_with_doorsense Name"
lock_online_with_doorsense_name.attributes.get("friendly_name")
== "online_with_doorsense Name"
)
data = {ATTR_ENTITY_ID: "lock.online_with_doorsense_name"} data = {ATTR_ENTITY_ID: "lock.online_with_doorsense_name"}
await hass.services.async_call(LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True)
await hass.async_block_till_done()
pubnub.message( pubnub.message(
pubnub, pubnub,
@ -254,17 +225,13 @@ async def test_one_lock_operation_pubnub_connected(
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.async_block_till_done() await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") lock_state = hass.states.get("lock.online_with_doorsense_name")
assert lock_online_with_doorsense_name.state == STATE_UNLOCKED assert lock_state.state == STATE_UNLOCKED
assert lock_online_with_doorsense_name.attributes.get("battery_level") == 92 assert lock_state.attributes["battery_level"] == 92
assert ( assert lock_state.attributes["friendly_name"] == "online_with_doorsense Name"
lock_online_with_doorsense_name.attributes.get("friendly_name")
== "online_with_doorsense Name"
)
await hass.services.async_call(LOCK_DOMAIN, SERVICE_LOCK, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_LOCK, data, blocking=True)
await hass.async_block_till_done()
pubnub.message( pubnub.message(
pubnub, pubnub,
@ -279,8 +246,8 @@ async def test_one_lock_operation_pubnub_connected(
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.async_block_till_done() await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") lock_state = hass.states.get("lock.online_with_doorsense_name")
assert lock_online_with_doorsense_name.state == STATE_LOCKED assert lock_state.state == STATE_LOCKED
# No activity means it will be unavailable until the activity feed has data # No activity means it will be unavailable until the activity feed has data
lock_operator_sensor = entity_registry.async_get( lock_operator_sensor = entity_registry.async_get(
@ -306,8 +273,8 @@ async def test_one_lock_operation_pubnub_connected(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") lock_state = hass.states.get("lock.online_with_doorsense_name")
assert lock_online_with_doorsense_name.state == STATE_UNLOCKED assert lock_state.state == STATE_UNLOCKED
async def test_lock_jammed(hass: HomeAssistant) -> None: async def test_lock_jammed(hass: HomeAssistant) -> None:
@ -325,22 +292,18 @@ async def test_lock_jammed(hass: HomeAssistant) -> None:
}, },
) )
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") lock_state = hass.states.get("lock.online_with_doorsense_name")
assert lock_online_with_doorsense_name.state == STATE_LOCKED assert lock_state.state == STATE_LOCKED
assert lock_online_with_doorsense_name.attributes.get("battery_level") == 92 assert lock_state.attributes["battery_level"] == 92
assert ( assert lock_state.attributes["friendly_name"] == "online_with_doorsense Name"
lock_online_with_doorsense_name.attributes.get("friendly_name")
== "online_with_doorsense Name"
)
data = {ATTR_ENTITY_ID: "lock.online_with_doorsense_name"} data = {ATTR_ENTITY_ID: "lock.online_with_doorsense_name"}
await hass.services.async_call(LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True) await hass.services.async_call(LOCK_DOMAIN, SERVICE_UNLOCK, data, blocking=True)
await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") lock_state = hass.states.get("lock.online_with_doorsense_name")
assert lock_online_with_doorsense_name.state == STATE_JAMMED assert lock_state.state == STATE_JAMMED
async def test_lock_throws_exception_on_unknown_status_code( async def test_lock_throws_exception_on_unknown_status_code(
@ -360,15 +323,12 @@ async def test_lock_throws_exception_on_unknown_status_code(
}, },
) )
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") lock_state = hass.states.get("lock.online_with_doorsense_name")
assert lock_online_with_doorsense_name.state == STATE_LOCKED assert lock_state.state == STATE_LOCKED
assert lock_online_with_doorsense_name.attributes.get("battery_level") == 92 assert lock_state.attributes["battery_level"] == 92
assert ( assert lock_state.attributes["friendly_name"] == "online_with_doorsense Name"
lock_online_with_doorsense_name.attributes.get("friendly_name")
== "online_with_doorsense Name"
)
data = {ATTR_ENTITY_ID: "lock.online_with_doorsense_name"} data = {ATTR_ENTITY_ID: "lock.online_with_doorsense_name"}
with pytest.raises(ClientResponseError): with pytest.raises(ClientResponseError):
@ -383,9 +343,7 @@ async def test_one_lock_unknown_state(hass: HomeAssistant) -> None:
) )
await _create_august_with_devices(hass, [lock_one]) await _create_august_with_devices(hass, [lock_one])
lock_brokenid_name = hass.states.get("lock.brokenid_name") assert hass.states.get("lock.brokenid_name").state == STATE_UNKNOWN
assert lock_brokenid_name.state == STATE_UNKNOWN
async def test_lock_bridge_offline(hass: HomeAssistant) -> None: async def test_lock_bridge_offline(hass: HomeAssistant) -> None:
@ -397,9 +355,7 @@ async def test_lock_bridge_offline(hass: HomeAssistant) -> None:
) )
await _create_august_with_devices(hass, [lock_one], activities=activities) await _create_august_with_devices(hass, [lock_one], activities=activities)
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert hass.states.get("lock.online_with_doorsense_name").state == STATE_UNAVAILABLE
assert lock_online_with_doorsense_name.state == STATE_UNAVAILABLE
async def test_lock_bridge_online(hass: HomeAssistant) -> None: async def test_lock_bridge_online(hass: HomeAssistant) -> None:
@ -411,14 +367,13 @@ async def test_lock_bridge_online(hass: HomeAssistant) -> None:
) )
await _create_august_with_devices(hass, [lock_one], activities=activities) await _create_august_with_devices(hass, [lock_one], activities=activities)
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert hass.states.get("lock.online_with_doorsense_name").state == STATE_LOCKED
assert lock_online_with_doorsense_name.state == STATE_LOCKED
async def test_lock_update_via_pubnub(hass: HomeAssistant) -> None: async def test_lock_update_via_pubnub(hass: HomeAssistant) -> None:
"""Test creation of a lock with doorsense and bridge.""" """Test creation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass) lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
states = hass.states
assert lock_one.pubsub_channel == "pubsub" assert lock_one.pubsub_channel == "pubsub"
pubnub = AugustPubNub() pubnub = AugustPubNub()
@ -428,9 +383,7 @@ async def test_lock_update_via_pubnub(hass: HomeAssistant) -> None:
) )
pubnub.connected = True pubnub.connected = True
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert states.get("lock.online_with_doorsense_name").state == STATE_LOCKED
assert lock_online_with_doorsense_name.state == STATE_LOCKED
pubnub.message( pubnub.message(
pubnub, pubnub,
@ -446,8 +399,7 @@ async def test_lock_update_via_pubnub(hass: HomeAssistant) -> None:
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.async_block_till_done() await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert states.get("lock.online_with_doorsense_name").state == STATE_UNLOCKING
assert lock_online_with_doorsense_name.state == STATE_UNLOCKING
pubnub.message( pubnub.message(
pubnub, pubnub,
@ -463,25 +415,21 @@ async def test_lock_update_via_pubnub(hass: HomeAssistant) -> None:
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.async_block_till_done() await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert states.get("lock.online_with_doorsense_name").state == STATE_LOCKING
assert lock_online_with_doorsense_name.state == STATE_LOCKING
async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(seconds=30)) async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(seconds=30))
await hass.async_block_till_done() await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert hass.states.get("lock.online_with_doorsense_name").state == STATE_LOCKING
assert lock_online_with_doorsense_name.state == STATE_LOCKING
pubnub.connected = True pubnub.connected = True
async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(seconds=30)) async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(seconds=30))
await hass.async_block_till_done() await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert states.get("lock.online_with_doorsense_name").state == STATE_LOCKING
assert lock_online_with_doorsense_name.state == STATE_LOCKING
# Ensure pubnub status is always preserved # Ensure pubnub status is always preserved
async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(hours=2)) async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(hours=2))
await hass.async_block_till_done() await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert states.get("lock.online_with_doorsense_name").state == STATE_LOCKING
assert lock_online_with_doorsense_name.state == STATE_LOCKING
pubnub.message( pubnub.message(
pubnub, pubnub,
@ -496,13 +444,11 @@ async def test_lock_update_via_pubnub(hass: HomeAssistant) -> None:
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.async_block_till_done() await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert states.get("lock.online_with_doorsense_name").state == STATE_UNLOCKING
assert lock_online_with_doorsense_name.state == STATE_UNLOCKING
async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(hours=4)) async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(hours=4))
await hass.async_block_till_done() await hass.async_block_till_done()
lock_online_with_doorsense_name = hass.states.get("lock.online_with_doorsense_name") assert states.get("lock.online_with_doorsense_name").state == STATE_UNLOCKING
assert lock_online_with_doorsense_name.state == STATE_UNLOCKING
await hass.config_entries.async_unload(config_entry.entry_id) await hass.config_entries.async_unload(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()

View File

@ -28,13 +28,9 @@ async def test_create_doorbell(hass: HomeAssistant) -> None:
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json") doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json")
await _create_august_with_devices(hass, [doorbell_one]) await _create_august_with_devices(hass, [doorbell_one])
sensor_k98gidt45gul_name_battery = hass.states.get( battery_state = hass.states.get("sensor.k98gidt45gul_name_battery")
"sensor.k98gidt45gul_name_battery" assert battery_state.state == "96"
) assert battery_state.attributes["unit_of_measurement"] == PERCENTAGE
assert sensor_k98gidt45gul_name_battery.state == "96"
assert (
sensor_k98gidt45gul_name_battery.attributes["unit_of_measurement"] == PERCENTAGE
)
async def test_create_doorbell_offline( async def test_create_doorbell_offline(
@ -44,9 +40,9 @@ async def test_create_doorbell_offline(
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json") doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json")
await _create_august_with_devices(hass, [doorbell_one]) await _create_august_with_devices(hass, [doorbell_one])
sensor_tmt100_name_battery = hass.states.get("sensor.tmt100_name_battery") battery_state = hass.states.get("sensor.tmt100_name_battery")
assert sensor_tmt100_name_battery.state == "81" assert battery_state.state == "81"
assert sensor_tmt100_name_battery.attributes["unit_of_measurement"] == PERCENTAGE assert battery_state.attributes["unit_of_measurement"] == PERCENTAGE
entry = entity_registry.async_get("sensor.tmt100_name_battery") entry = entity_registry.async_get("sensor.tmt100_name_battery")
assert entry assert entry
@ -60,8 +56,7 @@ async def test_create_doorbell_hardwired(hass: HomeAssistant) -> None:
) )
await _create_august_with_devices(hass, [doorbell_one]) await _create_august_with_devices(hass, [doorbell_one])
sensor_tmt100_name_battery = hass.states.get("sensor.tmt100_name_battery") assert hass.states.get("sensor.tmt100_name_battery") is None
assert sensor_tmt100_name_battery is None
async def test_create_lock_with_linked_keypad( async def test_create_lock_with_linked_keypad(
@ -71,25 +66,21 @@ async def test_create_lock_with_linked_keypad(
lock_one = await _mock_lock_from_fixture(hass, "get_lock.doorsense_init.json") lock_one = await _mock_lock_from_fixture(hass, "get_lock.doorsense_init.json")
await _create_august_with_devices(hass, [lock_one]) await _create_august_with_devices(hass, [lock_one])
sensor_a6697750d607098bae8d6baa11ef8063_name_battery = hass.states.get( battery_state = hass.states.get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_battery" "sensor.a6697750d607098bae8d6baa11ef8063_name_battery"
) )
assert sensor_a6697750d607098bae8d6baa11ef8063_name_battery.state == "88" assert battery_state.state == "88"
assert ( assert battery_state.attributes["unit_of_measurement"] == PERCENTAGE
sensor_a6697750d607098bae8d6baa11ef8063_name_battery.attributes[
"unit_of_measurement"
]
== PERCENTAGE
)
entry = entity_registry.async_get( entry = entity_registry.async_get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_battery" "sensor.a6697750d607098bae8d6baa11ef8063_name_battery"
) )
assert entry assert entry
assert entry.unique_id == "A6697750D607098BAE8D6BAA11EF8063_device_battery" assert entry.unique_id == "A6697750D607098BAE8D6BAA11EF8063_device_battery"
state = hass.states.get("sensor.front_door_lock_keypad_battery") keypad_battery_state = hass.states.get("sensor.front_door_lock_keypad_battery")
assert state.state == "62" assert keypad_battery_state.state == "62"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE assert keypad_battery_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE
entry = entity_registry.async_get("sensor.front_door_lock_keypad_battery") entry = entity_registry.async_get("sensor.front_door_lock_keypad_battery")
assert entry assert entry
assert entry.unique_id == "5bc65c24e6ef2a263e1450a8_linked_keypad_battery" assert entry.unique_id == "5bc65c24e6ef2a263e1450a8_linked_keypad_battery"
@ -101,42 +92,32 @@ async def test_create_lock_with_low_battery_linked_keypad(
"""Test creation of a lock with a linked keypad that both have a battery.""" """Test creation of a lock with a linked keypad that both have a battery."""
lock_one = await _mock_lock_from_fixture(hass, "get_lock.low_keypad_battery.json") lock_one = await _mock_lock_from_fixture(hass, "get_lock.low_keypad_battery.json")
await _create_august_with_devices(hass, [lock_one]) await _create_august_with_devices(hass, [lock_one])
states = hass.states
sensor_a6697750d607098bae8d6baa11ef8063_name_battery = hass.states.get( battery_state = states.get("sensor.a6697750d607098bae8d6baa11ef8063_name_battery")
"sensor.a6697750d607098bae8d6baa11ef8063_name_battery" assert battery_state.state == "88"
) assert battery_state.attributes["unit_of_measurement"] == PERCENTAGE
assert sensor_a6697750d607098bae8d6baa11ef8063_name_battery.state == "88"
assert (
sensor_a6697750d607098bae8d6baa11ef8063_name_battery.attributes[
"unit_of_measurement"
]
== PERCENTAGE
)
entry = entity_registry.async_get( entry = entity_registry.async_get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_battery" "sensor.a6697750d607098bae8d6baa11ef8063_name_battery"
) )
assert entry assert entry
assert entry.unique_id == "A6697750D607098BAE8D6BAA11EF8063_device_battery" assert entry.unique_id == "A6697750D607098BAE8D6BAA11EF8063_device_battery"
state = hass.states.get("sensor.front_door_lock_keypad_battery") keypad_battery_state = states.get("sensor.front_door_lock_keypad_battery")
assert state.state == "10" assert keypad_battery_state.state == "10"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE assert keypad_battery_state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE
entry = entity_registry.async_get("sensor.front_door_lock_keypad_battery") entry = entity_registry.async_get("sensor.front_door_lock_keypad_battery")
assert entry assert entry
assert entry.unique_id == "5bc65c24e6ef2a263e1450a8_linked_keypad_battery" assert entry.unique_id == "5bc65c24e6ef2a263e1450a8_linked_keypad_battery"
# No activity means it will be unavailable until someone unlocks/locks it # No activity means it will be unavailable until someone unlocks/locks it
lock_operator_sensor = entity_registry.async_get( operator_entry = entity_registry.async_get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_operator" "sensor.a6697750d607098bae8d6baa11ef8063_name_operator"
) )
assert ( assert operator_entry.unique_id == "A6697750D607098BAE8D6BAA11EF8063_lock_operator"
lock_operator_sensor.unique_id
== "A6697750D607098BAE8D6BAA11EF8063_lock_operator" operator_state = states.get("sensor.a6697750d607098bae8d6baa11ef8063_name_operator")
) assert operator_state.state == STATE_UNKNOWN
assert (
hass.states.get("sensor.a6697750d607098bae8d6baa11ef8063_name_operator").state
== STATE_UNKNOWN
)
async def test_lock_operator_bluetooth( async def test_lock_operator_bluetooth(