mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00

* Add NASweb integration * Fix DeviceInfo import * Remove commented out code * Change class name for uniquness * Drop CoordinatorEntity inheritance * Rename class Output to more descriptive: RelaySwitch * Update required webio-api version * Implement on-the-fly addition/removal of entities * Set coordinator name matching device name * Set entities with too old status as unavailable * Drop Optional in favor of modern typing * Fix spelling of a variable * Rename commons to more fitting name: helper * Remove redundant code * Let unload fail when there is no coordinator * Fix bad docstring * Rename cord to coordinator for clarity * Remove default value for pop and let it raise exception * Drop workaround and use get_url from helper.network * Use webhook to send data from device * Deinitialize coordinator when no longer needed * Use Python formattable string * Use dataclass to store integration data in hass.data * Raise ConfigEntryNotReady when appropriate * Refactor NASwebData class * Move RelaySwitch to switch.py * Fix ConfigFlow tests * Create issues when entry fails to load * Respond when correctly received status update * Depend on webhook instead of http * Create issue when status is not received during entry set up * Make issue_id unique across integration entries * Remove unnecessary initializations * Inherit CoordinatorEntity to avoid code duplication * Optimize property access via assignment in __init__ * Use preexisting mechanism to fill schema with user input * Fix translation strings * Handle unavailable or unreachable internal url * Implement custom coordinator for push driven data updates * Move module-specific constants to respective modules * Fix requirements_all.txt * Fix CODEOWNERS file * Raise ConfigEntryError instead of issue creation * Fix entity registry import * Use HassKey as key in hass.data * Use typed ConfigEntry * Store runtime data in config entry * Rewrite to be more Pythonic * Move add/remove of switch entities to switch.py * Skip unnecessary check * Remove unnecessary type hints * Remove unnecessary nonlocal * Use a more descriptive docstring * Add docstrings to NASwebCoordinator * Fix formatting * Use correct return type * Fix tests to align with changed code * Remove commented code * Use serial number as config entry id * Catch AbortFlow exception * Update tests to check ConfigEntry Unique ID * Remove unnecessary form abort
62 lines
2.3 KiB
Python
62 lines
2.3 KiB
Python
"""Common fixtures for the NASweb tests."""
|
|
|
|
from collections.abc import Generator
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_setup_entry() -> Generator[AsyncMock]:
|
|
"""Override async_setup_entry."""
|
|
with patch(
|
|
"homeassistant.components.nasweb.async_setup_entry", return_value=True
|
|
) as mock_setup_entry:
|
|
yield mock_setup_entry
|
|
|
|
|
|
BASE_CONFIG_FLOW = "homeassistant.components.nasweb.config_flow."
|
|
BASE_NASWEB_DATA = "homeassistant.components.nasweb.nasweb_data."
|
|
BASE_COORDINATOR = "homeassistant.components.nasweb.coordinator."
|
|
TEST_SERIAL_NUMBER = "0011223344556677"
|
|
|
|
|
|
@pytest.fixture
|
|
def validate_input_all_ok() -> Generator[dict[str, AsyncMock | MagicMock]]:
|
|
"""Yield dictionary of mocked functions required for successful test_form execution."""
|
|
with (
|
|
patch(
|
|
BASE_CONFIG_FLOW + "WebioAPI.check_connection",
|
|
return_value=True,
|
|
) as check_connection,
|
|
patch(
|
|
BASE_CONFIG_FLOW + "WebioAPI.refresh_device_info",
|
|
return_value=True,
|
|
) as refresh_device_info,
|
|
patch(
|
|
BASE_NASWEB_DATA + "NASwebData.get_webhook_url",
|
|
return_value="http://127.0.0.1:8123/api/webhook/de705e77291402afa0dd961426e9f19bb53631a9f2a106c52cfd2d2266913c04",
|
|
) as get_webhook_url,
|
|
patch(
|
|
BASE_CONFIG_FLOW + "WebioAPI.get_serial_number",
|
|
return_value=TEST_SERIAL_NUMBER,
|
|
) as get_serial,
|
|
patch(
|
|
BASE_CONFIG_FLOW + "WebioAPI.status_subscription",
|
|
return_value=True,
|
|
) as status_subscription,
|
|
patch(
|
|
BASE_NASWEB_DATA + "NotificationCoordinator.check_connection",
|
|
return_value=True,
|
|
) as check_status_confirmation,
|
|
):
|
|
yield {
|
|
BASE_CONFIG_FLOW + "WebioAPI.check_connection": check_connection,
|
|
BASE_CONFIG_FLOW + "WebioAPI.refresh_device_info": refresh_device_info,
|
|
BASE_NASWEB_DATA + "NASwebData.get_webhook_url": get_webhook_url,
|
|
BASE_CONFIG_FLOW + "WebioAPI.get_serial_number": get_serial,
|
|
BASE_CONFIG_FLOW + "WebioAPI.status_subscription": status_subscription,
|
|
BASE_NASWEB_DATA
|
|
+ "NotificationCoordinator.check_connection": check_status_confirmation,
|
|
}
|