init home-assistant
This commit is contained in:
14
home-assistant/tests/components/tedee/__init__.py
Normal file
14
home-assistant/tests/components/tedee/__init__.py
Normal file
@@ -0,0 +1,14 @@
|
||||
"""Add tests for Tedee components."""
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def setup_integration(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Set up the acaia integration for testing."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
91
home-assistant/tests/components/tedee/conftest.py
Normal file
91
home-assistant/tests/components/tedee/conftest.py
Normal file
@@ -0,0 +1,91 @@
|
||||
"""Fixtures for Tedee integration tests."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Generator
|
||||
import json
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from aiotedee.bridge import TedeeBridge
|
||||
from aiotedee.lock import TedeeLock
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.tedee.const import CONF_LOCAL_ACCESS_TOKEN, DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_WEBHOOK_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
WEBHOOK_ID = "bq33efxmdi3vxy55q2wbnudbra7iv8mjrq9x0gea33g4zqtd87093pwveg8xcb33"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_config_entry() -> MockConfigEntry:
|
||||
"""Return the default mocked config entry."""
|
||||
return MockConfigEntry(
|
||||
title="My Tedee",
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_LOCAL_ACCESS_TOKEN: "api_token",
|
||||
CONF_HOST: "192.168.1.42",
|
||||
CONF_WEBHOOK_ID: WEBHOOK_ID,
|
||||
},
|
||||
unique_id="0000-0000",
|
||||
version=1,
|
||||
minor_version=2,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[AsyncMock]:
|
||||
"""Mock setting up a config entry."""
|
||||
with patch(
|
||||
"homeassistant.components.tedee.async_setup_entry", return_value=True
|
||||
) as mock_setup:
|
||||
yield mock_setup
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_tedee() -> Generator[MagicMock]:
|
||||
"""Return a mocked Tedee client."""
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.tedee.coordinator.TedeeClient", autospec=True
|
||||
) as tedee_mock,
|
||||
patch(
|
||||
"homeassistant.components.tedee.config_flow.TedeeClient",
|
||||
new=tedee_mock,
|
||||
),
|
||||
):
|
||||
tedee = tedee_mock.return_value
|
||||
|
||||
tedee.get_locks.return_value = None
|
||||
tedee.sync.return_value = None
|
||||
tedee.get_bridges.return_value = [
|
||||
TedeeBridge(1234, "0000-0000", "Bridge-AB1C"),
|
||||
TedeeBridge(5678, "9999-9999", "Bridge-CD2E"),
|
||||
]
|
||||
tedee.get_local_bridge.return_value = TedeeBridge(0, "0000-0000", "Bridge-AB1C")
|
||||
|
||||
tedee.parse_webhook_message.return_value = None
|
||||
tedee.register_webhook.return_value = 1
|
||||
tedee.delete_webhooks.return_value = None
|
||||
|
||||
locks_json = json.loads(load_fixture("locks.json", DOMAIN))
|
||||
|
||||
lock_list = [TedeeLock(**lock) for lock in locks_json]
|
||||
tedee.locks_dict = {lock.lock_id: lock for lock in lock_list}
|
||||
|
||||
yield tedee
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def init_integration(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_tedee: MagicMock
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the Tedee integration for testing."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
return mock_config_entry
|
||||
26
home-assistant/tests/components/tedee/fixtures/locks.json
Normal file
26
home-assistant/tests/components/tedee/fixtures/locks.json
Normal file
@@ -0,0 +1,26 @@
|
||||
[
|
||||
{
|
||||
"lock_name": "Lock-1A2B",
|
||||
"lock_id": 12345,
|
||||
"lock_type": 2,
|
||||
"state": 2,
|
||||
"battery_level": 70,
|
||||
"is_connected": true,
|
||||
"is_charging": false,
|
||||
"state_change_result": 0,
|
||||
"is_enabled_pullspring": 1,
|
||||
"duration_pullspring": 2
|
||||
},
|
||||
{
|
||||
"lock_name": "Lock-2C3D",
|
||||
"lock_id": 98765,
|
||||
"lock_type": 4,
|
||||
"state": 2,
|
||||
"battery_level": 70,
|
||||
"is_connected": true,
|
||||
"is_charging": false,
|
||||
"state_change_result": 0,
|
||||
"is_enabled_pullspring": 0,
|
||||
"duration_pullspring": 0
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,373 @@
|
||||
# serializer version: 1
|
||||
# name: test_binary_sensors[binary_sensor.lock_1a2b_charging-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.lock_1a2b_charging',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.BATTERY_CHARGING: 'battery_charging'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Charging',
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '12345-charging',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_1a2b_charging-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'battery_charging',
|
||||
'friendly_name': 'Lock-1A2B Charging',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.lock_1a2b_charging',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_1a2b_lock_uncalibrated-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.lock_1a2b_lock_uncalibrated',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.PROBLEM: 'problem'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Lock uncalibrated',
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'uncalibrated',
|
||||
'unique_id': '12345-uncalibrated',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_1a2b_lock_uncalibrated-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'problem',
|
||||
'friendly_name': 'Lock-1A2B Lock uncalibrated',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.lock_1a2b_lock_uncalibrated',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_1a2b_pullspring_enabled-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.lock_1a2b_pullspring_enabled',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Pullspring enabled',
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'pullspring_enabled',
|
||||
'unique_id': '12345-pullspring_enabled',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_1a2b_pullspring_enabled-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Lock-1A2B Pullspring enabled',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.lock_1a2b_pullspring_enabled',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_1a2b_semi_locked-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.lock_1a2b_semi_locked',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Semi locked',
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'semi_locked',
|
||||
'unique_id': '12345-semi_locked',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_1a2b_semi_locked-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Lock-1A2B Semi locked',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.lock_1a2b_semi_locked',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_2c3d_charging-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.lock_2c3d_charging',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.BATTERY_CHARGING: 'battery_charging'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Charging',
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '98765-charging',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_2c3d_charging-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'battery_charging',
|
||||
'friendly_name': 'Lock-2C3D Charging',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.lock_2c3d_charging',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_2c3d_lock_uncalibrated-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.lock_2c3d_lock_uncalibrated',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.PROBLEM: 'problem'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Lock uncalibrated',
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'uncalibrated',
|
||||
'unique_id': '98765-uncalibrated',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_2c3d_lock_uncalibrated-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'problem',
|
||||
'friendly_name': 'Lock-2C3D Lock uncalibrated',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.lock_2c3d_lock_uncalibrated',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_2c3d_pullspring_enabled-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.lock_2c3d_pullspring_enabled',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Pullspring enabled',
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'pullspring_enabled',
|
||||
'unique_id': '98765-pullspring_enabled',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_2c3d_pullspring_enabled-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Lock-2C3D Pullspring enabled',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.lock_2c3d_pullspring_enabled',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_2c3d_semi_locked-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.lock_2c3d_semi_locked',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Semi locked',
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'semi_locked',
|
||||
'unique_id': '98765-semi_locked',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.lock_2c3d_semi_locked-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Lock-2C3D Semi locked',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.lock_2c3d_semi_locked',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,29 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'0': dict({
|
||||
'battery_level': 70,
|
||||
'duration_pullspring': 2,
|
||||
'is_charging': False,
|
||||
'is_connected': True,
|
||||
'is_enabled_pullspring': 1,
|
||||
'lock_id': '**REDACTED**',
|
||||
'lock_name': 'Lock-1A2B',
|
||||
'lock_type': 2,
|
||||
'state': 2,
|
||||
'state_change_result': 0,
|
||||
}),
|
||||
'1': dict({
|
||||
'battery_level': 70,
|
||||
'duration_pullspring': 0,
|
||||
'is_charging': False,
|
||||
'is_connected': True,
|
||||
'is_enabled_pullspring': 0,
|
||||
'lock_id': '**REDACTED**',
|
||||
'lock_name': 'Lock-2C3D',
|
||||
'lock_type': 4,
|
||||
'state': 2,
|
||||
'state_change_result': 0,
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,65 @@
|
||||
# serializer version: 1
|
||||
# name: test_bridge_device
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'tedee',
|
||||
'0000-0000',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Tedee',
|
||||
'model': 'Bridge',
|
||||
'model_id': None,
|
||||
'name': 'Bridge-AB1C',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': '0000-0000',
|
||||
'suggested_area': None,
|
||||
'sw_version': None,
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_lock_device
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'tedee',
|
||||
'12345',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Tedee',
|
||||
'model': 'Tedee PRO',
|
||||
'model_id': 'Tedee PRO',
|
||||
'name': 'Lock-1A2B',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': None,
|
||||
'via_device_id': <ANY>,
|
||||
})
|
||||
# ---
|
||||
174
home-assistant/tests/components/tedee/snapshots/test_lock.ambr
Normal file
174
home-assistant/tests/components/tedee/snapshots/test_lock.ambr
Normal file
@@ -0,0 +1,174 @@
|
||||
# serializer version: 1
|
||||
# name: test_lock_without_pullspring
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Lock-2C3D',
|
||||
'supported_features': <LockEntityFeature: 0>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'lock.lock_2c3d',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unlocked',
|
||||
})
|
||||
# ---
|
||||
# name: test_lock_without_pullspring.1
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'lock',
|
||||
'entity_category': None,
|
||||
'entity_id': 'lock.lock_2c3d',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': None,
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '98765-lock',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_lock_without_pullspring.2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'tedee',
|
||||
'98765',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Tedee',
|
||||
'model': 'Tedee GO',
|
||||
'model_id': 'Tedee GO',
|
||||
'name': 'Lock-2C3D',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': None,
|
||||
'via_device_id': <ANY>,
|
||||
})
|
||||
# ---
|
||||
# name: test_locks[lock.lock_1a2b-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'lock',
|
||||
'entity_category': None,
|
||||
'entity_id': 'lock.lock_1a2b',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': None,
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': <LockEntityFeature: 1>,
|
||||
'translation_key': None,
|
||||
'unique_id': '12345-lock',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_locks[lock.lock_1a2b-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Lock-1A2B',
|
||||
'supported_features': <LockEntityFeature: 1>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'lock.lock_1a2b',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unlocked',
|
||||
})
|
||||
# ---
|
||||
# name: test_locks[lock.lock_2c3d-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'lock',
|
||||
'entity_category': None,
|
||||
'entity_id': 'lock.lock_2c3d',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': None,
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '98765-lock',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_locks[lock.lock_2c3d-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Lock-2C3D',
|
||||
'supported_features': <LockEntityFeature: 0>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'lock.lock_2c3d',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unlocked',
|
||||
})
|
||||
# ---
|
||||
205
home-assistant/tests/components/tedee/snapshots/test_sensor.ambr
Normal file
205
home-assistant/tests/components/tedee/snapshots/test_sensor.ambr
Normal file
@@ -0,0 +1,205 @@
|
||||
# serializer version: 1
|
||||
# name: test_sensors[sensor.lock_1a2b_battery-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'sensor.lock_1a2b_battery',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.BATTERY: 'battery'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Battery',
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '12345-battery_sensor',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.lock_1a2b_battery-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'battery',
|
||||
'friendly_name': 'Lock-1A2B Battery',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.lock_1a2b_battery',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '70',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.lock_1a2b_pullspring_duration-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'sensor.lock_1a2b_pullspring_duration',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.DURATION: 'duration'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Pullspring duration',
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'pullspring_duration',
|
||||
'unique_id': '12345-pullspring_duration',
|
||||
'unit_of_measurement': <UnitOfTime.SECONDS: 's'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.lock_1a2b_pullspring_duration-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'duration',
|
||||
'friendly_name': 'Lock-1A2B Pullspring duration',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': <UnitOfTime.SECONDS: 's'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.lock_1a2b_pullspring_duration',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.lock_2c3d_battery-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'sensor.lock_2c3d_battery',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.BATTERY: 'battery'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Battery',
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '98765-battery_sensor',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.lock_2c3d_battery-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'battery',
|
||||
'friendly_name': 'Lock-2C3D Battery',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.lock_2c3d_battery',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '70',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.lock_2c3d_pullspring_duration-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'sensor.lock_2c3d_pullspring_duration',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.DURATION: 'duration'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Pullspring duration',
|
||||
'platform': 'tedee',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'pullspring_duration',
|
||||
'unique_id': '98765-pullspring_duration',
|
||||
'unit_of_measurement': <UnitOfTime.SECONDS: 's'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.lock_2c3d_pullspring_duration-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'duration',
|
||||
'friendly_name': 'Lock-2C3D Pullspring duration',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': <UnitOfTime.SECONDS: 's'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.lock_2c3d_pullspring_duration',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0',
|
||||
})
|
||||
# ---
|
||||
58
home-assistant/tests/components/tedee/test_binary_sensor.py
Normal file
58
home-assistant/tests/components/tedee/test_binary_sensor.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""Tests for the Tedee Binary Sensors."""
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from aiotedee import TedeeLock
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform
|
||||
|
||||
BINARY_SENSORS = ("charging", "semi_locked", "pullspring_enabled", "lock_uncalibrated")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_binary_sensors(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test tedee binary sensor."""
|
||||
with patch("homeassistant.components.tedee.PLATFORMS", [Platform.BINARY_SENSOR]):
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_new_binary_sensors(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Ensure binary sensors for new lock are added automatically."""
|
||||
|
||||
for key in BINARY_SENSORS:
|
||||
state = hass.states.get(f"binary_sensor.lock_4e5f_{key}")
|
||||
assert state is None
|
||||
|
||||
mock_tedee.locks_dict[666666] = TedeeLock("Lock-4E5F", 666666, 2)
|
||||
|
||||
freezer.tick(timedelta(minutes=10))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
for key in BINARY_SENSORS:
|
||||
state = hass.states.get(f"binary_sensor.lock_4e5f_{key}")
|
||||
assert state
|
||||
187
home-assistant/tests/components/tedee/test_config_flow.py
Normal file
187
home-assistant/tests/components/tedee/test_config_flow.py
Normal file
@@ -0,0 +1,187 @@
|
||||
"""Test the Tedee config flow."""
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from aiotedee import (
|
||||
TedeeClientException,
|
||||
TedeeDataUpdateException,
|
||||
TedeeLocalAuthException,
|
||||
)
|
||||
from aiotedee.bridge import TedeeBridge
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.tedee.const import CONF_LOCAL_ACCESS_TOKEN, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER, ConfigFlowResult
|
||||
from homeassistant.const import CONF_HOST, CONF_WEBHOOK_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from .conftest import WEBHOOK_ID
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
FLOW_UNIQUE_ID = "112233445566778899"
|
||||
LOCAL_ACCESS_TOKEN = "api_token"
|
||||
|
||||
|
||||
async def test_flow(hass: HomeAssistant, mock_tedee: MagicMock) -> None:
|
||||
"""Test config flow with one bridge."""
|
||||
with patch(
|
||||
"homeassistant.components.tedee.config_flow.webhook_generate_id",
|
||||
return_value=WEBHOOK_ID,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_HOST: "192.168.1.62",
|
||||
CONF_LOCAL_ACCESS_TOKEN: "token",
|
||||
},
|
||||
)
|
||||
|
||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result2["data"] == {
|
||||
CONF_HOST: "192.168.1.62",
|
||||
CONF_LOCAL_ACCESS_TOKEN: "token",
|
||||
CONF_WEBHOOK_ID: WEBHOOK_ID,
|
||||
}
|
||||
|
||||
|
||||
async def test_flow_already_configured(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test config flow aborts when already configured."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_HOST: "192.168.1.62",
|
||||
CONF_LOCAL_ACCESS_TOKEN: "token",
|
||||
},
|
||||
)
|
||||
assert result2["type"] is FlowResultType.ABORT
|
||||
assert result2["reason"] == "already_configured"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "error"),
|
||||
[
|
||||
(TedeeClientException("boom."), {CONF_HOST: "invalid_host"}),
|
||||
(
|
||||
TedeeLocalAuthException("boom."),
|
||||
{CONF_LOCAL_ACCESS_TOKEN: "invalid_api_key"},
|
||||
),
|
||||
(TedeeDataUpdateException("boom."), {"base": "cannot_connect"}),
|
||||
],
|
||||
)
|
||||
async def test_config_flow_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
side_effect: Exception,
|
||||
error: dict[str, str],
|
||||
) -> None:
|
||||
"""Test the config flow errors."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
|
||||
mock_tedee.get_local_bridge.side_effect = side_effect
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_HOST: "192.168.1.42",
|
||||
CONF_LOCAL_ACCESS_TOKEN: "wrong_token",
|
||||
},
|
||||
)
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["errors"] == error
|
||||
assert len(mock_tedee.get_local_bridge.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_reauth_flow(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_tedee: MagicMock
|
||||
) -> None:
|
||||
"""Test that the reauth flow works."""
|
||||
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
reauth_result = await mock_config_entry.start_reauth_flow(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
reauth_result["flow_id"],
|
||||
{
|
||||
CONF_LOCAL_ACCESS_TOKEN: LOCAL_ACCESS_TOKEN,
|
||||
},
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reauth_successful"
|
||||
|
||||
|
||||
async def __do_reconfigure_flow(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||
) -> ConfigFlowResult:
|
||||
"""Initialize a reconfigure flow."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
reconfigure_result = await mock_config_entry.start_reconfigure_flow(hass)
|
||||
|
||||
assert reconfigure_result["type"] is FlowResultType.FORM
|
||||
assert reconfigure_result["step_id"] == "reconfigure"
|
||||
|
||||
return await hass.config_entries.flow.async_configure(
|
||||
reconfigure_result["flow_id"],
|
||||
{CONF_LOCAL_ACCESS_TOKEN: LOCAL_ACCESS_TOKEN, CONF_HOST: "192.168.1.43"},
|
||||
)
|
||||
|
||||
|
||||
async def test_reconfigure_flow(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_tedee: MagicMock
|
||||
) -> None:
|
||||
"""Test that the reconfigure flow works."""
|
||||
|
||||
result = await __do_reconfigure_flow(hass, mock_config_entry)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
|
||||
entry = hass.config_entries.async_get_entry(mock_config_entry.entry_id)
|
||||
assert entry
|
||||
assert entry.title == "My Tedee"
|
||||
assert entry.data == {
|
||||
CONF_HOST: "192.168.1.43",
|
||||
CONF_LOCAL_ACCESS_TOKEN: LOCAL_ACCESS_TOKEN,
|
||||
CONF_WEBHOOK_ID: WEBHOOK_ID,
|
||||
}
|
||||
|
||||
|
||||
async def test_reconfigure_unique_id_mismatch(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_tedee: MagicMock
|
||||
) -> None:
|
||||
"""Ensure reconfigure flow aborts when the bride changes."""
|
||||
|
||||
mock_tedee.get_local_bridge.return_value = TedeeBridge(
|
||||
0, "1111-1111", "Bridge-R2D2"
|
||||
)
|
||||
|
||||
result = await __do_reconfigure_flow(hass, mock_config_entry)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "unique_id_mismatch"
|
||||
22
home-assistant/tests/components/tedee/test_diagnostics.py
Normal file
22
home-assistant/tests/components/tedee/test_diagnostics.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""Tests for the diagnostics data provided by the Tedee integration."""
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
init_integration: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
|
||||
== snapshot
|
||||
)
|
||||
249
home-assistant/tests/components/tedee/test_init.py
Normal file
249
home-assistant/tests/components/tedee/test_init.py
Normal file
@@ -0,0 +1,249 @@
|
||||
"""Test initialization of tedee."""
|
||||
|
||||
from http import HTTPStatus
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from aiotedee.exception import (
|
||||
TedeeAuthException,
|
||||
TedeeClientException,
|
||||
TedeeWebhookException,
|
||||
)
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.tedee.const import CONF_LOCAL_ACCESS_TOKEN, DOMAIN
|
||||
from homeassistant.components.webhook import async_generate_url
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_HOST, CONF_WEBHOOK_ID, EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from . import setup_integration
|
||||
from .conftest import WEBHOOK_ID
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_load_unload_config_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tedee: MagicMock,
|
||||
) -> None:
|
||||
"""Test loading and unloading the integration."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"side_effect", [TedeeClientException(""), TedeeAuthException("")]
|
||||
)
|
||||
async def test_config_entry_not_ready(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tedee: MagicMock,
|
||||
side_effect: Exception,
|
||||
) -> None:
|
||||
"""Test the Tedee configuration entry not ready."""
|
||||
mock_tedee.get_locks.side_effect = side_effect
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert len(mock_tedee.get_locks.mock_calls) == 1
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_cleanup_on_shutdown(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tedee: MagicMock,
|
||||
) -> None:
|
||||
"""Test the webhook is cleaned up on shutdown."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||
await hass.async_block_till_done()
|
||||
mock_tedee.delete_webhook.assert_called_once()
|
||||
|
||||
|
||||
async def test_webhook_cleanup_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tedee: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the webhook is cleaned up on shutdown."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
mock_tedee.delete_webhook.side_effect = TedeeWebhookException("")
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||
await hass.async_block_till_done()
|
||||
mock_tedee.delete_webhook.assert_called_once()
|
||||
assert "Failed to unregister Tedee webhook from bridge" in caplog.text
|
||||
|
||||
|
||||
async def test_webhook_registration_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tedee: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the webhook is cleaned up on shutdown."""
|
||||
mock_tedee.register_webhook.side_effect = TedeeWebhookException("")
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
mock_tedee.register_webhook.assert_called_once()
|
||||
assert "Failed to register Tedee webhook from bridge" in caplog.text
|
||||
|
||||
|
||||
async def test_webhook_registration_cleanup_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tedee: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the errors during webhook cleanup during registration."""
|
||||
mock_tedee.cleanup_webhooks_by_host.side_effect = TedeeWebhookException("")
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
mock_tedee.cleanup_webhooks_by_host.assert_called_once()
|
||||
assert "Failed to cleanup Tedee webhooks by host:" in caplog.text
|
||||
|
||||
|
||||
async def test_lock_device(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tedee: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Ensure the lock device is registered."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
device = device_registry.async_get_device({(mock_config_entry.domain, "12345")})
|
||||
assert device
|
||||
assert device == snapshot
|
||||
|
||||
|
||||
async def test_bridge_device(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tedee: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Ensure the bridge device is registered."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
device = device_registry.async_get_device(
|
||||
{(mock_config_entry.domain, mock_tedee.get_local_bridge.return_value.serial)}
|
||||
)
|
||||
assert device
|
||||
assert device == snapshot
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
(
|
||||
"body",
|
||||
"expected_code",
|
||||
"side_effect",
|
||||
),
|
||||
[
|
||||
(
|
||||
{"hello": "world"},
|
||||
HTTPStatus.OK,
|
||||
None,
|
||||
), # Success
|
||||
(
|
||||
None,
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
None,
|
||||
), # Missing data
|
||||
(
|
||||
{},
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
TedeeWebhookException,
|
||||
), # Error
|
||||
],
|
||||
)
|
||||
async def test_webhook_post(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tedee: MagicMock,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
body: dict[str, Any],
|
||||
expected_code: HTTPStatus,
|
||||
side_effect: Exception,
|
||||
) -> None:
|
||||
"""Test webhook callback."""
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
client = await hass_client_no_auth()
|
||||
webhook_url = async_generate_url(hass, WEBHOOK_ID)
|
||||
mock_tedee.parse_webhook_message.side_effect = side_effect
|
||||
resp = await client.post(urlparse(webhook_url).path, json=body)
|
||||
|
||||
# Wait for remaining tasks to complete.
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert resp.status == expected_code
|
||||
|
||||
|
||||
async def test_config_flow_entry_migrate_2_1(hass: HomeAssistant) -> None:
|
||||
"""Test that config entry fails setup if the version is from the future."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
version=2,
|
||||
minor_version=1,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
assert not await hass.config_entries.async_setup(entry.entry_id)
|
||||
|
||||
|
||||
async def test_migration(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
) -> None:
|
||||
"""Test migration of the config entry."""
|
||||
|
||||
mock_config_entry = MockConfigEntry(
|
||||
title="My Tedee",
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_LOCAL_ACCESS_TOKEN: "api_token",
|
||||
CONF_HOST: "192.168.1.42",
|
||||
},
|
||||
version=1,
|
||||
minor_version=1,
|
||||
unique_id="0000-0000",
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.tedee.webhook_generate_id",
|
||||
return_value=WEBHOOK_ID,
|
||||
):
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_config_entry.version == 1
|
||||
assert mock_config_entry.minor_version == 2
|
||||
assert mock_config_entry.data[CONF_WEBHOOK_ID] == WEBHOOK_ID
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
318
home-assistant/tests/components/tedee/test_lock.py
Normal file
318
home-assistant/tests/components/tedee/test_lock.py
Normal file
@@ -0,0 +1,318 @@
|
||||
"""Tests for tedee lock."""
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import MagicMock, patch
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from aiotedee import TedeeLock, TedeeLockState
|
||||
from aiotedee.exception import (
|
||||
TedeeClientException,
|
||||
TedeeDataUpdateException,
|
||||
TedeeLocalAuthException,
|
||||
)
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.lock import (
|
||||
DOMAIN as LOCK_DOMAIN,
|
||||
SERVICE_LOCK,
|
||||
SERVICE_OPEN,
|
||||
SERVICE_UNLOCK,
|
||||
LockState,
|
||||
)
|
||||
from homeassistant.components.webhook import async_generate_url
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceNotSupported
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import setup_integration
|
||||
from .conftest import WEBHOOK_ID
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_locks(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test tedee locks."""
|
||||
with patch("homeassistant.components.tedee.PLATFORMS", [Platform.LOCK]):
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_lock_service_calls(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
) -> None:
|
||||
"""Test the tedee lock."""
|
||||
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_LOCK,
|
||||
{
|
||||
ATTR_ENTITY_ID: "lock.lock_1a2b",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(mock_tedee.lock.mock_calls) == 1
|
||||
mock_tedee.lock.assert_called_once_with(12345)
|
||||
state = hass.states.get("lock.lock_1a2b")
|
||||
assert state
|
||||
assert state.state == LockState.LOCKING
|
||||
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_UNLOCK,
|
||||
{
|
||||
ATTR_ENTITY_ID: "lock.lock_1a2b",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(mock_tedee.unlock.mock_calls) == 1
|
||||
mock_tedee.unlock.assert_called_once_with(12345)
|
||||
state = hass.states.get("lock.lock_1a2b")
|
||||
assert state
|
||||
assert state.state == LockState.UNLOCKING
|
||||
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_OPEN,
|
||||
{
|
||||
ATTR_ENTITY_ID: "lock.lock_1a2b",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(mock_tedee.open.mock_calls) == 1
|
||||
mock_tedee.open.assert_called_once_with(12345)
|
||||
state = hass.states.get("lock.lock_1a2b")
|
||||
assert state
|
||||
assert state.state == LockState.UNLOCKING
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_lock_without_pullspring(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the tedee lock without pullspring."""
|
||||
# Fetch translations
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
|
||||
state = hass.states.get("lock.lock_2c3d")
|
||||
assert state
|
||||
assert state == snapshot
|
||||
|
||||
entry = entity_registry.async_get(state.entity_id)
|
||||
assert entry
|
||||
assert entry == snapshot
|
||||
|
||||
assert entry.device_id
|
||||
device = device_registry.async_get(entry.device_id)
|
||||
assert device
|
||||
assert device == snapshot
|
||||
|
||||
with pytest.raises(
|
||||
ServiceNotSupported,
|
||||
match=f"Entity lock.lock_2c3d does not support action {LOCK_DOMAIN}.{SERVICE_OPEN}",
|
||||
):
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_OPEN,
|
||||
{
|
||||
ATTR_ENTITY_ID: "lock.lock_2c3d",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(mock_tedee.open.mock_calls) == 0
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_lock_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
) -> None:
|
||||
"""Test event errors."""
|
||||
mock_tedee.lock.side_effect = TedeeClientException("Boom")
|
||||
with pytest.raises(HomeAssistantError) as exc_info:
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_LOCK,
|
||||
{
|
||||
ATTR_ENTITY_ID: "lock.lock_1a2b",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert exc_info.value.translation_key == "lock_failed"
|
||||
|
||||
mock_tedee.unlock.side_effect = TedeeClientException("Boom")
|
||||
with pytest.raises(HomeAssistantError) as exc_info:
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_UNLOCK,
|
||||
{
|
||||
ATTR_ENTITY_ID: "lock.lock_1a2b",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert exc_info.value.translation_key == "unlock_failed"
|
||||
|
||||
mock_tedee.open.side_effect = TedeeClientException("Boom")
|
||||
with pytest.raises(HomeAssistantError) as exc_info:
|
||||
await hass.services.async_call(
|
||||
LOCK_DOMAIN,
|
||||
SERVICE_OPEN,
|
||||
{
|
||||
ATTR_ENTITY_ID: "lock.lock_1a2b",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert exc_info.value.translation_key == "open_failed"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
@pytest.mark.parametrize(
|
||||
"side_effect",
|
||||
[
|
||||
TedeeClientException("Boom"),
|
||||
TedeeLocalAuthException("Boom"),
|
||||
TimeoutError,
|
||||
TedeeDataUpdateException("Boom"),
|
||||
],
|
||||
)
|
||||
async def test_update_failed(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
side_effect: Exception,
|
||||
) -> None:
|
||||
"""Test update failed."""
|
||||
mock_tedee.sync.side_effect = side_effect
|
||||
freezer.tick(timedelta(minutes=10))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("lock.lock_1a2b")
|
||||
assert state is not None
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_cleanup_removed_locks(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Ensure removed locks are cleaned up."""
|
||||
|
||||
devices = dr.async_entries_for_config_entry(
|
||||
device_registry, mock_config_entry.entry_id
|
||||
)
|
||||
|
||||
locks = [device.name for device in devices]
|
||||
assert "Lock-1A2B" in locks
|
||||
|
||||
# remove a lock and wait for coordinator
|
||||
mock_tedee.locks_dict.pop(12345)
|
||||
freezer.tick(timedelta(minutes=10))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
devices = dr.async_entries_for_config_entry(
|
||||
device_registry, mock_config_entry.entry_id
|
||||
)
|
||||
|
||||
locks = [device.name for device in devices]
|
||||
assert "Lock-1A2B" not in locks
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_new_lock(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Ensure new lock is added automatically."""
|
||||
|
||||
state = hass.states.get("lock.lock_4e5f")
|
||||
assert state is None
|
||||
|
||||
mock_tedee.locks_dict[666666] = TedeeLock("Lock-4E5F", 666666, 2)
|
||||
mock_tedee.locks_dict[777777] = TedeeLock(
|
||||
"Lock-6G7H",
|
||||
777777,
|
||||
4,
|
||||
is_enabled_pullspring=True,
|
||||
)
|
||||
|
||||
freezer.tick(timedelta(minutes=10))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("lock.lock_4e5f")
|
||||
assert state
|
||||
state = hass.states.get("lock.lock_6g7h")
|
||||
assert state
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
@pytest.mark.parametrize(
|
||||
("lib_state", "expected_state"),
|
||||
[
|
||||
(TedeeLockState.LOCKED, LockState.LOCKED),
|
||||
(TedeeLockState.HALF_OPEN, STATE_UNKNOWN),
|
||||
(TedeeLockState.UNKNOWN, STATE_UNKNOWN),
|
||||
(TedeeLockState.UNCALIBRATED, STATE_UNAVAILABLE),
|
||||
],
|
||||
)
|
||||
async def test_webhook_update(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
lib_state: TedeeLockState,
|
||||
expected_state: str,
|
||||
) -> None:
|
||||
"""Test updated data set through webhook."""
|
||||
|
||||
state = hass.states.get("lock.lock_1a2b")
|
||||
assert state
|
||||
assert state.state == LockState.UNLOCKED
|
||||
|
||||
webhook_data = {"dummystate": lib_state.value}
|
||||
# is updated in the lib, so mock and assert below
|
||||
mock_tedee.locks_dict[12345].state = lib_state
|
||||
client = await hass_client_no_auth()
|
||||
webhook_url = async_generate_url(hass, WEBHOOK_ID)
|
||||
|
||||
await client.post(
|
||||
urlparse(webhook_url).path,
|
||||
json=webhook_data,
|
||||
)
|
||||
mock_tedee.parse_webhook_message.assert_called_once_with(webhook_data)
|
||||
|
||||
state = hass.states.get("lock.lock_1a2b")
|
||||
assert state
|
||||
assert state.state == expected_state
|
||||
59
home-assistant/tests/components/tedee/test_sensor.py
Normal file
59
home-assistant/tests/components/tedee/test_sensor.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""Tests for the Tedee Sensors."""
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from aiotedee import TedeeLock
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform
|
||||
|
||||
SENSORS = (
|
||||
"battery",
|
||||
"pullspring_duration",
|
||||
)
|
||||
|
||||
|
||||
async def test_sensors(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test tedee sensors."""
|
||||
with patch("homeassistant.components.tedee.PLATFORMS", [Platform.SENSOR]):
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_new_sensors(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Ensure sensors for new lock are added automatically."""
|
||||
|
||||
for key in SENSORS:
|
||||
state = hass.states.get(f"sensor.lock_4e5f_{key}")
|
||||
assert state is None
|
||||
|
||||
mock_tedee.locks_dict[666666] = TedeeLock("Lock-4E5F", 666666, 2)
|
||||
|
||||
freezer.tick(timedelta(minutes=10))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
for key in SENSORS:
|
||||
state = hass.states.get(f"sensor.lock_4e5f_{key}")
|
||||
assert state
|
||||
Reference in New Issue
Block a user