init home-assistant
This commit is contained in:
1
home-assistant/tests/components/tailwind/__init__.py
Normal file
1
home-assistant/tests/components/tailwind/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Integration tests for the Tailwind integration."""
|
||||
78
home-assistant/tests/components/tailwind/conftest.py
Normal file
78
home-assistant/tests/components/tailwind/conftest.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""Fixtures for the Tailwind integration tests."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from gotailwind import TailwindDeviceStatus
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.tailwind.const import DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def device_fixture() -> str:
|
||||
"""Return the device fixtures for a specific device."""
|
||||
return "iq3"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_config_entry() -> MockConfigEntry:
|
||||
"""Return the default mocked config entry."""
|
||||
return MockConfigEntry(
|
||||
title="Tailwind iQ3",
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_HOST: "127.0.0.127",
|
||||
CONF_TOKEN: "123456",
|
||||
},
|
||||
unique_id="3c:e9:0e:6d:21:84",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[None]:
|
||||
"""Mock setting up a config entry."""
|
||||
with patch(
|
||||
"homeassistant.components.tailwind.async_setup_entry", return_value=True
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_tailwind(device_fixture: str) -> Generator[MagicMock]:
|
||||
"""Return a mocked Tailwind client."""
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.tailwind.coordinator.Tailwind", autospec=True
|
||||
) as tailwind_mock,
|
||||
patch(
|
||||
"homeassistant.components.tailwind.config_flow.Tailwind",
|
||||
new=tailwind_mock,
|
||||
),
|
||||
):
|
||||
tailwind = tailwind_mock.return_value
|
||||
tailwind.status.return_value = TailwindDeviceStatus.from_json(
|
||||
load_fixture(f"{device_fixture}.json", DOMAIN)
|
||||
)
|
||||
yield tailwind
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def init_integration(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tailwind: MagicMock,
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the Tailwind 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()
|
||||
|
||||
return mock_config_entry
|
||||
24
home-assistant/tests/components/tailwind/fixtures/iq3.json
Normal file
24
home-assistant/tests/components/tailwind/fixtures/iq3.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"result": "OK",
|
||||
"product": "iQ3",
|
||||
"dev_id": "_3c_e9_e_6d_21_84_",
|
||||
"proto_ver": "0.1",
|
||||
"door_num": 2,
|
||||
"night_mode_en": 0,
|
||||
"fw_ver": "10.10",
|
||||
"led_brightness": 100,
|
||||
"data": {
|
||||
"door1": {
|
||||
"index": 0,
|
||||
"status": "open",
|
||||
"lockup": 0,
|
||||
"disabled": 0
|
||||
},
|
||||
"door2": {
|
||||
"index": 1,
|
||||
"status": "open",
|
||||
"lockup": 0,
|
||||
"disabled": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
# serializer version: 1
|
||||
# name: test_number_entities[binary_sensor.door_1_operational_problem]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'problem',
|
||||
'friendly_name': 'Door 1 Operational problem',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.door_1_operational_problem',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities[binary_sensor.door_1_operational_problem].1
|
||||
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.door_1_operational_problem',
|
||||
'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': 'Operational problem',
|
||||
'platform': 'tailwind',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'operational_problem',
|
||||
'unique_id': '_3c_e9_e_6d_21_84_-door1-locked_out',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities[binary_sensor.door_1_operational_problem].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(
|
||||
'tailwind',
|
||||
'_3c_e9_e_6d_21_84_-door1',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Tailwind',
|
||||
'model': 'iQ3',
|
||||
'model_id': None,
|
||||
'name': 'Door 1',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': '10.10',
|
||||
'via_device_id': <ANY>,
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities[binary_sensor.door_2_operational_problem]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'problem',
|
||||
'friendly_name': 'Door 2 Operational problem',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.door_2_operational_problem',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities[binary_sensor.door_2_operational_problem].1
|
||||
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.door_2_operational_problem',
|
||||
'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': 'Operational problem',
|
||||
'platform': 'tailwind',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'operational_problem',
|
||||
'unique_id': '_3c_e9_e_6d_21_84_-door2-locked_out',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities[binary_sensor.door_2_operational_problem].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(
|
||||
'tailwind',
|
||||
'_3c_e9_e_6d_21_84_-door2',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Tailwind',
|
||||
'model': 'iQ3',
|
||||
'model_id': None,
|
||||
'name': 'Door 2',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': '10.10',
|
||||
'via_device_id': <ANY>,
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,84 @@
|
||||
# serializer version: 1
|
||||
# name: test_number_entities
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'identify',
|
||||
'friendly_name': 'Tailwind iQ3 Identify',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'button.tailwind_iq3_identify',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities.1
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'button',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'button.tailwind_iq3_identify',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <ButtonDeviceClass.IDENTIFY: 'identify'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Identify',
|
||||
'platform': 'tailwind',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': '_3c_e9_e_6d_21_84_-identify',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities.2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
tuple(
|
||||
'mac',
|
||||
'3c:e9:0e:6d:21:84',
|
||||
),
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'tailwind',
|
||||
'_3c_e9_e_6d_21_84_',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Tailwind',
|
||||
'model': 'iQ3',
|
||||
'model_id': None,
|
||||
'name': 'Tailwind iQ3',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': '10.10',
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,161 @@
|
||||
# serializer version: 1
|
||||
# name: test_cover_entities[cover.door_1]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'garage',
|
||||
'friendly_name': 'Door 1',
|
||||
'supported_features': <CoverEntityFeature: 3>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'cover.door_1',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'open',
|
||||
})
|
||||
# ---
|
||||
# name: test_cover_entities[cover.door_1].1
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'cover',
|
||||
'entity_category': None,
|
||||
'entity_id': 'cover.door_1',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <CoverDeviceClass.GARAGE: 'garage'>,
|
||||
'original_icon': None,
|
||||
'original_name': None,
|
||||
'platform': 'tailwind',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': <CoverEntityFeature: 3>,
|
||||
'translation_key': None,
|
||||
'unique_id': '_3c_e9_e_6d_21_84_-door1',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_cover_entities[cover.door_1].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(
|
||||
'tailwind',
|
||||
'_3c_e9_e_6d_21_84_-door1',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Tailwind',
|
||||
'model': 'iQ3',
|
||||
'model_id': None,
|
||||
'name': 'Door 1',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': '10.10',
|
||||
'via_device_id': <ANY>,
|
||||
})
|
||||
# ---
|
||||
# name: test_cover_entities[cover.door_2]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'garage',
|
||||
'friendly_name': 'Door 2',
|
||||
'supported_features': <CoverEntityFeature: 3>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'cover.door_2',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'open',
|
||||
})
|
||||
# ---
|
||||
# name: test_cover_entities[cover.door_2].1
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'cover',
|
||||
'entity_category': None,
|
||||
'entity_id': 'cover.door_2',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <CoverDeviceClass.GARAGE: 'garage'>,
|
||||
'original_icon': None,
|
||||
'original_name': None,
|
||||
'platform': 'tailwind',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': <CoverEntityFeature: 3>,
|
||||
'translation_key': None,
|
||||
'unique_id': '_3c_e9_e_6d_21_84_-door2',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_cover_entities[cover.door_2].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(
|
||||
'tailwind',
|
||||
'_3c_e9_e_6d_21_84_-door2',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Tailwind',
|
||||
'model': 'iQ3',
|
||||
'model_id': None,
|
||||
'name': 'Door 2',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': '10.10',
|
||||
'via_device_id': <ANY>,
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,28 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'data': dict({
|
||||
'door1': dict({
|
||||
'disabled': 0,
|
||||
'door_id': 'door1',
|
||||
'index': 0,
|
||||
'lockup': 0,
|
||||
'status': 'open',
|
||||
}),
|
||||
'door2': dict({
|
||||
'disabled': 0,
|
||||
'door_id': 'door2',
|
||||
'index': 1,
|
||||
'lockup': 0,
|
||||
'status': 'open',
|
||||
}),
|
||||
}),
|
||||
'dev_id': '_3c_e9_e_6d_21_84_',
|
||||
'door_num': 2,
|
||||
'fw_ver': '10.10',
|
||||
'led_brightness': 100,
|
||||
'night_mode_en': 0,
|
||||
'product': 'iQ3',
|
||||
'proto_ver': '0.1',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,93 @@
|
||||
# serializer version: 1
|
||||
# name: test_number_entities
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Tailwind iQ3 Status LED brightness',
|
||||
'max': 100,
|
||||
'min': 0,
|
||||
'mode': <NumberMode.AUTO: 'auto'>,
|
||||
'step': 1,
|
||||
'unit_of_measurement': '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'number.tailwind_iq3_status_led_brightness',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '100',
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities.1
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'max': 100,
|
||||
'min': 0,
|
||||
'mode': <NumberMode.AUTO: 'auto'>,
|
||||
'step': 1,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'number',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'number.tailwind_iq3_status_led_brightness',
|
||||
'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': 'Status LED brightness',
|
||||
'platform': 'tailwind',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'brightness',
|
||||
'unique_id': '_3c_e9_e_6d_21_84_-brightness',
|
||||
'unit_of_measurement': '%',
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities.2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
tuple(
|
||||
'mac',
|
||||
'3c:e9:0e:6d:21:84',
|
||||
),
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'tailwind',
|
||||
'_3c_e9_e_6d_21_84_',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Tailwind',
|
||||
'model': 'iQ3',
|
||||
'model_id': None,
|
||||
'name': 'Tailwind iQ3',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': '10.10',
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,35 @@
|
||||
"""Tests for binary sensor entities provided by the Tailwind integration."""
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("init_integration")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"entity_id",
|
||||
[
|
||||
"binary_sensor.door_1_operational_problem",
|
||||
"binary_sensor.door_2_operational_problem",
|
||||
],
|
||||
)
|
||||
async def test_number_entities(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
entity_id: str,
|
||||
) -> None:
|
||||
"""Test binary sensor entities provided by the Tailwind integration."""
|
||||
assert (state := hass.states.get(entity_id))
|
||||
assert snapshot == state
|
||||
|
||||
assert (entity_entry := entity_registry.async_get(state.entity_id))
|
||||
assert snapshot == entity_entry
|
||||
|
||||
assert entity_entry.device_id
|
||||
assert (device_entry := device_registry.async_get(entity_entry.device_id))
|
||||
assert snapshot == device_entry
|
||||
66
home-assistant/tests/components/tailwind/test_button.py
Normal file
66
home-assistant/tests/components/tailwind/test_button.py
Normal file
@@ -0,0 +1,66 @@
|
||||
"""Tests for button entities provided by the Tailwind integration."""
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from gotailwind import TailwindError
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
|
||||
from homeassistant.components.tailwind.const import DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.usefixtures("init_integration"),
|
||||
pytest.mark.freeze_time("2023-12-17 15:25:00"),
|
||||
]
|
||||
|
||||
|
||||
async def test_number_entities(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_tailwind: MagicMock,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test button entities provided by the Tailwind integration."""
|
||||
assert (state := hass.states.get("button.tailwind_iq3_identify"))
|
||||
assert snapshot == state
|
||||
|
||||
assert (entity_entry := entity_registry.async_get(state.entity_id))
|
||||
assert snapshot == entity_entry
|
||||
|
||||
assert entity_entry.device_id
|
||||
assert (device_entry := device_registry.async_get(entity_entry.device_id))
|
||||
assert snapshot == device_entry
|
||||
|
||||
assert len(mock_tailwind.identify.mock_calls) == 0
|
||||
await hass.services.async_call(
|
||||
BUTTON_DOMAIN,
|
||||
SERVICE_PRESS,
|
||||
{ATTR_ENTITY_ID: state.entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(mock_tailwind.identify.mock_calls) == 1
|
||||
mock_tailwind.identify.assert_called_with()
|
||||
|
||||
assert (state := hass.states.get(state.entity_id))
|
||||
assert state.state == "2023-12-17T15:25:00+00:00"
|
||||
|
||||
# Test error handling
|
||||
mock_tailwind.identify.side_effect = TailwindError("Some error")
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="Some error") as excinfo:
|
||||
await hass.services.async_call(
|
||||
BUTTON_DOMAIN,
|
||||
SERVICE_PRESS,
|
||||
{ATTR_ENTITY_ID: state.entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert excinfo.value.translation_domain == DOMAIN
|
||||
assert excinfo.value.translation_key == "communication_error"
|
||||
435
home-assistant/tests/components/tailwind/test_config_flow.py
Normal file
435
home-assistant/tests/components/tailwind/test_config_flow.py
Normal file
@@ -0,0 +1,435 @@
|
||||
"""Configuration flow tests for the Tailwind integration."""
|
||||
|
||||
from ipaddress import ip_address
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from gotailwind import (
|
||||
TailwindAuthenticationError,
|
||||
TailwindConnectionError,
|
||||
TailwindUnsupportedFirmwareVersionError,
|
||||
)
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.components.dhcp import DhcpServiceInfo
|
||||
from homeassistant.components.tailwind.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_DHCP, SOURCE_USER, SOURCE_ZEROCONF
|
||||
from homeassistant.const import CONF_HOST, CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_tailwind")
|
||||
async def test_user_flow(hass: HomeAssistant) -> None:
|
||||
"""Test the full happy path user flow from start to finish."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: "127.0.0.1",
|
||||
CONF_TOKEN: "987654",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
config_entry = result["result"]
|
||||
assert config_entry.unique_id == "3c:e9:0e:6d:21:84"
|
||||
assert config_entry.data == {
|
||||
CONF_HOST: "127.0.0.1",
|
||||
CONF_TOKEN: "987654",
|
||||
}
|
||||
assert not config_entry.options
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "expected_error"),
|
||||
[
|
||||
(TailwindConnectionError, {CONF_HOST: "cannot_connect"}),
|
||||
(TailwindAuthenticationError, {CONF_TOKEN: "invalid_auth"}),
|
||||
(Exception, {"base": "unknown"}),
|
||||
],
|
||||
)
|
||||
async def test_user_flow_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_tailwind: MagicMock,
|
||||
side_effect: Exception,
|
||||
expected_error: dict[str, str],
|
||||
) -> None:
|
||||
"""Test we show user form on a connection error."""
|
||||
mock_tailwind.status.side_effect = side_effect
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={
|
||||
CONF_HOST: "127.0.0.1",
|
||||
CONF_TOKEN: "987654",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == expected_error
|
||||
|
||||
mock_tailwind.status.side_effect = None
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: "127.0.0.2",
|
||||
CONF_TOKEN: "123456",
|
||||
},
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
config_entry = result["result"]
|
||||
assert config_entry.unique_id == "3c:e9:0e:6d:21:84"
|
||||
assert config_entry.data == {
|
||||
CONF_HOST: "127.0.0.2",
|
||||
CONF_TOKEN: "123456",
|
||||
}
|
||||
assert not config_entry.options
|
||||
|
||||
|
||||
async def test_user_flow_unsupported_firmware_version(
|
||||
hass: HomeAssistant, mock_tailwind: MagicMock
|
||||
) -> None:
|
||||
"""Test configuration flow aborts when the firmware version is not supported."""
|
||||
mock_tailwind.status.side_effect = TailwindUnsupportedFirmwareVersionError
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={
|
||||
CONF_HOST: "127.0.0.1",
|
||||
CONF_TOKEN: "987654",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "unsupported_firmware"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_tailwind")
|
||||
async def test_user_flow_already_configured(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test configuration flow aborts when the device is already configured.
|
||||
|
||||
Also, ensures the existing config entry is updated with the new host.
|
||||
"""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
assert mock_config_entry.data[CONF_HOST] == "127.0.0.127"
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={
|
||||
CONF_HOST: "127.0.0.1",
|
||||
CONF_TOKEN: "987654",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert mock_config_entry.data[CONF_HOST] == "127.0.0.1"
|
||||
assert mock_config_entry.data[CONF_TOKEN] == "987654"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_tailwind")
|
||||
async def test_zeroconf_flow(
|
||||
hass: HomeAssistant,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the zeroconf happy flow from start to finish."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_ZEROCONF},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=ip_address("127.0.0.1"),
|
||||
ip_addresses=[ip_address("127.0.0.1")],
|
||||
port=80,
|
||||
hostname="tailwind-3ce90e6d2184.local.",
|
||||
name="mock_name",
|
||||
properties={
|
||||
"device_id": "_3c_e9_e_6d_21_84_",
|
||||
"product": "iQ3",
|
||||
"SW ver": "10.10",
|
||||
"vendor": "tailwind",
|
||||
},
|
||||
type="mock_type",
|
||||
),
|
||||
)
|
||||
|
||||
assert result["step_id"] == "zeroconf_confirm"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
|
||||
progress = hass.config_entries.flow.async_progress()
|
||||
assert len(progress) == 1
|
||||
assert progress[0].get("flow_id") == result["flow_id"]
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={CONF_TOKEN: "987654"}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
config_entry = result["result"]
|
||||
assert config_entry.unique_id == "3c:e9:0e:6d:21:84"
|
||||
assert config_entry.data == {
|
||||
CONF_HOST: "127.0.0.1",
|
||||
CONF_TOKEN: "987654",
|
||||
}
|
||||
assert not config_entry.options
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("properties", "expected_reason"),
|
||||
[
|
||||
({"SW ver": "10.10"}, "no_device_id"),
|
||||
({"device_id": "_3c_e9_e_6d_21_84_", "SW ver": "0.0"}, "unsupported_firmware"),
|
||||
],
|
||||
)
|
||||
async def test_zeroconf_flow_abort_incompatible_properties(
|
||||
hass: HomeAssistant, properties: dict[str, str], expected_reason: str
|
||||
) -> None:
|
||||
"""Test the zeroconf aborts when it advertises incompatible data."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_ZEROCONF},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=ip_address("127.0.0.1"),
|
||||
ip_addresses=[ip_address("127.0.0.1")],
|
||||
port=80,
|
||||
hostname="tailwind-3ce90e6d2184.local.",
|
||||
name="mock_name",
|
||||
properties=properties,
|
||||
type="mock_type",
|
||||
),
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == expected_reason
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "expected_error"),
|
||||
[
|
||||
(TailwindConnectionError, {"base": "cannot_connect"}),
|
||||
(TailwindAuthenticationError, {CONF_TOKEN: "invalid_auth"}),
|
||||
(Exception, {"base": "unknown"}),
|
||||
],
|
||||
)
|
||||
async def test_zeroconf_flow_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_tailwind: MagicMock,
|
||||
side_effect: Exception,
|
||||
expected_error: dict[str, str],
|
||||
) -> None:
|
||||
"""Test we show form on a error."""
|
||||
mock_tailwind.status.side_effect = side_effect
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_ZEROCONF},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=ip_address("127.0.0.1"),
|
||||
ip_addresses=[ip_address("127.0.0.1")],
|
||||
port=80,
|
||||
hostname="tailwind-3ce90e6d2184.local.",
|
||||
name="mock_name",
|
||||
properties={
|
||||
"device_id": "_3c_e9_e_6d_21_84_",
|
||||
"product": "iQ3",
|
||||
"SW ver": "10.10",
|
||||
"vendor": "tailwind",
|
||||
},
|
||||
type="mock_type",
|
||||
),
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_TOKEN: "123456",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "zeroconf_confirm"
|
||||
assert result["errors"] == expected_error
|
||||
|
||||
mock_tailwind.status.side_effect = None
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_TOKEN: "123456",
|
||||
},
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
config_entry = result["result"]
|
||||
assert config_entry.unique_id == "3c:e9:0e:6d:21:84"
|
||||
assert config_entry.data == {
|
||||
CONF_HOST: "127.0.0.1",
|
||||
CONF_TOKEN: "123456",
|
||||
}
|
||||
assert not config_entry.options
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_tailwind")
|
||||
async def test_zeroconf_flow_not_discovered_again(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the zeroconf doesn't re-discover an existing device.
|
||||
|
||||
Also, ensures the existing config entry is updated with the new host.
|
||||
"""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
assert mock_config_entry.data[CONF_HOST] == "127.0.0.127"
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_ZEROCONF},
|
||||
data=zeroconf.ZeroconfServiceInfo(
|
||||
ip_address=ip_address("127.0.0.1"),
|
||||
ip_addresses=[ip_address("127.0.0.1")],
|
||||
port=80,
|
||||
hostname="tailwind-3ce90e6d2184.local.",
|
||||
name="mock_name",
|
||||
properties={
|
||||
"device_id": "_3c_e9_e_6d_21_84_",
|
||||
"product": "iQ3",
|
||||
"SW ver": "10.10",
|
||||
"vendor": "tailwind",
|
||||
},
|
||||
type="mock_type",
|
||||
),
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert mock_config_entry.data[CONF_HOST] == "127.0.0.1"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_tailwind")
|
||||
async def test_reauth_flow(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the reauthentication configuration flow."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
assert mock_config_entry.data[CONF_TOKEN] == "123456"
|
||||
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_TOKEN: "987654"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reauth_successful"
|
||||
|
||||
assert mock_config_entry.data[CONF_TOKEN] == "987654"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "expected_error"),
|
||||
[
|
||||
(TailwindConnectionError, {"base": "cannot_connect"}),
|
||||
(TailwindAuthenticationError, {CONF_TOKEN: "invalid_auth"}),
|
||||
(Exception, {"base": "unknown"}),
|
||||
],
|
||||
)
|
||||
async def test_reauth_flow_errors(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tailwind: MagicMock,
|
||||
side_effect: Exception,
|
||||
expected_error: dict[str, str],
|
||||
) -> None:
|
||||
"""Test we show form on a error."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
mock_tailwind.status.side_effect = side_effect
|
||||
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_TOKEN: "123456",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
assert result["errors"] == expected_error
|
||||
|
||||
mock_tailwind.status.side_effect = None
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_TOKEN: "123456",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reauth_successful"
|
||||
|
||||
|
||||
async def test_dhcp_discovery_updates_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test DHCP discovery updates config entries."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
assert mock_config_entry.data[CONF_HOST] == "127.0.0.127"
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_DHCP},
|
||||
data=DhcpServiceInfo(
|
||||
hostname="tailwind-3ce90e6d2184.local.",
|
||||
ip="127.0.0.1",
|
||||
macaddress="3ce90e6d2184",
|
||||
),
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert mock_config_entry.data[CONF_HOST] == "127.0.0.1"
|
||||
|
||||
|
||||
async def test_dhcp_discovery_ignores_unknown(hass: HomeAssistant) -> None:
|
||||
"""Test DHCP discovery is only used for updates.
|
||||
|
||||
Anything else will just abort the flow.
|
||||
"""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_DHCP},
|
||||
data=DhcpServiceInfo(
|
||||
hostname="tailwind-3ce90e6d2184.local.",
|
||||
ip="127.0.0.1",
|
||||
macaddress="3ce90e6d2184",
|
||||
),
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "unknown"
|
||||
209
home-assistant/tests/components/tailwind/test_cover.py
Normal file
209
home-assistant/tests/components/tailwind/test_cover.py
Normal file
@@ -0,0 +1,209 @@
|
||||
"""Tests for cover entities provided by the Tailwind integration."""
|
||||
|
||||
from unittest.mock import ANY, MagicMock
|
||||
|
||||
from gotailwind import (
|
||||
TailwindDoorAlreadyInStateError,
|
||||
TailwindDoorDisabledError,
|
||||
TailwindDoorLockedOutError,
|
||||
TailwindDoorOperationCommand,
|
||||
TailwindError,
|
||||
)
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
DOMAIN as COVER_DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
SERVICE_OPEN_COVER,
|
||||
)
|
||||
from homeassistant.components.tailwind.const import DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("init_integration")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"entity_id",
|
||||
[
|
||||
"cover.door_1",
|
||||
"cover.door_2",
|
||||
],
|
||||
)
|
||||
async def test_cover_entities(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
entity_id: str,
|
||||
) -> None:
|
||||
"""Test cover entities provided by the Tailwind integration."""
|
||||
assert (state := hass.states.get(entity_id))
|
||||
assert state == snapshot
|
||||
|
||||
assert (entity_entry := entity_registry.async_get(state.entity_id))
|
||||
assert entity_entry == snapshot
|
||||
|
||||
assert entity_entry.device_id
|
||||
assert (device_entry := device_registry.async_get(entity_entry.device_id))
|
||||
assert device_entry == snapshot
|
||||
|
||||
|
||||
async def test_cover_operations(
|
||||
hass: HomeAssistant,
|
||||
mock_tailwind: MagicMock,
|
||||
) -> None:
|
||||
"""Test operating the doors."""
|
||||
assert len(mock_tailwind.operate.mock_calls) == 0
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_OPEN_COVER,
|
||||
{
|
||||
ATTR_ENTITY_ID: "cover.door_1",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
mock_tailwind.operate.assert_called_with(
|
||||
door=ANY, operation=TailwindDoorOperationCommand.OPEN
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{
|
||||
ATTR_ENTITY_ID: "cover.door_1",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
mock_tailwind.operate.assert_called_with(
|
||||
door=ANY, operation=TailwindDoorOperationCommand.CLOSE
|
||||
)
|
||||
|
||||
# Test door disabled error handling
|
||||
mock_tailwind.operate.side_effect = TailwindDoorDisabledError("Door disabled")
|
||||
|
||||
with pytest.raises(HomeAssistantError) as excinfo:
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_OPEN_COVER,
|
||||
{
|
||||
ATTR_ENTITY_ID: "cover.door_1",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert str(excinfo.value) == "The door is disabled and cannot be operated"
|
||||
|
||||
assert excinfo.value.translation_domain == DOMAIN
|
||||
assert excinfo.value.translation_key == "door_disabled"
|
||||
|
||||
with pytest.raises(HomeAssistantError) as excinfo:
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{
|
||||
ATTR_ENTITY_ID: "cover.door_1",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert str(excinfo.value) == "The door is disabled and cannot be operated"
|
||||
assert excinfo.value.translation_domain == DOMAIN
|
||||
assert excinfo.value.translation_key == "door_disabled"
|
||||
|
||||
# Test door locked out error handling
|
||||
mock_tailwind.operate.side_effect = TailwindDoorLockedOutError("Door locked out")
|
||||
|
||||
with pytest.raises(HomeAssistantError) as excinfo:
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_OPEN_COVER,
|
||||
{
|
||||
ATTR_ENTITY_ID: "cover.door_1",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert str(excinfo.value) == "The door is locked out and cannot be operated"
|
||||
assert excinfo.value.translation_domain == DOMAIN
|
||||
assert excinfo.value.translation_key == "door_locked_out"
|
||||
|
||||
with pytest.raises(HomeAssistantError) as excinfo:
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{
|
||||
ATTR_ENTITY_ID: "cover.door_1",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert str(excinfo.value) == "The door is locked out and cannot be operated"
|
||||
assert excinfo.value.translation_domain == DOMAIN
|
||||
assert excinfo.value.translation_key == "door_locked_out"
|
||||
|
||||
# Test door error handling
|
||||
mock_tailwind.operate.side_effect = TailwindError("Some error")
|
||||
|
||||
with pytest.raises(HomeAssistantError) as excinfo:
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_OPEN_COVER,
|
||||
{
|
||||
ATTR_ENTITY_ID: "cover.door_1",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert (
|
||||
str(excinfo.value)
|
||||
== "An error occurred while communicating with the Tailwind device"
|
||||
)
|
||||
assert excinfo.value.translation_domain == DOMAIN
|
||||
assert excinfo.value.translation_key == "communication_error"
|
||||
|
||||
with pytest.raises(HomeAssistantError) as excinfo:
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{
|
||||
ATTR_ENTITY_ID: "cover.door_1",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert (
|
||||
str(excinfo.value)
|
||||
== "An error occurred while communicating with the Tailwind device"
|
||||
)
|
||||
assert excinfo.value.translation_domain == DOMAIN
|
||||
assert excinfo.value.translation_key == "communication_error"
|
||||
|
||||
# Test door already in state
|
||||
mock_tailwind.operate.side_effect = TailwindDoorAlreadyInStateError(
|
||||
"Door is already in the requested state"
|
||||
)
|
||||
|
||||
# This call should not raise an exception
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_OPEN_COVER,
|
||||
{
|
||||
ATTR_ENTITY_ID: "cover.door_1",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
# This call should not raise an exception
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{
|
||||
ATTR_ENTITY_ID: "cover.door_1",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
22
home-assistant/tests/components/tailwind/test_diagnostics.py
Normal file
22
home-assistant/tests/components/tailwind/test_diagnostics.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""Tests for diagnostics provided by the Tailwind integration."""
|
||||
|
||||
from syrupy.assertion 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
|
||||
)
|
||||
74
home-assistant/tests/components/tailwind/test_init.py
Normal file
74
home-assistant/tests/components/tailwind/test_init.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""Integration tests for the Tailwind integration."""
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from gotailwind import TailwindAuthenticationError, TailwindConnectionError
|
||||
|
||||
from homeassistant.components.tailwind.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_load_unload_config_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tailwind: MagicMock,
|
||||
) -> None:
|
||||
"""Test the Tailwind configuration entry loading/unloading."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
assert len(mock_tailwind.status.mock_calls) == 1
|
||||
|
||||
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert not hass.data.get(DOMAIN)
|
||||
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
|
||||
async def test_config_entry_not_ready(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tailwind: MagicMock,
|
||||
) -> None:
|
||||
"""Test the Tailwind configuration entry not ready."""
|
||||
mock_tailwind.status.side_effect = TailwindConnectionError
|
||||
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_tailwind.status.mock_calls) == 1
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_config_entry_authentication_failed(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_tailwind: MagicMock,
|
||||
) -> None:
|
||||
"""Test trigger reauthentication flow."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
mock_tailwind.status.side_effect = TailwindAuthenticationError
|
||||
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
flows = hass.config_entries.flow.async_progress()
|
||||
assert len(flows) == 1
|
||||
|
||||
flow = flows[0]
|
||||
assert flow["step_id"] == "reauth_confirm"
|
||||
assert flow["handler"] == DOMAIN
|
||||
|
||||
assert "context" in flow
|
||||
assert flow["context"].get("source") == SOURCE_REAUTH
|
||||
assert flow["context"].get("entry_id") == mock_config_entry.entry_id
|
||||
71
home-assistant/tests/components/tailwind/test_number.py
Normal file
71
home-assistant/tests/components/tailwind/test_number.py
Normal file
@@ -0,0 +1,71 @@
|
||||
"""Tests for number entities provided by the Tailwind integration."""
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from gotailwind import TailwindError
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components import number
|
||||
from homeassistant.components.number import ATTR_VALUE, SERVICE_SET_VALUE
|
||||
from homeassistant.components.tailwind.const import DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("init_integration")
|
||||
|
||||
|
||||
async def test_number_entities(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_tailwind: MagicMock,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test number entities provided by the Tailwind integration."""
|
||||
assert (state := hass.states.get("number.tailwind_iq3_status_led_brightness"))
|
||||
assert snapshot == state
|
||||
|
||||
assert (entity_entry := entity_registry.async_get(state.entity_id))
|
||||
assert snapshot == entity_entry
|
||||
|
||||
assert entity_entry.device_id
|
||||
assert (device_entry := device_registry.async_get(entity_entry.device_id))
|
||||
assert snapshot == device_entry
|
||||
|
||||
assert len(mock_tailwind.status_led.mock_calls) == 0
|
||||
await hass.services.async_call(
|
||||
number.DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
{
|
||||
ATTR_ENTITY_ID: state.entity_id,
|
||||
ATTR_VALUE: 42,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(mock_tailwind.status_led.mock_calls) == 1
|
||||
mock_tailwind.status_led.assert_called_with(brightness=42)
|
||||
|
||||
# Test error handling
|
||||
mock_tailwind.status_led.side_effect = TailwindError("Some error")
|
||||
|
||||
with pytest.raises(HomeAssistantError) as excinfo:
|
||||
await hass.services.async_call(
|
||||
number.DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
{
|
||||
ATTR_ENTITY_ID: state.entity_id,
|
||||
ATTR_VALUE: 42,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert (
|
||||
str(excinfo.value)
|
||||
== "An error occurred while communicating with the Tailwind device"
|
||||
)
|
||||
assert excinfo.value.translation_domain == DOMAIN
|
||||
assert excinfo.value.translation_key == "communication_error"
|
||||
Reference in New Issue
Block a user