Skip to content

Commit

Permalink
Fix ConfigType fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
pawlizio committed Jan 5, 2024
1 parent 8464b76 commit 0f0765d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
6 changes: 1 addition & 5 deletions tests/components/velux/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,4 @@ def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
@pytest.fixture(name="config_type")
def config_type(hass: HomeAssistant) -> ConfigType:
"""Create and register mock config entry."""
config_type = ConfigType(
domain=DOMAIN,
data={CONF_HOST: HOST, CONF_PASSWORD: PASSWORD},
)
return config_type
return {DOMAIN: {CONF_HOST: HOST, CONF_PASSWORD: PASSWORD}}
25 changes: 25 additions & 0 deletions tests/components/velux/test_init.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
"""Tests for the Velux component initialisation."""
from typing import cast
from unittest.mock import patch

from homeassistant.components.velux import DOMAIN
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
from homeassistant.const import CONF_HOST, CONF_PASSWORD
from homeassistant.core import HomeAssistant
from homeassistant.helpers.issue_registry import DATA_REGISTRY, IssueRegistry
from homeassistant.helpers.typing import ConfigType
from homeassistant.setup import async_setup_component

from .conftest import TestPyVLX

Expand Down Expand Up @@ -36,3 +41,23 @@ async def test_reboot_service(hass: HomeAssistant, config_entry: ConfigEntry) ->
await hass.services.async_call(DOMAIN, "reboot_gateway")
await hass.async_block_till_done()
assert pyvlx.reboot_initiated


@patch("homeassistant.components.velux.PyVLX", new=TestPyVLX)
@patch("homeassistant.components.velux.config_flow.PyVLX", new=TestPyVLX)
async def test_async_setup(hass: HomeAssistant, config_type: ConfigType) -> None:
"""Test async_setup method."""
with patch("homeassistant.components.velux.PyVLX", autospec=True) as pyvlx:
assert not hass.data.get(DOMAIN)
assert DOMAIN not in hass.config.components
assert await async_setup_component(hass=hass, domain=DOMAIN, config=config_type)
await hass.async_block_till_done()
assert DOMAIN in hass.config.components
await hass.async_block_till_done()
pyvlx.assert_called_once_with(
host=config_type[DOMAIN][CONF_HOST],
password=config_type[DOMAIN][CONF_PASSWORD],
)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
issue_registry = cast(IssueRegistry, hass.data[DATA_REGISTRY])
assert issue_registry.issues.get((DOMAIN, "deprecated_yaml"))

0 comments on commit 0f0765d

Please sign in to comment.