Use registry fixtures in tests (o-p) (#118292)
This commit is contained in:
parent
ead0e797c1
commit
301c17cba7
20 changed files with 116 additions and 99 deletions
|
@ -7,7 +7,7 @@ from homeassistant.helpers import entity_registry as er
|
||||||
from . import init_integration
|
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."""
|
"""Test the underlying sensors."""
|
||||||
printer = {
|
printer = {
|
||||||
"state": {
|
"state": {
|
||||||
|
@ -18,8 +18,6 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
||||||
}
|
}
|
||||||
await init_integration(hass, "binary_sensor", printer=printer)
|
await init_integration(hass, "binary_sensor", printer=printer)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
state = hass.states.get("binary_sensor.octoprint_printing")
|
state = hass.states.get("binary_sensor.octoprint_printing")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
|
@ -35,12 +33,12 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
||||||
assert entry.unique_id == "Printing Error-uuid"
|
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."""
|
"""Test the underlying sensors when the printer is offline."""
|
||||||
await init_integration(hass, "binary_sensor", printer=None)
|
await init_integration(hass, "binary_sensor", printer=None)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
state = hass.states.get("binary_sensor.octoprint_printing")
|
state = hass.states.get("binary_sensor.octoprint_printing")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant.helpers import entity_registry as er
|
||||||
from . import init_integration
|
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."""
|
"""Test the underlying camera."""
|
||||||
with patch(
|
with patch(
|
||||||
"pyoctoprintapi.OctoprintClient.get_webcam_info",
|
"pyoctoprintapi.OctoprintClient.get_webcam_info",
|
||||||
|
@ -26,14 +26,14 @@ async def test_camera(hass: HomeAssistant) -> None:
|
||||||
):
|
):
|
||||||
await init_integration(hass, CAMERA_DOMAIN)
|
await init_integration(hass, CAMERA_DOMAIN)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
entry = entity_registry.async_get("camera.octoprint_camera")
|
entry = entity_registry.async_get("camera.octoprint_camera")
|
||||||
assert entry is not None
|
assert entry is not None
|
||||||
assert entry.unique_id == "uuid"
|
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."""
|
"""Test that the camera does not load if there is not one configured."""
|
||||||
with patch(
|
with patch(
|
||||||
"pyoctoprintapi.OctoprintClient.get_webcam_info",
|
"pyoctoprintapi.OctoprintClient.get_webcam_info",
|
||||||
|
@ -48,13 +48,13 @@ async def test_camera_disabled(hass: HomeAssistant) -> None:
|
||||||
):
|
):
|
||||||
await init_integration(hass, CAMERA_DOMAIN)
|
await init_integration(hass, CAMERA_DOMAIN)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
entry = entity_registry.async_get("camera.octoprint_camera")
|
entry = entity_registry.async_get("camera.octoprint_camera")
|
||||||
assert entry is None
|
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."""
|
"""Test that the camera does not load if there is not one configured."""
|
||||||
with patch(
|
with patch(
|
||||||
"pyoctoprintapi.OctoprintClient.get_webcam_info",
|
"pyoctoprintapi.OctoprintClient.get_webcam_info",
|
||||||
|
@ -62,7 +62,5 @@ async def test_no_supported_camera(hass: HomeAssistant) -> None:
|
||||||
):
|
):
|
||||||
await init_integration(hass, CAMERA_DOMAIN)
|
await init_integration(hass, CAMERA_DOMAIN)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
entry = entity_registry.async_get("camera.octoprint_camera")
|
entry = entity_registry.async_get("camera.octoprint_camera")
|
||||||
assert entry is None
|
assert entry is None
|
||||||
|
|
|
@ -29,7 +29,13 @@ from tests.common import MockConfigEntry
|
||||||
(_patch_login_and_data_offline_device, set()),
|
(_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."""
|
"""Test that the sensors are setup with the expected values."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -42,9 +48,7 @@ async def test_sensors(hass: HomeAssistant, patcher, connections) -> None:
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert config_entry.state is ConfigEntryState.LOADED
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
ent = entity_registry.async_get("sensor.my_generator_latest_firmware")
|
ent = entity_registry.async_get("sensor.my_generator_latest_firmware")
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
dev = device_registry.async_get(ent.device_id)
|
dev = device_registry.async_get(ent.device_id)
|
||||||
assert dev.connections == connections
|
assert dev.connections == connections
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,7 @@ async def test_update_options(
|
||||||
@patch("homeassistant.components.onewire.PLATFORMS", [Platform.SENSOR])
|
@patch("homeassistant.components.onewire.PLATFORMS", [Platform.SENSOR])
|
||||||
async def test_registry_cleanup(
|
async def test_registry_cleanup(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
owproxy: MagicMock,
|
owproxy: MagicMock,
|
||||||
hass_ws_client: WebSocketGenerator,
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
@ -88,7 +89,6 @@ async def test_registry_cleanup(
|
||||||
assert await async_setup_component(hass, "config", {})
|
assert await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
entry_id = config_entry.entry_id
|
entry_id = config_entry.entry_id
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
live_id = "10.111111111111"
|
live_id = "10.111111111111"
|
||||||
dead_id = "28.111111111111"
|
dead_id = "28.111111111111"
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,9 @@ from homeassistant.helpers import entity_registry as er
|
||||||
from . import MAC, setup_onvif_integration
|
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."""
|
"""Test states of the Reboot button."""
|
||||||
await setup_onvif_integration(hass)
|
await setup_onvif_integration(hass)
|
||||||
|
|
||||||
|
@ -19,8 +21,7 @@ async def test_reboot_button(hass: HomeAssistant) -> None:
|
||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == STATE_UNKNOWN
|
||||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == ButtonDeviceClass.RESTART
|
assert state.attributes.get(ATTR_DEVICE_CLASS) == ButtonDeviceClass.RESTART
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entry = entity_registry.async_get("button.testcamera_reboot")
|
||||||
entry = registry.async_get("button.testcamera_reboot")
|
|
||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == f"{MAC}_reboot"
|
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()
|
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."""
|
"""Test states of the SetDateAndTime button."""
|
||||||
await setup_onvif_integration(hass)
|
await setup_onvif_integration(hass)
|
||||||
|
|
||||||
|
@ -50,8 +53,7 @@ async def test_set_dateandtime_button(hass: HomeAssistant) -> None:
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entry = entity_registry.async_get("button.testcamera_set_system_date_and_time")
|
||||||
entry = registry.async_get("button.testcamera_set_system_date_and_time")
|
|
||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == f"{MAC}_setsystemdatetime"
|
assert entry.unique_id == f"{MAC}_setsystemdatetime"
|
||||||
|
|
||||||
|
|
|
@ -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."""
|
"""Test dhcp updates existing host."""
|
||||||
config_entry, _camera, device = await setup_onvif_integration(hass)
|
config_entry, _camera, device = await setup_onvif_integration(hass)
|
||||||
device.profiles = device.async_get_profiles()
|
device.profiles = device.async_get_profiles()
|
||||||
registry = dr.async_get(hass)
|
devices = dr.async_entries_for_config_entry(device_registry, config_entry.entry_id)
|
||||||
devices = dr.async_entries_for_config_entry(registry, config_entry.entry_id)
|
|
||||||
assert len(devices) == 1
|
assert len(devices) == 1
|
||||||
device = devices[0]
|
device = devices[0]
|
||||||
assert device.model == "TestModel"
|
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(
|
async def test_discovered_by_dhcp_does_nothing_if_host_is_the_same(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant, device_registry: dr.DeviceRegistry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test dhcp update does nothing if host is the same."""
|
"""Test dhcp update does nothing if host is the same."""
|
||||||
config_entry, _camera, device = await setup_onvif_integration(hass)
|
config_entry, _camera, device = await setup_onvif_integration(hass)
|
||||||
device.profiles = device.async_get_profiles()
|
device.profiles = device.async_get_profiles()
|
||||||
registry = dr.async_get(hass)
|
devices = dr.async_entries_for_config_entry(device_registry, config_entry.entry_id)
|
||||||
devices = dr.async_entries_for_config_entry(registry, config_entry.entry_id)
|
|
||||||
assert len(devices) == 1
|
assert len(devices) == 1
|
||||||
device = devices[0]
|
device = devices[0]
|
||||||
assert device.model == "TestModel"
|
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(
|
async def test_discovered_by_dhcp_does_not_update_if_already_loaded(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant, device_registry: dr.DeviceRegistry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test dhcp does not update existing host if its already loaded."""
|
"""Test dhcp does not update existing host if its already loaded."""
|
||||||
config_entry, _camera, device = await setup_onvif_integration(hass)
|
config_entry, _camera, device = await setup_onvif_integration(hass)
|
||||||
device.profiles = device.async_get_profiles()
|
device.profiles = device.async_get_profiles()
|
||||||
registry = dr.async_get(hass)
|
devices = dr.async_entries_for_config_entry(device_registry, config_entry.entry_id)
|
||||||
devices = dr.async_entries_for_config_entry(registry, config_entry.entry_id)
|
|
||||||
assert len(devices) == 1
|
assert len(devices) == 1
|
||||||
device = devices[0]
|
device = devices[0]
|
||||||
assert device.model == "TestModel"
|
assert device.model == "TestModel"
|
||||||
|
|
|
@ -10,7 +10,9 @@ from homeassistant.helpers import entity_registry as er
|
||||||
from . import MAC, Capabilities, setup_onvif_integration
|
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."""
|
"""Test states of the Wiper switch."""
|
||||||
_config, _camera, device = await setup_onvif_integration(hass)
|
_config, _camera, device = await setup_onvif_integration(hass)
|
||||||
device.profiles = device.async_get_profiles()
|
device.profiles = device.async_get_profiles()
|
||||||
|
@ -19,8 +21,7 @@ async def test_wiper_switch(hass: HomeAssistant) -> None:
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entry = entity_registry.async_get("switch.testcamera_wiper")
|
||||||
entry = registry.async_get("switch.testcamera_wiper")
|
|
||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == f"{MAC}_wiper"
|
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
|
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."""
|
"""Test states of the autofocus switch."""
|
||||||
_config, _camera, device = await setup_onvif_integration(hass)
|
_config, _camera, device = await setup_onvif_integration(hass)
|
||||||
device.profiles = device.async_get_profiles()
|
device.profiles = device.async_get_profiles()
|
||||||
|
@ -80,8 +83,7 @@ async def test_autofocus_switch(hass: HomeAssistant) -> None:
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entry = entity_registry.async_get("switch.testcamera_autofocus")
|
||||||
entry = registry.async_get("switch.testcamera_autofocus")
|
|
||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == f"{MAC}_autofocus"
|
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
|
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."""
|
"""Test states of the autofocus switch."""
|
||||||
_config, _camera, device = await setup_onvif_integration(hass)
|
_config, _camera, device = await setup_onvif_integration(hass)
|
||||||
device.profiles = device.async_get_profiles()
|
device.profiles = device.async_get_profiles()
|
||||||
|
@ -141,8 +145,7 @@ async def test_infrared_switch(hass: HomeAssistant) -> None:
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
entry = entity_registry.async_get("switch.testcamera_ir_lamp")
|
||||||
entry = registry.async_get("switch.testcamera_ir_lamp")
|
|
||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == f"{MAC}_ir_lamp"
|
assert entry.unique_id == f"{MAC}_ir_lamp"
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,9 @@ MOCK_CONFIG_ENTRY = MockConfigEntry(
|
||||||
|
|
||||||
# This tests needs to be adjusted to remove lingering tasks
|
# This tests needs to be adjusted to remove lingering tasks
|
||||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
@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."""
|
"""Test that the device registry is initialized correctly."""
|
||||||
MOCK_CONFIG_ENTRY.add_to_hass(hass)
|
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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
gw_dev = device_registry.async_get_device(identifiers={(DOMAIN, MOCK_GATEWAY_ID)})
|
gw_dev = device_registry.async_get_device(identifiers={(DOMAIN, MOCK_GATEWAY_ID)})
|
||||||
assert gw_dev.sw_version == VERSION_OLD
|
assert gw_dev.sw_version == VERSION_OLD
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,12 @@ from tests.common import MockConfigEntry
|
||||||
|
|
||||||
async def test_smartmeter(
|
async def test_smartmeter(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the P1 Monitor - SmartMeter sensors."""
|
"""Test the P1 Monitor - SmartMeter sensors."""
|
||||||
entry_id = init_integration.entry_id
|
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")
|
state = hass.states.get("sensor.smartmeter_power_consumption")
|
||||||
entry = entity_registry.async_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(
|
async def test_phases(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the P1 Monitor - Phases sensors."""
|
"""Test the P1 Monitor - Phases sensors."""
|
||||||
entry_id = init_integration.entry_id
|
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")
|
state = hass.states.get("sensor.phases_voltage_phase_l1")
|
||||||
entry = entity_registry.async_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(
|
async def test_settings(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the P1 Monitor - Settings sensors."""
|
"""Test the P1 Monitor - Settings sensors."""
|
||||||
entry_id = init_integration.entry_id
|
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")
|
state = hass.states.get("sensor.settings_energy_consumption_price_low")
|
||||||
entry = entity_registry.async_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(
|
async def test_watermeter(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the P1 Monitor - WaterMeter sensors."""
|
"""Test the P1 Monitor - WaterMeter sensors."""
|
||||||
entry_id = init_integration.entry_id
|
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")
|
state = hass.states.get("sensor.watermeter_consumption_day")
|
||||||
entry = entity_registry.async_get("sensor.watermeter_consumption_day")
|
entry = entity_registry.async_get("sensor.watermeter_consumption_day")
|
||||||
assert entry
|
assert entry
|
||||||
|
@ -242,11 +242,12 @@ async def test_no_watermeter(
|
||||||
["sensor.smartmeter_gas_consumption"],
|
["sensor.smartmeter_gas_consumption"],
|
||||||
)
|
)
|
||||||
async def test_smartmeter_disabled_by_default(
|
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:
|
) -> None:
|
||||||
"""Test the P1 Monitor - SmartMeter sensors that are disabled by default."""
|
"""Test the P1 Monitor - SmartMeter sensors that are disabled by default."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state is None
|
assert state is None
|
||||||
|
|
||||||
|
|
|
@ -571,7 +571,10 @@ async def test_ws_update_require_admin(
|
||||||
|
|
||||||
|
|
||||||
async def test_ws_delete(
|
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:
|
) -> None:
|
||||||
"""Test deleting via WS."""
|
"""Test deleting via WS."""
|
||||||
manager = hass.data[DOMAIN][1]
|
manager = hass.data[DOMAIN][1]
|
||||||
|
@ -589,8 +592,7 @@ async def test_ws_delete(
|
||||||
|
|
||||||
assert resp["success"]
|
assert resp["success"]
|
||||||
assert len(hass.states.async_entity_ids("person")) == 0
|
assert len(hass.states.async_entity_ids("person")) == 0
|
||||||
ent_reg = er.async_get(hass)
|
assert not entity_registry.async_is_registered("person.tracked_person")
|
||||||
assert not ent_reg.async_is_registered("person.tracked_person")
|
|
||||||
|
|
||||||
|
|
||||||
async def test_ws_delete_require_admin(
|
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
|
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."""
|
"""Test we automatically remove removed device trackers."""
|
||||||
storage_collection = hass.data[DOMAIN][1]
|
storage_collection = hass.data[DOMAIN][1]
|
||||||
reg = er.async_get(hass)
|
entry = entity_registry.async_get_or_create(
|
||||||
entry = reg.async_get_or_create(
|
|
||||||
"device_tracker", "mobile_app", "bla", suggested_object_id="pixel"
|
"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]}
|
{"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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert storage_collection.data[person["id"]]["device_trackers"] == []
|
assert storage_collection.data[person["id"]]["device_trackers"] == []
|
||||||
|
|
|
@ -9,13 +9,15 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
|
|
||||||
|
|
||||||
async def test_cleanup_orphaned_devices(
|
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:
|
) -> None:
|
||||||
"""Test cleaning up orphaned devices on startup."""
|
"""Test cleaning up orphaned devices on startup."""
|
||||||
test_device_id = {(DOMAIN, "temporary_device_123")}
|
test_device_id = {(DOMAIN, "temporary_device_123")}
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
test_device = device_registry.async_get_or_create(
|
test_device = device_registry.async_get_or_create(
|
||||||
|
@ -45,6 +47,8 @@ async def test_cleanup_orphaned_devices(
|
||||||
|
|
||||||
async def test_migrate_transient_devices(
|
async def test_migrate_transient_devices(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
entry,
|
entry,
|
||||||
setup_plex_server,
|
setup_plex_server,
|
||||||
requests_mock: requests_mock.Mocker,
|
requests_mock: requests_mock.Mocker,
|
||||||
|
@ -55,8 +59,6 @@ async def test_migrate_transient_devices(
|
||||||
non_plexweb_device_id = {(DOMAIN, "1234567890123456-com-plexapp-android")}
|
non_plexweb_device_id = {(DOMAIN, "1234567890123456-com-plexapp-android")}
|
||||||
plex_client_service_device_id = {(DOMAIN, "plex.tv-clients")}
|
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)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
# Pre-create devices and entities to test device migration
|
# Pre-create devices and entities to test device migration
|
||||||
|
|
|
@ -74,6 +74,7 @@ class MockPlexTVEpisode(MockPlexMedia):
|
||||||
|
|
||||||
async def test_library_sensor_values(
|
async def test_library_sensor_values(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
setup_plex_server,
|
setup_plex_server,
|
||||||
mock_websocket,
|
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
|
assert hass.states.get("sensor.plex_server_1_library_tv_shows") is None
|
||||||
|
|
||||||
# Enable sensor and validate values
|
# Enable sensor and validate values
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
entity_registry.async_update_entity(
|
entity_registry.async_update_entity(
|
||||||
entity_id="sensor.plex_server_1_library_tv_shows", disabled_by=None
|
entity_id="sensor.plex_server_1_library_tv_shows", disabled_by=None
|
||||||
)
|
)
|
||||||
|
|
|
@ -92,6 +92,7 @@ async def test_gateway_config_entry_not_ready(
|
||||||
)
|
)
|
||||||
async def test_migrate_unique_id_temperature(
|
async def test_migrate_unique_id_temperature(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
mock_smile_anna: MagicMock,
|
mock_smile_anna: MagicMock,
|
||||||
entitydata: dict,
|
entitydata: dict,
|
||||||
|
@ -101,7 +102,6 @@ async def test_migrate_unique_id_temperature(
|
||||||
"""Test migration of unique_id."""
|
"""Test migration of unique_id."""
|
||||||
mock_config_entry.add_to_hass(hass)
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
entity: entity_registry.RegistryEntry = entity_registry.async_get_or_create(
|
entity: entity_registry.RegistryEntry = entity_registry.async_get_or_create(
|
||||||
**entitydata,
|
**entitydata,
|
||||||
config_entry=mock_config_entry,
|
config_entry=mock_config_entry,
|
||||||
|
@ -144,6 +144,7 @@ async def test_migrate_unique_id_temperature(
|
||||||
)
|
)
|
||||||
async def test_migrate_unique_id_relay(
|
async def test_migrate_unique_id_relay(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
mock_smile_adam: MagicMock,
|
mock_smile_adam: MagicMock,
|
||||||
entitydata: dict,
|
entitydata: dict,
|
||||||
|
@ -153,8 +154,7 @@ async def test_migrate_unique_id_relay(
|
||||||
"""Test migration of unique_id."""
|
"""Test migration of unique_id."""
|
||||||
mock_config_entry.add_to_hass(hass)
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
entity: er.RegistryEntry = entity_registry.async_get_or_create(
|
||||||
entity: entity_registry.RegistryEntry = entity_registry.async_get_or_create(
|
|
||||||
**entitydata,
|
**entitydata,
|
||||||
config_entry=mock_config_entry,
|
config_entry=mock_config_entry,
|
||||||
)
|
)
|
||||||
|
|
|
@ -153,14 +153,16 @@ async def test_stretch_switch_changes(
|
||||||
|
|
||||||
|
|
||||||
async def test_unique_id_migration_plug_relay(
|
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:
|
) -> None:
|
||||||
"""Test unique ID migration of -plugs to -relay."""
|
"""Test unique ID migration of -plugs to -relay."""
|
||||||
mock_config_entry.add_to_hass(hass)
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
registry = er.async_get(hass)
|
|
||||||
# Entry to migrate
|
# Entry to migrate
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
SWITCH_DOMAIN,
|
SWITCH_DOMAIN,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
"21f2b542c49845e6bb416884c55778d6-plug",
|
"21f2b542c49845e6bb416884c55778d6-plug",
|
||||||
|
@ -169,7 +171,7 @@ async def test_unique_id_migration_plug_relay(
|
||||||
disabled_by=None,
|
disabled_by=None,
|
||||||
)
|
)
|
||||||
# Entry not needing migration
|
# Entry not needing migration
|
||||||
registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
SWITCH_DOMAIN,
|
SWITCH_DOMAIN,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
"675416a629f343c495449970e2ca37b5-relay",
|
"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.playstation_smart_plug") is not None
|
||||||
assert hass.states.get("switch.ziggo_modem") 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
|
||||||
assert entity_entry.unique_id == "21f2b542c49845e6bb416884c55778d6-relay"
|
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
|
||||||
assert entity_entry.unique_id == "675416a629f343c495449970e2ca37b5-relay"
|
assert entity_entry.unique_id == "675416a629f343c495449970e2ca37b5-relay"
|
||||||
|
|
|
@ -26,7 +26,9 @@ from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors(
|
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:
|
) -> None:
|
||||||
"""Test creation of the sensors."""
|
"""Test creation of the sensors."""
|
||||||
|
|
||||||
|
@ -46,7 +48,6 @@ async def test_sensors(
|
||||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
reg_device = device_registry.async_get_device(
|
reg_device = device_registry.async_get_device(
|
||||||
identifiers={("powerwall", MOCK_GATEWAY_DIN)},
|
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(
|
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:
|
) -> None:
|
||||||
"""Test we can migrate unique ids of the sensors."""
|
"""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 = MockConfigEntry(domain=DOMAIN, data={CONF_IP_ADDRESS: "1.2.3.4"})
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
@ -261,7 +263,7 @@ async def test_unique_id_migrate(
|
||||||
identifiers={("powerwall", old_unique_id)},
|
identifiers={("powerwall", old_unique_id)},
|
||||||
manufacturer="Tesla",
|
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",
|
"sensor",
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
unique_id=f"{old_unique_id}_load_instant_power",
|
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 reg_device is not None
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
ent_reg.async_get_entity_id(
|
entity_registry.async_get_entity_id(
|
||||||
"sensor", DOMAIN, f"{old_unique_id}_load_instant_power"
|
"sensor", DOMAIN, f"{old_unique_id}_load_instant_power"
|
||||||
)
|
)
|
||||||
is None
|
is None
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
ent_reg.async_get_entity_id(
|
entity_registry.async_get_entity_id(
|
||||||
"sensor", DOMAIN, f"{new_unique_id}_load_instant_power"
|
"sensor", DOMAIN, f"{new_unique_id}_load_instant_power"
|
||||||
)
|
)
|
||||||
is not None
|
is not None
|
||||||
|
|
|
@ -47,11 +47,13 @@ def mock_status(request):
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_registry(
|
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:
|
) -> None:
|
||||||
"""Tests that the devices are registered in the entity registry."""
|
"""Tests that the devices are registered in the entity registry."""
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
entry = entity_registry.async_get(PROSEGUR_ALARM_ENTITY)
|
entry = entity_registry.async_get(PROSEGUR_ALARM_ENTITY)
|
||||||
# Prosegur alarm device unique_id is the contract id associated to the alarm account
|
# Prosegur alarm device unique_id is the contract id associated to the alarm account
|
||||||
assert entry.unique_id == CONTRACT
|
assert entry.unique_id == CONTRACT
|
||||||
|
|
|
@ -22,12 +22,11 @@ from tests.common import MockConfigEntry
|
||||||
|
|
||||||
async def test_sensors(
|
async def test_sensors(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the Pure Energie - SmartBridge sensors."""
|
"""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")
|
state = hass.states.get("sensor.pem_energy_consumption_total")
|
||||||
entry = entity_registry.async_get("sensor.pem_energy_consumption_total")
|
entry = entity_registry.async_get("sensor.pem_energy_consumption_total")
|
||||||
assert entry
|
assert entry
|
||||||
|
|
|
@ -275,7 +275,10 @@ async def test_options_add_sensor_duplicate(
|
||||||
|
|
||||||
|
|
||||||
async def test_options_remove_sensor(
|
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:
|
) -> None:
|
||||||
"""Test removing a sensor via the options flow."""
|
"""Test removing a sensor via the options flow."""
|
||||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
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["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "remove_sensor"
|
assert result["step_id"] == "remove_sensor"
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
device_entry = device_registry.async_get_device(
|
device_entry = device_registry.async_get_device(
|
||||||
identifiers={(DOMAIN, str(TEST_SENSOR_INDEX1))}
|
identifiers={(DOMAIN, str(TEST_SENSOR_INDEX1))}
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,11 +24,11 @@ from tests.common import MockConfigEntry
|
||||||
|
|
||||||
async def test_sensors(
|
async def test_sensors(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
init_integration: MockConfigEntry,
|
init_integration: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the PVOutput sensors."""
|
"""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")
|
state = hass.states.get("sensor.frenck_s_solar_farm_energy_consumed")
|
||||||
entry = entity_registry.async_get("sensor.frenck_s_solar_farm_energy_consumed")
|
entry = entity_registry.async_get("sensor.frenck_s_solar_farm_energy_consumed")
|
||||||
|
|
|
@ -30,6 +30,7 @@ _MOCK_TIME_BAD_AUTH_RESPONSES = datetime(2023, 1, 8, 12, 0, tzinfo=dt_util.UTC)
|
||||||
|
|
||||||
async def test_config_flow(
|
async def test_config_flow(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
freezer: FrozenDateTimeFactory,
|
freezer: FrozenDateTimeFactory,
|
||||||
pvpc_aioclient_mock: AiohttpClientMocker,
|
pvpc_aioclient_mock: AiohttpClientMocker,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -82,8 +83,7 @@ async def test_config_flow(
|
||||||
assert pvpc_aioclient_mock.call_count == 1
|
assert pvpc_aioclient_mock.call_count == 1
|
||||||
|
|
||||||
# Check removal
|
# Check removal
|
||||||
registry = er.async_get(hass)
|
registry_entity = entity_registry.async_get("sensor.esios_pvpc")
|
||||||
registry_entity = registry.async_get("sensor.esios_pvpc")
|
|
||||||
assert await hass.config_entries.async_remove(registry_entity.config_entry_id)
|
assert await hass.config_entries.async_remove(registry_entity.config_entry_id)
|
||||||
|
|
||||||
# and add it again with UI
|
# and add it again with UI
|
||||||
|
|
Loading…
Add table
Reference in a new issue