Fix namespace-import pylint warning in shelly tests (#119349)

This commit is contained in:
epenet 2024-06-11 08:08:47 +02:00 committed by GitHub
parent a3ac0af56d
commit 08eb8232e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 119 additions and 133 deletions

View file

@ -20,12 +20,12 @@ from homeassistant.components.shelly.const import (
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.device_registry import (
CONNECTION_NETWORK_MAC,
DeviceRegistry,
format_mac,
)
from homeassistant.helpers.entity_registry import async_get
from tests.common import MockConfigEntry, async_fire_time_changed
@ -113,7 +113,7 @@ def register_entity(
capabilities: Mapping[str, Any] | None = None,
) -> str:
"""Register enabled entity, return entity_id."""
entity_registry = async_get(hass)
entity_registry = er.async_get(hass)
entity_registry.async_get_or_create(
domain,
DOMAIN,
@ -132,7 +132,7 @@ def get_entity(
unique_id: str,
) -> str | None:
"""Get Shelly entity."""
entity_registry = async_get(hass)
entity_registry = er.async_get(hass)
return entity_registry.async_get_entity_id(
domain, DOMAIN, f"{MOCK_MAC}-{unique_id}"
)
@ -145,9 +145,9 @@ def get_entity_state(hass: HomeAssistant, entity_id: str) -> str:
return entity.state
def register_device(device_reg: DeviceRegistry, config_entry: ConfigEntry) -> None:
def register_device(device_registry: DeviceRegistry, config_entry: ConfigEntry) -> None:
"""Register Shelly device."""
device_reg.async_get_or_create(
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(CONNECTION_NETWORK_MAC, format_mac(MOCK_MAC))},
)

View file

@ -15,7 +15,7 @@ from homeassistant.core import HomeAssistant, ServiceCall
from . import MOCK_MAC
from tests.common import async_capture_events, async_mock_service, mock_device_registry
from tests.common import async_capture_events, async_mock_service
MOCK_SETTINGS = {
"name": "Test name",
@ -286,12 +286,6 @@ def mock_ws_server():
yield
@pytest.fixture
def device_reg(hass: HomeAssistant):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
@pytest.fixture
def calls(hass: HomeAssistant) -> list[ServiceCall]:
"""Track calls to a mock service."""

View file

@ -162,12 +162,12 @@ async def test_block_sleeping_binary_sensor(
async def test_block_restored_sleeping_binary_sensor(
hass: HomeAssistant,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored sleeping binary sensor."""
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass, BINARY_SENSOR_DOMAIN, "test_name_motion", "sensor_0-motion", entry
)
@ -189,12 +189,12 @@ async def test_block_restored_sleeping_binary_sensor(
async def test_block_restored_sleeping_binary_sensor_no_last_state(
hass: HomeAssistant,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored sleeping binary sensor missing last state."""
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass, BINARY_SENSOR_DOMAIN, "test_name_motion", "sensor_0-motion", entry
)
@ -297,12 +297,12 @@ async def test_rpc_sleeping_binary_sensor(
async def test_rpc_restored_sleeping_binary_sensor(
hass: HomeAssistant,
mock_rpc_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test RPC restored binary sensor."""
entry = await init_integration(hass, 2, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass, BINARY_SENSOR_DOMAIN, "test_name_cloud", "cloud-cloud", entry
)
@ -326,12 +326,12 @@ async def test_rpc_restored_sleeping_binary_sensor(
async def test_rpc_restored_sleeping_binary_sensor_no_last_state(
hass: HomeAssistant,
mock_rpc_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test RPC restored sleeping binary sensor missing last state."""
entry = await init_integration(hass, 2, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass, BINARY_SENSOR_DOMAIN, "test_name_cloud", "cloud-cloud", entry
)

View file

@ -244,7 +244,7 @@ async def test_climate_set_preset_mode(
async def test_block_restored_climate(
hass: HomeAssistant,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored climate."""
@ -253,7 +253,7 @@ async def test_block_restored_climate(
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
monkeypatch.delattr(mock_block_device.blocks[EMETER_BLOCK_ID], "targetTemp")
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass,
CLIMATE_DOMAIN,
@ -310,7 +310,7 @@ async def test_block_restored_climate(
async def test_block_restored_climate_us_customery(
hass: HomeAssistant,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored climate with US CUSTOMATY unit system."""
@ -320,7 +320,7 @@ async def test_block_restored_climate_us_customery(
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
monkeypatch.delattr(mock_block_device.blocks[EMETER_BLOCK_ID], "targetTemp")
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass,
CLIMATE_DOMAIN,
@ -382,14 +382,14 @@ async def test_block_restored_climate_us_customery(
async def test_block_restored_climate_unavailable(
hass: HomeAssistant,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored climate unavailable state."""
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass,
CLIMATE_DOMAIN,
@ -409,14 +409,14 @@ async def test_block_restored_climate_unavailable(
async def test_block_restored_climate_set_preset_before_online(
hass: HomeAssistant,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored climate set preset before device is online."""
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass,
CLIMATE_DOMAIN,
@ -510,14 +510,14 @@ async def test_block_set_mode_auth_error(
async def test_block_restored_climate_auth_error(
hass: HomeAssistant,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored climate with authentication error during init."""
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass,
CLIMATE_DOMAIN,

View file

@ -27,14 +27,7 @@ from homeassistant.components.shelly.const import (
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
from homeassistant.const import ATTR_DEVICE_ID, STATE_ON, STATE_UNAVAILABLE
from homeassistant.core import Event, HomeAssistant, State
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers.device_registry import (
CONNECTION_NETWORK_MAC,
DeviceRegistry,
async_entries_for_config_entry,
async_get as async_get_dev_reg,
format_mac,
)
from homeassistant.helpers import device_registry as dr, issue_registry as ir
from . import (
MOCK_MAC,
@ -343,6 +336,7 @@ async def test_block_device_push_updates_failure(
async def test_block_button_click_event(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mock_block_device: Mock,
events: list[Event],
monkeypatch: pytest.MonkeyPatch,
@ -360,8 +354,7 @@ async def test_block_button_click_event(
mock_block_device.mock_online()
await hass.async_block_till_done()
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
# Generate button click event
mock_block_device.mock_update()
@ -508,6 +501,7 @@ async def test_rpc_connection_error_during_unload(
async def test_rpc_click_event(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mock_rpc_device: Mock,
events: list[Event],
monkeypatch: pytest.MonkeyPatch,
@ -515,8 +509,7 @@ async def test_rpc_click_event(
"""Test RPC click event."""
entry = await init_integration(hass, 2)
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
# Generate config change from switch to light
inject_rpc_device_event(
@ -805,21 +798,23 @@ async def test_rpc_polling_disconnected(
async def test_rpc_update_entry_fw_ver(
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mock_rpc_device: Mock,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test RPC update entry firmware version."""
monkeypatch.setitem(mock_rpc_device.status["sys"], "wakeup_period", 600)
entry = await init_integration(hass, 2, sleep_period=600)
dev_reg = async_get_dev_reg(hass)
# Make device online
mock_rpc_device.mock_online()
await hass.async_block_till_done(wait_background_tasks=True)
assert entry.unique_id
device = dev_reg.async_get_device(
device = device_registry.async_get_device(
identifiers={(DOMAIN, entry.entry_id)},
connections={(CONNECTION_NETWORK_MAC, format_mac(entry.unique_id))},
connections={(dr.CONNECTION_NETWORK_MAC, dr.format_mac(entry.unique_id))},
)
assert device
assert device.sw_version == "some fw string"
@ -829,9 +824,9 @@ async def test_rpc_update_entry_fw_ver(
mock_rpc_device.mock_update()
await hass.async_block_till_done()
device = dev_reg.async_get_device(
device = device_registry.async_get_device(
identifiers={(DOMAIN, entry.entry_id)},
connections={(CONNECTION_NETWORK_MAC, format_mac(entry.unique_id))},
connections={(dr.CONNECTION_NETWORK_MAC, dr.format_mac(entry.unique_id))},
)
assert device
assert device.sw_version == "99.0.0"
@ -859,16 +854,16 @@ async def test_rpc_runs_connected_events_when_initialized(
async def test_block_sleeping_device_connection_error(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
freezer: FrozenDateTimeFactory,
mock_block_device: Mock,
device_reg: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test block sleeping device connection error during initialize."""
sleep_period = 1000
entry = await init_integration(hass, 1, sleep_period=sleep_period, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass, BINARY_SENSOR_DOMAIN, "test_name_motion", "sensor_0-motion", entry
)
@ -904,16 +899,16 @@ async def test_block_sleeping_device_connection_error(
async def test_rpc_sleeping_device_connection_error(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
freezer: FrozenDateTimeFactory,
mock_rpc_device: Mock,
device_reg: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test RPC sleeping device connection error during initialize."""
sleep_period = 1000
entry = await init_integration(hass, 2, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass, BINARY_SENSOR_DOMAIN, "test_name_cloud", "cloud-cloud", entry
)

View file

@ -20,12 +20,7 @@ from homeassistant.components.shelly.const import (
)
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers.device_registry import (
CONNECTION_NETWORK_MAC,
DeviceRegistry,
async_entries_for_config_entry,
async_get as async_get_dev_reg,
)
from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component
from . import init_integration
@ -44,6 +39,7 @@ from tests.common import MockConfigEntry, async_get_device_automations
)
async def test_get_triggers_block_device(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mock_block_device: Mock,
monkeypatch: pytest.MonkeyPatch,
button_type: str,
@ -59,8 +55,7 @@ async def test_get_triggers_block_device(
],
)
entry = await init_integration(hass, 1)
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
expected_triggers = []
if is_valid:
@ -84,12 +79,11 @@ async def test_get_triggers_block_device(
async def test_get_triggers_rpc_device(
hass: HomeAssistant, mock_rpc_device: Mock
hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_rpc_device: Mock
) -> None:
"""Test we get the expected triggers from a shelly RPC device."""
entry = await init_integration(hass, 2)
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
expected_triggers = [
{
@ -118,12 +112,11 @@ async def test_get_triggers_rpc_device(
async def test_get_triggers_button(
hass: HomeAssistant, mock_block_device: Mock
hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_block_device: Mock
) -> None:
"""Test we get the expected triggers from a shelly button."""
entry = await init_integration(hass, 1, model=MODEL_BUTTON1)
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
expected_triggers = [
{
@ -145,13 +138,15 @@ async def test_get_triggers_button(
async def test_get_triggers_non_initialized_devices(
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mock_block_device: Mock,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test we get the empty triggers for non-initialized devices."""
monkeypatch.setattr(mock_block_device, "initialized", False)
entry = await init_integration(hass, 1)
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
expected_triggers = []
@ -163,15 +158,15 @@ async def test_get_triggers_non_initialized_devices(
async def test_get_triggers_for_invalid_device_id(
hass: HomeAssistant, device_reg: DeviceRegistry, mock_block_device: Mock
hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_block_device: Mock
) -> None:
"""Test error raised for invalid shelly device_id."""
await init_integration(hass, 1)
config_entry = MockConfigEntry(domain=DOMAIN, data={})
config_entry.add_to_hass(hass)
invalid_device = device_reg.async_get_or_create(
invalid_device = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
with pytest.raises(InvalidDeviceAutomationConfig):
@ -181,12 +176,14 @@ async def test_get_triggers_for_invalid_device_id(
async def test_if_fires_on_click_event_block_device(
hass: HomeAssistant, calls: list[ServiceCall], mock_block_device: Mock
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
calls: list[ServiceCall],
mock_block_device: Mock,
) -> None:
"""Test for click_event trigger firing for block device."""
entry = await init_integration(hass, 1)
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
assert await async_setup_component(
hass,
@ -223,12 +220,14 @@ async def test_if_fires_on_click_event_block_device(
async def test_if_fires_on_click_event_rpc_device(
hass: HomeAssistant, calls: list[ServiceCall], mock_rpc_device: Mock
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
calls: list[ServiceCall],
mock_rpc_device: Mock,
) -> None:
"""Test for click_event trigger firing for rpc device."""
entry = await init_integration(hass, 2)
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
assert await async_setup_component(
hass,
@ -266,6 +265,7 @@ async def test_if_fires_on_click_event_rpc_device(
async def test_validate_trigger_block_device_not_ready(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
calls: list[ServiceCall],
mock_block_device: Mock,
monkeypatch: pytest.MonkeyPatch,
@ -273,8 +273,7 @@ async def test_validate_trigger_block_device_not_ready(
"""Test validate trigger config when block device is not ready."""
monkeypatch.setattr(mock_block_device, "initialized", False)
entry = await init_integration(hass, 1)
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
assert await async_setup_component(
hass,
@ -311,6 +310,7 @@ async def test_validate_trigger_block_device_not_ready(
async def test_validate_trigger_rpc_device_not_ready(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
calls: list[ServiceCall],
mock_rpc_device: Mock,
monkeypatch: pytest.MonkeyPatch,
@ -318,8 +318,7 @@ async def test_validate_trigger_rpc_device_not_ready(
"""Test validate trigger config when RPC device is not ready."""
monkeypatch.setattr(mock_rpc_device, "initialized", False)
entry = await init_integration(hass, 2)
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
assert await async_setup_component(
hass,
@ -355,12 +354,14 @@ async def test_validate_trigger_rpc_device_not_ready(
async def test_validate_trigger_invalid_triggers(
hass: HomeAssistant, mock_block_device: Mock, caplog: pytest.LogCaptureFixture
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mock_block_device: Mock,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test for click_event with invalid triggers."""
entry = await init_integration(hass, 1)
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
assert await async_setup_component(
hass,
@ -389,6 +390,7 @@ async def test_validate_trigger_invalid_triggers(
async def test_rpc_no_runtime_data(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
calls: list[ServiceCall],
mock_rpc_device: Mock,
monkeypatch: pytest.MonkeyPatch,
@ -396,8 +398,7 @@ async def test_rpc_no_runtime_data(
"""Test the device trigger for the RPC device when there is no runtime_data in the entry."""
entry = await init_integration(hass, 2)
monkeypatch.delattr(entry, "runtime_data")
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
assert await async_setup_component(
hass,
@ -434,6 +435,7 @@ async def test_rpc_no_runtime_data(
async def test_block_no_runtime_data(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
calls: list[ServiceCall],
mock_block_device: Mock,
monkeypatch: pytest.MonkeyPatch,
@ -441,8 +443,7 @@ async def test_block_no_runtime_data(
"""Test the device trigger for the block device when there is no runtime_data in the entry."""
entry = await init_integration(hass, 1)
monkeypatch.delattr(entry, "runtime_data")
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
assert await async_setup_component(
hass,

View file

@ -117,13 +117,13 @@ async def test_shared_device_mac(
gen: int,
mock_block_device: Mock,
mock_rpc_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
caplog: pytest.LogCaptureFixture,
) -> None:
"""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_reg.async_get_or_create(
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(CONNECTION_NETWORK_MAC, format_mac(MOCK_MAC))},
)
@ -243,13 +243,13 @@ async def test_sleeping_block_device_online(
device_sleep: int,
mock_block_device: Mock,
monkeypatch: pytest.MonkeyPatch,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test sleeping block device online."""
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id="shelly")
config_entry.add_to_hass(hass)
device_reg.async_get_or_create(
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(CONNECTION_NETWORK_MAC, format_mac(MOCK_MAC))},
)

View file

@ -11,10 +11,7 @@ from homeassistant.components.shelly.const import (
)
from homeassistant.const import ATTR_DEVICE_ID
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import (
async_entries_for_config_entry,
async_get as async_get_dev_reg,
)
from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component
from . import init_integration
@ -23,12 +20,11 @@ from tests.components.logbook.common import MockRow, mock_humanify
async def test_humanify_shelly_click_event_block_device(
hass: HomeAssistant, mock_block_device: Mock
hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_block_device: Mock
) -> None:
"""Test humanifying Shelly click event for block device."""
entry = await init_integration(hass, 1)
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
hass.config.components.add("recorder")
assert await async_setup_component(hass, "logbook", {})
@ -74,12 +70,11 @@ async def test_humanify_shelly_click_event_block_device(
async def test_humanify_shelly_click_event_rpc_device(
hass: HomeAssistant, mock_rpc_device: Mock
hass: HomeAssistant, device_registry: dr.DeviceRegistry, mock_rpc_device: Mock
) -> None:
"""Test humanifying Shelly click event for rpc device."""
entry = await init_integration(hass, 2)
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
hass.config.components.add("recorder")
assert await async_setup_component(hass, "logbook", {})

View file

@ -61,12 +61,12 @@ async def test_block_number_update(
async def test_block_restored_number(
hass: HomeAssistant,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored number."""
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
capabilities = {
"min": 0,
"max": 100,
@ -107,12 +107,12 @@ async def test_block_restored_number(
async def test_block_restored_number_no_last_state(
hass: HomeAssistant,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored number missing last state."""
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
capabilities = {
"min": 0,
"max": 100,

View file

@ -28,7 +28,7 @@ from homeassistant.const import (
)
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.device_registry import DeviceRegistry
from homeassistant.helpers.entity_registry import EntityRegistry, async_get
from homeassistant.helpers.entity_registry import EntityRegistry
from homeassistant.setup import async_setup_component
from . import (
@ -182,12 +182,12 @@ async def test_block_sleeping_sensor(
async def test_block_restored_sleeping_sensor(
hass: HomeAssistant,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored sleeping sensor."""
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass, SENSOR_DOMAIN, "test_name_temperature", "sensor_0-temp", entry
)
@ -215,12 +215,12 @@ async def test_block_restored_sleeping_sensor(
async def test_block_restored_sleeping_sensor_no_last_state(
hass: HomeAssistant,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored sleeping sensor missing last state."""
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass, SENSOR_DOMAIN, "test_name_temperature", "sensor_0-temp", entry
)
@ -282,12 +282,12 @@ async def test_block_sensor_removal(
async def test_block_not_matched_restored_sleeping_sensor(
hass: HomeAssistant,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block not matched to restored sleeping sensor."""
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass, SENSOR_DOMAIN, "test_name_temperature", "sensor_0-temp", entry
)
@ -443,7 +443,7 @@ async def test_rpc_polling_sensor(
async def test_rpc_sleeping_sensor(
hass: HomeAssistant,
mock_rpc_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test RPC online sleeping sensor."""
@ -477,12 +477,12 @@ async def test_rpc_sleeping_sensor(
async def test_rpc_restored_sleeping_sensor(
hass: HomeAssistant,
mock_rpc_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test RPC restored sensor."""
entry = await init_integration(hass, 2, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass,
SENSOR_DOMAIN,
@ -515,12 +515,12 @@ async def test_rpc_restored_sleeping_sensor(
async def test_rpc_restored_sleeping_sensor_no_last_state(
hass: HomeAssistant,
mock_rpc_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test RPC restored sensor missing last state."""
entry = await init_integration(hass, 2, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass,
SENSOR_DOMAIN,
@ -549,16 +549,17 @@ async def test_rpc_restored_sleeping_sensor_no_last_state(
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_rpc_em1_sensors(hass: HomeAssistant, mock_rpc_device: Mock) -> None:
async def test_rpc_em1_sensors(
hass: HomeAssistant, entity_registry: EntityRegistry, mock_rpc_device: Mock
) -> None:
"""Test RPC sensors for EM1 component."""
registry = async_get(hass)
await init_integration(hass, 2)
state = hass.states.get("sensor.test_name_em0_power")
assert state
assert state.state == "85.3"
entry = registry.async_get("sensor.test_name_em0_power")
entry = entity_registry.async_get("sensor.test_name_em0_power")
assert entry
assert entry.unique_id == "123456789ABC-em1:0-power_em1"
@ -566,7 +567,7 @@ async def test_rpc_em1_sensors(hass: HomeAssistant, mock_rpc_device: Mock) -> No
assert state
assert state.state == "123.3"
entry = registry.async_get("sensor.test_name_em1_power")
entry = entity_registry.async_get("sensor.test_name_em1_power")
assert entry
assert entry.unique_id == "123456789ABC-em1:1-power_em1"
@ -574,7 +575,7 @@ async def test_rpc_em1_sensors(hass: HomeAssistant, mock_rpc_device: Mock) -> No
assert state
assert state.state == "123.4564"
entry = registry.async_get("sensor.test_name_em0_total_active_energy")
entry = entity_registry.async_get("sensor.test_name_em0_total_active_energy")
assert entry
assert entry.unique_id == "123456789ABC-em1data:0-total_act_energy"
@ -582,7 +583,7 @@ async def test_rpc_em1_sensors(hass: HomeAssistant, mock_rpc_device: Mock) -> No
assert state
assert state.state == "987.6543"
entry = registry.async_get("sensor.test_name_em1_total_active_energy")
entry = entity_registry.async_get("sensor.test_name_em1_total_active_energy")
assert entry
assert entry.unique_id == "123456789ABC-em1data:1-total_act_energy"

View file

@ -115,14 +115,14 @@ async def test_block_restored_motion_switch(
hass: HomeAssistant,
model: str,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored motion active switch."""
entry = await init_integration(
hass, 1, sleep_period=1000, model=model, skip_setup=True
)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass,
SWITCH_DOMAIN,
@ -151,14 +151,14 @@ async def test_block_restored_motion_switch_no_last_state(
hass: HomeAssistant,
model: str,
mock_block_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test block restored motion active switch missing last state."""
entry = await init_integration(
hass, 1, sleep_period=1000, model=model, skip_setup=True
)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass,
SWITCH_DOMAIN,

View file

@ -379,12 +379,12 @@ async def test_rpc_sleeping_update(
async def test_rpc_restored_sleeping_update(
hass: HomeAssistant,
mock_rpc_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test RPC restored update entity."""
entry = await init_integration(hass, 2, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass,
UPDATE_DOMAIN,
@ -429,7 +429,7 @@ async def test_rpc_restored_sleeping_update(
async def test_rpc_restored_sleeping_update_no_last_state(
hass: HomeAssistant,
mock_rpc_device: Mock,
device_reg: DeviceRegistry,
device_registry: DeviceRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test RPC restored update entity missing last state."""
@ -442,7 +442,7 @@ async def test_rpc_restored_sleeping_update_no_last_state(
},
)
entry = await init_integration(hass, 2, sleep_period=1000, skip_setup=True)
register_device(device_reg, entry)
register_device(device_registry, entry)
entity_id = register_entity(
hass,
UPDATE_DOMAIN,