Use registry fixtures in tests (o-p) (#118292)

This commit is contained in:
epenet 2024-05-28 13:42:38 +02:00 committed by GitHub
parent ead0e797c1
commit 301c17cba7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 116 additions and 99 deletions

View file

@ -7,7 +7,7 @@ from homeassistant.helpers import entity_registry as er
from . import init_integration
async def test_sensors(hass: HomeAssistant) -> None:
async def test_sensors(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None:
"""Test the underlying sensors."""
printer = {
"state": {
@ -18,8 +18,6 @@ async def test_sensors(hass: HomeAssistant) -> None:
}
await init_integration(hass, "binary_sensor", printer=printer)
entity_registry = er.async_get(hass)
state = hass.states.get("binary_sensor.octoprint_printing")
assert state is not None
assert state.state == STATE_ON
@ -35,12 +33,12 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert entry.unique_id == "Printing Error-uuid"
async def test_sensors_printer_offline(hass: HomeAssistant) -> None:
async def test_sensors_printer_offline(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test the underlying sensors when the printer is offline."""
await init_integration(hass, "binary_sensor", printer=None)
entity_registry = er.async_get(hass)
state = hass.states.get("binary_sensor.octoprint_printing")
assert state is not None
assert state.state == STATE_UNAVAILABLE

View file

@ -11,7 +11,7 @@ from homeassistant.helpers import entity_registry as er
from . import init_integration
async def test_camera(hass: HomeAssistant) -> None:
async def test_camera(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None:
"""Test the underlying camera."""
with patch(
"pyoctoprintapi.OctoprintClient.get_webcam_info",
@ -26,14 +26,14 @@ async def test_camera(hass: HomeAssistant) -> None:
):
await init_integration(hass, CAMERA_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("camera.octoprint_camera")
assert entry is not None
assert entry.unique_id == "uuid"
async def test_camera_disabled(hass: HomeAssistant) -> None:
async def test_camera_disabled(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test that the camera does not load if there is not one configured."""
with patch(
"pyoctoprintapi.OctoprintClient.get_webcam_info",
@ -48,13 +48,13 @@ async def test_camera_disabled(hass: HomeAssistant) -> None:
):
await init_integration(hass, CAMERA_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("camera.octoprint_camera")
assert entry is None
async def test_no_supported_camera(hass: HomeAssistant) -> None:
async def test_no_supported_camera(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test that the camera does not load if there is not one configured."""
with patch(
"pyoctoprintapi.OctoprintClient.get_webcam_info",
@ -62,7 +62,5 @@ async def test_no_supported_camera(hass: HomeAssistant) -> None:
):
await init_integration(hass, CAMERA_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("camera.octoprint_camera")
assert entry is None

View file

@ -29,7 +29,13 @@ from tests.common import MockConfigEntry
(_patch_login_and_data_offline_device, set()),
],
)
async def test_sensors(hass: HomeAssistant, patcher, connections) -> None:
async def test_sensors(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
patcher,
connections,
) -> None:
"""Test that the sensors are setup with the expected values."""
config_entry = MockConfigEntry(
domain=DOMAIN,
@ -42,9 +48,7 @@ async def test_sensors(hass: HomeAssistant, patcher, connections) -> None:
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.LOADED
entity_registry = er.async_get(hass)
ent = entity_registry.async_get("sensor.my_generator_latest_firmware")
device_registry = dr.async_get(hass)
dev = device_registry.async_get(ent.device_id)
assert dev.connections == connections

View file

@ -80,6 +80,7 @@ async def test_update_options(
@patch("homeassistant.components.onewire.PLATFORMS", [Platform.SENSOR])
async def test_registry_cleanup(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
config_entry: ConfigEntry,
owproxy: MagicMock,
hass_ws_client: WebSocketGenerator,
@ -88,7 +89,6 @@ async def test_registry_cleanup(
assert await async_setup_component(hass, "config", {})
entry_id = config_entry.entry_id
device_registry = dr.async_get(hass)
live_id = "10.111111111111"
dead_id = "28.111111111111"

View file

@ -10,7 +10,9 @@ from homeassistant.helpers import entity_registry as er
from . import MAC, setup_onvif_integration
async def test_reboot_button(hass: HomeAssistant) -> None:
async def test_reboot_button(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test states of the Reboot button."""
await setup_onvif_integration(hass)
@ -19,8 +21,7 @@ async def test_reboot_button(hass: HomeAssistant) -> None:
assert state.state == STATE_UNKNOWN
assert state.attributes.get(ATTR_DEVICE_CLASS) == ButtonDeviceClass.RESTART
registry = er.async_get(hass)
entry = registry.async_get("button.testcamera_reboot")
entry = entity_registry.async_get("button.testcamera_reboot")
assert entry
assert entry.unique_id == f"{MAC}_reboot"
@ -42,7 +43,9 @@ async def test_reboot_button_press(hass: HomeAssistant) -> None:
devicemgmt.SystemReboot.assert_called_once()
async def test_set_dateandtime_button(hass: HomeAssistant) -> None:
async def test_set_dateandtime_button(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test states of the SetDateAndTime button."""
await setup_onvif_integration(hass)
@ -50,8 +53,7 @@ async def test_set_dateandtime_button(hass: HomeAssistant) -> None:
assert state
assert state.state == STATE_UNKNOWN
registry = er.async_get(hass)
entry = registry.async_get("button.testcamera_set_system_date_and_time")
entry = entity_registry.async_get("button.testcamera_set_system_date_and_time")
assert entry
assert entry.unique_id == f"{MAC}_setsystemdatetime"

View file

@ -673,12 +673,13 @@ async def test_option_flow(hass: HomeAssistant, option_value: bool) -> None:
}
async def test_discovered_by_dhcp_updates_host(hass: HomeAssistant) -> None:
async def test_discovered_by_dhcp_updates_host(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test dhcp updates existing host."""
config_entry, _camera, device = await setup_onvif_integration(hass)
device.profiles = device.async_get_profiles()
registry = dr.async_get(hass)
devices = dr.async_entries_for_config_entry(registry, config_entry.entry_id)
devices = dr.async_entries_for_config_entry(device_registry, config_entry.entry_id)
assert len(devices) == 1
device = devices[0]
assert device.model == "TestModel"
@ -697,13 +698,12 @@ async def test_discovered_by_dhcp_updates_host(hass: HomeAssistant) -> None:
async def test_discovered_by_dhcp_does_nothing_if_host_is_the_same(
hass: HomeAssistant,
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test dhcp update does nothing if host is the same."""
config_entry, _camera, device = await setup_onvif_integration(hass)
device.profiles = device.async_get_profiles()
registry = dr.async_get(hass)
devices = dr.async_entries_for_config_entry(registry, config_entry.entry_id)
devices = dr.async_entries_for_config_entry(device_registry, config_entry.entry_id)
assert len(devices) == 1
device = devices[0]
assert device.model == "TestModel"
@ -722,13 +722,12 @@ async def test_discovered_by_dhcp_does_nothing_if_host_is_the_same(
async def test_discovered_by_dhcp_does_not_update_if_already_loaded(
hass: HomeAssistant,
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test dhcp does not update existing host if its already loaded."""
config_entry, _camera, device = await setup_onvif_integration(hass)
device.profiles = device.async_get_profiles()
registry = dr.async_get(hass)
devices = dr.async_entries_for_config_entry(registry, config_entry.entry_id)
devices = dr.async_entries_for_config_entry(device_registry, config_entry.entry_id)
assert len(devices) == 1
device = devices[0]
assert device.model == "TestModel"

View file

@ -10,7 +10,9 @@ from homeassistant.helpers import entity_registry as er
from . import MAC, Capabilities, setup_onvif_integration
async def test_wiper_switch(hass: HomeAssistant) -> None:
async def test_wiper_switch(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test states of the Wiper switch."""
_config, _camera, device = await setup_onvif_integration(hass)
device.profiles = device.async_get_profiles()
@ -19,8 +21,7 @@ async def test_wiper_switch(hass: HomeAssistant) -> None:
assert state
assert state.state == STATE_UNKNOWN
registry = er.async_get(hass)
entry = registry.async_get("switch.testcamera_wiper")
entry = entity_registry.async_get("switch.testcamera_wiper")
assert entry
assert entry.unique_id == f"{MAC}_wiper"
@ -71,7 +72,9 @@ async def test_turn_wiper_switch_off(hass: HomeAssistant) -> None:
assert state.state == STATE_OFF
async def test_autofocus_switch(hass: HomeAssistant) -> None:
async def test_autofocus_switch(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test states of the autofocus switch."""
_config, _camera, device = await setup_onvif_integration(hass)
device.profiles = device.async_get_profiles()
@ -80,8 +83,7 @@ async def test_autofocus_switch(hass: HomeAssistant) -> None:
assert state
assert state.state == STATE_UNKNOWN
registry = er.async_get(hass)
entry = registry.async_get("switch.testcamera_autofocus")
entry = entity_registry.async_get("switch.testcamera_autofocus")
assert entry
assert entry.unique_id == f"{MAC}_autofocus"
@ -132,7 +134,9 @@ async def test_turn_autofocus_switch_off(hass: HomeAssistant) -> None:
assert state.state == STATE_OFF
async def test_infrared_switch(hass: HomeAssistant) -> None:
async def test_infrared_switch(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test states of the autofocus switch."""
_config, _camera, device = await setup_onvif_integration(hass)
device.profiles = device.async_get_profiles()
@ -141,8 +145,7 @@ async def test_infrared_switch(hass: HomeAssistant) -> None:
assert state
assert state.state == STATE_UNKNOWN
registry = er.async_get(hass)
entry = registry.async_get("switch.testcamera_ir_lamp")
entry = entity_registry.async_get("switch.testcamera_ir_lamp")
assert entry
assert entry.unique_id == f"{MAC}_ir_lamp"

View file

@ -32,7 +32,9 @@ MOCK_CONFIG_ENTRY = MockConfigEntry(
# This tests needs to be adjusted to remove lingering tasks
@pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_device_registry_insert(hass: HomeAssistant) -> None:
async def test_device_registry_insert(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test that the device registry is initialized correctly."""
MOCK_CONFIG_ENTRY.add_to_hass(hass)
@ -47,8 +49,6 @@ async def test_device_registry_insert(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
device_registry = dr.async_get(hass)
gw_dev = device_registry.async_get_device(identifiers={(DOMAIN, MOCK_GATEWAY_ID)})
assert gw_dev.sw_version == VERSION_OLD

View file

@ -30,12 +30,12 @@ from tests.common import MockConfigEntry
async def test_smartmeter(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test the P1 Monitor - SmartMeter sensors."""
entry_id = init_integration.entry_id
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get("sensor.smartmeter_power_consumption")
entry = entity_registry.async_get("sensor.smartmeter_power_consumption")
@ -87,12 +87,12 @@ async def test_smartmeter(
async def test_phases(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test the P1 Monitor - Phases sensors."""
entry_id = init_integration.entry_id
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get("sensor.phases_voltage_phase_l1")
entry = entity_registry.async_get("sensor.phases_voltage_phase_l1")
@ -144,12 +144,12 @@ async def test_phases(
async def test_settings(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test the P1 Monitor - Settings sensors."""
entry_id = init_integration.entry_id
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get("sensor.settings_energy_consumption_price_low")
entry = entity_registry.async_get("sensor.settings_energy_consumption_price_low")
@ -196,12 +196,12 @@ async def test_settings(
async def test_watermeter(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test the P1 Monitor - WaterMeter sensors."""
entry_id = init_integration.entry_id
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get("sensor.watermeter_consumption_day")
entry = entity_registry.async_get("sensor.watermeter_consumption_day")
assert entry
@ -242,11 +242,12 @@ async def test_no_watermeter(
["sensor.smartmeter_gas_consumption"],
)
async def test_smartmeter_disabled_by_default(
hass: HomeAssistant, init_integration: MockConfigEntry, entity_id: str
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
entity_id: str,
) -> None:
"""Test the P1 Monitor - SmartMeter sensors that are disabled by default."""
entity_registry = er.async_get(hass)
state = hass.states.get(entity_id)
assert state is None

View file

@ -571,7 +571,10 @@ async def test_ws_update_require_admin(
async def test_ws_delete(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
entity_registry: er.EntityRegistry,
storage_setup,
) -> None:
"""Test deleting via WS."""
manager = hass.data[DOMAIN][1]
@ -589,8 +592,7 @@ async def test_ws_delete(
assert resp["success"]
assert len(hass.states.async_entity_ids("person")) == 0
ent_reg = er.async_get(hass)
assert not ent_reg.async_is_registered("person.tracked_person")
assert not entity_registry.async_is_registered("person.tracked_person")
async def test_ws_delete_require_admin(
@ -685,11 +687,12 @@ async def test_update_person_when_user_removed(
assert storage_collection.data[person["id"]]["user_id"] is None
async def test_removing_device_tracker(hass: HomeAssistant, storage_setup) -> None:
async def test_removing_device_tracker(
hass: HomeAssistant, entity_registry: er.EntityRegistry, storage_setup
) -> None:
"""Test we automatically remove removed device trackers."""
storage_collection = hass.data[DOMAIN][1]
reg = er.async_get(hass)
entry = reg.async_get_or_create(
entry = entity_registry.async_get_or_create(
"device_tracker", "mobile_app", "bla", suggested_object_id="pixel"
)
@ -697,7 +700,7 @@ async def test_removing_device_tracker(hass: HomeAssistant, storage_setup) -> No
{"name": "Hello", "device_trackers": [entry.entity_id]}
)
reg.async_remove(entry.entity_id)
entity_registry.async_remove(entry.entity_id)
await hass.async_block_till_done()
assert storage_collection.data[person["id"]]["device_trackers"] == []

View file

@ -9,13 +9,15 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er
async def test_cleanup_orphaned_devices(
hass: HomeAssistant, entry, setup_plex_server
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
entry,
setup_plex_server,
) -> None:
"""Test cleaning up orphaned devices on startup."""
test_device_id = {(DOMAIN, "temporary_device_123")}
device_registry = dr.async_get(hass)
entity_registry = er.async_get(hass)
entry.add_to_hass(hass)
test_device = device_registry.async_get_or_create(
@ -45,6 +47,8 @@ async def test_cleanup_orphaned_devices(
async def test_migrate_transient_devices(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
entry,
setup_plex_server,
requests_mock: requests_mock.Mocker,
@ -55,8 +59,6 @@ async def test_migrate_transient_devices(
non_plexweb_device_id = {(DOMAIN, "1234567890123456-com-plexapp-android")}
plex_client_service_device_id = {(DOMAIN, "plex.tv-clients")}
device_registry = dr.async_get(hass)
entity_registry = er.async_get(hass)
entry.add_to_hass(hass)
# Pre-create devices and entities to test device migration

View file

@ -74,6 +74,7 @@ class MockPlexTVEpisode(MockPlexMedia):
async def test_library_sensor_values(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
caplog: pytest.LogCaptureFixture,
setup_plex_server,
mock_websocket,
@ -118,7 +119,6 @@ async def test_library_sensor_values(
assert hass.states.get("sensor.plex_server_1_library_tv_shows") is None
# Enable sensor and validate values
entity_registry = er.async_get(hass)
entity_registry.async_update_entity(
entity_id="sensor.plex_server_1_library_tv_shows", disabled_by=None
)

View file

@ -92,6 +92,7 @@ async def test_gateway_config_entry_not_ready(
)
async def test_migrate_unique_id_temperature(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry,
mock_smile_anna: MagicMock,
entitydata: dict,
@ -101,7 +102,6 @@ async def test_migrate_unique_id_temperature(
"""Test migration of unique_id."""
mock_config_entry.add_to_hass(hass)
entity_registry = er.async_get(hass)
entity: entity_registry.RegistryEntry = entity_registry.async_get_or_create(
**entitydata,
config_entry=mock_config_entry,
@ -144,6 +144,7 @@ async def test_migrate_unique_id_temperature(
)
async def test_migrate_unique_id_relay(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry,
mock_smile_adam: MagicMock,
entitydata: dict,
@ -153,8 +154,7 @@ async def test_migrate_unique_id_relay(
"""Test migration of unique_id."""
mock_config_entry.add_to_hass(hass)
entity_registry = er.async_get(hass)
entity: entity_registry.RegistryEntry = entity_registry.async_get_or_create(
entity: er.RegistryEntry = entity_registry.async_get_or_create(
**entitydata,
config_entry=mock_config_entry,
)

View file

@ -153,14 +153,16 @@ async def test_stretch_switch_changes(
async def test_unique_id_migration_plug_relay(
hass: HomeAssistant, mock_smile_adam: MagicMock, mock_config_entry: MockConfigEntry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_smile_adam: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test unique ID migration of -plugs to -relay."""
mock_config_entry.add_to_hass(hass)
registry = er.async_get(hass)
# Entry to migrate
registry.async_get_or_create(
entity_registry.async_get_or_create(
SWITCH_DOMAIN,
DOMAIN,
"21f2b542c49845e6bb416884c55778d6-plug",
@ -169,7 +171,7 @@ async def test_unique_id_migration_plug_relay(
disabled_by=None,
)
# Entry not needing migration
registry.async_get_or_create(
entity_registry.async_get_or_create(
SWITCH_DOMAIN,
DOMAIN,
"675416a629f343c495449970e2ca37b5-relay",
@ -184,10 +186,10 @@ async def test_unique_id_migration_plug_relay(
assert hass.states.get("switch.playstation_smart_plug") is not None
assert hass.states.get("switch.ziggo_modem") is not None
entity_entry = registry.async_get("switch.playstation_smart_plug")
entity_entry = entity_registry.async_get("switch.playstation_smart_plug")
assert entity_entry
assert entity_entry.unique_id == "21f2b542c49845e6bb416884c55778d6-relay"
entity_entry = registry.async_get("switch.ziggo_modem")
entity_entry = entity_registry.async_get("switch.ziggo_modem")
assert entity_entry
assert entity_entry.unique_id == "675416a629f343c495449970e2ca37b5-relay"

View file

@ -26,7 +26,9 @@ from tests.common import MockConfigEntry, async_fire_time_changed
async def test_sensors(
hass: HomeAssistant, entity_registry_enabled_by_default: None
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry_enabled_by_default: None,
) -> None:
"""Test creation of the sensors."""
@ -46,7 +48,6 @@ async def test_sensors(
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
device_registry = dr.async_get(hass)
reg_device = device_registry.async_get_device(
identifiers={("powerwall", MOCK_GATEWAY_DIN)},
)
@ -245,11 +246,12 @@ async def test_sensors_with_empty_meters(hass: HomeAssistant) -> None:
async def test_unique_id_migrate(
hass: HomeAssistant, entity_registry_enabled_by_default: None
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
entity_registry_enabled_by_default: None,
) -> None:
"""Test we can migrate unique ids of the sensors."""
device_registry = dr.async_get(hass)
ent_reg = er.async_get(hass)
config_entry = MockConfigEntry(domain=DOMAIN, data={CONF_IP_ADDRESS: "1.2.3.4"})
config_entry.add_to_hass(hass)
@ -261,7 +263,7 @@ async def test_unique_id_migrate(
identifiers={("powerwall", old_unique_id)},
manufacturer="Tesla",
)
old_mysite_load_power_entity = ent_reg.async_get_or_create(
old_mysite_load_power_entity = entity_registry.async_get_or_create(
"sensor",
DOMAIN,
unique_id=f"{old_unique_id}_load_instant_power",
@ -292,13 +294,13 @@ async def test_unique_id_migrate(
assert reg_device is not None
assert (
ent_reg.async_get_entity_id(
entity_registry.async_get_entity_id(
"sensor", DOMAIN, f"{old_unique_id}_load_instant_power"
)
is None
)
assert (
ent_reg.async_get_entity_id(
entity_registry.async_get_entity_id(
"sensor", DOMAIN, f"{new_unique_id}_load_instant_power"
)
is not None

View file

@ -47,11 +47,13 @@ def mock_status(request):
async def test_entity_registry(
hass: HomeAssistant, init_integration, mock_auth, mock_status
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
init_integration,
mock_auth,
mock_status,
) -> None:
"""Tests that the devices are registered in the entity registry."""
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(PROSEGUR_ALARM_ENTITY)
# Prosegur alarm device unique_id is the contract id associated to the alarm account
assert entry.unique_id == CONTRACT

View file

@ -22,12 +22,11 @@ from tests.common import MockConfigEntry
async def test_sensors(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test the Pure Energie - SmartBridge sensors."""
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get("sensor.pem_energy_consumption_total")
entry = entity_registry.async_get("sensor.pem_energy_consumption_total")
assert entry

View file

@ -275,7 +275,10 @@ async def test_options_add_sensor_duplicate(
async def test_options_remove_sensor(
hass: HomeAssistant, config_entry, setup_config_entry
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
config_entry,
setup_config_entry,
) -> None:
"""Test removing a sensor via the options flow."""
result = await hass.config_entries.options.async_init(config_entry.entry_id)
@ -288,7 +291,6 @@ async def test_options_remove_sensor(
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "remove_sensor"
device_registry = dr.async_get(hass)
device_entry = device_registry.async_get_device(
identifiers={(DOMAIN, str(TEST_SENSOR_INDEX1))}
)

View file

@ -24,11 +24,11 @@ from tests.common import MockConfigEntry
async def test_sensors(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
) -> None:
"""Test the PVOutput sensors."""
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
state = hass.states.get("sensor.frenck_s_solar_farm_energy_consumed")
entry = entity_registry.async_get("sensor.frenck_s_solar_farm_energy_consumed")

View file

@ -30,6 +30,7 @@ _MOCK_TIME_BAD_AUTH_RESPONSES = datetime(2023, 1, 8, 12, 0, tzinfo=dt_util.UTC)
async def test_config_flow(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
freezer: FrozenDateTimeFactory,
pvpc_aioclient_mock: AiohttpClientMocker,
) -> None:
@ -82,8 +83,7 @@ async def test_config_flow(
assert pvpc_aioclient_mock.call_count == 1
# Check removal
registry = er.async_get(hass)
registry_entity = registry.async_get("sensor.esios_pvpc")
registry_entity = entity_registry.async_get("sensor.esios_pvpc")
assert await hass.config_entries.async_remove(registry_entity.config_entry_id)
# and add it again with UI