init home-assistant

This commit is contained in:
2026-11-19 15:15:32 -05:00
parent 2e81d9d300
commit feec6ef9fb
19230 changed files with 3335526 additions and 0 deletions

View File

@@ -0,0 +1 @@
"""Fast.com integration tests."""

View File

@@ -0,0 +1,6 @@
# serializer version: 1
# name: test_get_config_entry_diagnostics
dict({
'coordinator_data': 50.3,
})
# ---

View File

@@ -0,0 +1,55 @@
"""Test for the Fast.com config flow."""
from unittest.mock import patch
import pytest
from homeassistant.components.fastdotcom.const import DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
async def test_user_form(hass: HomeAssistant) -> None:
"""Test the full user configuration flow."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
with patch(
"homeassistant.components.fastdotcom.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Fast.com"
assert result["data"] == {}
assert result["options"] == {}
assert len(mock_setup_entry.mock_calls) == 1
@pytest.mark.parametrize("source", [SOURCE_USER, SOURCE_IMPORT])
async def test_single_instance_allowed(
hass: HomeAssistant,
source: str,
) -> None:
"""Test we abort if already setup."""
mock_config_entry = MockConfigEntry(domain=DOMAIN)
mock_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": source}
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "single_instance_allowed"

View File

@@ -0,0 +1,56 @@
"""Test the FastdotcomDataUpdateCoordindator."""
from datetime import timedelta
from unittest.mock import patch
from freezegun.api import FrozenDateTimeFactory
from homeassistant.components.fastdotcom.const import DEFAULT_NAME, DOMAIN
from homeassistant.components.fastdotcom.coordinator import DEFAULT_INTERVAL
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, async_fire_time_changed
async def test_fastdotcom_data_update_coordinator(
hass: HomeAssistant, freezer: FrozenDateTimeFactory
) -> None:
"""Test the update coordinator."""
config_entry = MockConfigEntry(
domain=DOMAIN,
unique_id="UNIQUE_TEST_ID",
title=DEFAULT_NAME,
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=5.0
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get("sensor.fast_com_download")
assert state is not None
assert state.state == "5.0"
with patch(
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=10.0
):
freezer.tick(timedelta(hours=DEFAULT_INTERVAL))
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get("sensor.fast_com_download")
assert state.state == "10.0"
with patch(
"homeassistant.components.fastdotcom.coordinator.fast_com",
side_effect=Exception("Test error"),
):
freezer.tick(timedelta(hours=DEFAULT_INTERVAL))
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get("sensor.fast_com_download")
assert state.state is STATE_UNAVAILABLE

View File

@@ -0,0 +1,43 @@
"""Test the Fast.com component diagnostics."""
from unittest.mock import patch
from syrupy import SnapshotAssertion
from homeassistant.components.fastdotcom.const import DEFAULT_NAME, DOMAIN
from homeassistant.config_entries import SOURCE_USER
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_get_config_entry_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
snapshot: SnapshotAssertion,
) -> None:
"""Test if get_config_entry_diagnostics returns the correct data."""
config_entry = MockConfigEntry(
version=1,
domain=DOMAIN,
title=DEFAULT_NAME,
source=SOURCE_USER,
options={},
entry_id="TEST_ENTRY_ID",
unique_id="UNIQUE_TEST_ID",
minor_version=1,
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=50.3
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert (
await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
== snapshot
)

View File

@@ -0,0 +1,71 @@
"""Test for Sensibo component Init."""
from __future__ import annotations
from unittest.mock import patch
from freezegun.api import FrozenDateTimeFactory
from homeassistant.components.fastdotcom.const import DEFAULT_NAME, DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, STATE_UNKNOWN
from homeassistant.core import CoreState, HomeAssistant
from tests.common import MockConfigEntry
async def test_unload_entry(hass: HomeAssistant) -> None:
"""Test unload an entry."""
config_entry = MockConfigEntry(
domain=DOMAIN,
unique_id="UNIQUE_TEST_ID",
title=DEFAULT_NAME,
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=5.0
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.LOADED
assert await hass.config_entries.async_unload(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.NOT_LOADED
async def test_delayed_speedtest_during_startup(
hass: HomeAssistant, freezer: FrozenDateTimeFactory
) -> None:
"""Test delayed speedtest during startup."""
config_entry = MockConfigEntry(
domain=DOMAIN,
unique_id="UNIQUE_TEST_ID",
title=DEFAULT_NAME,
)
config_entry.add_to_hass(hass)
original_state = hass.state
hass.set_state(CoreState.starting)
with patch("homeassistant.components.fastdotcom.coordinator.fast_com"):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
hass.set_state(original_state)
assert config_entry.state is ConfigEntryState.LOADED
state = hass.states.get("sensor.fast_com_download")
# Assert state is Unknown as fast.com isn't starting until HA has started
assert state.state is STATE_UNKNOWN
with patch(
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=5.0
):
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()
state = hass.states.get("sensor.fast_com_download")
assert state is not None
assert state.state == "5.0"
assert config_entry.state is ConfigEntryState.LOADED

View File

@@ -0,0 +1,32 @@
"""Test the FastdotcomDataUpdateCoordindator."""
from unittest.mock import patch
from freezegun.api import FrozenDateTimeFactory
from homeassistant.components.fastdotcom.const import DEFAULT_NAME, DOMAIN
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
async def test_fastdotcom_data_update_coordinator(
hass: HomeAssistant, freezer: FrozenDateTimeFactory
) -> None:
"""Test the update coordinator."""
config_entry = MockConfigEntry(
domain=DOMAIN,
unique_id="UNIQUE_TEST_ID",
title=DEFAULT_NAME,
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=5.0
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get("sensor.fast_com_download")
assert state is not None
assert state.state == "5.0"