Use registry fixtures in tests (m-n) (#118291)
This commit is contained in:
parent
8837c50da7
commit
ead0e797c1
22 changed files with 185 additions and 166 deletions
|
@ -29,6 +29,7 @@ from .common import load_and_parse_node_fixture, setup_integration_with_node_fix
|
|||
)
|
||||
async def test_device_registry_single_node_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
matter_client: MagicMock,
|
||||
node_fixture: str,
|
||||
name: str,
|
||||
|
@ -40,8 +41,7 @@ async def test_device_registry_single_node_device(
|
|||
matter_client,
|
||||
)
|
||||
|
||||
dev_reg = dr.async_get(hass)
|
||||
entry = dev_reg.async_get_device(
|
||||
entry = device_registry.async_get_device(
|
||||
identifiers={
|
||||
(DOMAIN, "deviceid_00000000000004D2-0000000000000001-MatterNodeDevice")
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ async def test_device_registry_single_node_device(
|
|||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||
async def test_device_registry_single_node_device_alt(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
matter_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test additional device with different attribute values."""
|
||||
|
@ -72,8 +73,7 @@ async def test_device_registry_single_node_device_alt(
|
|||
matter_client,
|
||||
)
|
||||
|
||||
dev_reg = dr.async_get(hass)
|
||||
entry = dev_reg.async_get_device(
|
||||
entry = device_registry.async_get_device(
|
||||
identifiers={
|
||||
(DOMAIN, "deviceid_00000000000004D2-0000000000000001-MatterNodeDevice")
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ async def test_device_registry_single_node_device_alt(
|
|||
@pytest.mark.skip("Waiting for a new test fixture")
|
||||
async def test_device_registry_bridge(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
matter_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test bridge devices are set up correctly with via_device."""
|
||||
|
@ -100,10 +101,10 @@ async def test_device_registry_bridge(
|
|||
matter_client,
|
||||
)
|
||||
|
||||
dev_reg = dr.async_get(hass)
|
||||
|
||||
# Validate bridge
|
||||
bridge_entry = dev_reg.async_get_device(identifiers={(DOMAIN, "mock-hub-id")})
|
||||
bridge_entry = device_registry.async_get_device(
|
||||
identifiers={(DOMAIN, "mock-hub-id")}
|
||||
)
|
||||
assert bridge_entry is not None
|
||||
|
||||
assert bridge_entry.name == "My Mock Bridge"
|
||||
|
@ -113,7 +114,7 @@ async def test_device_registry_bridge(
|
|||
assert bridge_entry.sw_version == "123.4.5"
|
||||
|
||||
# Device 1
|
||||
device1_entry = dev_reg.async_get_device(
|
||||
device1_entry = device_registry.async_get_device(
|
||||
identifiers={(DOMAIN, "mock-id-kitchen-ceiling")}
|
||||
)
|
||||
assert device1_entry is not None
|
||||
|
@ -126,7 +127,7 @@ async def test_device_registry_bridge(
|
|||
assert device1_entry.sw_version == "67.8.9"
|
||||
|
||||
# Device 2
|
||||
device2_entry = dev_reg.async_get_device(
|
||||
device2_entry = device_registry.async_get_device(
|
||||
identifiers={(DOMAIN, "mock-id-living-room-ceiling")}
|
||||
)
|
||||
assert device2_entry is not None
|
||||
|
|
|
@ -202,6 +202,7 @@ async def test_set_wifi_credentials(
|
|||
async def test_node_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
matter_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test the node diagnostics command."""
|
||||
|
@ -212,8 +213,7 @@ async def test_node_diagnostics(
|
|||
matter_client,
|
||||
)
|
||||
# get the device registry entry for the mocked node
|
||||
dev_reg = dr.async_get(hass)
|
||||
entry = dev_reg.async_get_device(
|
||||
entry = device_registry.async_get_device(
|
||||
identifiers={
|
||||
(DOMAIN, "deviceid_00000000000004D2-0000000000000001-MatterNodeDevice")
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ async def test_node_diagnostics(
|
|||
assert msg["result"] == diag_res
|
||||
|
||||
# repeat test with a device id that does not have a node attached
|
||||
new_entry = dev_reg.async_get_or_create(
|
||||
new_entry = device_registry.async_get_or_create(
|
||||
config_entry_id=list(entry.config_entries)[0],
|
||||
identifiers={(DOMAIN, "MatterNodeDevice")},
|
||||
)
|
||||
|
@ -276,6 +276,7 @@ async def test_node_diagnostics(
|
|||
async def test_ping_node(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
matter_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test the ping_node command."""
|
||||
|
@ -286,8 +287,7 @@ async def test_ping_node(
|
|||
matter_client,
|
||||
)
|
||||
# get the device registry entry for the mocked node
|
||||
dev_reg = dr.async_get(hass)
|
||||
entry = dev_reg.async_get_device(
|
||||
entry = device_registry.async_get_device(
|
||||
identifiers={
|
||||
(DOMAIN, "deviceid_00000000000004D2-0000000000000001-MatterNodeDevice")
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ async def test_ping_node(
|
|||
assert msg["result"] == ping_result
|
||||
|
||||
# repeat test with a device id that does not have a node attached
|
||||
new_entry = dev_reg.async_get_or_create(
|
||||
new_entry = device_registry.async_get_or_create(
|
||||
config_entry_id=list(entry.config_entries)[0],
|
||||
identifiers={(DOMAIN, "MatterNodeDevice")},
|
||||
)
|
||||
|
@ -336,6 +336,7 @@ async def test_ping_node(
|
|||
async def test_open_commissioning_window(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
matter_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test the open_commissioning_window command."""
|
||||
|
@ -346,8 +347,7 @@ async def test_open_commissioning_window(
|
|||
matter_client,
|
||||
)
|
||||
# get the device registry entry for the mocked node
|
||||
dev_reg = dr.async_get(hass)
|
||||
entry = dev_reg.async_get_device(
|
||||
entry = device_registry.async_get_device(
|
||||
identifiers={
|
||||
(DOMAIN, "deviceid_00000000000004D2-0000000000000001-MatterNodeDevice")
|
||||
}
|
||||
|
@ -380,7 +380,7 @@ async def test_open_commissioning_window(
|
|||
assert msg["result"] == dataclass_to_dict(commissioning_parameters)
|
||||
|
||||
# repeat test with a device id that does not have a node attached
|
||||
new_entry = dev_reg.async_get_or_create(
|
||||
new_entry = device_registry.async_get_or_create(
|
||||
config_entry_id=list(entry.config_entries)[0],
|
||||
identifiers={(DOMAIN, "MatterNodeDevice")},
|
||||
)
|
||||
|
@ -402,6 +402,7 @@ async def test_open_commissioning_window(
|
|||
async def test_remove_matter_fabric(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
matter_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test the remove_matter_fabric command."""
|
||||
|
@ -412,8 +413,7 @@ async def test_remove_matter_fabric(
|
|||
matter_client,
|
||||
)
|
||||
# get the device registry entry for the mocked node
|
||||
dev_reg = dr.async_get(hass)
|
||||
entry = dev_reg.async_get_device(
|
||||
entry = device_registry.async_get_device(
|
||||
identifiers={
|
||||
(DOMAIN, "deviceid_00000000000004D2-0000000000000001-MatterNodeDevice")
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ async def test_remove_matter_fabric(
|
|||
matter_client.remove_matter_fabric.assert_called_once_with(1, 3)
|
||||
|
||||
# repeat test with a device id that does not have a node attached
|
||||
new_entry = dev_reg.async_get_or_create(
|
||||
new_entry = device_registry.async_get_or_create(
|
||||
config_entry_id=list(entry.config_entries)[0],
|
||||
identifiers={(DOMAIN, "MatterNodeDevice")},
|
||||
)
|
||||
|
@ -458,6 +458,7 @@ async def test_remove_matter_fabric(
|
|||
async def test_interview_node(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
matter_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test the interview_node command."""
|
||||
|
@ -468,8 +469,7 @@ async def test_interview_node(
|
|||
matter_client,
|
||||
)
|
||||
# get the device registry entry for the mocked node
|
||||
dev_reg = dr.async_get(hass)
|
||||
entry = dev_reg.async_get_device(
|
||||
entry = device_registry.async_get_device(
|
||||
identifiers={
|
||||
(DOMAIN, "deviceid_00000000000004D2-0000000000000001-MatterNodeDevice")
|
||||
}
|
||||
|
@ -485,7 +485,7 @@ async def test_interview_node(
|
|||
matter_client.interview_node.assert_called_once_with(1)
|
||||
|
||||
# repeat test with a device id that does not have a node attached
|
||||
new_entry = dev_reg.async_get_or_create(
|
||||
new_entry = device_registry.async_get_or_create(
|
||||
config_entry_id=list(entry.config_entries)[0],
|
||||
identifiers={(DOMAIN, "MatterNodeDevice")},
|
||||
)
|
||||
|
|
|
@ -84,19 +84,22 @@ async def test_not_tracking_home(hass: HomeAssistant, mock_weather) -> None:
|
|||
assert len(hass.states.async_entity_ids("weather")) == 0
|
||||
|
||||
|
||||
async def test_remove_hourly_entity(hass: HomeAssistant, mock_weather) -> None:
|
||||
async def test_remove_hourly_entity(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_weather
|
||||
) -> None:
|
||||
"""Test removing the hourly entity."""
|
||||
|
||||
# Pre-create registry entry for disabled by default hourly weather
|
||||
registry = er.async_get(hass)
|
||||
registry.async_get_or_create(
|
||||
entity_registry.async_get_or_create(
|
||||
WEATHER_DOMAIN,
|
||||
DOMAIN,
|
||||
"10-20-hourly",
|
||||
suggested_object_id="forecast_somewhere_hourly",
|
||||
disabled_by=None,
|
||||
)
|
||||
assert list(registry.entities.keys()) == ["weather.forecast_somewhere_hourly"]
|
||||
assert list(entity_registry.entities.keys()) == [
|
||||
"weather.forecast_somewhere_hourly"
|
||||
]
|
||||
|
||||
await hass.config_entries.flow.async_init(
|
||||
"met",
|
||||
|
@ -105,4 +108,4 @@ async def test_remove_hourly_entity(hass: HomeAssistant, mock_weather) -> None:
|
|||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.async_entity_ids("weather") == ["weather.forecast_somewhere"]
|
||||
assert list(registry.entities.keys()) == ["weather.forecast_somewhere"]
|
||||
assert list(entity_registry.entities.keys()) == ["weather.forecast_somewhere"]
|
||||
|
|
|
@ -31,9 +31,10 @@ from tests.common import MockConfigEntry, async_fire_time_changed, patch
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_device_registry_devices(hass: HomeAssistant) -> None:
|
||||
def mock_device_registry_devices(
|
||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry
|
||||
) -> None:
|
||||
"""Create device registry devices so the device tracker entities are enabled."""
|
||||
dev_reg = dr.async_get(hass)
|
||||
config_entry = MockConfigEntry(domain="something_else")
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
|
@ -45,7 +46,7 @@ def mock_device_registry_devices(hass: HomeAssistant) -> None:
|
|||
"00:00:00:00:00:04",
|
||||
)
|
||||
):
|
||||
dev_reg.async_get_or_create(
|
||||
device_registry.async_get_or_create(
|
||||
name=f"Device {idx}",
|
||||
config_entry_id=config_entry.entry_id,
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, device)},
|
||||
|
|
|
@ -152,6 +152,7 @@ async def test_entry_diagnostics(
|
|||
async def test_redact_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
|
@ -266,9 +267,10 @@ async def test_redact_diagnostics(
|
|||
}
|
||||
|
||||
# Disable the entity and remove the state
|
||||
ent_registry = er.async_get(hass)
|
||||
device_tracker_entry = er.async_entries_for_device(ent_registry, device_entry.id)[0]
|
||||
ent_registry.async_update_entity(
|
||||
device_tracker_entry = er.async_entries_for_device(
|
||||
entity_registry, device_entry.id
|
||||
)[0]
|
||||
entity_registry.async_update_entity(
|
||||
device_tracker_entry.entity_id, disabled_by=er.RegistryEntryDisabler.USER
|
||||
)
|
||||
hass.states.async_remove(device_tracker_entry.entity_id)
|
||||
|
|
|
@ -76,25 +76,23 @@ async def test_expired_token_refresh_failure(
|
|||
)
|
||||
async def test_devices_created_count(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mock_myuplink_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test that one device is created."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
|
||||
assert len(device_registry.devices) == 1
|
||||
|
||||
|
||||
async def test_devices_multiple_created_count(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mock_myuplink_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test that multiple device are created."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
|
||||
assert len(device_registry.devices) == 2
|
||||
|
|
|
@ -203,7 +203,11 @@ async def test_ineligible_device(
|
|||
|
||||
|
||||
async def test_camera_device(
|
||||
hass: HomeAssistant, setup_platform: PlatformSetup, camera_device: None
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
setup_platform: PlatformSetup,
|
||||
camera_device: None,
|
||||
) -> None:
|
||||
"""Test a basic camera with a live stream."""
|
||||
await setup_platform()
|
||||
|
@ -214,12 +218,10 @@ async def test_camera_device(
|
|||
assert camera.state == STATE_STREAMING
|
||||
assert camera.attributes.get(ATTR_FRIENDLY_NAME) == "My Camera"
|
||||
|
||||
registry = er.async_get(hass)
|
||||
entry = registry.async_get("camera.my_camera")
|
||||
entry = entity_registry.async_get("camera.my_camera")
|
||||
assert entry.unique_id == f"{DEVICE_ID}-camera"
|
||||
assert entry.domain == "camera"
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get(entry.device_id)
|
||||
assert device.name == "My Camera"
|
||||
assert device.model == "Camera"
|
||||
|
|
|
@ -86,7 +86,10 @@ def calls(hass):
|
|||
|
||||
|
||||
async def test_get_triggers(
|
||||
hass: HomeAssistant, create_device: CreateDevice, setup_platform: PlatformSetup
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
) -> None:
|
||||
"""Test we get the expected triggers from a nest."""
|
||||
create_device.create(
|
||||
|
@ -100,7 +103,6 @@ async def test_get_triggers(
|
|||
)
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||
|
||||
expected_triggers = [
|
||||
|
@ -126,7 +128,10 @@ async def test_get_triggers(
|
|||
|
||||
|
||||
async def test_multiple_devices(
|
||||
hass: HomeAssistant, create_device: CreateDevice, setup_platform: PlatformSetup
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
) -> None:
|
||||
"""Test we get the expected triggers from a nest."""
|
||||
create_device.create(
|
||||
|
@ -149,10 +154,9 @@ async def test_multiple_devices(
|
|||
)
|
||||
await setup_platform()
|
||||
|
||||
registry = er.async_get(hass)
|
||||
entry1 = registry.async_get("camera.camera_1")
|
||||
entry1 = entity_registry.async_get("camera.camera_1")
|
||||
assert entry1.unique_id == "device-id-1-camera"
|
||||
entry2 = registry.async_get("camera.camera_2")
|
||||
entry2 = entity_registry.async_get("camera.camera_2")
|
||||
assert entry2.unique_id == "device-id-2-camera"
|
||||
|
||||
triggers = await async_get_device_automations(
|
||||
|
@ -181,7 +185,10 @@ async def test_multiple_devices(
|
|||
|
||||
|
||||
async def test_triggers_for_invalid_device_id(
|
||||
hass: HomeAssistant, create_device: CreateDevice, setup_platform: PlatformSetup
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
) -> None:
|
||||
"""Get triggers for a device not found in the API."""
|
||||
create_device.create(
|
||||
|
@ -195,7 +202,6 @@ async def test_triggers_for_invalid_device_id(
|
|||
)
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||
assert device_entry is not None
|
||||
|
||||
|
@ -215,14 +221,16 @@ async def test_triggers_for_invalid_device_id(
|
|||
|
||||
|
||||
async def test_no_triggers(
|
||||
hass: HomeAssistant, create_device: CreateDevice, setup_platform: PlatformSetup
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
) -> None:
|
||||
"""Test we get the expected triggers from a nest."""
|
||||
create_device.create(raw_data=make_camera(device_id=DEVICE_ID, traits={}))
|
||||
await setup_platform()
|
||||
|
||||
registry = er.async_get(hass)
|
||||
entry = registry.async_get("camera.my_camera")
|
||||
entry = entity_registry.async_get("camera.my_camera")
|
||||
assert entry.unique_id == f"{DEVICE_ID}-camera"
|
||||
|
||||
triggers = await async_get_device_automations(
|
||||
|
@ -233,6 +241,7 @@ async def test_no_triggers(
|
|||
|
||||
async def test_fires_on_camera_motion(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
calls,
|
||||
|
@ -249,7 +258,6 @@ async def test_fires_on_camera_motion(
|
|||
)
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||
|
||||
assert await setup_automation(hass, device_entry.id, "camera_motion")
|
||||
|
@ -267,6 +275,7 @@ async def test_fires_on_camera_motion(
|
|||
|
||||
async def test_fires_on_camera_person(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
calls,
|
||||
|
@ -283,7 +292,6 @@ async def test_fires_on_camera_person(
|
|||
)
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||
|
||||
assert await setup_automation(hass, device_entry.id, "camera_person")
|
||||
|
@ -301,6 +309,7 @@ async def test_fires_on_camera_person(
|
|||
|
||||
async def test_fires_on_camera_sound(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
calls,
|
||||
|
@ -317,7 +326,6 @@ async def test_fires_on_camera_sound(
|
|||
)
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||
|
||||
assert await setup_automation(hass, device_entry.id, "camera_sound")
|
||||
|
@ -335,6 +343,7 @@ async def test_fires_on_camera_sound(
|
|||
|
||||
async def test_fires_on_doorbell_chime(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
calls,
|
||||
|
@ -351,7 +360,6 @@ async def test_fires_on_doorbell_chime(
|
|||
)
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||
|
||||
assert await setup_automation(hass, device_entry.id, "doorbell_chime")
|
||||
|
@ -369,6 +377,7 @@ async def test_fires_on_doorbell_chime(
|
|||
|
||||
async def test_trigger_for_wrong_device_id(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
calls,
|
||||
|
@ -385,7 +394,6 @@ async def test_trigger_for_wrong_device_id(
|
|||
)
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||
|
||||
assert await setup_automation(hass, device_entry.id, "camera_motion")
|
||||
|
@ -402,6 +410,7 @@ async def test_trigger_for_wrong_device_id(
|
|||
|
||||
async def test_trigger_for_wrong_event_type(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
calls,
|
||||
|
@ -418,7 +427,6 @@ async def test_trigger_for_wrong_event_type(
|
|||
)
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||
|
||||
assert await setup_automation(hass, device_entry.id, "camera_motion")
|
||||
|
@ -435,6 +443,7 @@ async def test_trigger_for_wrong_event_type(
|
|||
|
||||
async def test_subscriber_automation(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls: list,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
|
@ -451,7 +460,6 @@ async def test_subscriber_automation(
|
|||
)
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||
|
||||
assert await setup_automation(hass, device_entry.id, "camera_motion")
|
||||
|
|
|
@ -86,6 +86,7 @@ async def test_entry_diagnostics(
|
|||
async def test_device_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
config_entry: MockConfigEntry,
|
||||
|
@ -96,7 +97,6 @@ async def test_device_diagnostics(
|
|||
await setup_platform()
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, NEST_DEVICE_ID)})
|
||||
assert device is not None
|
||||
|
||||
|
|
|
@ -152,6 +152,8 @@ def create_events(events, device_id=DEVICE_ID, timestamp=None):
|
|||
)
|
||||
async def test_event(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
auth,
|
||||
setup_platform,
|
||||
subscriber,
|
||||
|
@ -163,13 +165,11 @@ async def test_event(
|
|||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
|
||||
registry = er.async_get(hass)
|
||||
entry = registry.async_get("camera.front")
|
||||
entry = entity_registry.async_get("camera.front")
|
||||
assert entry is not None
|
||||
assert entry.unique_id == "some-device-id-camera"
|
||||
assert entry.domain == "camera"
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get(entry.device_id)
|
||||
assert device.name == "Front"
|
||||
assert device.model == expected_model
|
||||
|
@ -195,13 +195,12 @@ async def test_event(
|
|||
],
|
||||
)
|
||||
async def test_camera_multiple_event(
|
||||
hass: HomeAssistant, subscriber, setup_platform
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Test a pubsub message for a camera person event."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
registry = er.async_get(hass)
|
||||
entry = registry.async_get("camera.front")
|
||||
entry = entity_registry.async_get("camera.front")
|
||||
assert entry is not None
|
||||
|
||||
event_map = {
|
||||
|
@ -284,13 +283,12 @@ async def test_event_message_without_device_event(
|
|||
],
|
||||
)
|
||||
async def test_doorbell_event_thread(
|
||||
hass: HomeAssistant, subscriber, setup_platform
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Test a series of pubsub messages in the same thread."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
registry = er.async_get(hass)
|
||||
entry = registry.async_get("camera.front")
|
||||
entry = entity_registry.async_get("camera.front")
|
||||
assert entry is not None
|
||||
|
||||
event_message_data = {
|
||||
|
@ -359,13 +357,12 @@ async def test_doorbell_event_thread(
|
|||
],
|
||||
)
|
||||
async def test_doorbell_event_session_update(
|
||||
hass: HomeAssistant, subscriber, setup_platform
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Test a pubsub message with updates to an existing session."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
registry = er.async_get(hass)
|
||||
entry = registry.async_get("camera.front")
|
||||
entry = entity_registry.async_get("camera.front")
|
||||
assert entry is not None
|
||||
|
||||
# Message #1 has a motion event
|
||||
|
@ -423,15 +420,14 @@ async def test_doorbell_event_session_update(
|
|||
|
||||
|
||||
async def test_structure_update_event(
|
||||
hass: HomeAssistant, subscriber, setup_platform
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Test a pubsub message for a new device being added."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
|
||||
# Entity for first device is registered
|
||||
registry = er.async_get(hass)
|
||||
assert registry.async_get("camera.front")
|
||||
assert entity_registry.async_get("camera.front")
|
||||
|
||||
new_device = Device.MakeDevice(
|
||||
{
|
||||
|
@ -450,7 +446,7 @@ async def test_structure_update_event(
|
|||
device_manager.add_device(new_device)
|
||||
|
||||
# Entity for new devie has not yet been loaded
|
||||
assert not registry.async_get("camera.back")
|
||||
assert not entity_registry.async_get("camera.back")
|
||||
|
||||
# Send a message that triggers the device to be loaded
|
||||
message = EventMessage.create_event(
|
||||
|
@ -478,9 +474,9 @@ async def test_structure_update_event(
|
|||
# No home assistant events published
|
||||
assert not events
|
||||
|
||||
assert registry.async_get("camera.front")
|
||||
assert entity_registry.async_get("camera.front")
|
||||
# Currently need a manual reload to detect the new entity
|
||||
assert not registry.async_get("camera.back")
|
||||
assert not entity_registry.async_get("camera.back")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -489,12 +485,13 @@ async def test_structure_update_event(
|
|||
["sdm.devices.traits.CameraMotion"],
|
||||
],
|
||||
)
|
||||
async def test_event_zones(hass: HomeAssistant, subscriber, setup_platform) -> None:
|
||||
async def test_event_zones(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, subscriber, setup_platform
|
||||
) -> None:
|
||||
"""Test events published with zone information."""
|
||||
events = async_capture_events(hass, NEST_EVENT)
|
||||
await setup_platform()
|
||||
registry = er.async_get(hass)
|
||||
entry = registry.async_get("camera.front")
|
||||
entry = entity_registry.async_get("camera.front")
|
||||
assert entry is not None
|
||||
|
||||
event_map = {
|
||||
|
|
|
@ -249,7 +249,9 @@ async def test_no_eligible_devices(hass: HomeAssistant, setup_platform) -> None:
|
|||
|
||||
|
||||
@pytest.mark.parametrize("device_traits", [CAMERA_TRAITS, BATTERY_CAMERA_TRAITS])
|
||||
async def test_supported_device(hass: HomeAssistant, setup_platform) -> None:
|
||||
async def test_supported_device(
|
||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry, setup_platform
|
||||
) -> None:
|
||||
"""Test a media source with a supported camera."""
|
||||
await setup_platform()
|
||||
|
||||
|
@ -257,7 +259,6 @@ async def test_supported_device(hass: HomeAssistant, setup_platform) -> None:
|
|||
camera = hass.states.get("camera.front")
|
||||
assert camera is not None
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -308,6 +309,7 @@ async def test_integration_unloaded(hass: HomeAssistant, auth, setup_platform) -
|
|||
async def test_camera_event(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
subscriber,
|
||||
auth,
|
||||
setup_platform,
|
||||
|
@ -319,7 +321,6 @@ async def test_camera_event(
|
|||
camera = hass.states.get("camera.front")
|
||||
assert camera is not None
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -410,7 +411,11 @@ async def test_camera_event(
|
|||
|
||||
|
||||
async def test_event_order(
|
||||
hass: HomeAssistant, auth, subscriber, setup_platform
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
subscriber,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test multiple events are in descending timestamp order."""
|
||||
await setup_platform()
|
||||
|
@ -449,7 +454,6 @@ async def test_event_order(
|
|||
camera = hass.states.get("camera.front")
|
||||
assert camera is not None
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -478,6 +482,7 @@ async def test_event_order(
|
|||
|
||||
async def test_multiple_image_events_in_session(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
|
@ -494,7 +499,6 @@ async def test_multiple_image_events_in_session(
|
|||
camera = hass.states.get("camera.front")
|
||||
assert camera is not None
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -593,6 +597,7 @@ async def test_multiple_image_events_in_session(
|
|||
@pytest.mark.parametrize("device_traits", [BATTERY_CAMERA_TRAITS])
|
||||
async def test_multiple_clip_preview_events_in_session(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
|
@ -608,7 +613,6 @@ async def test_multiple_clip_preview_events_in_session(
|
|||
camera = hass.states.get("camera.front")
|
||||
assert camera is not None
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -691,12 +695,11 @@ async def test_multiple_clip_preview_events_in_session(
|
|||
|
||||
|
||||
async def test_browse_invalid_device_id(
|
||||
hass: HomeAssistant, auth, setup_platform
|
||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry, auth, setup_platform
|
||||
) -> None:
|
||||
"""Test a media source request for an invalid device id."""
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -712,12 +715,11 @@ async def test_browse_invalid_device_id(
|
|||
|
||||
|
||||
async def test_browse_invalid_event_id(
|
||||
hass: HomeAssistant, auth, setup_platform
|
||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry, auth, setup_platform
|
||||
) -> None:
|
||||
"""Test a media source browsing for an invalid event id."""
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -735,12 +737,11 @@ async def test_browse_invalid_event_id(
|
|||
|
||||
|
||||
async def test_resolve_missing_event_id(
|
||||
hass: HomeAssistant, auth, setup_platform
|
||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry, auth, setup_platform
|
||||
) -> None:
|
||||
"""Test a media source request missing an event id."""
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -767,12 +768,11 @@ async def test_resolve_invalid_device_id(
|
|||
|
||||
|
||||
async def test_resolve_invalid_event_id(
|
||||
hass: HomeAssistant, auth, setup_platform
|
||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry, auth, setup_platform
|
||||
) -> None:
|
||||
"""Test resolving media for an invalid event id."""
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -793,6 +793,7 @@ async def test_resolve_invalid_event_id(
|
|||
@pytest.mark.parametrize("device_traits", [BATTERY_CAMERA_TRAITS])
|
||||
async def test_camera_event_clip_preview(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mp4,
|
||||
|
@ -820,7 +821,6 @@ async def test_camera_event_clip_preview(
|
|||
camera = hass.states.get("camera.front")
|
||||
assert camera is not None
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -911,11 +911,14 @@ async def test_event_media_render_invalid_device_id(
|
|||
|
||||
|
||||
async def test_event_media_render_invalid_event_id(
|
||||
hass: HomeAssistant, auth, hass_client: ClientSessionGenerator, setup_platform
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
setup_platform,
|
||||
) -> None:
|
||||
"""Test event media API called with an invalid device id."""
|
||||
await setup_platform()
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -927,6 +930,7 @@ async def test_event_media_render_invalid_event_id(
|
|||
|
||||
async def test_event_media_failure(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
|
@ -955,7 +959,6 @@ async def test_event_media_failure(
|
|||
camera = hass.states.get("camera.front")
|
||||
assert camera is not None
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -982,6 +985,7 @@ async def test_event_media_failure(
|
|||
|
||||
async def test_media_permission_unauthorized(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
hass_admin_user: MockUser,
|
||||
|
@ -993,7 +997,6 @@ async def test_media_permission_unauthorized(
|
|||
camera = hass.states.get("camera.front")
|
||||
assert camera is not None
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -1012,6 +1015,7 @@ async def test_media_permission_unauthorized(
|
|||
|
||||
async def test_multiple_devices(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
create_device,
|
||||
|
@ -1029,7 +1033,6 @@ async def test_multiple_devices(
|
|||
)
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device1 = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device1
|
||||
device2 = device_registry.async_get_device(identifiers={(DOMAIN, device_id2)})
|
||||
|
@ -1106,6 +1109,7 @@ def event_store() -> Generator[None, None, None]:
|
|||
@pytest.mark.parametrize("device_traits", [BATTERY_CAMERA_TRAITS])
|
||||
async def test_media_store_persistence(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
event_store,
|
||||
|
@ -1116,7 +1120,6 @@ async def test_media_store_persistence(
|
|||
"""Test the disk backed media store persistence."""
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -1169,7 +1172,6 @@ async def test_media_store_persistence(
|
|||
await hass.config_entries.async_reload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -1200,6 +1202,7 @@ async def test_media_store_persistence(
|
|||
@pytest.mark.parametrize("device_traits", [BATTERY_CAMERA_TRAITS])
|
||||
async def test_media_store_save_filesystem_error(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
|
@ -1228,7 +1231,6 @@ async def test_media_store_save_filesystem_error(
|
|||
camera = hass.states.get("camera.front")
|
||||
assert camera is not None
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -1253,6 +1255,7 @@ async def test_media_store_save_filesystem_error(
|
|||
|
||||
async def test_media_store_load_filesystem_error(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
|
@ -1265,7 +1268,6 @@ async def test_media_store_load_filesystem_error(
|
|||
camera = hass.states.get("camera.front")
|
||||
assert camera is not None
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -1307,6 +1309,7 @@ async def test_media_store_load_filesystem_error(
|
|||
@pytest.mark.parametrize(("device_traits", "cache_size"), [(BATTERY_CAMERA_TRAITS, 5)])
|
||||
async def test_camera_event_media_eviction(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
|
@ -1315,7 +1318,6 @@ async def test_camera_event_media_eviction(
|
|||
"""Test media files getting evicted from the cache."""
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
@ -1384,6 +1386,7 @@ async def test_camera_event_media_eviction(
|
|||
|
||||
async def test_camera_image_resize(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
auth,
|
||||
hass_client: ClientSessionGenerator,
|
||||
subscriber,
|
||||
|
@ -1392,7 +1395,6 @@ async def test_camera_image_resize(
|
|||
"""Test scaling a thumbnail for an event image."""
|
||||
await setup_platform()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get_device(identifiers={(DOMAIN, DEVICE_ID)})
|
||||
assert device
|
||||
assert device.name == DEVICE_NAME
|
||||
|
|
|
@ -41,7 +41,11 @@ def device_traits() -> dict[str, Any]:
|
|||
|
||||
|
||||
async def test_thermostat_device(
|
||||
hass: HomeAssistant, create_device: CreateDevice, setup_platform: PlatformSetup
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
) -> None:
|
||||
"""Test a thermostat with temperature and humidity sensors."""
|
||||
create_device.create(
|
||||
|
@ -77,16 +81,14 @@ async def test_thermostat_device(
|
|||
assert humidity.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
|
||||
assert humidity.attributes.get(ATTR_FRIENDLY_NAME) == "My Sensor Humidity"
|
||||
|
||||
registry = er.async_get(hass)
|
||||
entry = registry.async_get("sensor.my_sensor_temperature")
|
||||
entry = entity_registry.async_get("sensor.my_sensor_temperature")
|
||||
assert entry.unique_id == f"{DEVICE_ID}-temperature"
|
||||
assert entry.domain == "sensor"
|
||||
|
||||
entry = registry.async_get("sensor.my_sensor_humidity")
|
||||
entry = entity_registry.async_get("sensor.my_sensor_humidity")
|
||||
assert entry.unique_id == f"{DEVICE_ID}-humidity"
|
||||
assert entry.domain == "sensor"
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get(entry.device_id)
|
||||
assert device.name == "My Sensor"
|
||||
assert device.model == "Thermostat"
|
||||
|
@ -240,7 +242,11 @@ async def test_event_updates_sensor(
|
|||
|
||||
@pytest.mark.parametrize("device_type", ["some-unknown-type"])
|
||||
async def test_device_with_unknown_type(
|
||||
hass: HomeAssistant, create_device: CreateDevice, setup_platform: PlatformSetup
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
) -> None:
|
||||
"""Test a device without a custom name, inferring name from structure."""
|
||||
create_device.create(
|
||||
|
@ -257,12 +263,10 @@ async def test_device_with_unknown_type(
|
|||
assert temperature.state == "25.1"
|
||||
assert temperature.attributes.get(ATTR_FRIENDLY_NAME) == "My Sensor Temperature"
|
||||
|
||||
registry = er.async_get(hass)
|
||||
entry = registry.async_get("sensor.my_sensor_temperature")
|
||||
entry = entity_registry.async_get("sensor.my_sensor_temperature")
|
||||
assert entry.unique_id == f"{DEVICE_ID}-temperature"
|
||||
assert entry.domain == "sensor"
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get(entry.device_id)
|
||||
assert device.name == "My Sensor"
|
||||
assert device.model is None
|
||||
|
|
|
@ -210,6 +210,7 @@ async def test_process_health(health: int, expected: str) -> None:
|
|||
)
|
||||
async def test_weather_sensor_enabling(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
config_entry: MockConfigEntry,
|
||||
uid: str,
|
||||
name: str,
|
||||
|
@ -221,8 +222,7 @@ async def test_weather_sensor_enabling(
|
|||
states_before = len(hass.states.async_all())
|
||||
assert hass.states.get(f"sensor.{name}") is None
|
||||
|
||||
registry = er.async_get(hass)
|
||||
registry.async_get_or_create(
|
||||
entity_registry.async_get_or_create(
|
||||
"sensor",
|
||||
"netatmo",
|
||||
uid,
|
||||
|
|
|
@ -6,7 +6,6 @@ from homeassistant.components.nexia.const import DOMAIN
|
|||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .util import async_init_integration
|
||||
|
@ -21,23 +20,24 @@ async def test_setup_retry_client_os_error(hass: HomeAssistant) -> None:
|
|||
|
||||
|
||||
async def test_device_remove_devices(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test we can only remove a device that no longer exists."""
|
||||
await async_setup_component(hass, "config", {})
|
||||
config_entry = await async_init_integration(hass)
|
||||
entry_id = config_entry.entry_id
|
||||
device_registry = dr.async_get(hass)
|
||||
|
||||
registry: EntityRegistry = er.async_get(hass)
|
||||
entity = registry.entities["sensor.nick_office_temperature"]
|
||||
entity = entity_registry.entities["sensor.nick_office_temperature"]
|
||||
|
||||
live_zone_device_entry = device_registry.async_get(entity.device_id)
|
||||
client = await hass_ws_client(hass)
|
||||
response = await client.remove_device(live_zone_device_entry.id, entry_id)
|
||||
assert not response["success"]
|
||||
|
||||
entity = registry.entities["sensor.master_suite_humidity"]
|
||||
entity = entity_registry.entities["sensor.master_suite_humidity"]
|
||||
live_thermostat_device_entry = device_registry.async_get(entity.device_id)
|
||||
response = await client.remove_device(live_thermostat_device_entry.id, entry_id)
|
||||
assert not response["success"]
|
||||
|
|
|
@ -48,7 +48,7 @@ ENTRY_DATA_NO_AREA: dict[str, Any] = {
|
|||
}
|
||||
|
||||
|
||||
async def test_sensors(hass: HomeAssistant) -> None:
|
||||
async def test_sensors(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None:
|
||||
"""Test the creation and values of the NINA sensors."""
|
||||
|
||||
with patch(
|
||||
|
@ -58,8 +58,6 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
|||
conf_entry: MockConfigEntry = MockConfigEntry(
|
||||
domain=DOMAIN, title="NINA", data=ENTRY_DATA
|
||||
)
|
||||
|
||||
entity_registry: er = er.async_get(hass)
|
||||
conf_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(conf_entry.entry_id)
|
||||
|
@ -164,7 +162,9 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
|||
assert state_w5.attributes.get("device_class") == BinarySensorDeviceClass.SAFETY
|
||||
|
||||
|
||||
async def test_sensors_without_corona_filter(hass: HomeAssistant) -> None:
|
||||
async def test_sensors_without_corona_filter(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||
) -> None:
|
||||
"""Test the creation and values of the NINA sensors without the corona filter."""
|
||||
|
||||
with patch(
|
||||
|
@ -174,8 +174,6 @@ async def test_sensors_without_corona_filter(hass: HomeAssistant) -> None:
|
|||
conf_entry: MockConfigEntry = MockConfigEntry(
|
||||
domain=DOMAIN, title="NINA", data=ENTRY_DATA_NO_CORONA
|
||||
)
|
||||
|
||||
entity_registry: er = er.async_get(hass)
|
||||
conf_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(conf_entry.entry_id)
|
||||
|
@ -292,7 +290,9 @@ async def test_sensors_without_corona_filter(hass: HomeAssistant) -> None:
|
|||
assert state_w5.attributes.get("device_class") == BinarySensorDeviceClass.SAFETY
|
||||
|
||||
|
||||
async def test_sensors_with_area_filter(hass: HomeAssistant) -> None:
|
||||
async def test_sensors_with_area_filter(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||
) -> None:
|
||||
"""Test the creation and values of the NINA sensors with an area filter."""
|
||||
|
||||
with patch(
|
||||
|
@ -302,8 +302,6 @@ async def test_sensors_with_area_filter(hass: HomeAssistant) -> None:
|
|||
conf_entry: MockConfigEntry = MockConfigEntry(
|
||||
domain=DOMAIN, title="NINA", data=ENTRY_DATA_NO_AREA
|
||||
)
|
||||
|
||||
entity_registry: er = er.async_get(hass)
|
||||
conf_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(conf_entry.entry_id)
|
||||
|
|
|
@ -303,7 +303,9 @@ async def test_options_flow_unexpected_exception(hass: HomeAssistant) -> None:
|
|||
assert result["type"] is FlowResultType.ABORT
|
||||
|
||||
|
||||
async def test_options_flow_entity_removal(hass: HomeAssistant) -> None:
|
||||
async def test_options_flow_entity_removal(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||
) -> None:
|
||||
"""Test if old entities are removed."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
|
@ -341,7 +343,6 @@ async def test_options_flow_entity_removal(hass: HomeAssistant) -> None:
|
|||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
entity_registry: er = er.async_get(hass)
|
||||
entries = er.async_entries_for_config_entry(
|
||||
entity_registry, config_entry.entry_id
|
||||
)
|
||||
|
|
|
@ -704,6 +704,7 @@ async def test_restore_number_restore_state(
|
|||
)
|
||||
async def test_custom_unit(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
device_class,
|
||||
native_unit,
|
||||
custom_unit,
|
||||
|
@ -712,8 +713,6 @@ async def test_custom_unit(
|
|||
custom_value,
|
||||
) -> None:
|
||||
"""Test custom unit."""
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
entry = entity_registry.async_get_or_create("number", "test", "very_unique")
|
||||
entity_registry.async_update_entity_options(
|
||||
entry.entity_id, "number", {"unit_of_measurement": custom_unit}
|
||||
|
@ -780,6 +779,7 @@ async def test_custom_unit(
|
|||
)
|
||||
async def test_custom_unit_change(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
native_unit,
|
||||
custom_unit,
|
||||
used_custom_unit,
|
||||
|
@ -789,7 +789,6 @@ async def test_custom_unit_change(
|
|||
default_value,
|
||||
) -> None:
|
||||
"""Test custom unit changes are picked up."""
|
||||
entity_registry = er.async_get(hass)
|
||||
entity0 = common.MockNumberEntity(
|
||||
name="Test",
|
||||
native_value=native_value,
|
||||
|
|
|
@ -142,7 +142,9 @@ async def test_unknown_state_sensors(hass: HomeAssistant) -> None:
|
|||
assert state2.state == "OQ"
|
||||
|
||||
|
||||
async def test_stale_options(hass: HomeAssistant) -> None:
|
||||
async def test_stale_options(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||
) -> None:
|
||||
"""Test creation of sensors with stale options to remove."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
|
@ -166,8 +168,7 @@ async def test_stale_options(hass: HomeAssistant) -> None:
|
|||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
registry = er.async_get(hass)
|
||||
entry = registry.async_get("sensor.ups1_battery_charge")
|
||||
entry = entity_registry.async_get("sensor.ups1_battery_charge")
|
||||
assert entry
|
||||
assert entry.unique_id == f"{config_entry.entry_id}_battery.charge"
|
||||
assert config_entry.data[CONF_RESOURCES] == ["battery.charge"]
|
||||
|
|
|
@ -36,6 +36,7 @@ from tests.common import MockConfigEntry
|
|||
)
|
||||
async def test_imperial_metric(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
units,
|
||||
result_observation,
|
||||
result_forecast,
|
||||
|
@ -43,10 +44,8 @@ async def test_imperial_metric(
|
|||
no_weather,
|
||||
) -> None:
|
||||
"""Test with imperial and metric units."""
|
||||
registry = er.async_get(hass)
|
||||
|
||||
for description in SENSOR_TYPES:
|
||||
registry.async_get_or_create(
|
||||
entity_registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
f"35_-75_{description.key}",
|
||||
|
@ -73,16 +72,18 @@ async def test_imperial_metric(
|
|||
|
||||
@pytest.mark.parametrize("values", [NONE_OBSERVATION, None])
|
||||
async def test_none_values(
|
||||
hass: HomeAssistant, mock_simple_nws, no_weather, values
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_simple_nws,
|
||||
no_weather,
|
||||
values,
|
||||
) -> None:
|
||||
"""Test with no values."""
|
||||
instance = mock_simple_nws.return_value
|
||||
instance.observation = values
|
||||
|
||||
registry = er.async_get(hass)
|
||||
|
||||
for description in SENSOR_TYPES:
|
||||
registry.async_get_or_create(
|
||||
entity_registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
f"35_-75_{description.key}",
|
||||
|
|
|
@ -315,10 +315,10 @@ async def test_error_observation(
|
|||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_new_config_entry(hass: HomeAssistant, no_sensor) -> None:
|
||||
async def test_new_config_entry(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, no_sensor
|
||||
) -> None:
|
||||
"""Test the expected entities are created."""
|
||||
registry = er.async_get(hass)
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=nws.DOMAIN,
|
||||
data=NWS_CONFIG,
|
||||
|
@ -330,7 +330,7 @@ async def test_new_config_entry(hass: HomeAssistant, no_sensor) -> None:
|
|||
|
||||
assert len(hass.states.async_entity_ids("weather")) == 1
|
||||
entry = hass.config_entries.async_entries()[0]
|
||||
assert len(er.async_entries_for_config_entry(registry, entry.entry_id)) == 1
|
||||
assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -450,6 +450,7 @@ async def test_forecast_service(
|
|||
async def test_forecast_subscription(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
entity_registry: er.EntityRegistry,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_simple_nws,
|
||||
|
@ -460,9 +461,8 @@ async def test_forecast_subscription(
|
|||
"""Test multiple forecast."""
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
registry = er.async_get(hass)
|
||||
# Pre-create the hourly entity
|
||||
registry.async_get_or_create(
|
||||
entity_registry.async_get_or_create(
|
||||
WEATHER_DOMAIN,
|
||||
nws.DOMAIN,
|
||||
"35_-75_hourly",
|
||||
|
@ -517,6 +517,7 @@ async def test_forecast_subscription(
|
|||
async def test_forecast_subscription_with_failing_coordinator(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
entity_registry: er.EntityRegistry,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_simple_nws_times_out,
|
||||
|
@ -527,9 +528,8 @@ async def test_forecast_subscription_with_failing_coordinator(
|
|||
"""Test a forecast subscription when the coordinator is failing to update."""
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
registry = er.async_get(hass)
|
||||
# Pre-create the hourly entity
|
||||
registry.async_get_or_create(
|
||||
entity_registry.async_get_or_create(
|
||||
WEATHER_DOMAIN,
|
||||
nws.DOMAIN,
|
||||
"35_-75_hourly",
|
||||
|
|
|
@ -16,14 +16,14 @@ from homeassistant.util import dt as dt_util
|
|||
from . import init_integration
|
||||
|
||||
|
||||
async def test_sensors(hass: HomeAssistant, nzbget_api) -> None:
|
||||
async def test_sensors(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, nzbget_api
|
||||
) -> None:
|
||||
"""Test the creation and values of the sensors."""
|
||||
now = dt_util.utcnow().replace(microsecond=0)
|
||||
with patch("homeassistant.components.nzbget.sensor.utcnow", return_value=now):
|
||||
entry = await init_integration(hass)
|
||||
|
||||
registry = er.async_get(hass)
|
||||
|
||||
uptime = now - timedelta(seconds=600)
|
||||
|
||||
sensors = {
|
||||
|
@ -76,7 +76,7 @@ async def test_sensors(hass: HomeAssistant, nzbget_api) -> None:
|
|||
}
|
||||
|
||||
for sensor_id, data in sensors.items():
|
||||
entity_entry = registry.async_get(f"sensor.nzbgettest_{sensor_id}")
|
||||
entity_entry = entity_registry.async_get(f"sensor.nzbgettest_{sensor_id}")
|
||||
assert entity_entry
|
||||
assert entity_entry.original_device_class == data[3]
|
||||
assert entity_entry.unique_id == f"{entry.entry_id}_{data[0]}"
|
||||
|
|
|
@ -15,16 +15,17 @@ from homeassistant.helpers.entity_component import async_update_entity
|
|||
from . import init_integration
|
||||
|
||||
|
||||
async def test_download_switch(hass: HomeAssistant, nzbget_api) -> None:
|
||||
async def test_download_switch(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, nzbget_api
|
||||
) -> None:
|
||||
"""Test the creation and values of the download switch."""
|
||||
instance = nzbget_api.return_value
|
||||
|
||||
entry = await init_integration(hass)
|
||||
assert entry
|
||||
|
||||
registry = er.async_get(hass)
|
||||
entity_id = "switch.nzbgettest_download"
|
||||
entity_entry = registry.async_get(entity_id)
|
||||
entity_entry = entity_registry.async_get(entity_id)
|
||||
assert entity_entry
|
||||
assert entity_entry.unique_id == f"{entry.entry_id}_download"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue