mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Cleanup add_to_hass method in Shelly tests (part 1) (#140075)
This commit is contained in:
parent
aa556d8678
commit
99b5adaef1
@ -40,13 +40,15 @@ async def init_integration(
|
|||||||
sleep_period=0,
|
sleep_period=0,
|
||||||
options: dict[str, Any] | None = None,
|
options: dict[str, Any] | None = None,
|
||||||
skip_setup: bool = False,
|
skip_setup: bool = False,
|
||||||
|
data: dict[str, Any] | None = None,
|
||||||
) -> MockConfigEntry:
|
) -> MockConfigEntry:
|
||||||
"""Set up the Shelly integration in Home Assistant."""
|
"""Set up the Shelly integration in Home Assistant."""
|
||||||
data = {
|
if data is None:
|
||||||
CONF_HOST: "192.168.1.37",
|
data = {
|
||||||
CONF_SLEEP_PERIOD: sleep_period,
|
CONF_HOST: "192.168.1.37",
|
||||||
"model": model,
|
CONF_SLEEP_PERIOD: sleep_period,
|
||||||
}
|
"model": model,
|
||||||
|
}
|
||||||
if gen is not None:
|
if gen is not None:
|
||||||
data[CONF_GEN] = gen
|
data[CONF_GEN] = gen
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ from homeassistant.setup import async_setup_component
|
|||||||
|
|
||||||
from . import init_integration
|
from . import init_integration
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, async_get_device_automations
|
from tests.common import async_get_device_automations
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -162,8 +162,7 @@ async def test_get_triggers_for_invalid_device_id(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test error raised for invalid shelly device_id."""
|
"""Test error raised for invalid shelly device_id."""
|
||||||
await init_integration(hass, 1)
|
await init_integration(hass, 1)
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data={})
|
config_entry = await init_integration(hass, 1, data={}, skip_setup=True)
|
||||||
config_entry.add_to_hass(hass)
|
|
||||||
invalid_device = device_registry.async_get_or_create(
|
invalid_device = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||||
|
@ -27,16 +27,10 @@ from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
|||||||
from homeassistant.const import CONF_HOST, CONF_PORT, STATE_ON, STATE_UNAVAILABLE
|
from homeassistant.const import CONF_HOST, CONF_PORT, STATE_ON, STATE_UNAVAILABLE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import issue_registry as ir
|
from homeassistant.helpers import issue_registry as ir
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||||
CONNECTION_NETWORK_MAC,
|
|
||||||
DeviceRegistry,
|
|
||||||
format_mac,
|
|
||||||
)
|
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import MOCK_MAC, init_integration, mutate_rpc_device_status
|
from . import init_integration, mutate_rpc_device_status
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
|
||||||
|
|
||||||
|
|
||||||
async def test_custom_coap_port(
|
async def test_custom_coap_port(
|
||||||
@ -121,12 +115,6 @@ async def test_shared_device_mac(
|
|||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test first time shared device with another domain."""
|
"""Test first time shared device with another domain."""
|
||||||
config_entry = MockConfigEntry(domain="test", data={}, unique_id="some_id")
|
|
||||||
config_entry.add_to_hass(hass)
|
|
||||||
device_registry.async_get_or_create(
|
|
||||||
config_entry_id=config_entry.entry_id,
|
|
||||||
connections={(CONNECTION_NETWORK_MAC, format_mac(MOCK_MAC))},
|
|
||||||
)
|
|
||||||
await init_integration(hass, gen, sleep_period=1000)
|
await init_integration(hass, gen, sleep_period=1000)
|
||||||
assert "will resume when device is online" in caplog.text
|
assert "will resume when device is online" in caplog.text
|
||||||
|
|
||||||
@ -135,12 +123,7 @@ async def test_setup_entry_not_shelly(
|
|||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test not Shelly entry."""
|
"""Test not Shelly entry."""
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
await init_integration(hass, 1, data={})
|
||||||
entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
assert await hass.config_entries.async_setup(entry.entry_id) is False
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert "probably comes from a custom integration" in caplog.text
|
assert "probably comes from a custom integration" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
@ -247,12 +230,7 @@ async def test_sleeping_block_device_online(
|
|||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test sleeping block device online."""
|
"""Test sleeping block device online."""
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id="shelly")
|
await init_integration(hass, 1, data={})
|
||||||
config_entry.add_to_hass(hass)
|
|
||||||
device_registry.async_get_or_create(
|
|
||||||
config_entry_id=config_entry.entry_id,
|
|
||||||
connections={(CONNECTION_NETWORK_MAC, format_mac(MOCK_MAC))},
|
|
||||||
)
|
|
||||||
|
|
||||||
monkeypatch.setitem(
|
monkeypatch.setitem(
|
||||||
mock_block_device.settings,
|
mock_block_device.settings,
|
||||||
@ -498,8 +476,7 @@ async def test_entry_missing_port(hass: HomeAssistant) -> None:
|
|||||||
"model": MODEL_PLUS_2PM,
|
"model": MODEL_PLUS_2PM,
|
||||||
CONF_GEN: 2,
|
CONF_GEN: 2,
|
||||||
}
|
}
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data=data, unique_id=MOCK_MAC)
|
entry = await init_integration(hass, 2, data=data, skip_setup=True)
|
||||||
entry.add_to_hass(hass)
|
|
||||||
with (
|
with (
|
||||||
patch("homeassistant.components.shelly.RpcDevice.initialize"),
|
patch("homeassistant.components.shelly.RpcDevice.initialize"),
|
||||||
patch(
|
patch(
|
||||||
@ -523,8 +500,7 @@ async def test_rpc_entry_custom_port(hass: HomeAssistant) -> None:
|
|||||||
CONF_GEN: 2,
|
CONF_GEN: 2,
|
||||||
CONF_PORT: 8001,
|
CONF_PORT: 8001,
|
||||||
}
|
}
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data=data, unique_id=MOCK_MAC)
|
entry = await init_integration(hass, 2, data=data, skip_setup=True)
|
||||||
entry.add_to_hass(hass)
|
|
||||||
with (
|
with (
|
||||||
patch("homeassistant.components.shelly.RpcDevice.initialize"),
|
patch("homeassistant.components.shelly.RpcDevice.initialize"),
|
||||||
patch(
|
patch(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user